Python のクイックスタートQuick start Python
MLflow は、エンド ツー エンドの機械学習ライフサイクルを管理するためのオープンソース プラットフォームです。MLflow is an open source platform for managing the end-to-end machine learning lifecycle. MLflow は、メトリックをログに記録するための単純な Api (モデル損失など)、パラメーター (学習率など)、および適合モデルを提供します。これにより、トレーニング結果の分析や、後でのモデルのデプロイが簡単になります。MLflow provides simple APIs for logging metrics (for example, model loss), parameters (for example, learning rate), and fitted models, making it easy to analyze training results or deploy models later on.
このセクションの内容:In this section:
- MLflow のインストールInstall MLflow
- トレーニングの実行を MLflow に自動的に記録するAutomatically log training runs to MLflow
- 結果の表示View results
- 追加のメトリック、パラメーター、およびモデルの追跡Track additional metrics, parameters, and models
- ノートブックの例Example notebooks
- 詳細情報Learn more
MLflow のインストールInstall MLflow
Machine Learning に Databricks Runtimeを使用している場合は、mlflow が既にインストールされています。If you’re using Databricks Runtime for Machine Learning, MLflow is already installed. それ以外の場合は、 PyPI から MLflow パッケージをインストールします。Otherwise, install the MLflow package from PyPI.
トレーニングの実行を MLflow に自動的に記録するAutomatically log training runs to MLflow
MLflow は、 mlflow.<framework>.autolog()
多くの ML フレームワークで記述されたトレーニングコードを自動的にログに記録する api を提供します。MLflow provides mlflow.<framework>.autolog()
APIs to automatically log training code written in many ML frameworks.
この API は、トレーニングコードを実行してモデル固有のメトリック、パラメーター、およびモデルアーティファクトをログに記録する前に呼び出すことができます。You can call this API before running training code to log model-specific metrics, parameters, and model artifacts.
TensorflowTensorflow
# Also autoinstruments tf.keras
import mlflow.tensorflow
mlflow.tensorflow.autolog()
KerasKeras
# Use import mlflow.tensorflow and mlflow.tensorflow.autolog() if using tf.keras
import mlflow.keras
mlflow.keras.autolog()
XgboostXgboost
import mlflow.xgboost
mlflow.xgboost.autolog()
LightgbmLightgbm
import mlflow.lightgbm
mlflow.lightgbm.autolog()
Scikit-learnScikit-learn
import mlflow.sklearn
mlflow.sklearn.autolog()
PysparkPyspark
でチューニングを実行 pyspark.ml
すると、メトリックとモデルが MLflow に自動的に記録されます。If performing tuning with pyspark.ml
, metrics and models are automatically logged to MLflow.
「 MLlib と自動 Mllib 追跡の Apache Spark」を参照してください。See Apache Spark MLlib and automated MLflow tracking
結果の表示View results
Machine learning コードを実行した後は、[実験の実行] サイドバーを使用して結果を表示できます。After executing your machine learning code, you can view results using the Experiment Runs sidebar. クイックスタートで使用される実験、実行、ノートブックのリビジョンを表示する方法については、「 notebook 実験の表示 」を参照してください。See View notebook experiment for instructions on how to view the experiment, run, and notebook revision used in the quick start.
追加のメトリック、パラメーター、およびモデルの追跡Track additional metrics, parameters, and models
Mlflow 追跡ログ apiを直接呼び出すことによって、追加情報をログに記録できます。You can log additional information by directly invoking the MLflow Tracking logging APIs.
数値メトリック:Numerical metrics:
import mlflow mlflow.log_metric("accuracy", 0.9)
トレーニングパラメーター:Training parameters:
import mlflow mlflow.log_param("learning_rate", 0.001)
モデル:Models:
Scikit-learnScikit-learn
import mlflow.sklearn mlflow.sklearn.log_model(model, "myModel")
PysparkPyspark
import mlflow.spark mlflow.spark.log_model(model, "myModel")
XgboostXgboost
import mlflow.xgboost mlflow.xgboost.log_model(model, "myModel")
TensorflowTensorflow
import mlflow.tensorflow mlflow.tensorflow.log_model(model, "myModel")
KerasKeras
import mlflow.keras mlflow.keras.log_model(model, "myModel")
PytorchPytorch
import mlflow.pytorch mlflow.pytorch.log_model(model, "myModel")
SpacySpacy
import mlflow.spacy mlflow.spacy.log_model(model, "myModel")
その他の成果物 (ファイル):Other artifacts (files):
import mlflow mlflow.log_artifact("/tmp/my-file", "myArtifactPath")
サンプルの NotebookExample notebooks
必要条件Requirements
Databricks Runtime 6.4 以上または Databricks Runtime 6.4 ML 以降。Databricks Runtime 6.4 or above or Databricks Runtime 6.4 ML or above.
ノートブックNotebooks
MLflow の追跡を Python で使用する場合は、MLflow API を使用することをお勧めし autolog()
ます。The recommended way to get started using MLflow tracking with Python is to use the MLflow autolog()
API. MLflow の autologging 機能を使用すると、1行のコードで、結果として得られるモデル、モデルの作成に使用されるパラメーター、およびモデルスコアが自動的にログに記録されます。With MLflow’s autologging capabilities, a single line of code automatically logs the resulting model, the parameters used to create the model, and a model score. 次の notebook は、autologging を使用して実行を設定する方法を示しています。The following notebook shows you how to set up a run using autologging.
MLflow 自動ログ記録クイック スタート Python ノートブックMLflow Autologging Quick Start Python notebook
トレーニングの実行ごとにログに記録されるメトリックをより詳細に制御する必要がある場合、またはテーブルやプロットなどの追加のアーティファクトをログに記録する必要がある場合は、次の notebook に示されている MLflow のログ記録 API 関数を使用できます。If you need more control over the metrics logged for each training run, or want to log additional artifacts such as tables or plots, you can use the MLflow logging API functions demonstrated in the following notebook.