TabularPredictor.calibrate_decision_threshold

TabularPredictor.calibrate_decision_threshold(data: DataFrame | str | None = None, metric: str | Scorer | None = None, model: str = 'best', decision_thresholds: int | List[float] = 25, secondary_decision_thresholds: int | None = 19, subsample_size: int | None = 1000000, verbose: bool = True) float[source]

在二元分类中校准决策阈值以优化给定的指标。 您可以将此方法的输出作为输入传递给predictor.set_decision_threshold以更新预测器。 如果predictor.problem_type != ‘binary’,将引发AssertionError。

请注意,虽然校准决策阈值可以帮助提高特定指标,但其他指标可能会因此得分降低。例如,在balanced_accuracy上进行校准通常会损害accuracy。用户在使用决策阈值校准时应牢记这一点。

Parameters:
  • data (pd.DataFramestr, 可选) – 用于校准的数据。必须包含标签列。 我们建议将此值保持为None,除非您是高级用户并了解其影响。 如果为None,将使用内部数据,例如保留验证数据或交叉验证预测。

  • metric (autogluon.core.metrics.Scorerstr, 默认 = None) – 在校准期间优化的指标。 如果为None,则使用 predictor.eval_metric

  • model (str, default = 'best') – 用于在校准阈值时预测概率的模型。 如果为‘best’,将使用predictor.model_best

  • decision_thresholds (int | List[float], default = 25) – 在0.5两侧搜索的决策阈值数量。 默认值为25,将导致搜索51个阈值:[0.00, 0.02, 0.04, …, 0.48, 0.50, 0.52, …, 0.96, 0.98, 1.00] 或者,可以传递一个决策阈值列表,并且只搜索列表中的阈值。

  • secondary_decision_thresholds (int | None, default = 19) –

    在第一阶段确定的阈值两侧检查的次级决策阈值的数量。 如果为None,则跳过。 例如,如果decision_thresholds=50并且0.14被确定为最佳阈值,而secondary_decision_threshold=9,

    那么将检查以下额外的阈值:

    [0.131, 0.132, 0.133, 0.134, 0.135, 0.136, 0.137, 0.138, 0.139, 0.141, 0.142, 0.143, 0.144, 0.145, 0.146, 0.147, 0.148, 0.149]

  • subsample_size (int | None, default = 1000000) – 当 subsample_size 不为 None 且 data 包含的行数超过 subsample_size 时,采样到 subsample_size 行以加快校准速度。 通常不需要使用超过 100 万行进行校准。

  • verbose (bool, default = True) – 如果为True,将记录校准过程的信息。

Returns:

  • 决策阈值 (一个介于0和1之间的浮点数,定义了预测的决策边界)

  • 最大化模型数据上的指标得分。