हम कितने defaults की उम्मीद कर सकते हैं?
मान लीजिए किसी बैंक ने 100 mortgage loans दिए। यह संभव है कि 0 से 100 के बीच कोई भी संख्या default हो जाए। आप यह जानना चाहते हैं कि किसी निश्चित संख्या के defaults की probability क्या है, जबकि एक loan के default होने की probability p = 0.05 है। इसे जाँचने के लिए आप एक simulation करेंगे। आप perform_bernoulli_trials() फंक्शन (जो आपने पिछले अभ्यास में लिखा था) का उपयोग करके 100 Bernoulli trials चलाएँगे और देखेंगे कि कितने defaults मिलते हैं। यहाँ "सफलता" का मतलब default है। (ध्यान रखें, "success" का अर्थ बस इतना है कि Bernoulli trial True आया — यानी क्या loan लेने वाले ने default किया?) आप यह 100 Bernoulli trials का सेट फिर से करेंगे। और बार-बार करेंगे जब तक हम इसे 1000 बार आज़मा न लें। फिर आप एक histogram plot करेंगे जो defaults की संख्या की probability को दिखाएगा.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Statistical Thinking in Python (Part 1)
अभ्यास निर्देश
- Random number generator को 42 से seed करें.
np.empty()का उपयोग करकेn_defaultsनाम का एक खाली array initialize करें। इसमें 1000 entries होनी चाहिए, क्योंकि हम 1000 simulations कर रहे हैं.perform_bernoulli_trials()फंक्शन का उपयोग करके 100 loans पर प्रति simulation defaults की संख्या निकालने के लिए1000iterations वाला एकforloop लिखें। यह दो arguments लेता है: trials की संख्याn— यहाँ 100 — और success की probabilityp— यहाँ default की probability0.05। Loop की हर iteration में परिणाम कोn_defaultsकी एक entry में स्टोर करें.n_defaultsका histogram plot करें।density=Truekeyword argument शामिल करें ताकि histogram की bar की ऊँचाई probability बताए.- अपना plot दिखाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Instantiate and seed random number generator
# Initialize the number of defaults: n_defaults
# Compute the number of defaults
for i in ____:
n_defaults[i] = ____
# Plot the histogram with default number of bins; label your axes
_ = plt.hist(____, ____)
_ = plt.xlabel('number of defaults out of 100 loans')
_ = plt.ylabel('probability')
# Show the plot