Example of gradient tree boosting with Scikit-Learn

In this example, we want to employ a gradient tree boosting classifier (class GradientBoostingClassifier) and check the impact of the maximum tree depth (parameter max_depth) on the performance. Considering the previous example, we start by setting n_estimators=50 and learning_rate=0.8:

import numpy as npfrom sklearn.ensemble import GradientBoostingClassifierfrom sklearn.model_selection import cross_val_scorescores_md = []eta = 0.8for md in range(2, 13):    gbc = GradientBoostingClassifier(n_estimators=50, learning_rate=eta, max_depth=md, random_state=1000)    scores_md.append(np.mean(cross_val_score(gbc, X, Y, cv=10)))

The result is shown in the following diagram:

10-fold Cross-validation accuracy ...

Get Mastering Machine Learning Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.