Wow, that was a lot to take in! Let’s take this opportunity to implement AdaBoost on a real dataset and solve a classification problem.
We will be using a dataset from UCI’s Machine Learning Repository to evaluate the acceptability of a car based on a set of features that encompasses their price and technical characteristics.
Create the base estimator for the AdaBoost classifier in the form a decision stump using
DecisionTreeClassifier() and store it in a variable named
decision_stump. Recall, that a decision stump is a decision tree with only two leaf nodes.
Print the parameters of the decision stump using the
Create an AdaBoost classification model with the
base_estimator parameter set to
n_estimators set to
5. Store the model in a variable named
Print the parameters of the AdaBoost model using the
ada_classifier using the training features (
X_train) and corresponding labels (
Predict the classes of the testing dataset (
X_test) and store them as an array in a variable named
Now we will explore some of the most common evaluation metrics for classification on our trained AdaBoost model.
- Calculate the accuracy and store it in a variable named
- Calculate the precision and store it in a variable named
- Calculate the recall and store it in a variable named
- Calculate the f1-score and store it in a variable named
Remove the comments from the code block to print the evaluation metrics you just stored.
Take a look at the confusion matrix by removing the comments in the following code block.