# `SGDRegressor`

### *class* capymoa.regressor.SGDRegressor[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/regressor/_sgd_regressor.py#L11)

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

Streaming stochastic gradient descent regressor.

This wraps [`sklearn.linear_model.SGDRegressor`](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html#sklearn.linear_model.SGDRegressor) for
ease of use in the streaming context. Some options are missing because
they are not relevant in the streaming context. Furthermore, the learning rate
is constant.

Example Usage:

```pycon
>>> from capymoa.datasets import Fried
>>> from capymoa.regressor import PassiveAggressiveRegressor
>>> from capymoa.evaluation import prequential_evaluation
>>> stream = Fried()
>>> schema = stream.get_schema()
>>> learner = SGDRegressor(schema)
>>> results = prequential_evaluation(stream, learner, max_instances=1000)
>>> results["cumulative"].rmse()
4.62...
```

#### \_\_init_\_(schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema), loss: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['squared_error', 'huber', 'epsilon_insensitive', 'squared_epsilon_insensitive'] = 'squared_error', penalty: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['l2', 'l1', 'elasticnet'] | [None](https://docs.python.org/3/builtins/constants.html#None) = 'l2', alpha: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.0001, l1_ratio: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.15, fit_intercept: [bool](https://docs.python.org/3/builtins/functions.html#bool) = True, epsilon: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.1, learning_rate: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'invscaling', eta0: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.01, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None) = None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/regressor/_sgd_regressor.py#L35)

Construct stochastic gradient descent Regressor.

* **Parameters:**
  * **schema** – Describes the datastream’s structure.
  * **loss** – The loss function to be used.
  * **penalty** – The penalty (aka regularization term) to be used.
  * **alpha** – Constant that multiplies the regularization term.
  * **l1_ratio** – The Elastic Net mixing parameter, with `0 <= l1_ratio <= 1`.
    `l1_ratio=0` corresponds to L2 penalty, `l1_ratio=1` to L1.
    Only used if `penalty` is ‘elasticnet’.
    Values must be in the range `[0.0, 1.0]`.
  * **fit_intercept** – Whether the intercept (bias) should be estimated
    or not. If False, the data is assumed to be already centered.
  * **epsilon** – Epsilon in the epsilon-insensitive loss functions; only
    if `loss` is ‘huber’, ‘epsilon_insensitive’, or
    ‘squared_epsilon_insensitive’. For ‘huber’, determines the threshold
    at which it becomes less important to get the prediction exactly right.
    For epsilon-insensitive, any differences between the current prediction
    and the correct label are ignored if they are less than this threshold.
  * **learning_rate** – The size of the gradient step.
  * **eta0** – The initial learning rate for the ‘constant’, ‘invscaling’ or
    ‘adaptive’ schedules. The default value is 0.0 as `eta0` is not used by
    the default schedule ‘optimal’.
  * **random_seed** – Seed for reproducibility.

#### *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 *: [SGDRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html#sklearn.linear_model.SGDRegressor)*

The underlying scikit-learn object
