W3cubDocs

/scikit-learn

sklearn.multioutput.RegressorChain

class sklearn.multioutput.RegressorChain(base_estimator, order=None, cv=None, random_state=None) [source]

A multi-label model that arranges regressions 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.

Read more in the User Guide.

Parameters:
base_estimator : estimator

The base estimator from which the classifier chain is built.

order : array-like, shape=[n_outputs] or ‘random’, optional

By default 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.:

order = [1, 3, 2, 4, 0]

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.

cv : int, cross-validation generator or an iterable, optional (default=None)

Determines whether to use cross validated predictions or true labels for the results of previous estimators in the chain. If cv is None the true labels are used when fitting. Otherwise possible inputs for cv are:

  • integer, to specify the number of folds in a (Stratified)KFold,
  • An object to be used as a cross-validation generator.
  • An iterable yielding train, test splits.
random_state : int, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

The random number generator is used to generate random chain orders.

Attributes:
estimators_ : list

A list of clones of base_estimator.

order_ : list

The order of labels in the classifier chain.

See also

ClassifierChain
Equivalent for classification
MultioutputRegressor
Learns each output independently rather than chaining.

Methods

fit(X, Y) Fit the model to data matrix X and targets Y.
get_params([deep]) Get parameters for this estimator.
predict(X) Predict on the data matrix X using the ClassifierChain model.
score(X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.
set_params(**params) Set the parameters of this estimator.
__init__(base_estimator, order=None, cv=None, random_state=None) [source]
fit(X, Y) [source]

Fit the model to data matrix X and targets Y.

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

The input data.

Y : array-like, shape (n_samples, n_classes)

The target values.

Returns:
self : object
get_params(deep=True) [source]

Get parameters for this estimator.

Parameters:
deep : boolean, optional

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

Returns:
params : mapping of string to any

Parameter names mapped to their values.

predict(X) [source]

Predict on the data matrix X using the ClassifierChain model.

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

The input data.

Returns:
Y_pred : array-like, shape (n_samples, n_classes)

The predicted values.

score(X, y, sample_weight=None) [source]

Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters:
X : array-like, shape = (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix instead, shape = (n_samples, n_samples_fitted], where n_samples_fitted is the number of samples used in the fitting for the estimator.

y : array-like, shape = (n_samples) or (n_samples, n_outputs)

True values for X.

sample_weight : array-like, shape = [n_samples], optional

Sample weights.

Returns:
score : float

R^2 of self.predict(X) wrt. y.

set_params(**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

© 2007–2018 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.multioutput.RegressorChain.html