This strategy consists of fitting one classifier per target. This is a
simple strategy for extending classifiers that do not natively support
multi-target classification.
Parameters:
estimator : estimator object
An estimator object implementing fit and predict.
A predict_proba method will be exposed only if estimator implements
it.
n_jobs : int or None, optional (default=None)
The number of jobs to run in parallel.
fit, predict and partial_fit (if supported
by the passed estimator) will be parallelized for each target.
When individual estimators are fast to train or predict,
using n_jobs>1 can result in slower performance due
to the parallelism overhead.
None means 1 unless in a joblib.parallel_backend context.
-1 means using all available processes / threads.
See Glossary for more details.
Attributes:
classes_ : ndarray of shape (n_classes,)
Class labels.
estimators_ : list of n_output estimators
Estimators used for predictions.
n_features_in_ : int
Number of features seen during fit. Only defined if the
underlying estimator exposes such an attribute when fit.
feature_names_in_ : ndarray of shape (n_features_in_,)
Names of features seen during fit. Only defined if the
underlying estimators expose such an attribute when fit.
If True, will return the parameters for this estimator and
contained subobjects that are estimators.
Returns:
params : dict
Parameter names mapped to their values.
partial_fit(X, y, classes=None, sample_weight=None, **partial_fit_params)
Incrementally fit a separate model for each class output.
Parameters:
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
y : {array-like, sparse matrix} of shape (n_samples, n_outputs)
Multi-output targets.
classes : list of ndarray of shape (n_outputs,), default=None
Each array is unique classes for one output in str/int.
Can be obtained via
[np.unique(y[:,i])foriinrange(y.shape[1])], where y
is the target matrix of the entire dataset.
This argument is required for the first call to partial_fit
and can be omitted in the subsequent calls.
Note that y doesn’t need to contain all labels in classes.
sample_weight : array-like of shape (n_samples,), default=None
Sample weights. If None, then samples are equally weighted.
Only supported if the underlying regressor supports sample
weights.
**partial_fit_params : dict of str -> object
Parameters passed to the estimator.partial_fit method of each
sub-estimator.
Only available if enable_metadata_routing=True. See the
User Guide.
Returns:
self : object
Returns a fitted instance.
predict(X)
Predict multi-output variable using model for each target variable.
Parameters:
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input data.
Returns:
y : {array-like, sparse matrix} of shape (n_samples, n_outputs)
Multi-output targets predicted across multiple predictors.
Note: Separate models are generated for each predictor.
predict_proba(X)
Return prediction probabilities for each class of each output.
This method will raise a ValueError if any of the
estimators do not have predict_proba.
Parameters:
X : array-like of shape (n_samples, n_features)
The input data.
Returns:
p : array of shape (n_samples, n_classes), or a list of n_outputs such arrays if n_outputs > 1.
The class probabilities of the input samples. The order of the
classes corresponds to that in the attribute classes_.
score(X, y)
Return the mean accuracy on the given test data and labels.
Parameters:
X : array-like of shape (n_samples, n_features)
Test samples.
y : array-like of shape (n_samples, n_outputs)
True values for X.
Returns:
scores : float
Mean accuracy of predicted target versus true target.
Configure whether metadata should be requested to be passed to the fit method.
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 fit 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 fit.
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.
Parameters:
sample_weight : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for sample_weight parameter in fit.
Returns:
self : object
The updated object.
set_params(**params)
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.
Configure whether metadata should be requested to be passed to the partial_fit method.
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 partial_fit 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 .
partial_fit
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.
Parameters:
classes : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for classes parameter in partial_fit.
sample_weight : str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for sample_weight parameter in partial_fit.