Katsu
Katsu

Reputation: 8925

`bootstrap_distribution` attribute in scipy.stats.bootstrap() gone?

Here is the documentation of scipy.stats.bootstrap(), showing that bootstrap_distribution is an attribute that should be included in the return object:

enter image description here Link to docs here

Here is my code that I'm running with, portfolio['X'] is just a simple column of floats in a pandas dataframe called portfolio.

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

Here is my output:

['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'

Upvotes: 3

Views: 1424

Answers (1)

Polatkan Polat
Polatkan Polat

Reputation: 576

this attribute seems to be added with 1.10.0 release , make sure your scipy is up to date

Upvotes: 4

Related Questions