引导程序#

astropy.stats.bootstrap(data, bootnum=100, samples=None, bootfunc=None)[源代码]#

在numpy数组上执行引导重采样。

Bootstrap重采样用于理解样本估计的置信区间。此函数返回使用替换重新采样的数据集版本(“案例引导”)。这些都可以通过一个函数或统计来产生一个值的分布,然后可以用来找到置信区间。

参数:
data : ndarray恩达雷

N-D阵列。引导重采样将在第一个索引上执行,因此第一个索引应该访问要引导的相关信息。

bootnum : int ,可选PYTHON:int,可选

引导重采样数

samples : int ,可选PYTHON:int,可选

每个重采样中的样本数。违约 None 将采样数设置为数据点的数目

bootfunc : function ,可选Python:函数,可选

函数来减少重采样的数据。每个引导重采样都将通过此函数进行,并返回结果。如果 None ,则将返回引导数据

返回:
boot : ndarray恩达雷

如果bootfunc为None,则每行都是数据的引导重采样。如果指定了bootfunc,则列将对应于bootfunc的输出。

实例

获取两次重采样数组:

>>> 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,)