|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
原文链接:https://zhuanlan.zhihu.com/p/107978939
声明:以下代码是在理解原文代码的基础上补充的理解注释,具体介绍看原文。
原文代码:
- import numpy as np
- from sklearn.utils import resample
-
- def scaleyellow(samples): #1次抽样中黄色/蓝色的比率
- count = 0.0
- total = samples.size
- for colour in samples:
- if (colour == 0):
- count += 1.0
- # print(count)
- return count / (total - count)
-
-
- blue = (np.ones(1000))
- yellow = (np.zeros(800))
-
- # yellow/blue=0.8
- all = np.hstack((blue, yellow))
- scale = 0.0
- iter = 10000
- for i in range(iter):
- bootstrapSamples = resample(all, n_samples=100, replace=1)#这里replace是什么?
- # print(bootstrapSamples)
- tempscale = scaleyellow(bootstrapSamples) #记录每次抽样黄球/蓝球的比率
- scale += tempscale
- print(scale / iter) #注意这里的书写!一共进行了10000此取均值,用均值估计总体
复制代码 |
|