MLflow 實驗
MLflow 實驗數據源提供標準 API 來載入 MLflow 實驗執行數據。 您可以從 筆記本實驗載入數據,也可以使用 MLflow 實驗名稱或實驗識別符。
要求
Databricks Runtime 6.0 ML 或更新版本。
從筆記本實驗載入數據
若要從筆記本實驗載入資料,請使用 load()
。
Python程式語言
df = spark.read.format("mlflow-experiment").load()
display(df)
Scala
val df = spark.read.format("mlflow-experiment").load()
display(df)
使用實驗標識碼載入數據
若要從一或多個工作區實驗載入數據,請指定如所示的實驗標識碼。
Python程式語言
df = spark.read.format("mlflow-experiment").load("3270527066281272")
display(df)
Scala
val df = spark.read.format("mlflow-experiment").load("3270527066281272,953590262154175")
display(df)
使用實驗名稱載入數據
您也可以將實驗名稱傳遞至 load()
方法。
Python程式語言
expId = mlflow.get_experiment_by_name("/Shared/diabetes_experiment/").experiment_id
df = spark.read.format("mlflow-experiment").load(expId)
display(df)
Scala
val expId = mlflow.getExperimentByName("/Shared/diabetes_experiment/").get.getExperimentId
val df = spark.read.format("mlflow-experiment").load(expId)
display(df)
根據計量和參數篩選數據
本節中的範例示範如何在從實驗載入數據之後篩選數據。
Python程式語言
df = spark.read.format("mlflow-experiment").load("3270527066281272")
filtered_df = df.filter("metrics.loss < 0.01 AND params.learning_rate > '0.001'")
display(filtered_df)
Scala
val df = spark.read.format("mlflow-experiment").load("3270527066281272")
val filtered_df = df.filter("metrics.loss < 1.85 AND params.num_epochs > '30'")
display(filtered_df)
圖式
數據源所傳回之 DataFrame 的架構為:
root
|-- run_id: string
|-- experiment_id: string
|-- metrics: map
| |-- key: string
| |-- value: double
|-- params: map
| |-- key: string
| |-- value: string
|-- tags: map
| |-- key: string
| |-- value: string
|-- start_time: timestamp
|-- end_time: timestamp
|-- status: string
|-- artifact_uri: string