MLOps Basics
MLOps is the practice of treating models like production software: versioned artifacts, reproducible training, automated deployment, and continuous monitoring. The minimum viable stack tracks experiments, registers models, and detects drift in production. This example sketches the pipeline shape using MLflow conventions.
Track experiments and register a model
EXAMPLE
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
mlflow.set_experiment('iris-classifier')
X, y = load_iris(return_X_y=True)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, random_state=42)
with mlflow.start_run() as run:
n_estimators = 100
max_depth = 5
mlflow.log_param('n_estimators', n_estimators)
mlflow.log_param('max_depth', max_depth)
model = RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth)
model.fit(X_tr, y_tr)
acc = accuracy_score(y_te, model.predict(X_te))
mlflow.log_metric('accuracy', acc)
# Log the model itself as a versioned artifact
mlflow.sklearn.log_model(model, 'model',
registered_model_name='iris-classifier')
print(f'run_id={run.info.run_id} accuracy={acc:.4f}')
# Later, load any registered version for serving:
# model = mlflow.pyfunc.load_model('models:/iris-classifier/Production')
Why it matters
Tracking experiments without registering models is half the job. The registry is what lets you promote a specific version to Staging or Production and roll back when monitoring catches drift.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
# Track experiments: MLflow, Weights & Biases. # Reproducible data: DVC. # Serve: FastAPI / BentoML / Seldon / KServe. # Monitor: drift, accuracy decay, data quality.Try it Yourself »
Discussion
Loading…