Resampling परिणामों का विज़ुअलाइज़ेशन
अब आप पिछले अभ्यास की अपनी simulation के परिणामों को visualize करेंगे! आप nba_weights के साथ काम जारी रखेंगे, जिसमें NBA खिलाड़ियों के एक समूह का वज़न (किलोग्राम में) है:
nba_weights = [96.7, 101.1, 97.9, 98.1, 98.1,
100.3, 101.0, 98.0, 97.4]
यह रहा आपके पिछले अभ्यास का simulation कोड:
simu_weights = []
for i in range(1000):
bootstrap_sample = random.choices(nba_weights, k=9)
simu_weights.append(np.mean(bootstrap_sample))
mean_weight = np.mean(simu_weights)
upper = np.quantile(simu_weights, 0.975)
lower = np.quantile(simu_weights, 0.025)
print(mean_weight, lower, upper)
पिछले अभ्यास में जो simu_weights सूची आपने बनाई थी, वह आपके लिए लोड कर दी गई है. इसी तरह mean_weight, lower और upper भी पहले से परिभाषित हैं, जो आपके confidence interval के mean और 2.5% तथा 97.5% quantile मान हैं.
निम्नलिखित पैकेज आपके लिए पहले से लोड हैं: random, numpy as np, seaborn as sns, और matplotlib.pyplot as plt.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Monte Carlo Simulations
अभ्यास निर्देश
- Simulated weights के distribution को plot करने के लिए
sns.displot()का उपयोग करें. - 95% confidence interval के लिए दो वर्टिकल लाइनों को (पहले
lower, फिरupper) लाल रंग में, और mean को हरे रंग में plot करने के लिएplt.axvline()का उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Plot the distribution of the simulated weights
____
# Plot vertical lines for the 95% confidence intervals and mean
plt.axvline(____, color="red")
plt.axvline(____, color="red")
plt.axvline(____, color="green")
plt.show()