scipy.stats.bootstrap()中的“bootstrap_distribution”属性是否消失?

vc9ivgsu  于 2023-01-13  发布在  Bootstrap
关注(0)|答案(1)|浏览(184)

下面是scipy.stats.bootstrap()的文档,说明bootstrap_distribution是一个应该包含在返回对象中的属性:


Link to docs here
这是我运行的代码,portfolio['X']只是一个简单的浮点数列,在一个叫做portfolio的panda Dataframe 中。

from scipy.stats import bootstrap

data = portfolio['X']
data = (data,)
res = bootstrap(data, np.std, n_resamples = 100, confidence_level = 0.95)
print(res.__dir__())
print( res.standard_error)
print( res.confidence_interval)

fig, ax = plt.subplots()
ax.hist(res.bootstrap_distribution, bins = 25)
ax.set_title( 'Bootstrap Distribution')
ax.set_xlabel( 'statistic value')
ax.set_ylabel( 'frequency')
plt.show()

以下是我的输出:

['confidence_interval', 'standard_error', '__annotations__', '__module__', '__dict__', '__weakref__', '__doc__', '__dataclass_params__', '__dataclass_fields__', '__init__', '__repr__', '__eq__', '__hash__', '__str__', '__getattribute__', '__setattr__', '__delattr__', '__lt__', '__le__', '__ne__', '__gt__', '__ge__', '__new__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']
0.06917310850614278
ConfidenceInterval(low=0.9366397203338929, high=1.2104462911847762)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-53-728a3ec52bd0> in <module>
      9 
     10 fig, ax = plt.subplots()
---> 11 ax.hist(res.bootstrap_distribution, bins = 25)
     12 ax.set_title( 'Bootstrap Distribution')
     13 ax.set_xlabel( 'statistic value')

AttributeError: 'BootstrapResult' object has no attribute 'bootstrap_distribution'
qyswt5oh

qyswt5oh1#

此属性似乎是添加到1.10.0版本的,请确保您的scipy是最新的

相关问题