Introduction to MLflow
Weston Bassler
Senior MLOps Engineer
Simplify ML library integration
Simplify Deployment
Convention called "Flavors"
Write custom tools from ML libraries
Flavors simplify the new for custom code
# Import flavor from mlflow module
import mlflow.FLAVOR
# Automatically log model and metrics
mlflow.FLAVOR.autolog()
# Scikit-learn built-in flavor
mlflow.sklearn.autolog()
# 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)
Model will be logged automatically on model.fit()
MODEL.get_params()
# 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}
# Model
lr = LinearRegression()
lr.fit(X, y)
# Model
lr = LinearRegression()
lr.fit(X, y)
Directory structure for a model:
model/
MLmodel
model.pkl
python_env.yaml
requirements.txt
# Autolog
mlflow.sklearn.autolog()
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
Introduction to MLflow