Introductie tot MLflow Models

Introductie tot MLflow

Weston Bassler

Senior MLOps Engineer

MLflow Models

  • Integreer ML-bibliotheken eenvoudiger

  • Vereenvoudig deployment

  • Conventie heet "flavors"

flavors

1 unsplash.com
Introductie tot MLflow

Ingebouwde flavors

AFBEELDINGEN VAN FLAVORS

  • Schrijf custom tools voor ML-bibliotheken

  • Flavors vereenvoudigen nieuwe custom code

# Importeer flavor uit mlflow-module
import mlflow.FLAVOR
1 mlflow.org
Introductie tot MLflow

Autolog

# Log model en metrics automatisch
mlflow.FLAVOR.autolog()
# Scikit-learn ingebouwde flavor
mlflow.sklearn.autolog()
Introductie tot MLflow

Scikit-learn flavor

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

# Autologging gebruiken mlflow.sklearn.autolog()
# Train het model
lr = LinearRegression()
lr.fit(X, y)

Model wordt automatisch gelogd bij model.fit()

Introductie tot MLflow

Veelgebruikte metrics

  • Regressie
    • mean squared error
    • root mean squared error
    • mean absolute error
    • r2 score
  • Classificatie
    • precision score
    • recall score
    • f1 score
    • accuracy score

Veelgebruikte parameters

MODEL.get_params()
Introductie tot MLflow

Veelgebruikte parameters

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

# Haal parameters op params = lr.get_params(deep=True)
params
{'copy_X': True, 'fit_intercept': True, 'n_jobs': None, 
    'normalize': 'deprecated', 'positive': False}
Introductie tot MLflow

Parameters autologgen

parameters

# Model
lr = LinearRegression()
lr.fit(X, y)
Introductie tot MLflow

Metrics autologgen

metrics

# Model
lr = LinearRegression()
lr.fit(X, y)
Introductie tot MLflow

Opslagformaat

Mappenstructuur van een model:

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

Artifacts

Introductie tot MLflow

Inhoud van 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
Introductie tot MLflow

MLmodel

MLmodel

Introductie tot MLflow

Laten we oefenen!

Introductie tot MLflow

Preparing Video For Download...