資料與模型版本控管

Developing Machine Learning Models for Production

Sinan Ozdemir

Data Scientist, Entrepreneur, and Author

主版與次版控管

兩種版本:主版與次版

  • 主版表示資料或模型有重大變更

  • 次版表示小幅變更

透過主版/次版,你能看出資料或模型變更的方式與內容

Developing Machine Learning Models for Production

訓練資料版本控管

  • 唯一的主版/次版標籤或時間戳
  • 確保實驗可重現且可追溯
  • 可輕鬆回到先前的資料版本
  • 檢視資料隨時間的變化

範例:

  1. Data V 1.0 是初始資料集
  2. Data V 1.1 加入更多特徵轉換
  3. Data V 1.2 新增特徵選取方法
  4. Data V 2.0 納入全新資料來源
Developing Machine Learning Models for Production

Feature store(特徵儲存庫)

  • 用於儲存與管理不同特徵版本的集中式儲存庫
  • 輕鬆追蹤特徵的不同版本
  • 在不同實驗中重複使用特徵
  • 提升協作與實驗的完整性
  • 減少重工
Developing Machine Learning Models for Production

ML 模型版本控管

  • 追蹤不同版本的 ML 模型
  • 確保實驗可重現且可追溯
  • 可輕鬆回滾到先前模型版本
  • 通常會對應訓練資料版本,但不一定總是如此

範例:

  1. Model V 1.0 是初始模型(Random Forest)
  2. Model V 1.1 為相同模型,針對 Data V 1.1 微調
  3. Model V 2.0 為 XGBoost 模型,針對 Data V 1.2 微調
  4. Model V 2.1 為 XGBoost 模型,針對 Data V 2.0 微調
Developing Machine Learning Models for Production

Model store(模型儲存庫)

  • 用於儲存與管理不同模型版本的集中式儲存庫
  • 輕鬆追蹤模型的不同版本
  • 可回滾至先前版本
Developing Machine Learning Models for Production

使用 MLflow 進行模型版本控管的範例

import mlflow

# Start a new mlflow run
with mlflow.start_run() as run:
    # Log model version as a parameter
    mlflow.log_param("model_version", "1.0")

    # Train and save the model
    model = train_model()
    mlflow.sklearn.log_model(model, "model")
Developing Machine Learning Models for Production

一起來練習吧!

Developing Machine Learning Models for Production

Preparing Video For Download...