sklearn.multioutput.MultiOutputClassifier

class sklearn.multioutput.MultiOutputClassifier(estimator, n_jobs=None)[source]

Multi target classification

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
estimatorestimator object

An estimator object implementing fit, score and predict_proba.

n_jobsint or None, optional (default=None)

The number of jobs to use for the computation. It does each target variable in y in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.

Attributes
estimators_list of n_output estimators

Estimators used for predictions.

Methods

fit(self, X, Y[, sample_weight])

Fit the model to data matrix X and targets Y.

get_params(self[, deep])

Get parameters for this estimator.

partial_fit(self, X, y[, classes, sample_weight])

Incrementally fit the model to data.

predict(self, X)

Predict multi-output variable using a model

predict_proba(self, X)

Probability estimates.

score(self, X, y)

Returns the mean accuracy on the given test data and labels.

set_params(self, \*\*params)

Set the parameters of this estimator.

__init__(self, estimator, n_jobs=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(self, X, Y, sample_weight=None)[source]

Fit the model to data matrix X and targets Y.

Parameters
X{array-like, sparse matrix} of shape (n_samples, n_features)

The input data.

Yarray-like of shape (n_samples, n_classes)

The target values.

sample_weightarray-like of shape (n_samples,) or None

Sample weights. If None, then samples are equally weighted. Only supported if the underlying classifier supports sample weights.

Returns
selfobject
get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

partial_fit(self, X, y, classes=None, sample_weight=None)[source]

Incrementally fit the model to data. Fit a separate model for each output variable.

Parameters
X(sparse) array-like, shape (n_samples, n_features)

Data.

y(sparse) array-like, shape (n_samples, n_outputs)

Multi-output targets.

classeslist of numpy arrays, shape (n_outputs)

Each array is unique classes for one output in str/int Can be obtained by via [np.unique(y[:, i]) for i in range(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_weightarray-like, shape = (n_samples) or None

Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.

Returns
selfobject
predict(self, X)[source]
Predict multi-output variable using a model

trained for each target variable.

Parameters
X(sparse) array-like, shape (n_samples, n_features)

Data.

Returns
y(sparse) array-like, shape (n_samples, n_outputs)

Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.

predict_proba(self, X)[source]

Probability estimates. Returns 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
Xarray-like, shape (n_samples, n_features)

Data

Returns
parray 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(self, X, y)[source]

Returns the mean accuracy on the given test data and labels.

Parameters
Xarray-like, shape [n_samples, n_features]

Test samples

yarray-like, shape [n_samples, n_outputs]

True values for X

Returns
scoresfloat

accuracy_score of self.predict(X) versus y

set_params(self, **params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self