Skip to content

EWARegressor

Exponentially Weighted Average regressor.

Parameters

  • models

    Typelist[base.Regressor]

    The regressors to hedge.

  • loss

    Typeoptim.losses.RegressionLoss | None

    DefaultNone

    The loss function that has to be minimized. Defaults to optim.losses.Squared.

  • learning_rate

    Default0.5

    The learning rate by which the model weights are multiplied at each iteration.

Attributes

  • models

Examples

from river import datasets
from river import ensemble
from river import evaluate
from river import linear_model
from river import metrics
from river import optim
from river import preprocessing
from river import stream

optimizers = [
    optim.SGD(0.01),
    optim.RMSProp(),
    optim.AdaGrad()
]

for optimizer in optimizers:

    dataset = datasets.TrumpApproval()
    metric = metrics.MAE()
    model = (
        preprocessing.StandardScaler() |
        linear_model.LinearRegression(
            optimizer=optimizer,
            intercept_lr=.1
        )
    )

    print(optimizer, evaluate.progressive_val_score(dataset, model, metric))
SGD MAE: 0.558735
RMSProp MAE: 0.522449
AdaGrad MAE: 0.477289

dataset = datasets.TrumpApproval()
metric = metrics.MAE()
hedge = (
    preprocessing.StandardScaler() |
    ensemble.EWARegressor(
        [
            linear_model.LinearRegression(optimizer=o, intercept_lr=.1)
            for o in optimizers
        ],
        learning_rate=0.005
    )
)

evaluate.progressive_val_score(dataset, hedge, metric)
MAE: 0.496298

Methods

learn_one

Fits to a set of features x and a real-valued target y.

Parameters

  • x
  • y

Returns

self

learn_predict_one
predict_one

Predict the output of features x.

Parameters

  • x

Returns

The prediction.