你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Objective 类

优化目标。

优化目标。

继承
azure.ai.ml.entities._mixins.RestTranslatableMixin
Objective

构造函数

Objective(goal: str | None, primary_metric: str | None = None)

参数

名称 说明
goal
必需
str

定义超参数优化支持的指标目标。 接受的值为:“最小化”、“最大化”。

primary_metric
str

要优化的指标的名称。

默认值: None
goal
必需
str

定义超参数优化支持的指标目标。 可接受的值为:“最小化”或“最大化”。

primary_metric
必需
str

要优化的指标的名称。

示例

将目标分配给 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"),
   )