Can anyone tell me how to solve exercise from week 19 ,first video.
You can start with this code:
fig, axs = plt.subplots(3, 1)
num_samples = 1000
i = 0
for sample_size in [100, 1000, 10000]:
#dice throw, uniform, outcome: 1, 2, 3, 4, 5, 6
#Each element represent the face up on dice(R.V), sum along the columns will form the new R.V.
samples = np.random.randint(1, 6, (num_samples, sample_size))
x = samples.sum(axis=1)
#see if CLT holds.
axs[i].hist(x, bins=50)
i = i + 1
Here, is my solution
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
#build Uniform distribution as the population, you can replace the uniform distribution by Binomial, Normal, etc.
s = np.random.uniform(0,1,1000000)
take sample from polulation
no_sample = [10,100,1000,10000] mean_sampl = [] sampl_size = 250 for i in no_sample: each_s_m = [] for j in range(0,i): rc = random.choices(s, k=sampl_size) each_s_m.append(sum(rc)/len(rc)) mean_sampl.append(each_s_m)
#> Plot the mean distribution
cols = 2 rows = 2 fig, ax = plt.subplots(rows, cols, figsize=(20,15)) n = 0 for i in range(0, rows): for j in range(0, cols): ax[i, j].hist(mean_sampl[n], 200, density=True) ax[i, j].set_title(label="number of sampling :" + str(no_sample[n])) n += 1 plt.show()