引导程序#
- astropy.stats.bootstrap(data, bootnum=100, samples=None, bootfunc=None)[源代码]#
在numpy数组上执行引导重采样。
Bootstrap重采样用于理解样本估计的置信区间。此函数返回使用替换重新采样的数据集版本(“案例引导”)。这些都可以通过一个函数或统计来产生一个值的分布,然后可以用来找到置信区间。
- 参数:
- 返回:
- boot :
ndarray
恩达雷 如果bootfunc为None,则每行都是数据的引导重采样。如果指定了bootfunc,则列将对应于bootfunc的输出。
- boot :
实例
获取两次重采样数组:
>>> from astropy.stats import bootstrap >>> import numpy as np >>> from astropy.utils import NumpyRNGContext >>> bootarr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) >>> with NumpyRNGContext(1): ... bootresult = bootstrap(bootarr, 2) ... >>> bootresult array([[6., 9., 0., 6., 1., 1., 2., 8., 7., 0.], [3., 5., 6., 3., 5., 3., 5., 8., 8., 0.]]) >>> bootresult.shape (2, 10)
获取数组的统计信息
>>> with NumpyRNGContext(1): ... bootresult = bootstrap(bootarr, 2, bootfunc=np.mean) ... >>> bootresult array([4. , 4.6])
获取阵列上有两个输出的统计信息
>>> test_statistic = lambda x: (np.sum(x), np.mean(x)) >>> with NumpyRNGContext(1): ... bootresult = bootstrap(bootarr, 3, bootfunc=test_statistic) >>> bootresult array([[40. , 4. ], [46. , 4.6], [35. , 3.5]]) >>> bootresult.shape (3, 2)
在数组上获取包含两个输出的统计信息,只保留第一个输出
>>> bootfunc = lambda x:test_statistic(x)[0] >>> with NumpyRNGContext(1): ... bootresult = bootstrap(bootarr, 3, bootfunc=bootfunc) ... >>> bootresult array([40., 46., 35.]) >>> bootresult.shape (3,)