在 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 {____} {____}"
"""