使用 Kolmogorov-Smirnov 檢定偵測資料漂移
在成功部署你的心臟疾病預測模型後,你持續監控其效能與輸入資料。你注意到 2 月份新收集的資料中,部分關鍵特徵的分佈和 1 月份訓練時的資料看起來有些不同。這類差異可能會影響模型效能,因此偵測並處理它們非常重要。
在本練習中,你將使用 Kolmogorov-Smirnov(K-S)檢定來偵測 1 月與 2 月資料集之間是否存在潛在的資料漂移。名為 january_data 與 february_data 的範例資料集已經為你載入。
本練習屬於課程
端到端機器學習
練習說明
- 從
scipy.stats模組匯入ks_2samp函式。 - 使用提供的範例資料集
january_data與february_data執行 Kolmogorov-Smirnov 檢定;計算檢定統計量與 p-value。 - 檢查 p-value 是否小於 0.05,代表存在資料漂移;若偵測到資料漂移,請列印
"Data drift detected.",否則列印"No data drift detected."
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the ks_2samp function
from ____.____ import ____
# Calculate the test statistic and p value
test_statistic, p_value = ____(____, ____)
# Check the p-value and print the detection result
if ____:
print("Data drift detected.")
else:
print("No data drift detected.")