
bootstrap置信区间:
假设不能知道总体分布F。但是有一个分布F的数据样本,容量为N。以此样品中重新取样的方式提取N容量的样品。这个样本称为bootstrap样本。从原始样本中独立提取多个bootstrap样本,统计推断出整个F,称为非参数bootstrap方法(也称为自助方法)。
使用bootstrap方法可以求得变量(参数)的置信区间,称作bootstrap置信区间。
bootstrap置信区间:
使用Python计算bootstrap置信区间:
这里以一维数据为例,取样本均值作为样本估计量。代码如下:
import numpy as np
def average(data):
return sum(data) / len(data)
def bootstrap(data, B, c, func):
"""
计算bootstrap置信区间
:param data: array 保存样本数据
:param B: 抽样次数 通常B>=1000
:param c: 置信水平
:param func: 样本估计量
:return: bootstrap置信区间上下限
"""
array = np.array(data)
n = len(array)
sample_result_arr = []
for i in range(B):
index_arr = np.random.randint(0, n, size=n)
data_sample = array[index_arr]
sample_result = func(data_sample)
sample_result_arr.append(sample_result)
a = 1 - c
k1 = int(B * a / 2)
k2 = int(B * (1 - a / 2))
auc_sample_arr_sorted = sorted(sample_result_arr)
lower = auc_sample_arr_sorted[k1]
higher = auc_sample_arr_sorted[k2]
return lower, higher
if __name__ == '__main__':
result = bootstrap(np.random.randint(0, 50, 50), 1000, 0.95, average)
print(result)
输出:
(20.48, 28.32)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END




















暂无评论内容