【发布时间】:2020-10-28 14:00:20
【问题描述】:
我有一个数据框(长度为 4 个数据点)并想做一个 Bootstrap X 次。
数据帧示例:
Index A B
0 1 2
1 1 2
2 1 2
3 1 2
我为引导重采样找到了这段代码
boot = resample(df, replace=True, n_samples=len(df), random_state=1)
print('Bootstrap Sample: %s' % boot)
但现在我喜欢重复这个 X 次。我该怎么做?
x=20 的输出。
Sample Nr. Index A B
1 0 1 2
1 1 2
2 1 2
3 1 2
...
20 0 1 2
1 1 2
1 1 2
2 1 2
谢谢你们。
最好的
【问题讨论】:
-
你的意思是我想从我的数据中获取 n 个不同的引导样本?
-
是的,没错@MiguelTrejo。上面的代码只能创建 1 个引导示例。但我想得到 X 很多(比如可能 > 1000)。非常感谢
-
你是指
sample函数还是resample函数?,你指定的参数是针对示例函数的? -
用于重采样功能。所以要更清楚地解释:1)我们有原始数据2)在重新采样的数据中创建这个原始数据的X倍。 2) 代码: boot = resample(df, replace=True, n_samples=len(df), random_state=1) print('Bootstrap Sample: %s' % boot) 从原始数据中仅创建 1 个重采样数据。 --> 所以从原始数据创建更多的重采样数据是目标(重复采样)。 @MiguelTrejo
标签: python dataframe resampling statistics-bootstrap