sklearn_utilities.torch.skorch package
- class sklearn_utilities.torch.skorch.AlgebraicErrors(*args, **kwargs)[source]
Bases:
ModuleAlgebraic errors. Loss = x^2 / sqrt(1 + x^2)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.AllowNan(loss: Module, *, has_nan: Literal['left', 'right', 'both'] = 'both')[source]
Bases:
ModuleReplaces NaNs in the target values with the predictions.
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.AsymmetricLoss(*, t: float, loss_pred_grater: Module = LNErrors(), loss_pred_less: Module = LNErrors())[source]
Bases:
Module- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.AsymmetricLosses(*, ts: Sequence[float] | int, loss: nn.Module = LNErrors())[source]
Bases:
ModuleAsymmetric loss with multioutput support.
- Parameters:
y_pred (torch.Tensor) – The predicted values. [B, Ts * Ny] or [B, Ts, Ny] or [B, Ny, Ts]
y_true (torch.Tensor) – The true values. [B, Ny] or [B] (if Ny == 1)
- Returns:
0-dim tensor with the loss.
- Return type:
torch.Tensor
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.LNErrors(n: int = 2)[source]
Bases:
ModuleReturns L^n errors (not mean of L^n errors).
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.LogCoshErrors(*, softplus: bool = True, eps: float | None = None)[source]
Bases:
ModuleLog cosh errors. Loss = log(cosh(errors + eps))
See also
https//datascience.stackexchange.com/questions/96271/logcoshloss-on-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.SkorchCNNReshaper(estimator: TEstimator, *, window_size: int | None)[source]
Bases:
EstimatorWrapperBase[TEstimator],Generic[TEstimator]skorch wrapper that reshapes tabular data for CNNs using sliding windows.
- estimator: TEstimator
- class sklearn_utilities.torch.skorch.SkorchCNNReshaperProba(estimator: TEstimator, *, window_size: int | None, m_type: Literal['mean', 'median', 'nanmean', 'nanmedian'] = 'mean', var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd'] = 'std')[source]
Bases:
SkorchReshaperProbaMixin[TEstimator],SkorchCNNReshaper[TEstimator],Generic[TEstimator]- estimator: TEstimator
- m_type: Literal['mean', 'median', 'nanmean', 'nanmedian']
M-statistics type to return from predict by default
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') SkorchCNNReshaperProba
Request metadata passed to the
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']
Variance type to return from predict by default
- class sklearn_utilities.torch.skorch.SkorchReshaper(estimator: TEstimator)[source]
Bases:
EstimatorWrapperBase[TEstimator],Generic[TEstimator]skorch wrapper that reshapes tabular data for NNs.
- estimator: TEstimator
- class sklearn_utilities.torch.skorch.SkorchReshaperProba(estimator: TEstimator, m_type: Literal['mean', 'median', 'nanmean', 'nanmedian'] = 'mean', var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd'] = 'std')[source]
Bases:
SkorchReshaperProbaMixin[TEstimator],SkorchReshaper[TEstimator],Generic[TEstimator]- estimator: TEstimator
- m_type: Literal['mean', 'median', 'nanmean', 'nanmedian']
M-statistics type to return from predict by default
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') SkorchReshaperProba
Request metadata passed to the
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']
Variance type to return from predict by default
- class sklearn_utilities.torch.skorch.XSigmoidErrors(*args, **kwargs)[source]
Bases:
ModuleXSigmoid errors. Loss = x * (2 * sigmoid(x) - 1)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.XTanhErrors(*args, **kwargs)[source]
Bases:
ModuleXTanh errors. Loss = x * tanh(x)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
Submodules
sklearn_utilities.torch.skorch.proba module
- class sklearn_utilities.torch.skorch.proba.AlgebraicErrors(*args, **kwargs)[source]
Bases:
ModuleAlgebraic errors. Loss = x^2 / sqrt(1 + x^2)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.AllowNan(loss: Module, *, has_nan: Literal['left', 'right', 'both'] = 'both')[source]
Bases:
ModuleReplaces NaNs in the target values with the predictions.
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.AsymmetricLoss(*, t: float, loss_pred_grater: Module = LNErrors(), loss_pred_less: Module = LNErrors())[source]
Bases:
Module- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.AsymmetricLosses(*, ts: Sequence[float] | int, loss: nn.Module = LNErrors())[source]
Bases:
ModuleAsymmetric loss with multioutput support.
- Parameters:
y_pred (torch.Tensor) – The predicted values. [B, Ts * Ny] or [B, Ts, Ny] or [B, Ny, Ts]
y_true (torch.Tensor) – The true values. [B, Ny] or [B] (if Ny == 1)
- Returns:
0-dim tensor with the loss.
- Return type:
torch.Tensor
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.LNErrors(n: int = 2)[source]
Bases:
ModuleReturns L^n errors (not mean of L^n errors).
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.LogCoshErrors(*, softplus: bool = True, eps: float | None = None)[source]
Bases:
ModuleLog cosh errors. Loss = log(cosh(errors + eps))
See also
https//datascience.stackexchange.com/questions/96271/logcoshloss-on-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.SkorchCNNReshaperProba(estimator: TEstimator, *, window_size: int | None, m_type: Literal['mean', 'median', 'nanmean', 'nanmedian'] = 'mean', var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd'] = 'std')[source]
Bases:
SkorchReshaperProbaMixin[TEstimator],SkorchCNNReshaper[TEstimator],Generic[TEstimator]- estimator: TEstimator
- m_type: Literal['mean', 'median', 'nanmean', 'nanmedian']
M-statistics type to return from predict by default
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') SkorchCNNReshaperProba
Request metadata passed to the
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']
Variance type to return from predict by default
- class sklearn_utilities.torch.skorch.proba.SkorchReshaperProba(estimator: TEstimator, m_type: Literal['mean', 'median', 'nanmean', 'nanmedian'] = 'mean', var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd'] = 'std')[source]
Bases:
SkorchReshaperProbaMixin[TEstimator],SkorchReshaper[TEstimator],Generic[TEstimator]- estimator: TEstimator
- m_type: Literal['mean', 'median', 'nanmean', 'nanmedian']
M-statistics type to return from predict by default
- set_predict_request(*, return_std: bool | None | str = '$UNCHANGED$', type_: bool | None | str = '$UNCHANGED$') SkorchReshaperProba
Request metadata passed to the
predictmethod.Note that this method is only relevant if
enable_metadata_routing=True(seesklearn.set_config()). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.New in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline. Otherwise it has no effect.- Parameters:
return_std (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
return_stdparameter inpredict.type (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
type_parameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']
Variance type to return from predict by default
- class sklearn_utilities.torch.skorch.proba.SkorchReshaperProbaMixin(estimator: TEstimator, *args: Any, m_type: Literal['mean', 'median', 'nanmean', 'nanmedian'] = 'mean', var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd'] = 'std', **kwargs: Any)[source]
Bases:
Generic[TEstimator]skorch wrapper mixin that converts quantile predictions to mean and std.
- estimator: TEstimator
- m_type: Literal['mean', 'median', 'nanmean', 'nanmedian']
M-statistics type to return from predict by default
- predict(X: TX, *, return_std: bool = False, type_: Literal['mean', 'median', 'nanmean', 'nanmedian', 'var', 'std', 'ptp', 'nanvar', 'nanstd'] | tuple[Literal['mean', 'median', 'nanmean', 'nanmedian'], Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']] | None = None, **predict_params: Any) TY | tuple[TY, TY][source]
- var_type: Literal['var', 'std', 'ptp', 'nanvar', 'nanstd']
Variance type to return from predict by default
- class sklearn_utilities.torch.skorch.proba.XSigmoidErrors(*args, **kwargs)[source]
Bases:
ModuleXSigmoid errors. Loss = x * (2 * sigmoid(x) - 1)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- class sklearn_utilities.torch.skorch.proba.XTanhErrors(*args, **kwargs)[source]
Bases:
ModuleXTanh errors. Loss = x * tanh(x)
See also
https//github.com/tuantle/regression-losses-pytorch
- forward(y_pred: Tensor, y_true: Tensor) Tensor[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
sklearn_utilities.torch.skorch.reshaper module
- class sklearn_utilities.torch.skorch.reshaper.SkorchCNNReshaper(estimator: TEstimator, *, window_size: int | None)[source]
Bases:
EstimatorWrapperBase[TEstimator],Generic[TEstimator]skorch wrapper that reshapes tabular data for CNNs using sliding windows.
- estimator: TEstimator
- class sklearn_utilities.torch.skorch.reshaper.SkorchReshaper(estimator: TEstimator)[source]
Bases:
EstimatorWrapperBase[TEstimator],Generic[TEstimator]skorch wrapper that reshapes tabular data for NNs.
- estimator: TEstimator