(Error-Correcting) Output-Code multiclass strategy.
Output-code based strategies consist in representing each class with a binary code (an array of 0s and 1s). At fitting time, one binary classifier per bit in the code book is fitted. At prediction time, the classifiers are used to project new points in the class space and the class closest to the points is chosen. The main advantage of these strategies is that the number of classifiers used can be controlled by the user, either for compressing the model (0 < code_size < 1) or for making the model more robust to errors (code_size > 1). See the documentation for more details.
Read more in the User Guide.
An estimator object implementing fit and one of decision_function or predict_proba.
Percentage of the number of classes to be used to create the code book. A number between 0 and 1 will require fewer classifiers than one-vs-the-rest. A number greater than 1 will require more classifiers than one-vs-the-rest.
The generator used to initialize the codebook. Pass an int for reproducible output across multiple function calls. See Glossary.
The number of jobs to use for the computation: the multiclass problems are computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
int(n_classes * code_size) estimators
Estimators used for predictions.
Array containing labels.
len(estimators_))
Binary array containing the code of each class.
Number of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.
Added in version 0.24.
n_features_in_,)
Names of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.
Added in version 1.0.
See also
OneVsRestClassifierOne-vs-all multiclass strategy.
OneVsOneClassifierOne-vs-one multiclass strategy.
“Solving multiclass learning problems via error-correcting output codes”, Dietterich T., Bakiri G., Journal of Artificial Intelligence Research 2, 1995.
“The error coding method and PICTs”, James G., Hastie T., Journal of Computational and Graphical statistics 7, 1998.
“The Elements of Statistical Learning”, Hastie T., Tibshirani R., Friedman J., page 606 (second-edition) 2008.
>>> from sklearn.multiclass import OutputCodeClassifier >>> from sklearn.ensemble import RandomForestClassifier >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=100, n_features=4, ... n_informative=2, n_redundant=0, ... random_state=0, shuffle=False) >>> clf = OutputCodeClassifier( ... estimator=RandomForestClassifier(random_state=0), ... random_state=0).fit(X, y) >>> clf.predict([[0, 0, 0, 0]]) array([1])
Fit underlying estimators.
Data.
Multi-class targets.
Parameters passed to the estimator.fit method of each sub-estimator.
Added in version 1.4: Only available if enable_metadata_routing=True. See Metadata Routing User Guide for more details.
Returns a fitted instance of self.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Added in version 1.4.
A MetadataRouter encapsulating routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict multi-class targets using underlying estimators.
Data.
Predicted multi-class targets.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) w.r.t. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Request metadata passed to the score method.
Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it to score.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.
Metadata routing for sample_weight parameter in score.
The updated object.
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.multiclass.OutputCodeClassifier.html