rolling_regressor
¶
Classes:
Name | Description |
---|---|
RollingRegressor |
Wrapper that feeds a sliding window of the most recent examples to the |
RollingRegressorInitialized |
RollingRegressorInitialized class built for regression tasks with a |
RollingRegressor
¶
RollingRegressor(
module: Type[Module],
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
is_feature_incremental: bool = False,
window_size: int = 10,
append_predict: bool = False,
device: str = "cpu",
seed: int = 42,
**kwargs
)
Bases: RollingDeepEstimator
, Regressor
Wrapper that feeds a sliding window of the most recent examples to the wrapped PyTorch regression model.
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
|
is_feature_incremental
|
bool
|
Whether the model should adapt to the appearance of previously features by adding units to the input layer of the network. |
False
|
device
|
str
|
Device to run the wrapped model on. Can be "cpu" or "cuda". |
'cpu'
|
seed
|
int
|
Random seed to be used for training the wrapped model. |
42
|
window_size
|
int
|
Number of recent examples to be fed to the wrapped model at each step. |
10
|
append_predict
|
bool
|
Whether to append inputs passed for prediction to the rolling window. |
False
|
**kwargs
|
Parameters to be passed to the |
{}
|
Methods:
Name | Description |
---|---|
clone |
Clones the estimator. |
draw |
Draws the wrapped model. |
initialize_module |
Parameters |
learn_one |
Performs one step of training with the sliding |
predict_one |
Predicts the target value for the current sliding |
Source code in deep_river/regression/rolling_regressor.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
learn_one
¶
Performs one step of training with the sliding window of the most recent examples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
y
|
RegTarget
|
Target value. |
required |
Returns:
Type | Description |
---|---|
RollingRegressor
|
The regressor itself. |
Source code in deep_river/regression/rolling_regressor.py
predict_one
¶
Predicts the target value for the current sliding window of most recent examples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
RegTarget
|
Predicted target value. |
Source code in deep_river/regression/rolling_regressor.py
RollingRegressorInitialized
¶
RollingRegressorInitialized(
module: Module,
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Type[Optimizer]] = "sgd",
lr: float = 0.001,
is_feature_incremental: bool = False,
device: str = "cpu",
seed: int = 42,
window_size: int = 10,
append_predict: bool = False,
**kwargs
)
Bases: RollingDeepEstimatorInitialized
, RegressorInitialized
RollingRegressorInitialized class built for regression tasks with a window-based learning mechanism. Handles incremental learning by maintaining a sliding window of training data for both individual examples and batches of data. Enables feature incremental updates and compatibility with PyTorch modules. Ideal for time-series or sequential data tasks where the training set changes dynamically.
Attributes:
Name | Type | Description |
---|---|---|
module |
Module
|
A PyTorch neural network model that defines the architecture of the regressor. |
loss_fn |
Union[str, Callable]
|
Loss function used for optimization. Either a string (e.g., "mse") or a callable. |
optimizer_fn |
Union[str, Type[Optimizer]]
|
Optimizer function or string used for training the neural network model. |
lr |
float
|
Learning rate for the optimizer. |
is_feature_incremental |
bool
|
Whether the model incrementally updates its features during training. |
device |
str
|
Target device for model training and inference (e.g., "cpu", "cuda"). |
seed |
int
|
Random seed for reproducibility. |
window_size |
int
|
Size of the sliding window used for storing the most recent training examples. |
append_predict |
bool
|
Whether predictions should contribute to the sliding window data. |
Methods:
Name | Description |
---|---|
learn_many |
Performs one step of training with the most recent training examples |
learn_one |
Performs one step of training with the most recent training examples |
predict_many |
Predict the probability of each label given the most recent examples |
predict_one |
Predict the probability of each label given the most recent examples |
Source code in deep_river/regression/rolling_regressor.py
learn_many
¶
Performs one step of training with the most recent training examples stored in the sliding window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
Input examples. |
required |
y
|
Series
|
Target values. |
required |
Returns:
Type | Description |
---|---|
Self
|
The regressor itself. |
Source code in deep_river/regression/rolling_regressor.py
learn_one
¶
Performs one step of training with the most recent training examples stored in the sliding window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
y
|
RegTarget
|
Target value. |
required |
Returns:
Type | Description |
---|---|
Self
|
The regressor itself. |
Source code in deep_river/regression/rolling_regressor.py
predict_many
¶
Predict the probability of each label given the most recent examples
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
DataFrame
|
|
required |
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame of probabilities for each label. |
Source code in deep_river/regression/rolling_regressor.py
predict_one
¶
Predict the probability of each label given the most recent examples stored in the sliding window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
Dict[ClfTarget, float]
|
Dictionary of probabilities for each label. |