# `SKRegressor`

### *class* capymoa.base.SKRegressor[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_regressor.py#L67)

Bases: [`Regressor`](capymoa.base.Regressor.md#capymoa.base.Regressor)

A wrapper class for using scikit-learn regressors in CapyMOA.

Some of scikit-learn’s regressors that are compatible with online learning
have been wrapped and tested already in CapyMOA (See [`capymoa.regressor`](capymoa.regressor.md#module-capymoa.regressor)).

However, if you want to use a scikit-learn regressor that has not been
wrapped yet, you can use this class to wrap it yourself. This requires
that the scikit-learn regressor implements the `partial_fit` and
`predict` methods.

For example, the following code demonstrates how to use a scikit-learn
regressor in CapyMOA:

```pycon
>>> from sklearn.linear_model import SGDRegressor
>>> from capymoa.datasets import Fried
>>> stream = Fried()
>>> sklearner = SGDRegressor(random_state=1)
>>> learner = SKRegressor(sklearner, stream.get_schema())
>>> for _ in range(10):
...     instance = stream.next_instance()
...     prediction = learner.predict(instance)
...     if prediction is not None:
...         print(f"y_value: {instance.y_value}, y_prediction: {prediction:.2f}")
...     else:
...         print(f"y_value: {instance.y_value}, y_prediction: None")
...     learner.train(instance)
y_value: 17.949, y_prediction: None
y_value: 13.815, y_prediction: 0.60
y_value: 20.766, y_prediction: 1.30
y_value: 18.301, y_prediction: 1.86
y_value: 22.989, y_prediction: 2.28
y_value: 25.986, y_prediction: 2.65
y_value: 17.15, y_prediction: 3.51
y_value: 14.006, y_prediction: 3.25
y_value: 18.566, y_prediction: 3.80
y_value: 12.107, y_prediction: 3.87
```

A word of caution: even compatible scikit-learn regressors are not
necessarily designed for online learning and might require some tweaking
to work well in an online setting.

See also [`capymoa.base.SKClassifier`](capymoa.base.SKClassifier.md#capymoa.base.SKClassifier) for scikit-learn classifiers.

#### \_\_init_\_(sklearner: [RegressorMixin](https://scikit-learn.org/stable/modules/generated/sklearn.base.RegressorMixin.html#sklearn.base.RegressorMixin), schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_regressor.py#L115)

Construct a scikit-learn regressor wrapper.

* **Parameters:**
  * **sklearner** – A scikit-learn classifier object to wrap that must
    implements `partial_fit` and `predict`.
  * **schema** – Describes the structure of the datastream.
  * **random_seed** – Random seed for reproducibility.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the scikit-learn algorithm does not implement
  `partial_fit` or `predict`.

#### *classmethod* from_params(schema: [Any](https://docs.python.org/3/library/typing.html#typing.Any) = None, params: [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1) → [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L170)

Construct an instance from parameters produced by `get_params`.

#### get_params() → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)][[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L163)

Return the hyper-parameters captured from the constructor.

#### predict(instance: [Instance](capymoa.core.Instance.md#capymoa.core.Instance)) → [float](https://docs.python.org/3/builtins/functions.html#float)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_regressor.py#L148)

#### train(instance: [RegressionInstance](capymoa.core.RegressionInstance.md#capymoa.core.RegressionInstance))[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_regressor.py#L141)

#### sklearner *: [RegressorMixin](https://scikit-learn.org/stable/modules/generated/sklearn.base.RegressorMixin.html#sklearn.base.RegressorMixin)*

The underlying scikit-learn object.
