Implementing gradient boosting with the XGBoost algorithm

XGBoost was created in 2014 and is based on gradient-boosting principles. It has become one of the most popular ensemble classification algorithms. It generates a bunch of interrelated trees and uses gradient descent to minimize the residual error. This makes it a perfect fit for distributed infrastructures, such as Apache Spark, or for cloud computing, such as Google Cloud or Amazon Web Services (AWS).

Let's now see how we can implement gradient boosting with the XGBoost algorithm:

  1. First, we will instantiate the XGBClassfier classifier and train the model using the training portion of the data:

  1. Then, we will generate predictions based on the newly trained model:
y_pred = classifier.predict(X_test)
cm = metrics.confusion_matrix(y_test, y_pred)
cm

The produces the following output :

  1. Finally, we will quantify the performance of the model:
accuracy= metrics.accuracy_score(y_test,y_pred)
recall = metrics.recall_score(y_test,y_pred)
precision = metrics.precision_score(y_test,y_pred)
print(accuracy,recall,precision)

This gives us the following output:

Next, let's look at the random forest algorithm.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.78