save_model#

save_model(sktime_model, path, conda_env=None, code_paths=None, mlflow_model=None, signature=None, input_example=None, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle')[source]#

Save a sktime model to a path on the local file system.

Parameters:
sktime_model

Fitted sktime model object.

pathstr

Local path where the model is to be saved.

conda_envUnion[dict, str], optional (default=None)

Either a dictionary representation of a Conda environment or the path to a conda environment yaml file.

code_pathsarray-like, optional (default=None)

A list of local filesystem paths to Python file dependencies (or directories containing file dependencies). These files are prepended to the system path when the model is loaded.

mlflow_model: mlflow.models.Model, optional (default=None)

mlflow.models.Model configuration to which to add the python_function flavor.

signaturemlflow.models.signature.ModelSignature, optional (default=None)

Model Signature mlflow.models.ModelSignature describes model input and output Schema. The model signature can be inferred from datasets with valid model input (e.g. the training dataset with target column omitted) and valid model output (e.g. model predictions generated on the training dataset), for example:

from mlflow.models.signature import infer_signature
train = df.drop_column("target_label")
predictions = ... # compute model predictions
signature = infer_signature(train, predictions)

Warning

if performing probabilistic forecasts (predict_interval, predict_quantiles) with a sktime model, the signature on the returned prediction object will not be correctly inferred due to the Pandas MultiIndex column type when using the these methods. infer_schema will function correctly if using the pyfunc flavor of the model, though.

input_exampleUnion[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional
(default=None)

Input example provides one or several instances of valid model input. The example can be used as a hint of what data to feed the model. The given example will be converted to a Pandas DataFrame and then serialized to json using the Pandas split-oriented format. Bytes are base64-encoded.

pip_requirementsUnion[Iterable, str], optional (default=None)

Either an iterable of pip requirement strings (e.g. [“sktime”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”)

extra_pip_requirementsUnion[Iterable, str], optional (default=None)

Either an iterable of pip requirement strings (e.g. [“pandas”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”)

serialization_formatstr, optional (default=”pickle”)

The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”

References

[1]

https://www.mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.Model.save

Examples

>>> from sktime.datasets import load_airline  
>>> from sktime.forecasting.arima import ARIMA  
>>> from sktime.utils import mlflow_sktime  
>>> y = load_airline()  
>>> forecaster = ARIMA(  
...     order=(1, 1, 0),
...     seasonal_order=(0, 1, 0, 12),
...     suppress_warnings=True)
>>> forecaster.fit(y)  
ARIMA(...)
>>> model_path = "model"  
>>> mlflow_sktime.save_model(  
...     sktime_model=forecaster,
...     path=model_path)  
>>> loaded_model = mlflow_sktime.load_model(model_uri=model_path)  
>>> loaded_model.predict(fh=[1, 2, 3])