multioutput
¶
Classes:
Name | Description |
---|---|
MultiTargetRegressor |
A Regressor that supports multiple targets. |
MultiTargetRegressorInitialized |
|
MultiTargetRegressor
¶
MultiTargetRegressor(
module: Type[Module],
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
device: str = "cpu",
seed: int = 42,
**kwargs
)
Bases: MultiTargetRegressor
, DeepEstimator
A Regressor that supports multiple targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Type[Module]
|
Torch Module that builds the autoencoder to be wrapped.
The Module should accept parameter |
required |
loss_fn
|
Union[str, Callable]
|
Loss function to be used for training the wrapped model.
Can be a loss function provided by |
'mse'
|
optimizer_fn
|
Union[str, Callable]
|
Optimizer to be used for training the wrapped model.
Can be an optimizer class provided by |
'sgd'
|
lr
|
float
|
Learning rate of the optimizer. |
0.001
|
device
|
str
|
Device to run the wrapped model on. Can be "cpu" or "gpu". |
'cpu'
|
seed
|
int
|
Random seed for the wrapped model. |
42
|
**kwargs
|
Parameters to be passed to the |
{}
|
Examples:
>>> from river import evaluate, compose
>>> from river import metrics
>>> from river import preprocessing
>>> from river import stream
>>> from sklearn import datasets
>>> from torch import nn
>>> from deep_river.regression.multioutput import MultiTargetRegressor
>>> class MyModule(nn.Module):
... def __init__(self, n_features):
... super(MyModule, self).__init__()
... self.dense0 = nn.Linear(n_features,3)
...
... def forward(self, X, **kwargs):
... X = self.dense0(X)
... return X
>>> dataset = stream.iter_sklearn_dataset(
... dataset=datasets.load_linnerud(),
... shuffle=True,
... seed=42
... )
>>> model = compose.Pipeline(
... preprocessing.StandardScaler(),
... MultiTargetRegressor(
... module=MyModule,
... loss_fn='mse',
... lr=0.3,
... optimizer_fn='sgd',
... ))
>>> metric = metrics.multioutput.MicroAverage(metrics.MAE())
>>> ev = evaluate.progressive_val_score(dataset, model, metric)
>>> print(f"MicroAverage(MAE): {metric.get():.2f}")
MicroAverage(MAE): 34.31
Methods:
Name | Description |
---|---|
clone |
Clones the estimator. |
draw |
Draws the wrapped model. |
initialize_module |
Parameters |
predict_one |
Predicts the target value for a single example. |
Source code in deep_river/regression/multioutput.py
clone
¶
Clones the estimator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_params
|
dict[Any, Any] | None
|
New parameters to be passed to the cloned estimator. |
None
|
include_attributes
|
If True, the attributes of the estimator will be copied to the cloned estimator. This is useful when the estimator is a transformer and the attributes are the learned parameters. |
False
|
Returns:
Type | Description |
---|---|
DeepEstimator
|
The cloned estimator. |
Source code in deep_river/base.py
draw
¶
Draws the wrapped model.
Source code in deep_river/base.py
initialize_module
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
The instance or class or callable to be initialized, e.g.
|
required | |
kwargs
|
dict
|
The keyword arguments to initialize the instance or class. Can be an empty dict. |
{}
|
Returns:
Type | Description |
---|---|
instance
|
The initialized component. |
Source code in deep_river/base.py
predict_one
¶
Predicts the target value for a single example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
RegTarget
|
Predicted target value. |
Source code in deep_river/regression/multioutput.py
MultiTargetRegressorInitialized
¶
MultiTargetRegressorInitialized(
module: Module,
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
is_feature_incremental: bool = False,
is_target_incremental: bool = False,
lr: float = 0.001,
device: str = "cpu",
seed: int = 42,
**kwargs
)
Bases: MultiTargetRegressor
, DeepEstimatorInitialized
Methods:
Name | Description |
---|---|
learn_many |
Learns from a batch of examples. |
learn_one |
Learns from a single example. |
predict_one |
Predicts the target value for a single example. |
Source code in deep_river/regression/multioutput.py
learn_many
¶
learn_one
¶
Learns from a single example.
Source code in deep_river/regression/multioutput.py
predict_one
¶
Predicts the target value for a single example.