pywatts.modules.wrappers package¶
Submodules¶
pywatts.modules.wrappers.base_wrapper module¶
-
class
pywatts.modules.wrappers.base_wrapper.
BaseWrapper
(name: str)¶ Bases:
pywatts_pipeline.core.transformer.base.BaseEstimator
,abc.ABC
The base wrappers class, where all wrappers have to inherit from.
Parameters: name (str) – Name of the module
pywatts.modules.wrappers.dl_wrapper module¶
-
class
pywatts.modules.wrappers.dl_wrapper.
DlWrapper
(model, name, fit_kwargs=None)¶ Bases:
pywatts.modules.wrappers.base_wrapper.BaseWrapper
,abc.ABC
Super class for deep learning framework wrappers
Parameters: - model – The deep learning model
- name (str) – The name of the wrappers
- fit_kwargs (dict) – The fit keyword arguments necessary for fitting the model
pywatts.modules.wrappers.function_module module¶
-
class
pywatts.modules.wrappers.function_module.
FunctionModule
(transform_method: Callable, fit_method: Optional[Callable] = None, name: str = 'FunctionModule')¶ Bases:
pywatts_pipeline.core.transformer.base.BaseEstimator
This module calls the function in its transform and optional fit method. It can be used, for executing own code in the pipeline. Note that the wrapped function is called with the same keyword arguments as the module.
Parameters: - transform_method (Callable) – The function which should be executed in the transform step.
- fit_method (Callable) – The function which should be executed in the fit step.
- name (str) – name of the instance (FunctionModule)
-
fit
(**kwargs) → xarray.core.dataarray.DataArray¶ Call the fit_method if available wrapped by this module on x.
Parameters: kwargs (xr.DataArray) – The input arrays
-
classmethod
load
(load_information)¶ Loads a condition from a JSON file and creates the corresponding Conditional
Parameters: load_information (Dict) – JSON file of the Conditional Returns: conditional module from file Return type: Conditional Warning
This method use pickle for loading the module. Note that this is not safe. Consequently, load only modules you trust. For more details about pickling see https://docs.python.org/3/library/pickle.html
-
save
(fm: pywatts_pipeline.core.util.filemanager.FileManager)¶ Saves the Conditional module to JSON file
Parameters: fm (FileManager) – A FileManager, from which the path where the JSON file is saved is fetches Returns: Dictionary with name, parameters, related module and class, and path to the file Return type: Dict
-
transform
(**kwargs) → xarray.core.dataarray.DataArray¶ Call the transform_method wrapped by this module on x.
Parameters: x (xarray.DataArray) – The input arrays Returns: The transformed DataArray Return type: xarray.DataArray
pywatts.modules.wrappers.keras_wrapper module¶
pywatts.modules.wrappers.pytorch_wrapper module¶
-
class
pywatts.modules.wrappers.pytorch_wrapper.
PyTorchWrapper
(model: torch.nn.modules.module.Module, optimizer, loss_fn, name: str = 'PyTorchWrapper', fit_kwargs=None)¶ Bases:
pywatts.modules.wrappers.dl_wrapper.DlWrapper
Wrapper for PyTorich Models.
Parameters: - model (torch.nn.Module,) – The pytorch model
- name (str) – The name of the wrappers
- fit_kwargs (Optional[Dict]) – Key word arguments used for fitting the model.
- loss_fn (Callable) – The loss function of the model.
- optimizer (Object) – The optimizer of the model.
-
fit
(**kwargs)¶ Calls the compile and the fit method of the wrapped pytorch module.
-
classmethod
load
(load_information) → pywatts.modules.wrappers.pytorch_wrapper.PyTorchWrapper¶ Method for restoring a pytorch Wrapper.
Parameters: load_information (Dict) – Dict which contains the information for restoring the wrappers Returns: The restored wrappers Return type: PyTorchWrapper
-
save
(fm: pywatts_pipeline.core.util.filemanager.FileManager)¶ Saves the pytorch wrappers and the containing model :param fm: Filemanager for getting the path :type fm: FileManager :return: Dictionary with additional information :rtype: Dict
-
transform
(**kwargs) → xarray.core.dataarray.DataArray¶ Calls predict of the underlying PyTorch model.
Parameters: x – The dataset for which a prediction should be performed Returns: The prediction. Each output of the PyTorch model is a separate data variable in the returned xarray.
-
class
pywatts.modules.wrappers.pytorch_wrapper.
TimeSeriesDataset
(x, y)¶ Bases:
torch.utils.data.dataset.Dataset
pywatts.modules.wrappers.sklearn_wrapper module¶
-
class
pywatts.modules.wrappers.sklearn_wrapper.
SKLearnWrapper
(module: sklearn.base.BaseEstimator, name: str = None)¶ Bases:
pywatts.modules.wrappers.base_wrapper.BaseWrapper
A wrappers class for sklearn modules. Should only used internal by the pipeline itself :param module: The sklearn module to wrap :type module: sklearn.base.BaseEstimator :param name: The name of the module :type name: str
-
fit
(**kwargs)¶ Fit the sklearn module :param x: input data :param y: target data
-
inverse_transform
(**kwargs) → xarray.core.dataarray.DataArray¶ Performs the inverse transform of a dataset with the wrapped sklearn module :param x: the input dataset :return: the transformed output
-
classmethod
load
(load_information) → pywatts.modules.wrappers.sklearn_wrapper.SKLearnWrapper¶ Parameters: load_information (Dict) – Information for reloading the SklearnWrapper Returns: The reloaded SklearnWrapper Return type: SKLearnWrapper Warning
This method use pickle for loading the module. Note that this is not safe. Consequently, load only modules you trust. For more details about pickling see https://docs.python.org/3/library/pickle.html
-
predict_proba
(**kwargs) → xarray.core.dataarray.DataArray¶ Performs the probabilistic transform of a dataset with the wrapped sklearn module :param x: the input dataset :return: the transformed output
-
save
(fm: pywatts_pipeline.core.util.filemanager.FileManager)¶ Saves the modules and the state of the module and returns a dictionary containing the relevant information.
Parameters: fm (FileManager) – the filemanager which can be used by the module for saving information about the module. Returns: A dictionary containing the information needed for restoring the module :rtype:Dict
-
transform
(**kwargs) → xarray.core.dataarray.DataArray¶ Transforms a dataset or predicts the result with the wrapped sklearn module :param x: the input dataset :return: the transformed output
-
pywatts.modules.wrappers.sm_time_series_model_wrapper module¶
-
class
pywatts.modules.wrappers.sm_time_series_model_wrapper.
SmTimeSeriesModelWrapper
(module: Type[statsmodels.tsa.base.tsa_model.TimeSeriesModel], name=None, module_kwargs=None, fit_kwargs=None, predict_kwargs=None, use_exog=True)¶ Bases:
pywatts.modules.wrappers.base_wrapper.BaseWrapper
Wrapper for statsmodels modules. When adding this module to the pipeline, all inputs that starts with target are handled as endogenous variables and all other as exogenous variables.
Parameters: - module – The statsmodels module to wrap. Not this module should not be initialised.
- name (str) – The name of the module
- module_kwargs (dict) – The module keyword arguments necessary for creating the statsmodel module
- fit_kwargs (dict) – The optional fit keyword arguments for fitting the model
- predict_kwargs (dict) – The optional predict keyword arguments for predicting with the model (except start and end)
-
fit
(**kwargs)¶ Fits the statsmodels module
Parameters: kwargs (xr.DataArray) – A dict of input arrays
-
classmethod
load
(load_information) → pywatts.modules.wrappers.sm_time_series_model_wrapper.SmTimeSeriesModelWrapper¶ Loads a statsmodels wrappers
Parameters: load_information (Dict) – Information for reloading the StatsmodelsWrapper Returns: The reloaded StatsmodelsWrapper Return type: SmTimeSeriesModelWrapper Warning
This method use pickle for loading the module. Note that this is not safe. Consequently, load only modules you trust. For more details about pickling see https://docs.python.org/3/library/pickle.html
-
save
(fm: pywatts_pipeline.core.util.filemanager.FileManager)¶ Saves the statsmodels wrappers and the containing model
Parameters: fm (FileManager) – FileManager for getting the path Returns: Dictionary with all information for restoting the module Return type: Dict
-
transform
(**kwargs) → xarray.core.dataarray.DataArray¶ Predicts the result with the wrapped statsmodels module
Parameters: kwargs (xr.DataArray) – A dict of input arrays Returns: the transformed dataarray Return type: xr.DataArray