修改阈值
在视频中,您了解了 NannyML 如何计算阈值,并学习了如何根据您的场景进行自定义。
在本练习中,您的任务是定义两个自定义的标准差阈值和常量阈值,然后将它们应用到针对 US Census 数据集的 CBPE 算法结果上。
参考集与分析集已分别预加载为 reference 和 analysis,nannyml 库也已导入。
本练习是课程的一部分
Python 中的机器学习监控
练习说明
- 从
nannyml.thresholds导入ConstantThreshold和StandardDeviationThreshold。 - 初始化标准差方法,并将
std_lower_multiplier与std_upper_multiplier参数设为2。 - 初始化常量阈值方法,将下界参数设为
0.9,上界设为0.98。 - 将常量阈值方法用于
f1指标,将标准差方法用于accuracy指标,并传递给 CBPE 算法。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import custom thresholds
from ____.____ import ____, ____
# Initialize custom thresholds
stdt = ____(____=____, ____=____)
ct = ____(____=____, ____=____)
# Initialize the CBPE algorithm
estimator = nannyml.CBPE(
problem_type='classification_binary',
y_pred_proba='predicted_probability',
y_pred='prediction',
y_true='employed',
metrics=['roc_auc', 'accuracy', 'f1'],
thresholds={____: ____, ____: ____})