pywatts.modules.wrappers package¶
Submodules¶
pywatts.modules.wrappers.base_wrapper module¶
-
class
pywatts.modules.wrappers.base_wrapper.BaseWrapper(name: str)¶ Bases:
pywatts.core.base.BaseEstimator,abc.ABCThe 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.ABCSuper 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.core.base.BaseEstimatorThis 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
-
get_params() → Dict[str, object]¶ Returns an empty dictionary, since this wrappers does not contain any parameters
Returns: Empty dictionary Return type: dict
-
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.core.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
-
set_params(*args, **kwargs)¶ Does nothing:
-
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¶
-
class
pywatts.modules.wrappers.keras_wrapper.KerasWrapper(model: Union[keras.engine.training.Model, Tuple[keras.engine.training.Model, Dict[str, keras.engine.training.Model]]], name: str = 'KerasWrapper', fit_kwargs=None, compile_kwargs=None, custom_objects=None)¶ Bases:
pywatts.modules.wrappers.dl_wrapper.DlWrapperWrapper class for keras models
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
- compile_kwargs (dict) – The compile keyword arguments necessary for compiling the model.
- custom_objects (dict) – This dict contains all custom objects needed by the keras model. Note, users that uses such customs objects (e.g. Custom Loss) need to specify this to enable the loading of the stored Keras model.
-
fit(**kwargs)¶ Calls the compile and the fit method of the wrapped keras module. :param x: The input data :param y: The target data
-
get_params() → Dict[str, object]¶ Returns the parameters of deep learning frameworks. :return: A dict containing the fit keyword arguments and the compile keyword arguments
-
classmethod
load(load_information) → pywatts.modules.wrappers.keras_wrapper.KerasWrapper¶ Load the keras model and instantiate a new keraswrapper class containing the model. :param params: The paramters which should be used for restoring the model. (Note: This models should be taken from the pipeline json file) :return: A wrapped keras model.
-
save(fm: pywatts.core.filemanager.FileManager) → dict¶ Stores the keras model at the given path :param fm: The Filemanager, which contains the path where the model should be stored :return: The path where the model is stored.
-
set_params(fit_kwargs=None, compile_kwargs=None, custom_objects=None)¶ Set the parameters of the deep learning wrappers :param fit_kwargs: keyword arguments for the fit method. :param compile_kwargs: keyword arguments for the compile methods. :param custom_objects: This dict contains all custom objects needed by the keras model. Note,
users that uses such customs objects (e.g. Custom Loss) need to specify this to enable the loading of the stored Keras model.
-
transform(**kwargs) → xarray.core.dataarray.DataArray¶ Calls predict of the underlying keras Model. :param x: The dataset for which a prediction should be performed :return: The prediction. Each output of the keras model is a separate data variable in the returned xarray.
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.DlWrapperWrapper 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.
-
get_params() → Dict[str, object]¶ Returns the parameters of deep learning frameworks. :return: A dict containing the fit keyword arguments and the compile keyword arguments
-
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.core.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
-
set_params(fit_kwargs=None, loss_fn=None, optimizer=None)¶ Set the parameters of the deep learning wrappers :param fit_kwargs: keyword arguments for the fit method. :param compile_kwargs: keyword arguments for the compile methods.
-
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.BaseWrapperA 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
-
get_params()¶ Return the parameter of the slkearn module :return:
-
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.core.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
-
set_params(**kwargs)¶ Set the parameter of the internal sklearn module :param kwargs: The parameter of the internal sklearn module :return:
-
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: str = None, module_kwargs=None, fit_kwargs=None, predict_kwargs=None, use_exog=True)¶ Bases:
pywatts.modules.wrappers.base_wrapper.BaseWrapperWrapper 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
-
get_params() → Dict[str, object]¶ Returns the parameters of the statsmodels module.
Returns: A dict containing the module keyword arguments, the fit keyword arguments, the predict keyword arguments and the fitted model parameters :rtype: Dict
-
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.core.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
-
set_params(module_kwargs=None, fit_kwargs=None, predict_kwargs=None, use_exog=None)¶ Set the parameters of the statsmodels wrappers
Parameters: - module_kwargs (Dict) – keyword arguments for the statsmodel module.
- fit_kwargs (Dict) – keyword arguments for the fit method.
- predict_kwargs (Dict) – keyword arguments for the predict method.
-
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