# `StochasticGradientTree`

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

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

Stochastic Gradient Tree regressor.

Stochastic Gradient Tree (SGT) <sup>[1](#f1)</sup> is an incremental decision tree that learns
using stochastic gradient information as its source of supervision, rather than
a heuristic such as information gain. Instead of using soft splits or rebuilding
a new tree for every update, as prior gradient-based tree learners did in the
batch setting, SGT accumulates per-node gradient and Hessian statistics online
and uses them to make hard splitting decisions incrementally. Because splitting
is driven only by the loss function’s gradients and Hessians, the same algorithm
can be applied to classification, regression, or multi-instance learning simply
by changing the loss function.

```pycon
>>> from capymoa.regressor import StochasticGradientTree
>>> from capymoa.datasets import Fried
>>> from capymoa.evaluation import prequential_evaluation
>>>
>>> stream = Fried()
>>> learner = StochasticGradientTree(stream.get_schema())
>>> results = prequential_evaluation(stream, learner, max_instances=1000)
>>> round(results["cumulative"].rmse(), 2)
15.49
```

* <a id='f1'>**[1]**</a> Gouk, Henry, Bernhard Pfahringer, and Eibe Frank. “Stochastic Gradient Trees.” Proceedings of The 11th Asian Conference on Machine Learning (ACML 2019). PMLR 101, 2019, pp. 1094-1109.

#### \_\_init_\_(schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema), grace_period: [int](https://docs.python.org/3/builtins/functions.html#int) = 200, lambda_: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.1, warm_start: [int](https://docs.python.org/3/builtins/functions.html#int) = 1000, confidence: [float](https://docs.python.org/3/builtins/functions.html#float) = 1e-06, split_test: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['TTest'] = 'TTest', disable_resplits: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/regressor/_sgt.py#L37)

Construct StochasticGradientTree regressor.

* **Parameters:**
  * **grace_period** – The number of instances a leaf should observe between
    split attempts.
  * **lambda** – Regularization parameter lambda.
  * **warm_start** – Number of instances to use for fitting the discretizers.
  * **confidence** – The level of confidence required that a split candidate is
    an improvement before the split is actually performed.
  * **split_test** – 

    Which type of hypothesis test to use for determining when
    to split.
    * `TTest`: Use a t-Test for checking statistical significance.
  * **disable_resplits** – Disable node resplitting.

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

#### *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)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_regressor.py#L59)

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