MLflow

Open Source Databricks MLOps Multi-language

Visão Geral

MLflow é uma plataforma open-source para gerenciar o ciclo de vida completo de machine learning, incluindo experimentação, reprodutibilidade, deployment e registro central de modelos.

Desenvolvido pela Databricks, MLflow oferece quatro componentes principais que trabalham juntos para simplificar o desenvolvimento e operação de modelos ML em qualquer biblioteca, algoritmo, ferramenta de deployment ou linguagem.

Componentes Principais

MLflow Tracking

Rastreamento de experimentos, parâmetros, métricas e artefatos

MLflow Projects

Formato padrão para empacotar código ML reutilizável

MLflow Models

Formato padrão para empacotar modelos ML

Model Registry

Armazenamento centralizado, versionamento e gerenciamento de modelos

Principais Características

  • Experiment Tracking: Rastreamento automático
  • Model Versioning: Controle de versões
  • Model Deployment: Deploy simplificado
  • Multi-framework: Suporte a qualquer biblioteca
  • REST API: Integração via API
  • UI Dashboard: Interface web intuitiva
  • Artifact Storage: Armazenamento de artefatos
  • Model Serving: Serving de modelos

Exemplo Prático

Exemplo de tracking de experimento com MLflow:

import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_wine
from sklearn.metrics import accuracy_score

# Configurar experimento
mlflow.set_experiment("wine_classification")

# Carregar dados
wine = load_wine()
X_train, X_test, y_train, y_test = train_test_split(
    wine.data, wine.target, test_size=0.2, random_state=42
)

# Iniciar run do MLflow
with mlflow.start_run():
    # Parâmetros do modelo
    n_estimators = 100
    max_depth = 6
    
    # Log parâmetros
    mlflow.log_param("n_estimators", n_estimators)
    mlflow.log_param("max_depth", max_depth)
    
    # Treinar modelo
    rf = RandomForestClassifier(
        n_estimators=n_estimators,
        max_depth=max_depth,
        random_state=42
    )
    rf.fit(X_train, y_train)
    
    # Fazer predições
    y_pred = rf.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    
    # Log métricas
    mlflow.log_metric("accuracy", accuracy)
    
    # Log modelo
    mlflow.sklearn.log_model(rf, "random_forest_model")
    
    # Log artefatos adicionais
    import matplotlib.pyplot as plt
    feature_importance = rf.feature_importances_
    plt.figure(figsize=(10, 6))
    plt.bar(wine.feature_names, feature_importance)
    plt.title("Feature Importance")
    plt.xticks(rotation=45)
    plt.tight_layout()
    plt.savefig("feature_importance.png")
    mlflow.log_artifact("feature_importance.png")
    
    print(f"Accuracy: {accuracy:.4f}")
    print(f"Run ID: {mlflow.active_run().info.run_id}")

Tutoriais e Recursos

Informações Rápidas
  • Desenvolvedor: Databricks
  • Primeira Versão: 2018
  • Linguagem: Python, R, Java, Scala
  • Licença: Apache 2.0
  • Versão Atual: 2.8+
Tecnologias Relacionadas