使用 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 值。 - 检查 p 值是否小于 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.")