在 MLproject 中加入參數
在 MLflow Projects 中定義參數,可以讓你的機器學習程式碼更容易重現。參數也能讓你在不必更動程式碼的情況下,用不同設定執行訓練實驗。
在這個練習中,你要為主要進入點把參數加入 MLproject 檔案。這個進入點會用來執行 train_model.py 指令碼,從保險資料訓練一個 Logistic Regression 模型。
這個指令碼接受兩個參數:n_jobs 和 fit_intercept,它們是用於訓練模型的超參數。你會先在 MLproject 檔案中加入 n_jobs 參數,接著加入 fit_intercept 參數。最後,將這兩個參數加入主要進入點所執行的指令中。
本練習屬於課程
MLflow 入門
練習說明
- 建立名為
n_jobs的參數,型別為int,預設值為1。 - 建立第二個名為
fit_intercept的參數,型別為bool,預設值為True。 - 將兩個參數都傳入指令中,並確保
n_jobs放在前面,後面接著fit_intercept。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
"""
name: insurance_model
python_env: python_env.yaml
entry_points:
main:
parameters:
# Create parameter for number of jobs as n_jobs
____:
____: ____
____: ____
# Create parameter for fit_intercept
____:
____: ____
____: ____
# Add parameters to be passed into the command
command: "python3.9 train_model.py {____} {____}"
"""