Independent multi-target classification
A dataset has several independent binary or multiclass target columns and the chosen classifier handles only one output at a time.
Scikit-Learn · Class
MultiOutputClassifier extends a single-output classifier to multi-target classification by fitting one classifier per target. It can parallelize target-wise fit, prediction, and supported partial fitting.
MultiOutputClassifier adapts a single-output classifier to multi-target classification by cloning and fitting one estimator for each target column. Predictions combine the separate estimators' outputs, while fitting, prediction, and supported incremental fitting can run across targets in parallel.
class sklearn.multioutput.MultiOutputClassifier(estimator, *, n_jobs=None)| Name | Type | Description |
|---|---|---|
estimator | estimator object | A classifier implementing fit and predict, used separately for each target. |
n_jobs | int or None, optional (default=None) | Number of parallel jobs for target-wise fit, predict, and supported partial_fit; default is None. |
from sklearn.datasets import make_multilabel_classification
from sklearn.linear_model import LogisticRegression
from sklearn.multioutput import MultiOutputClassifier
X, y = make_multilabel_classification(n_classes=3, random_state=0)
model = MultiOutputClassifier(LogisticRegression(max_iter=1000))
model.fit(X, y)
predictions = model.predict(X[:2])
print(predictions.shape)This creates three binary targets, trains one logistic-regression classifier per target, and predicts all target columns for two samples.
A dataset has several independent binary or multiclass target columns and the chosen classifier handles only one output at a time.
A multilabel problem requires adding multi-output support to an ordinary classifier.
A target-wise workload is large enough to benefit from concurrent estimator operations.
It is a meta-estimator for multi-target classification. It fits one classifier independently for each target and is useful for classifiers that do not natively support multi-target classification.
Follow-up: How would you extend it to a base classifier that supports incremental learning? Use an estimator implementing partial_fit, then call the wrapper's partial_fit with the required class information.
The constructor takes an estimator implementing fit and predict, plus optional n_jobs. The estimator is used as the base model for every target output.
Follow-up: What should you verify before wrapping an estimator? Verify that it supports the operations required by the wrapper, such as fit, predict, and—when needed—partial_fit.
The wrapper parallelizes fit and predict for each target when n_jobs is configured; partial_fit is also parallelized if the base estimator supports it. n_jobs=None uses the default non-parallel behavior.
Follow-up: When might parallelization be counterproductive? If each target fit or prediction is very small, job-management overhead can outweigh the benefit.
ClassifierChainMultiOutputRegressorsklearn.multioutput