Skill: guohongbin-git/mlops-observability-cn (version 1.0.0)

--- name: mlops-observability-cn version: 1.0.0 description: Full stack observability - reproducibility, lineage, monitoring, alerting license: MIT --- # MLOps Observability 👁️ Glass box system - reproducible, traceable, monitored. ## Features ### 1. MLflow Tracking 📊 Complete tracking setup: ```bash cp references/mlflow-tracking.py ../your-project/src/tracking.py ``` Tracks: - Config (params) - Metrics (accuracy, loss) - Models (sklearn/pytorch) - Datasets (lineage) - Git commit (reproducibility) ### 2. Drift Detection 📉 Using Evidently: ```python from evidently import Report from evidently.metrics import DataDriftTable report = Report(metrics=[DataDriftTable()]) report.run(reference_data=train, current_data=prod) ``` ### 3. Explainability (SHAP) 🔍 ```python import shap explainer = shap.TreeExplainer(model) shap_values = explainer.shap_values(X) shap.summary_plot(shap_values, X) ``` ## Quick Start ```bash # Copy tracking code cp references/mlflow-tracking.py ./src/ # Add to training script: # from tracking import setup_tracking, log_training_run ``` ## Reproducibility ```python # Set all seeds import random, numpy as np, torch random.seed(42) np.random.seed(42) torch.manual_seed(42) # Track git commit import git commit = git.Repo().head.commit.hexsha mlflow.log_param("git_commit", commit) ``` ## Monitoring Checklist - [ ] Random seeds fixed - [ ] MLflow tracking enabled - [ ] System metrics logged - [ ] Drift detection setup - [ ] SHAP explanations saved - [ ] Alerts configured ## Alerting - **Local**: `plyer` notifications - **Production**: PagerDuty (critical) / Slack (warnings) ## Author Converted from [MLOps Coding Course](https://github.com/MLOps-Courses/mlops-coding-skills) ## Changelog ### v1.0.0 (2026-02-18) - Initial OpenClaw conversion - Added MLflow tracking code

path: package.json
content: {
  "name": "mlops-observability-cn",
  "version": "1.0.0",
  "description": "MLOps Observability - Reproducibility, lineage, monitoring, alerting",
  "main": "SKILL.md",
  "keywords": [
    "mlops",
    "observability",
    "mlflow",
    "monitoring",
    "drift-detection",
    "shap"
  ],
  "author": "money-maker-ai",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/MLOps-Courses/mlops-coding-skills"
  }
}


path: references/mlflow-tracking.py
content: # MLflow tracking example

import mlflow
from mlflow import MlflowClient
from pathlib import Path
import pandas as pd


def setup_tracking():
    """Setup MLflow tracking"""
    # Local tracking
    mlflow.set_tracking_uri("file:./mlruns")
    
    # Or remote server
    # mlflow.set_tracking_uri("http://localhost:5000")
    
    # Set experiment
    mlflow.set_experiment("my-experiment")


def log_training_run(config: dict, metrics: dict, model):
    """Log a complete training run"""
    with mlflow.start_run():
        # Log config
        mlflow.log_params(config)
        
        # Auto-log sklearn/pytorch/tensorflow
        mlflow.autolog()
        
        # Log custom metrics
        for name, value in metrics.items():
            mlflow.log_metric(name, value)
        
        # Log model
        mlflow.sklearn.log_model(model, "model")
        
        # Log dataset
        df = pd.read_csv(config['data_path'])
        dataset = mlflow.data.from_pandas(df, name="training_data")
        mlflow.log_input(dataset, context="training")
        
        # Log git commit
        import git
        repo = git.Repo()
        commit = repo.head.commit.hexsha
        mlflow.set_tag("git_commit", commit)


def register_model(model_name: str, run_id: str):
    """Register model to MLflow Model Registry"""
    client = MlflowClient()
    
    # Register
    model_uri = f"runs:/{run_id}/model"
    model_version = client.create_model_version(
        name=model_name,
        source=model_uri,
        run_id=run_id
    )
    
    # Set alias
    client.set_registered_model_alias(
        name=model_name,
        alias="production",
        version=model_version.version
    )
    
    print(f"✅ Registered {model_name} v{model_version.version}")


def load_production_model(model_name: str):
    """Load production model from registry"""
    client = MlflowClient()
    
    # Get by alias
    model_version = client.get_model_version_by_alias(
        name=model_name,
        alias="production"
    )
    
    # Load model
    model = mlflow.sklearn.load_model(
        f"models:/{model_name}/{model_version.version}"
    )
    
    return model


# Usage example
if __name__ == "__main__":
    setup_tracking()
    
    config = {
        "n_estimators": 100,
        "max_depth": 10,
        "data_path": "data/train.csv"
    }
    
    # After training
    metrics = {
        "accuracy": 0.95,
        "f1_score": 0.93
    }
    
    # log_training_run(config, metrics, trained_model)


Security scan verdicts — ClawScan: clean | static analysis:  | VirusTotal: clean | SkillSpector: clean (LOW)