Introducere în modelele MLflow

Introducere în MLflow

Weston Bassler

Senior MLOps Engineer

Modele MLflow

  • Simplifică integrarea bibliotecilor ML

  • Simplifică implementarea

  • Convenție numită "Flavors"

flavors

1 unsplash.com
Introducere în MLflow

Flavors integrate

IMAGINI CU FLAVORS

  • Scrieți instrumente personalizate din biblioteci ML

  • Flavors elimină nevoia de cod personalizat

# Import flavor from mlflow module
import mlflow.FLAVOR
1 mlflow.org
Introducere în MLflow

Autolog

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

Flavor Scikit-learn

# 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)

Modelul va fi înregistrat automat la model.fit()

Introducere în MLflow

Metrici frecvente

  • Regresie
    • eroare pătratică medie
    • rădăcina erorii pătratice medii
    • eroare absolută medie
    • scor r2
  • Clasificare
    • scor de precizie
    • scor de recall
    • scor f1
    • scor de acuratețe

Parametri frecvenți

MODEL.get_params()
Introducere în MLflow

Parametri frecvenți

# 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}
Introducere în MLflow

Autolog parametri

parametri

# Model
lr = LinearRegression()
lr.fit(X, y)
Introducere în MLflow

Autolog metrici

metrici

# Model
lr = LinearRegression()
lr.fit(X, y)
Introducere în MLflow

Format de stocare

Structura de directoare a unui model:

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

Artefacte

Introducere în MLflow

Conținutul fișierului 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
Introducere în MLflow

MLmodel

MLmodel

Introducere în MLflow

Să exersăm!

Introducere în MLflow

Preparing Video For Download...