BaggingClassifier: मूल बातें

Python में Ensemble Methods

Román de las Heras

Data Scientist, Appodeal

Heterogeneous बनाम Homogeneous फ़ंक्शंस

Heterogeneous Ensemble फ़ंक्शन

het_est = HeterogeneousEnsemble(
    estimators=[('est1', est1), ('est2', est2), ...],
    # additional parameters
)

Homogeneous Ensemble फ़ंक्शन

hom_est = HomogeneousEnsemble(
    est_base,
    n_estimators=chosen_number,
    # additional parameters
)
Python में Ensemble Methods

BaggingClassifier

Bagging Classifier उदाहरण:

# Instantiate the base estimator ("weak" model)
clf_dt = DecisionTreeClassifier(max_depth=3)
# Build the Bagging classifier with 5 estimators
clf_bag = BaggingClassifier(
    clf_dt,
    n_estimators=5
)
# Fit the Bagging model to the training set
clf_bag.fit(X_train, y_train)
# Make predictions on the test set
y_pred = clf_bag.predict(X_test)
Python में Ensemble Methods

BaggingRegressor

Bagging Regressor उदाहरण:

# Instantiate the base estimator ("weak" model)
reg_lr = LinearRegression()
# Build the Bagging regressor with 10 estimators
reg_bag = BaggingRegressor(
    reg_lr
)
# Fit the Bagging model to the training set
reg_bag.fit(X_train, y_train)
# Make predictions on the test set
y_pred = reg_bag.predict(X_test)
Python में Ensemble Methods

Out-of-bag स्कोर

  • जिन उदाहरणों पर कोई estimator सैंपल से बाहर था, उन पर व्यक्तिगत भविष्यवाणियाँ निकालें
  • व्यक्तिगत भविष्यवाणियाँ मिलाएँ
  • उन भविष्यवाणियों पर मीट्रिक का आकलन करें:
    • Classification: accuracy
    • Regression: R^2
clf_bag = BaggingClassifier(
    clf_dt,
    oob_score=True
)
clf_bag.fit(X_train, y_train)
print(clf_bag.oob_score_)
0.9328125
pred = clf_bag.predict(X_test)
print(accuracy_score(y_test, pred))
0.9625
Python में Ensemble Methods

अब आपकी बारी!

Python में Ensemble Methods

Preparing Video For Download...