शुरू करेंमुफ़्त में शुरू करें

Bootstrapping के साथ प्रशिक्षण

आइए अब एक "कमज़ोर" decision tree classifier बनाते हैं और उसे training set से replacement सहित निकाले गए सैंपल पर train करते हैं. इससे आप समझेंगे कि bagging ensemble की हर iteration में क्या होता है.

सैंपल लेने के लिए आप pandas की .sample() मेथड का उपयोग करेंगे, जिसमें replace पैरामीटर होता है. उदाहरण के लिए, नीचे दी गई कोड लाइन पूरे DataFrame df से replacement सहित सैंपल लेती है:

df.sample(frac=1.0, replace=True, random_state=42)

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Ensemble Methods

पाठ्यक्रम देखें

अभ्यास निर्देश

  • पूरे (frac=1.0) training set X_train से replacement सहित (replace=True) सैंपल लें.
  • max_depth = 4 पैरामीटर के साथ एक decision tree classifier बनाएँ.
  • मॉडल को सैंपल किए गए training डेटा पर fit करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Take a sample with replacement
X_train_sample = X_train.____(____, ____, random_state=42)
y_train_sample = y_train.loc[X_train_sample.index]

# Build a "weak" Decision Tree classifier
clf = ____(____, random_state=500)

# Fit the model to the training sample
____
कोड संपादित करें और चलाएँ