Skip to main content

module mlforecast.flavor

Global Variables

  • MLMODEL_FILE_NAME
  • INVALID_PARAMETER_VALUE
  • DEFAULT_AWAIT_MAX_SLEEP_SECONDS
  • FLAVOR_NAME

function get_default_pip_requirements

get_default_pip_requirements()
Create list of default pip requirements for MLflow Models. Returns:
  • list: list of default pip requirements for MLflow Models produced by this flavor.
  • Calls to : func:save_model() and :func:log_model() produce a pip environment that, at a minimum, contains these requirements.

function get_default_conda_env

get_default_conda_env()
Return default Conda environment for MLflow Models. Returns: The default Conda environment for MLflow Models produced by calls to
  • :func: save_model() and :func:log_model()

function save_model

save_model(
    model,
    path,
    conda_env=None,
    code_paths=None,
    mlflow_model=None,
    signature=None,
    input_example=None,
    pip_requirements=None,
    extra_pip_requirements=None
)
Save an MLForecast model to a local path Args:
  • model (MLForecast): Fitted MLForecast model object.
  • path (str): Local path where the model is to be saved.
  • conda_env (Union[dict, str], optional): Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. Defaults to None.
  • code_paths (array-like, optional): 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. Defaults to None.
  • mlflow_model (mlflow.models.Model, optional): mlflow.models.Model configuration to which to add the python_function flavor. Defaults to None.
  • signature (mlflow.models.signature.ModelSignature, optional): Model Signature mlflow.models.ModelSignature describes
  • model input and output : py:class:Schema <mlflow.types.Schema>. The model
  • signature can be : py:func:inferred <mlflow.models.infer_signature> 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:
  • .. code-block: : py
from mlflow.models import infer_signature train = df.drop_column(“target_label”) predictions = … # compute model predictions signature = infer_signature(train, predictions) Defaults to None.
  • input_example (Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional): 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. Defaults to None.
  • pip_requirements (Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“mlforecast”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.
  • extra_pip_requirements (Union[Iterable, str], optional): 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”). Defaults to None.
  • serialization_format (str, optional): The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”. Defaults to “pickle”.

function log_model

log_model(
    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,
    **kwargs
)
Log an MLForecast model as an MLflow artifact for the current run. Args:
  • model (MLForecast): Fitted MLForecast model object.
  • artifact_path (str): Run-relative artifact path to save the model to.
  • conda_env (Union[dict, str], optional): Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. Defaults to None.
  • code_paths (array-like, optional): 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. Defaults to None.
  • registered_model_name (str, optional): If given, create a model version under registered_model_name, also creating a registered model if one with the given name does not exist. Defaults to None.
  • signature (mlflow.models.signature.ModelSignature, optional): Model Signature mlflow.models.ModelSignature describes
  • model input and output : py:class:Schema <mlflow.types.Schema>. The model
  • signature can be : py:func:inferred <mlflow.models.infer_signature> 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:
  • .. code-block: : py
from mlflow.models import infer_signature train = df.drop_column(“target_label”) predictions = … # compute model predictions signature = infer_signature(train, predictions) Defaults to None.
  • input_example (Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional): 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. Defaults to None.
  • await_registration_for (int, optional): 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. Defaults to None.
  • pip_requirements (Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“mlforecast”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.
  • extra_pip_requirements (Union[Iterable, str], optional): 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”). Defaults to None.
  • kwargs: Additional arguments for :py:class:mlflow.models.model.Model
Returns:
  • A : py:class:ModelInfo <mlflow.models.model.ModelInfo> instance that contains the metadata of the logged model.

function load_model

load_model(model_uri, dst_path=None)
Load an MLForecast model from a local file or a run. Args:
  • model_uri (str): 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
    • mlflow-artifacts:/path/to/model
For more information about supported URI schemes, see Referencing Artifacts: ``` Returns: An MLForecast model instance.