Online Machine Learning Quiz

100+ Objective Machine Learning Questions. Lets see how many can you answer?

Start Quiz

Friday, 8 March 2019

Implement AdaBoost in Python using Scikit Learn Library in Machine Learning

We are going to implement Adaboost algorithm in Python using Scikit Learn library. This is an ensemble learning technique and we will use AdaBoostClassifier to solve IRIS dataset problem. 

You can download my Jupyter notebook implementing Adaboost from here.

Step 1: Import the required Python libraries

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.ensemble import AdaBoostClassifier
from sklearn.metrics import confusion_matrix, accuracy_score, classification_report

Step 2: Load and examine the dataset

dataset = datasets.load_iris()

Step 3: Mention X and Y axis

X =
y =

Step 4: Split the dataset into training and testing dataset

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)

Step 5: Create and fit the model

model = AdaBoostClassifier(n_estimators=50, learning_rate=1), y_train)

Step 6: Predict from the model

y_pred = model.predict(X_test)

Step 7: Check the accuracy

confusionMatrix = confusion_matrix(y_test, y_pred)
accuracyScore = accuracy_score(y_test, y_pred)
classificationReport = classification_report(y_test, y_pred)
print(accuracyScore * 100)

To learn more about Adaboost, you can refer my below posts:

Difference between Random Forest and AdaBoost in Machine Learning
Difference between AdaBoost and Gradient Boosting Machine (GBM)

No comments:

Post a Comment