Introduktion till MLflow-modeller

Introduktion till MLflow

Weston Bassler

Senior MLOps Engineer

MLflow-modeller

  • Förenklar integration av ML-bibliotek

  • Förenklar driftsättning

  • Konvention kallad "Flavors"

flavors

1 unsplash.com
Introduktion till MLflow

Inbyggda flavors

BILDER PÅ FLAVORS

  • Skriv egna verktyg från ML-bibliotek

  • Flavors minskar behovet av egen kod

# Import flavor from mlflow module
import mlflow.FLAVOR
1 mlflow.org
Introduktion till MLflow

Autolog

# Automatically log model and metrics
mlflow.FLAVOR.autolog()
# Scikit-learn built-in flavor
mlflow.sklearn.autolog()
Introduktion till MLflow

Scikit-learn-flavor

# Import scikit-learn
import mlflow
from sklearn.linear_model import \
    LinearRegression

# Using auto-logging mlflow.sklearn.autolog()
# Train the model
lr = LinearRegression()
lr.fit(X, y)

Modellen loggas automatiskt vid model.fit()

Introduktion till MLflow

Vanliga mätvärden

  • Regression
    • mean squared error
    • root mean squared error
    • mean absolute error
    • r2 score
  • Klassificering
    • precision score
    • recall score
    • f1 score
    • accuracy score

Vanliga parametrar

MODEL.get_params()
Introduktion till MLflow

Vanliga parametrar

# Train the model
lr = LinearRegression()
lr.fit(X, y)

# Get params params = lr.get_params(deep=True)
params
{'copy_X': True, 'fit_intercept': True, 'n_jobs': None, 
    'normalize': 'deprecated', 'positive': False}
Introduktion till MLflow

Autolog – parametrar

parametrar

# Model
lr = LinearRegression()
lr.fit(X, y)
Introduktion till MLflow

Autolog – mätvärden

mätvärden

# Model
lr = LinearRegression()
lr.fit(X, y)
Introduktion till MLflow

Lagringsformat

Katalogstruktur för en modell:

model/
    MLmodel
    model.pkl
    python_env.yaml
    requirements.txt
# Autolog
mlflow.sklearn.autolog()

Artefakter

Introduktion till MLflow

Innehåll i MLmodel

artifact_path: model
flavors:
  python_function:
    env:
      virtualenv: python_env.yaml
    loader_module: mlflow.sklearn
    model_path: model.pkl
    predict_fn: predict
    python_version: 3.10.8
  sklearn:
    code: null
    pickled_model: model.pkl
    serialization_format: cloudpickle
    sklearn_version: 1.1.3
Introduktion till MLflow

MLmodel

MLmodel

Introduktion till MLflow

Nu kör vi en övning!

Introduktion till MLflow

Preparing Video For Download...