आउट-ऑफ-बैग इवैल्युएशन

Python में Tree-Based Models के साथ Machine Learning

Elie Kawerk

Data Scientist

बैगिंग

  • एक ही मॉडल के लिए कुछ इंस्टेंस कई बार सैंपल हो सकते हैं,

  • कुछ इंस्टेंस बिल्कुल भी सैंपल नहीं होते.

Python में Tree-Based Models के साथ Machine Learning

आउट-ऑफ-बैग (OOB) इंस्टेंस

  • औसतन, हर मॉडल के लिए 63% ट्रेनिंग इंस्टेंस सैंपल होते हैं.

  • बचे हुए 37% OOB इंस्टेंस होते हैं.

Python में Tree-Based Models के साथ Machine Learning

OOB इवैल्युएशन

oob-evaluation

Python में Tree-Based Models के साथ Machine Learning

sklearn में OOB इवैल्युएशन (Breast Cancer डेटासेट)

# Import models and split utility function
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

# Set seed for reproducibility
SEED = 1

# Split data into 70% train and 30% test
X_train, X_test, y_train, y_test =  train_test_split(X, y, test_size= 0.3,
                                                     stratify= y,
                                                     random_state=SEED)

Python में Tree-Based Models के साथ Machine Learning
# Instantiate a classification-tree 'dt'
dt = DecisionTreeClassifier(max_depth=4,
                            min_samples_leaf=0.16,
                            random_state=SEED)

# Instantiate a BaggingClassifier 'bc'; set oob_score = True bc = BaggingClassifier(base_estimator=dt, n_estimators=300, oob_score=True, n_jobs=-1)
# Fit 'bc' to the training set bc.fit(X_train, y_train) # Predict the test set labels y_pred = bc.predict(X_test)
Python में Tree-Based Models के साथ Machine Learning
# Evaluate test set accuracy
test_accuracy = accuracy_score(y_test, y_pred)

# Extract the OOB accuracy from 'bc' oob_accuracy = bc.oob_score_ # Print test set accuracy print('Test set accuracy: {:.3f}'.format(test_accuracy))
Test set accuracy: 0.936
# Print OOB accuracy
print('OOB accuracy: {:.3f}'.format(oob_accuracy))
OOB accuracy: 0.925
Python में Tree-Based Models के साथ Machine Learning

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

Python में Tree-Based Models के साथ Machine Learning

Preparing Video For Download...