開始使用免費開始

使用 Kolmogorov-Smirnov 檢定偵測資料漂移

在成功部署你的心臟疾病預測模型後,你持續監控其效能與輸入資料。你注意到 2 月份新收集的資料中,部分關鍵特徵的分佈和 1 月份訓練時的資料看起來有些不同。這類差異可能會影響模型效能,因此偵測並處理它們非常重要。

在本練習中,你將使用 Kolmogorov-Smirnov(K-S)檢定來偵測 1 月與 2 月資料集之間是否存在潛在的資料漂移。名為 january_datafebruary_data 的範例資料集已經為你載入。

本練習屬於課程

端到端機器學習

檢視課程

練習說明

  • scipy.stats 模組匯入 ks_2samp 函式。
  • 使用提供的範例資料集 january_datafebruary_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.")
編輯並執行程式碼