Ada Boost
Ada Boost
In [2]:
# Creating a decision tree classifier instance
dtree = DecisionTreeClassifier(criterion='entropy', max_depth=1, random_sta
# Instantiate the bagging classifier
adbclassifier = AdaBoostClassifier(base_estimator=dtree,
n_estimators=100,
learning_rate=0.01,
random_state=1)
# Fit the AdaBoost classifier
model = adbclassifier.fit(X_train, y_train)
#Predict the response for test dataset
y_pred = model.predict(X_test)
# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
C:\ProgramData\anaconda3\lib\site-packages\sklearn\ensemble\_base.py:166: FutureWarning:
`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.
warnings.warn(
Accuracy: 0.9415204678362573
In [3]:
from sklearn.ensemble import RandomForestClassifier
# Creating a decision tree classifier instance
rf = RandomForestClassifier(n_estimators=20, random_state=0)
n_estimators=100,
learning_rate=0.01,
random_state=1)
Accuracy: 0.9707602339181286
C:\ProgramData\anaconda3\lib\site-packages\sklearn\ensemble\_base.py:166: FutureWarning:
`base_estimator` was renamed to `estimator` in version 1.2 and will be removed in 1.4.
warnings.warn(