ClassifierChain
- class sklearn.multioutput.ClassifierChain(estimator, *, order=None, cv=None, chain_method='predict', random_state=None, verbose=False)
A multi-label model that arranges binary classifiers into a chain.
Each model makes a prediction in the order specified by the chain using all of the available features provided to the model plus the predictions of models that are earlier in the chain.
For an example of how to use ClassifierChain and benefit from its
ensemble, see
ClassifierChain on a yeast dataset example.
Read more in the User Guide.
The base estimator from which the classifier chain is built.
If None, the order will be determined by the order of columns in
the label matrix Y.:
order = [0, 1, 2, ..., Y.shape[1] - 1]
The order of the chain can be explicitly set by providing a list of integers. For example, for a chain of length 5.:
Determines whether to use cross validated predictions or true labels for the results of previous estimators in the chain. Possible inputs for cv are:
None, to use true labels when fitting,
integer, to specify the number of folds in a (Stratified)KFold,
an iterable yielding (train, test) splits as arrays of indices.
Prediction method to be used by estimators in the chain for the ‘prediction’ features of previous estimators in the chain.
if str, name of the method;
if a list of str, provides the method names in order of
preference. The method used corresponds to the first method in
the list that is implemented by base_estimator.
If order='random', determines random number generation for the
chain order.
In addition, it controls the random seed given at each base_estimator
at each chaining iteration. Thus, it is only used when base_estimator
exposes a random_state.
Pass an int for reproducible output across multiple function calls.
See Glossary.
If True, chain progress is output as each model is completed.
A list of arrays of length len(estimators_) containing the
class labels for each estimator in the chain.
A list of clones of base_estimator.
The order of labels in the classifier chain.
Prediction method used by estimators in the chain for the prediction features.
Number of features seen during fit. Only defined if the
underlying base_estimator exposes such an attribute when fit.
Jesse Read, Bernhard Pfahringer, Geoff Holmes, Eibe Frank, “Classifier Chains for Multi-label Classification”, 2009.
>>> from sklearn.datasets import make_multilabel_classification
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.multioutput import ClassifierChain
>>> X, Y = make_multilabel_classification(
... n_samples
Evaluate the decision_function of the models in the chain.
The input data.
Returns the decision function of the sample for each model in the chain.
Fit the model to data matrix X and targets Y.
The input data.
The target values.
Parameters passed to the method of each step.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
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 on the data matrix X using the ClassifierChain model.
The input data.
The predicted values.
Predict logarithm of probability estimates.
The input data.
The predicted logarithm of the probabilities.
Predict probability estimates.
The input data.
The predicted probabilities.
Return accuracy on provided 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 .
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.
Configure whether metadata should be requested to be passed to the method.
Multilabel classification using a classifier chain
means that the first model in the chain will make predictions for column 1 in the Y matrix, the second model will make predictions for column 3, etc.
If order is random a random ordering will be used.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
Only available if enable_metadata_routing=True. See the
User Guide.
Class instance.
Sample weights.
Mean accuracy of self.predict(X) w.r.t. y.
Estimator instance.
Note that this method is only relevant when this estimator is used as a
sub-estimator within a meta-estimator and metadata routing is enabled
with enable_metadata_routing=True (see sklearn.set_config).
Please check the 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.
Metadata routing for sample_weight parameter in score.
The updated object.