skmultiflow.meta.RegressorChain

class skmultiflow.meta.RegressorChain(base_estimator=SGDRegressor(), order=None, random_state=None)[source]

Regressor Chains for multi-output learning.

Parameters
base_estimator: skmultiflow.core.BaseSKMObject or sklearn.BaseEstimator (default=SGDRegressor)

Each member of the ensemble is an instance of the base estimator.

orderstr (default=None)

None to use default order, ‘random’ for random order.

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.

Notes

Regressor Chains are a modification of Classifier Chains [1] for regression.

References

1

Read, Jesse, Bernhard Pfahringer, Geoff Holmes, and Eibe Frank. “Classifier chains for multi-label classification.” In Joint European Conference on Machine Learning and Knowledge Discovery in Databases, pp. 254-269. Springer, Berlin, Heidelberg, 2009.

Examples

>>> from sklearn.linear_model import SGDRegressor
>>> from skmultiflow.meta import RegressorChain
>>> from skmultiflow.data import make_logical
>>>
>>> X, Y = make_logical(random_state=1)
>>>
>>> print("TRUE: ")
>>> print(Y)
>>> print("vs")
>>>
>>> print("RC")
>>> rc = RegressorChain(SGDRegressor(loss='squared_loss', random_state=1))
>>> rc.fit(X, Y)
>>> print(rc.predict(X))
>>>
>>> print("RRC")
>>> rc = RegressorChain(SGDRegressor(loss='squared_loss', random_state=1),
>>>                     order='random', random_state=1)
>>> rc.fit(X, Y)
>>> print(rc.predict(X))

Methods

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

Fit the model.

get_info(self)

Collects and returns the information about the configuration of the estimator

get_params(self[, deep])

Get parameters for this estimator.

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

Partially (incrementally) fit the model.

predict(self, X)

Predict target values for the passed data.

predict_proba(self, X)

Not implemented for this method.

reset(self)

Resets the estimator to its initial state.

score(self, X, y[, sample_weight])

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

set_params(self, **params)

Set the parameters of this estimator.

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

Fit the model.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The features to train the model.

y: numpy.ndarray of shape (n_samples, n_targets)

An array-like with the target values of all samples in X.

sample_weight: Not used (default=None)
Returns
self
get_info(self)[source]

Collects and returns the information about the configuration of the estimator

Returns
string

Configuration of the estimator.

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, sample_weight=None)[source]

Partially (incrementally) fit the model.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The features to train the model.

y: numpy.ndarray of shape (n_samples)

An array-like with the target values of all samples in X.

sample_weight: Not used (default=None)
Returns
self
predict(self, X)[source]

Predict target values for the passed data.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The set of data samples to predict the target values for.

Returns
A numpy.ndarray with all the predictions for the samples in X.
predict_proba(self, X)[source]

Not implemented for this method.

reset(self)[source]

Resets the estimator to its initial state.

Returns
self
score(self, 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
Xarray-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.

yarray-like, shape = (n_samples) or (n_samples, n_outputs)

True values for X.

sample_weightarray-like, shape = [n_samples], optional

Sample weights.

Returns
scorefloat

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

Notes

The R2 score used when calling score on a regressor will use multioutput='uniform_average' from version 0.23 to keep consistent with metrics.r2_score. This will influence the score method of all the multioutput regressors (except for multioutput.MultiOutputRegressor). To specify the default value manually and avoid the warning, please either call metrics.r2_score directly or make a custom scorer with metrics.make_scorer (the built-in scorer 'r2' uses multioutput='uniform_average').

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