Skip to main content

MLflavors: A collection of custom MLflow flavors.

Project description

The MLflavors package adds MLflow support for some popular machine learning frameworks currently not considered for inclusion as MLflow built-in flavors. You can use this package just like MLflow built-in flavors to save and load your models. Some of the key benefits are listed below:

  • Save your trained model as an MLflow artifact

  • Load your model from MLflow for batch inference tasks

  • Serve your model for real-time inference to an endpoint in the cloud (e.g. Databricks, Azure ML, AWS Sagemaker, etc.) using MLflow built-in deployment tools

  • Get inspiration for creating your own MLflow custom flavor

The following open-source libraries are currently supported:

Framework

Tutorials

Category

Orbit

MLflow-Orbit

Time Series Forecasting

Sktime

MLflow-Sktime

Time Series Forecasting

StatsForecast

MLflow-StatsForecast

Time Series Forecasting

PyOD

MLflow-PyOD

Anomaly Detection

SDV

MLflow-SDV

Synthetic Data Generation

The MLflow interface for the supported frameworks closely follows the design of built-in flavors.

Documentation

Usage examples for all flavors and the API reference can be found in the package documenation.

Installation

Installing from PyPI:

$ pip install mlflavors

Quickstart

Save an Orbit ETS model as an artifact to MLflow:

import mlflavors

from orbit.models import ETS
from orbit.utils.dataset import load_iclaims

df = load_iclaims()

test_size = 52
train_df = df[:-test_size]
test_df = df[-test_size:]

ets = ETS(
    response_col="claims",
    date_col="week",
    seasonality=52,
    seed=8888,
)
ets.fit(df=train_df)

mlflavors.orbit.save_model(
    orbit_model=ets,
    path="model",
)

Make a prediction loading the model from MLflow in native format:

loaded_model = mlflavors.orbit.load_model("model")
loaded_model.predict(test_df, decompose=True, store_prediction_array=True, seed=2023)

Make a prediction loading the model from MLflow in pyfunc format:

# Convert test data to 2D numpy array so it can be passed to pyfunc predict using
# a single-row Pandas DataFrame configuration argument
X_test_array = test_df.to_numpy()

# Create configuration DataFrame
predict_conf = pd.DataFrame(
    [
        {
            "X": X_test_array,
            "X_cols": test_df.columns,
            "X_dtypes": list(test_df.dtypes),
            "decompose": True,
            "store_prediction_array": True,
            "seed": 2023,
        }
    ]
)

loaded_pyfunc = mlflavors.orbit.pyfunc.load_model("model")
loaded_pyfunc.predict(predict_conf)

Contributing

Contributions from the community are welcome, I will be happy to support the inclusion and development of new features and flavors. To open an issue or request a new feature, please open a GitHub issue.

Versioning

Versions and changes are documented in the changelog .

Development

To set up your local development environment, create a virtual environment, such as:

$ conda create -n mlflavors-dev python=3.9
$ source activate mlflavors-dev

Install project locally:

$ python -m pip install --upgrade pip
$ pip install -e ".[dev,docs]"

Install pre-commit hooks:

$ pre-commit install

Run tests:

$ pytest tests/unit --cov

Build Sphinx docs:

$ cd docs
$ make html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlflavors-0.1.0rc1.tar.gz (23.3 kB view hashes)

Uploaded Source

Built Distribution

mlflavors-0.1.0rc1-py3-none-any.whl (32.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page