Bootstrapping परिचय

Python में Sampling

James Chapman

Curriculum Manager, DataCamp

With or without

बिना रिप्लेसमेंट का सैंपलिंग:

कसीनो टेबल पर ताश के पत्ते।

रिप्लेसमेंट के साथ सैंपलिंग ("resampling"):

चार घूमते पासे।

Python में Sampling

बिना रिप्लेसमेंट की सरल रैंडम सैंपलिंग

Population:

पंक्तियों और स्तंभों में सजे कॉफी बीन्स।

Sample:

पंक्तियों और स्तंभों में सजे कॉफी बीन्स, जिनमें से अधिकतर ग्रे किए गए हैं।

Python में Sampling

रिप्लेसमेंट की सरल रैंडम सैंपलिंग

Population:

पंक्तियों और स्तंभों में सजे कॉफी बीन्स।

Resample:

कॉफी बीन्स का रैंडम सैंपल, जिनमें कुछ डुप्लिकेट हैं।

Python में Sampling

रिप्लेसमेंट के साथ क्यों सैंपल करें?

  • coffee_ratings: सभी कॉफी की बड़ी जनसंख्या का एक सैंपल
  • हमारे सैंपल की हर कॉफी कई काल्पनिक जनसंख्या कॉफी का प्रतिनिधित्व करती है
  • रिप्लेसमेंट के साथ सैंपलिंग एक प्रॉक्सी है
Python में Sampling

कॉफी डेटा तैयारी

coffee_focus = coffee_ratings[["variety", "country_of_origin", "flavor"]]
coffee_focus = coffee_focus.reset_index()
      index  variety country_of_origin  flavor
0         0     None          Ethiopia    8.83
1         1    Other          Ethiopia    8.67
2         2  Bourbon         Guatemala    8.50
3         3     None          Ethiopia    8.58
4         4    Other          Ethiopia    8.50
...     ...      ...               ...     ...
1333   1333     None           Ecuador    7.58
1334   1334     None           Ecuador    7.67
1335   1335     None     United States    7.33
1336   1336     None             India    6.83
1337   1337     None           Vietnam    6.67

[1338 rows x 4 columns]
Python में Sampling

.sample() से रिसैंपलिंग

coffee_resamp = coffee_focus.sample(frac=1, replace=True)
      index  variety country_of_origin  flavor
1140   1140  Bourbon         Guatemala    7.25
57       57  Bourbon         Guatemala    8.00
1152   1152  Bourbon            Mexico    7.08
621     621  Caturra          Thailand    7.50
44       44     SL28             Kenya    8.08
...     ...      ...               ...     ...
996     996   Typica            Mexico    7.33
1090   1090  Bourbon         Guatemala    7.33
918     918    Other         Guatemala    7.42
249     249  Caturra          Colombia    7.67
467     467  Caturra          Colombia    7.50

[1338 rows x 4 columns]
Python में Sampling

दोहराई गई कॉफियाँ

coffee_resamp["index"].value_counts()
658     5
167     4
363     4
357     4
1047    4
       ..
771     1
770     1
766     1
764     1
0       1
Name: index, Length: 868, dtype: int64
Python में Sampling

मिसिंग कॉफियाँ

num_unique_coffees = len(coffee_resamp.drop_duplicates(subset="index"))
868
len(coffee_ratings) - num_unique_coffees
470
Python में Sampling

Bootstrapping

जनसंख्या से सैंपलिंग का उलटा

Sampling: जनसंख्या से छोटे सैंपल की ओर जाना

Bootstrapping: सैंपल से सैद्धांतिक जनसंख्या बनाना

Bootstrapping उपयोग मामला:

  • एक ही सैंपल से सैंपलिंग वैरिएबिलिटी को समझना

एक काउबॉय बूट।

Python में Sampling

Bootstrapping प्रक्रिया

  1. मूल सैंपल के बराबर आकार का एक रिसैंपल बनाइए
  2. इस bootstrap सैंपल के लिए इच्छित स्टैटिस्टिक निकालिए
  3. चरण 1 और 2 कई बार दोहराइए

बने हुए स्टैटिस्टिक्स को bootstrap statistics कहते हैं, और ये मिलकर bootstrap distribution बनाते हैं

Python में Sampling

कॉफी के mean flavor का Bootstrapping

import numpy as np

mean_flavors_1000 = []
for i in range(1000):
mean_flavors_1000.append(
np.mean(coffee_sample.sample(frac=1, replace=True)['flavor'])
)
Python में Sampling

Bootstrap distribution हिस्टोग्राम

import matplotlib.pyplot as plt
plt.hist(mean_flavors_1000)
plt.show()

mean flavor का bootstrap distribution

Python में Sampling

अभ्यास करते हैं!

Python में Sampling

Preparing Video For Download...