MLFlowで実験を記録する

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

MLFlow

MLflow がないと…

  • 実験が未追跡・散在
  • 実行が不揃いで比較困難
  • 再現不能・紛失

MLflow があると…

  • 実験実行を追跡・整理
  • 標準化された実行を比較
  • 再現可能
  • 共有・デプロイが容易
End-to-End Machine Learning

実験の作成

mlflow.set_experiment()

  • 実験名を設定
  • 実行のワークスペースを提供

 

使い方:

import mlflow

# Set an experiment name, which is a workspace for your runs
mlflow.set_experiment("Heart Disease Classification")
End-to-End Machine Learning

実験の実行

# Start a new run in this experiment
with mlflow.start_run():
    # Train a model, get the prediction accuracy
    logistic_model = LogisticRegression()

# Log parameters, eg: mlflow.log_param("n_estimators", logistic_model.n_estimators)
# Log metrics (accuracy in this case) mlflow.log_metric("accuracy", logistic_model.accuracy)
# Print out metrics print("Model accuracy: %.3f" % accuracy)
Model accuracy: 0.96
End-to-End Machine Learning

実験の取得

 

mlflow.get_run(run_id)

  • 特定の実行のメタデータ

 

mlflow.search_runs()

  • 複数実行の指標を DataFrame で返す

使い方:

# Fetch the run data and print params
run_data = mlflow.get_run(run_id)
print(run_data.data.params)
print(run_data.data.metrics)

# Search all runs in experiment
exp_id = run_data.info.experiment_id
runs_df = mlflow.search_runs(exp_id)
{'epochs': '20', 'accuracy': 0.95}
End-to-End Machine Learning

MLFlow UI

 

MLFlow の実験ダッシュボード

 

MLFlow の実験ページ例

End-to-End Machine Learning

MLFlow UI(続き)

 

指標の改善を示すグラフ例

 

実行間での指標比較例

End-to-End Machine Learning

MLflow リソース

  • MLflow の概要 MLflow の概要
  • MLflow 公式サイト MLflow 公式サイト
End-to-End Machine Learning

Passons à la pratique !

End-to-End Machine Learning

Preparing Video For Download...