調整閾值
在影片中,你看到 NannyML 如何計算閾值,並學到如何依需求自訂。
在這個練習中,你的工作是定義兩種自訂的標準差與常數閾值,然後將它們套用到美國人口普查資料集上,來自 CBPE 演算法的結果。
reference 與 analysis 兩個參考與分析資料集,以及 nannyml 函式庫都已預先載入。
本練習屬於課程
在 Python 中監控 Machine Learning
練習說明
- 從
nannyml.thresholds匯入ConstantThreshold與StandardDeviationThreshold。 - 初始化標準差方法,並將
std_lower_multiplier與std_upper_multiplier參數設為2。 - 初始化常數閾值方法,將 lower 參數設為
0.9、upper 設為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={____: ____, ____: ____})