k-s检验代码

https://blog.csdn.net/chehec2010/article/details/136991421?ops_request_misc=%257B%2522request%255Fid%2522%253A%25226cc12115b364e2a38467993f08a18139%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=6cc12115b364e2a38467993f08a18139&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-136991421-null-null.142^v100^pc_search_result_base5&utm_term=ks%E6%A3%80%E9%AA%8Cpython&spm=1018.2226.3001.4187

from scipy.stats import ks_2samp
import numpy as np

# 假设这是两个数据集的数据
data_set_1 = np.random.normal(0, 1, 1000) # 正态分布,均值0,标准差1
data_set_2 = np.random.normal(0.5, 1.5, 1000) # 正态分布,均值0.5,标准差1.5

# 进行KS检验
statistic, p_value = ks_2samp(data_set_1, data_set_2)

# 输出结果
print(f"KS统计量: {statistic}")
print(f"P值: {p_value}")

# 判断显著性
alpha = 0.05
if p_value < alpha:
print("两个数据集的分布有显著差异。")
else:
print("两个数据集的分布没有显著差异。")
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/chehec2010/article/details/136991421

posted on 2024-12-06 09:06  独上兰舟1  阅读(5)  评论(0编辑  收藏  举报