regressor
¶
Classes:
Name | Description |
---|---|
Regressor |
Wrapper for PyTorch regression models that enables |
RegressorInitialized |
Wrapper for PyTorch classification models that supports feature and class incremental learning. |
Regressor
¶
Regressor(
module: Type[Module],
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
is_feature_incremental: bool = False,
device: str = "cpu",
seed: int = 42,
**kwargs
)
Bases: DeepEstimator
, MiniBatchRegressor
Wrapper for PyTorch regression models that enables compatibility with River.
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 "cuda". |
'cpu'
|
seed
|
int
|
Random seed to be used for training the wrapped model. |
42
|
**kwargs
|
Parameters to be passed to the |
{}
|
Examples:
Methods:
Name | Description |
---|---|
clone |
Clones the estimator. |
draw |
Draws the wrapped model. |
initialize_module |
Parameters |
learn_many |
Performs one step of training with a batch of examples. |
learn_one |
Performs one step of training with a single example. |
predict_many |
Predicts the target value for a batch of examples. |
predict_one |
Predicts the target value for a single example. |
Source code in deep_river/regression/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_many
¶
Performs one step of training with a batch of examples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Input examples. |
required | |
y
|
Series
|
Target values. |
required |
Returns:
Type | Description |
---|---|
Regressor
|
The regressor itself. |
Source code in deep_river/regression/regressor.py
learn_one
¶
Performs one step of training with a single example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
y
|
RegTarget
|
Target value. |
required |
Returns:
Type | Description |
---|---|
Regressor
|
The regressor itself. |
Source code in deep_river/regression/regressor.py
predict_many
¶
Predicts the target value for a batch of examples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Input examples. |
required |
Returns:
Type | Description |
---|---|
List
|
Predicted target values. |
Source code in deep_river/regression/regressor.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/regressor.py
RegressorInitialized
¶
RegressorInitialized(
module: Module,
loss_fn: Union[str, Callable],
optimizer_fn: Union[str, Type[Optimizer]],
lr: float = 0.001,
output_is_logit: bool = True,
is_feature_incremental: bool = False,
device: str = "cpu",
seed: int = 42,
**kwargs
)
Bases: DeepEstimatorInitialized
, MiniBatchRegressor
Wrapper for PyTorch classification models that supports feature and class incremental learning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Module
|
A PyTorch model. Can be pre-initialized or uninitialized. |
required |
loss_fn
|
Union[str, Callable]
|
Loss function for training. Can be a string ('mse', 'cross_entropy', etc.) or a PyTorch function. |
required |
optimizer_fn
|
Union[str, Type[Optimizer]]
|
Optimizer for training (e.g., "adam", "sgd", or a PyTorch optimizer class). |
required |
lr
|
float
|
Learning rate of the optimizer. |
0.001
|
output_is_logit
|
bool
|
If True, applies softmax/sigmoid during inference. |
True
|
is_class_incremental
|
bool
|
If True, adds neurons when new classes appear. |
False
|
is_feature_incremental
|
bool
|
If True, adds neurons when new features appear. |
False
|
device
|
str
|
Whether to use "cpu" or "cuda". |
"cpu"
|
seed
|
Optional[int]
|
Random seed for reproducibility. |
None
|
**kwargs
|
Additional parameters for model initialization. |
{}
|
Methods:
Name | Description |
---|---|
predict_many |
Predicts probabilities for multiple examples. |
predict_one |
Predicts the target value for a single example. |
Source code in deep_river/regression/regressor.py
predict_many
¶
Predicts probabilities for multiple examples.
Source code in deep_river/regression/regressor.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. |