intro-stat-learning / ISLP_labs

Up-to-date version of labs for ISLP
BSD 2-Clause "Simplified" License
660 stars 388 forks source link

Chapter 5 Conceptual exercise 2h #22

Closed Cookiee-monster closed 9 months ago

Cookiee-monster commented 9 months ago

Hi, I think I found an error in the code snippet in exercise 2 in Chapter 5.

In the book (page 225) it's given as:

rng = np.random.default_rng(10) 
store = np.empty(10000)
for i in range(10000):
    store[i] = np.sum(rng.choice(100, replace=True) == 4) >0
np.mean(store)

During each iteration, only one number is chosen instead of a full sample.

I think it should be corrected to:

rng = np.random.default_rng(10) 
store = np.empty(10000)
for i in range(10000):
    store[i] = np.sum(rng.choice(100, size=100, replace=True) == 4) >0
    # as we would like to sample 100 observations at each attempt and check if 4 is among them
np.mean(store)

It gives 0.6362 which is the probability of the jth observation chosen when n goes infinity.

BR Grzegorz

jonathan-taylor commented 9 months ago

Your are correct. This error has previously been identified here:

https://www.statlearning.com/errata-python-edition