-
-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Closed
Labels
Description
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)