開始使用免費開始

調整閾值

在影片中,你看到 NannyML 如何計算閾值,並學到如何依需求自訂。

在這個練習中,你的工作是定義兩種自訂的標準差與常數閾值,然後將它們套用到美國人口普查資料集上,來自 CBPE 演算法的結果。

referenceanalysis 兩個參考與分析資料集,以及 nannyml 函式庫都已預先載入。

本練習屬於課程

在 Python 中監控 Machine Learning

檢視課程

練習說明

  • nannyml.thresholds 匯入 ConstantThresholdStandardDeviationThreshold
  • 初始化標準差方法,並將 std_lower_multiplierstd_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={____: ____, ____: ____})
編輯並執行程式碼