Thanks to visit codestin.com
Credit goes to github.com

Skip to content

StackingClassifier to support multilabel classification #17979

@lewisbails

Description

@lewisbails

It would be great if StackingClassifier supported multi-label classification. For example, currently, if the final estimator is a logistic regression model with a one-vs-rest multi-class setup, fitting the StackingClassifier returns a ValueError because we cannot fit the LabelEncoder with targets like [[1,1,0], [0,0,1], ...].

def fit(self, X, y, sample_weight=None):
...
    check_classification_targets(y)
    self._le = LabelEncoder().fit(y) # ValueError if y is like [[1,1,0], [0,1,0], ...] i.e. multilabel-indicator
    self.classes_ = self._le.classes_
    return super().fit(X, self._le.transform(y), sample_weight)

I propose not having a LabelEncoder for targets that are multilabel-indicator type.

def fit(self, X, y, sample_weight=None):
...
    check_classification_targets(y)
    if type_of_target(y) != 'multilabel-indicator':
        self._le = LabelEncoder().fit(y)
    else:
        # some kind of "passthrough" encoder?
    self.classes_ = self._le.classes_
    return super().fit(X, self._le.transform(y), sample_weight)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions