Objective 類別
優化目標。
優化目標。
- 繼承
-
azure.ai.ml.entities._mixins.RestTranslatableMixinObjective
建構函式
Objective(goal: str | None, primary_metric: str | None = None)
參數
名稱 | Description |
---|---|
goal
必要
|
定義超參數微調支援的計量目標。 接受的值包括:「最小化」、「最大化」。 |
primary_metric
|
要優化的計量名稱。 預設值: None
|
goal
必要
|
定義超參數微調支援的計量目標。 可接受的值為:「最小化」或「最大化」。 |
primary_metric
必要
|
要優化的計量名稱。 |
範例
將目標指派給 SweepJob。
from azure.ai.ml.entities import CommandJob
from azure.ai.ml.sweep import BayesianSamplingAlgorithm, Objective, SweepJob, SweepJobLimits
command_job = CommandJob(
inputs=dict(kernel="linear", penalty=1.0),
compute=cpu_cluster,
environment=f"{job_env.name}:{job_env.version}",
code="./scripts",
command="python scripts/train.py --kernel $kernel --penalty $penalty",
experiment_name="sklearn-iris-flowers",
)
sweep = SweepJob(
sampling_algorithm=BayesianSamplingAlgorithm(),
trial=command_job,
search_space={"ss": Choice(type="choice", values=[{"space1": True}, {"space2": True}])},
inputs={"input1": {"file": "top_level.csv", "mode": "ro_mount"}},
compute="top_level",
limits=SweepJobLimits(trial_timeout=600),
objective=Objective(goal="maximize", primary_metric="accuracy"),
)