API reference
Orbit
The mlflavors.orbit
module provides an API for logging and loading orbit
models. This module exports orbit models with the following flavors:
- orbit (native) format
This is the main flavor that can be loaded back into orbit, which relies on pickle internally to serialize a model.
Note that pickle serialization requires using the same python environment (version) in whatever environment you’re going to use this model for inference to ensure that the model will load with appropriate version of pickle.
mlflow.pyfunc
formatProduced for use by generic pyfunc-based deployment tools and batch inference.
The interface for utilizing an orbit model loaded as a
pyfunc
type for generating forecast predictions uses a single-rowPandas DataFrame
configuration argument. The following columns in this configurationPandas DataFrame
are supported:Column
Type
Description
X
numpy ndarray or list (required)
Exogenous regressor for future time period events.For more information, read the underlying library explanation:X_cols
list (required)
Column names of the exogenous regressor matrix(Required to construct Pandas DataFrame inside model wrapper class).X_dtypes (required)
list (required)
Data types of the exogenous regressor matrix(Required to construct Pandas DataFrame inside model wrapper class).decompose
bool (optional)
If True, returns each prediction component separately.(Default:False
)store_prediction_array
bool (optional)
If True, prediction array is stored.(Default:False
)seed
int (optional)
Seed in prediction is set to be random by default unless provided.(Default:None
)
- mlflavors.orbit.get_default_conda_env(include_cloudpickle=False)[source]
- Returns
The default Conda environment for MLflow Models produced by calls to
save_model()
andlog_model()
.
- mlflavors.orbit.get_default_pip_requirements(include_cloudpickle=False)[source]
- Returns
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
save_model()
andlog_model()
produce a pip environment that, at minimum, contains these requirements.
- mlflavors.orbit.load_model(model_uri, dst_path=None)[source]
Load an orbit model from a local file or a run.
- Parameters
model_uri –
The location, in URI format, of the MLflow model, for example:
/Users/me/path/to/local/model
relative/path/to/local/model
s3://my_bucket/path/to/model
runs:/<mlflow_run_id>/run-relative/path/to/model
models:/<model_name>/<model_version>
models:/<model_name>/<stage>
For more information about supported URI schemes, see Referencing Artifacts.
dst_path – The local filesystem path to which to download the model artifact. This directory must already exist. If unspecified, a local output path will be created.
- Returns
An orbit model.
- mlflavors.orbit.log_model(orbit_model, artifact_path, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle', **kwargs)[source]
Log an orbit model as an MLflow artifact for the current run. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
orbit_model – Fitted orbit model object.
artifact_path – Run-relative artifact path to save the model instance to.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "orbit==x.y.z" ], }, ], }
code_paths – 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.
registered_model_name – This argument may change or be removed in a future release without warning. If given, create a model version under
registered_model_name
, also creating a registered model if one with the given name does not exist.signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.await_registration_for – Number of seconds to wait for the model version to finish being created and is in
READY
status. By default, the function waits for five minutes. Specify 0 or None to skip waiting.pip_requirements – Either an iterable of pip requirement strings (e.g.
["orbit", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
- Returns
A
ModelInfo
instance that contains the metadata of the logged model.
- mlflavors.orbit.save_model(orbit_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 an orbit model to a path on the local file system. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
orbit_model – Fitted orbit model object.
path – Local path where the model is to be saved.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "orbit==x.y.z" ], }, ], }
code_paths – 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 configuration to which to add the python_function flavor.
signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.pip_requirements – Either an iterable of pip requirement strings (e.g.
["orbit", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
Sktime
The mlflavors.sktime
module provides an API for logging and loading sktime
models. This module exports sktime models with the following flavors:
- sktime (native) format
This is the main flavor that can be loaded back into sktime, which relies on pickle internally to serialize a model.
Note that pickle serialization requires using the same python environment (version) in whatever environment you’re going to use this model for inference to ensure that the model will load with appropriate version of pickle.
mlflow.pyfunc
formatProduced for use by generic pyfunc-based deployment tools and batch inference.
The interface for utilizing a sktime model loaded as a
pyfunc
type for generating forecast predictions uses a single-rowPandas DataFrame
configuration argument. The following columns in this configurationPandas DataFrame
are supported:Column
Type
Description
predict_method
str (required)
Specifies the sktime predict method. The supported predict methods arepredict
,predict_interval
,predict_quantiles
, andpredict_var
.fh
list (optional)
Specifies the number of future periods to generate starting from the lastdatetime value of the training dataset, utilizing the frequency of the inputtraining series when the model was trained. (for example, if the trainingdata series elements represent one value per hour, in order to forecast 3hours of future data, set the columnfh
to[1,2,3]
. If the parameteris not provided it must be passed duringfit()
.(Default:None
)X_dtypes
numpy ndarray or list (optional)
Exogenous regressor for future time period events.For more information, read the underlying library explanation:coverage
float (optional)
The nominal coverage value for calculating prediction interval forecasts.Can only be provided in combination with predict methodpredict_interval
.(Default:0.9
)alpha
float (optional)
The probability value for calculating prediction quantile forecasts.Can only be provided in combination with predict methodpredict_quantiles
.(Default:None
)cov
bool (optional)
If True, computes covariance matrix forecast.Can only be provided in combination with predict methodpredict_var
.(Default:False
)
An example configuration for the pyfunc
predict of a sktime model is shown below,
using an interval forecast with nominal coverage value [0.9,0.95]
, a future forecast
horizon of 3 periods, and no exogenous regressor elements:
Index |
predict_method |
coverage |
fh |
---|---|---|---|
0 |
predict_interval |
[0.9,0.95] |
[1,2,3] |
- mlflavors.sktime.get_default_conda_env(include_cloudpickle=False)[source]
- Returns
The default Conda environment for MLflow Models produced by calls to
save_model()
andlog_model()
.
- mlflavors.sktime.get_default_pip_requirements(include_cloudpickle=False)[source]
- Returns
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
save_model()
andlog_model()
produce a pip environment that, at minimum, contains these requirements.
- mlflavors.sktime.load_model(model_uri, dst_path=None)[source]
Load a sktime model from a local file or a run.
- Parameters
model_uri –
The location, in URI format, of the MLflow model, for example:
/Users/me/path/to/local/model
relative/path/to/local/model
s3://my_bucket/path/to/model
runs:/<mlflow_run_id>/run-relative/path/to/model
models:/<model_name>/<model_version>
models:/<model_name>/<stage>
For more information about supported URI schemes, see Referencing Artifacts.
dst_path – The local filesystem path to which to download the model artifact. This directory must already exist. If unspecified, a local output path will be created.
- Returns
A sktime model.
- mlflavors.sktime.log_model(sktime_model, artifact_path, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle', **kwargs)[source]
Log a sktime model as an MLflow artifact for the current run. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
sktime_model – Fitted sktime model object.
artifact_path – Run-relative artifact path to save the model instance to.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "sktime==x.y.z" ], }, ], }
code_paths – 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.
registered_model_name – This argument may change or be removed in a future release without warning. If given, create a model version under
registered_model_name
, also creating a registered model if one with the given name does not exist.signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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 asktime
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 thepyfunc
flavor of the model, though.input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.await_registration_for – Number of seconds to wait for the model version to finish being created and is in
READY
status. By default, the function waits for five minutes. Specify 0 or None to skip waiting.pip_requirements – 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"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
- Returns
A
ModelInfo
instance that contains the metadata of the logged model.
- mlflavors.sktime.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. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
sktime_model – Fitted sktime model object.
path – Local path where the model is to be saved.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "sktime==x.y.z" ], }, ], }
code_paths – 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 configuration to which to add the python_function flavor.
signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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 asktime
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 thepyfunc
flavor of the model, though.input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.pip_requirements – 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"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
StatsForecast
The mlflavors.statsforecast
module provides an API for logging and loading
statsforecast models. This module exports statsforecast models with the following
flavors:
- statsforecast (native) format
This is the main flavor that can be loaded back into statsforecast, which relies on pickle internally to serialize a model.
Note that pickle serialization requires using the same python environment (version) in whatever environment you’re going to use this model for inference to ensure that the model will load with appropriate version of pickle.
mlflow.pyfunc
formatProduced for use by generic pyfunc-based deployment tools and batch inference.
The interface for utilizing an statsforecast model loaded as a
pyfunc
type for generating forecast predictions uses a single-rowPandas DataFrame
configuration argument. The following columns in this configurationPandas DataFrame
are supported:Column
Type
Description
X
numpy ndarray or list (optional)
Exogenous regressor for future time period events.For more information, read the underlying library explanation:(Default:None
)X_cols
list (optional)
Column names of the exogenous regressor matrix(Required to construct Pandas DataFrame inside model wrapper class).(Default:None
)X_dtypes
list (optional)
Data types of the exogenous regressor matrix(Required to construct Pandas DataFrame inside model wrapper class).(Default:None
)h
int (required)
Specifies the number of future periods to generate starting from the lastdatetime value of the training dataset, utilizing the frequency of the inputtraining series when the model was trained. (for example, if the trainingdata series elements represent one value per hour, in order to forecast 3hours of future data, set the columnfh
to3
.level
list (optional)
A list of floats with the confidence levels of the prediction intervals. Forexample,level=[95]
means that the range of values should include theactual future value with probability 95%.(Default:None
)
- mlflavors.statsforecast.get_default_conda_env(include_cloudpickle=False)[source]
- Returns
The default Conda environment for MLflow Models produced by calls to
save_model()
andlog_model()
.
- mlflavors.statsforecast.get_default_pip_requirements(include_cloudpickle=False)[source]
- Returns
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
save_model()
andlog_model()
produce a pip environment that, at minimum, contains these requirements.
- mlflavors.statsforecast.load_model(model_uri, dst_path=None)[source]
Load an statsforecast model from a local file or a run.
- Parameters
model_uri –
The location, in URI format, of the MLflow model, for example:
/Users/me/path/to/local/model
relative/path/to/local/model
s3://my_bucket/path/to/model
runs:/<mlflow_run_id>/run-relative/path/to/model
models:/<model_name>/<model_version>
models:/<model_name>/<stage>
For more information about supported URI schemes, see Referencing Artifacts.
dst_path – The local filesystem path to which to download the model artifact. This directory must already exist. If unspecified, a local output path will be created.
- Returns
An statsforecast model.
- mlflavors.statsforecast.log_model(statsforecast_model, artifact_path, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle', **kwargs)[source]
Log an statsforecast model as an MLflow artifact for the current run. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
statsforecast_model – Fitted statsforecast model object.
artifact_path – Run-relative artifact path to save the model instance to.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "statsforecast==x.y.z" ], }, ], }
code_paths – 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.
registered_model_name – This argument may change or be removed in a future release without warning. If given, create a model version under
registered_model_name
, also creating a registered model if one with the given name does not exist.signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.await_registration_for – Number of seconds to wait for the model version to finish being created and is in
READY
status. By default, the function waits for five minutes. Specify 0 or None to skip waiting.pip_requirements – Either an iterable of pip requirement strings (e.g.
["statsforecast", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
- Returns
A
ModelInfo
instance that contains the metadata of the logged model.
- mlflavors.statsforecast.save_model(statsforecast_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 an statsforecast model to a path on the local file system. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
statsforecast_model – Fitted statsforecast model object.
path – Local path where the model is to be saved.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "statsforecast==x.y.z" ], }, ], }
code_paths – 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 configuration to which to add the python_function flavor.
signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.pip_requirements – Either an iterable of pip requirement strings (e.g.
["statsforecast", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
PyOD
The mlflavors.pyod
module provides an API for logging and loading
pyod models. This module exports pyod models with the following
flavors:
- pyod (native) format
This is the main flavor that can be loaded back into pyod, which relies on pickle internally to serialize a model.
Note that pickle serialization requires using the same python environment (version) in whatever environment you’re going to use this model for inference to ensure that the model will load with appropriate version of pickle.
mlflow.pyfunc
formatProduced for use by generic pyfunc-based deployment tools and batch inference.
The interface for utilizing an pyod model loaded as a
pyfunc
type for generating predictions uses a single-rowPandas DataFrame
configuration argument. The following columns in this configurationPandas DataFrame
are supported:Column
Type
Description
predict_method
str (required)
Specifies the pyod predict method. The supported predict methods arepredict
,predict_proba
,predict_confidence
, anddecision_function
.X
numpy ndarray or list (required)
The input samples.For more information, read the underlying library explanation:return_confidence
bool (optional)
If True, returns prediction confidence as well.Can only be provided in combination with predict methodpredict
andpredict_proba
.(Default:False
)method
str (optional)
The probability conversion method.Can only be provided in combination with predict methodpredict_proba
.(Default:linear
)
- mlflavors.pyod.get_default_conda_env(include_cloudpickle=False)[source]
- Returns
The default Conda environment for MLflow Models produced by calls to
save_model()
andlog_model()
.
- mlflavors.pyod.get_default_pip_requirements(include_cloudpickle=False)[source]
- Returns
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
save_model()
andlog_model()
produce a pip environment that, at minimum, contains these requirements.
- mlflavors.pyod.load_model(model_uri, dst_path=None)[source]
Load an pyod model from a local file or a run.
- Parameters
model_uri –
The location, in URI format, of the MLflow model, for example:
/Users/me/path/to/local/model
relative/path/to/local/model
s3://my_bucket/path/to/model
runs:/<mlflow_run_id>/run-relative/path/to/model
models:/<model_name>/<model_version>
models:/<model_name>/<stage>
For more information about supported URI schemes, see Referencing Artifacts.
dst_path – The local filesystem path to which to download the model artifact. This directory must already exist. If unspecified, a local output path will be created.
- Returns
An pyod model.
- mlflavors.pyod.log_model(pyod_model, artifact_path, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle', **kwargs)[source]
Log an pyod model as an MLflow artifact for the current run. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
pyod_model – Fitted pyod model object.
artifact_path – Run-relative artifact path to save the model instance to.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "pyod==x.y.z" ], }, ], }
code_paths – 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.
registered_model_name – This argument may change or be removed in a future release without warning. If given, create a model version under
registered_model_name
, also creating a registered model if one with the given name does not exist.signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.await_registration_for – Number of seconds to wait for the model version to finish being created and is in
READY
status. By default, the function waits for five minutes. Specify 0 or None to skip waiting.pip_requirements – Either an iterable of pip requirement strings (e.g.
["pyod", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
- Returns
A
ModelInfo
instance that contains the metadata of the logged model.
- mlflavors.pyod.save_model(pyod_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 an pyod model to a path on the local file system. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
pyod_model – Fitted pyod model object.
path – Local path where the model is to be saved.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "pyod==x.y.z" ], }, ], }
code_paths – 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 configuration to which to add the python_function flavor.
signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.pip_requirements – Either an iterable of pip requirement strings (e.g.
["pyod", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
SDV
The mlflavors.sdv
module provides an API for logging and loading
sdv models. This module exports sdv models with the following
flavors:
- sdv (native) format
This is the main flavor that can be loaded back into sdv, which relies on pickle internally to serialize a model.
Note that pickle serialization requires using the same python environment (version) in whatever environment you’re going to use this model for inference to ensure that the model will load with appropriate version of pickle.
mlflow.pyfunc
formatProduced for use by generic pyfunc-based deployment tools and batch inference.
Currently only the
sample
method is supported in thepyfunc
flavor. Additional methods (e.g.sample_remaining_columns
) could be added in a similar fashion.The interface for utilizing an sdv model loaded as a
pyfunc
type for generating predictions uses a single-rowPandas DataFrame
configuration argument. The following columns in this configurationPandas DataFrame
are supported:Column
Type
Description
modality
str (required)
Specifies the sdv table modalities. The supported modalities aresingle_table
,multi_table
, andsequential
.For more information, read the underlying library explanation:num_rows
int (required)
An integer >0, describing the number of rows to sample.Can only be provided in combination with modalitysingle_table
.num_sequences
int (required)
An integer >0, describing the number of sequences to sample.Can only be provided in combination with modalitysequential
.batch_size
int (optional)
An integer >0, describing the number of rows to sample at a time.Can only be provided in combination with modalitysingle_table
.(Default:num_rows
)max_tries_per_batch
int (optional)
An integer >0, describing the number of sampling attempts to make per batch.Can only be provided in combination with modalitysingle_table
.(Default:100
)output_file_path
str (optional)
A string describing a CSV filepath for writing the synthetic data.Can only be provided in combination with modalitysingle_table
.(Default:None
)scale
float (optional)
A float >0.0 that describes how much to scale the data by.Can only be provided in combination with modalitymulti_table
.(Default:1.0
)sequence_length
int (optional)
An integer >0 describing the length of each sequence.Can only be provided in combination with modalitysequential
.(Default:None
)
- mlflavors.sdv.get_default_conda_env(include_cloudpickle=False)[source]
- Returns
The default Conda environment for MLflow Models produced by calls to
save_model()
andlog_model()
.
- mlflavors.sdv.get_default_pip_requirements(include_cloudpickle=False)[source]
- Returns
A list of default pip requirements for MLflow Models produced by this flavor. Calls to
save_model()
andlog_model()
produce a pip environment that, at minimum, contains these requirements.
- mlflavors.sdv.load_model(model_uri, dst_path=None)[source]
Load an sdv model from a local file or a run.
- Parameters
model_uri –
The location, in URI format, of the MLflow model, for example:
/Users/me/path/to/local/model
relative/path/to/local/model
s3://my_bucket/path/to/model
runs:/<mlflow_run_id>/run-relative/path/to/model
models:/<model_name>/<model_version>
models:/<model_name>/<stage>
For more information about supported URI schemes, see Referencing Artifacts.
dst_path – The local filesystem path to which to download the model artifact. This directory must already exist. If unspecified, a local output path will be created.
- Returns
An sdv model.
- mlflavors.sdv.log_model(sdv_model, artifact_path, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, serialization_format='pickle', **kwargs)[source]
Log an sdv model as an MLflow artifact for the current run. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
sdv_model – Fitted sdv model object.
artifact_path – Run-relative artifact path to save the model instance to.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "sdv==x.y.z" ], }, ], }
code_paths – 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.
registered_model_name – This argument may change or be removed in a future release without warning. If given, create a model version under
registered_model_name
, also creating a registered model if one with the given name does not exist.signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.await_registration_for – Number of seconds to wait for the model version to finish being created and is in
READY
status. By default, the function waits for five minutes. Specify 0 or None to skip waiting.pip_requirements – Either an iterable of pip requirement strings (e.g.
["sdv", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”
- Returns
A
ModelInfo
instance that contains the metadata of the logged model.
- mlflavors.sdv.save_model(sdv_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 an sdv model to a path on the local file system. Produces an MLflow Model containing the following flavors:
mlflow.pyfunc
- Parameters
sdv_model – Fitted sdv model object.
path – Local path where the model is to be saved.
conda_env –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At minimum, it should specify the dependencies contained in
get_default_conda_env()
. IfNone
, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()
is added to the model. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. pip requirements fromconda_env
are written to a piprequirements.txt
file and the full conda environment is written toconda.yaml
. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "sdv==x.y.z" ], }, ], }
code_paths – 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 configuration to which to add the python_function flavor.
signature –
Model Signature mlflow.models.ModelSignature describes model input and output
Schema
. The model signature can beinferred
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)
input_example – 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 thePandas
split-oriented format. Bytes are base64-encoded.pip_requirements – Either an iterable of pip requirement strings (e.g.
["sdv", "-r requirements.txt", "-c constraints.txt"]
) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"
). If provided, this describes the environment this model should be run in. IfNone
, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()
from the current software environment. If the requirement inference fails, it falls back to usingget_default_pip_requirements()
. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.extra_pip_requirements –
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"
). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txt
andconstraints.txt
files, respectively, and stored as part of the model. Requirements are also written to thepip
section of the model’s conda environment (conda.yaml
) file.Warning
The following arguments can’t be specified at the same time:
conda_env
pip_requirements
extra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirements
andextra_pip_requirements
.serialization_format – The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”