我试图实现jackknife方法来计算大量数据(几百万个数据点)的均值及其相应的方差。因为我有大量的数据,如果每次只漏掉一个元素,那就没什么帮助了。我遗漏了单个元素的代码:
def jackknife(x, func):
"""Jackknife estimate of the estimator func"""
x = np.asarray(x)
n = len(x)
idx = np.arange(n)
return np.sum(func(x[idx!=i]) for i in range(n))/float(n)
def jackknife_var(x, func):
"""Jackknife estiamte of the variance of the estimator func."""
x = np.asarray(x)
n = len(x)
idx = np.arange(n)
j_est = jackknife(x, func)
return j_est, (n-1)/(n + 0.0) * np.sum((func(x[idx!=i]) - j_est)**2.0 for i in range(n))
考虑到庞大的数据集,这是相当缓慢的。有人知道如何有效地实现10%数据遗漏的jackknife方法吗?你知道吗
或许可以尝试使用^{} ?你知道吗
相关问题 更多 >
编程相关推荐