Book Image

Hands-On Gradient Boosting with XGBoost and scikit-learn

By : Corey Wade
Book Image

Hands-On Gradient Boosting with XGBoost and scikit-learn

By: Corey Wade

Overview of this book

XGBoost is an industry-proven, open-source software library that provides a gradient boosting framework for scaling billions of data points quickly and efficiently. The book introduces machine learning and XGBoost in scikit-learn before building up to the theory behind gradient boosting. You’ll cover decision trees and analyze bagging in the machine learning context, learning hyperparameters that extend to XGBoost along the way. You’ll build gradient boosting models from scratch and extend gradient boosting to big data while recognizing speed limitations using timers. Details in XGBoost are explored with a focus on speed enhancements and deriving parameters mathematically. With the help of detailed case studies, you’ll practice building and fine-tuning XGBoost classifiers and regressors using scikit-learn and the original Python API. You'll leverage XGBoost hyperparameters to improve scores, correct missing values, scale imbalanced datasets, and fine-tune alternative base learners. Finally, you'll apply advanced XGBoost techniques like building non-correlated ensembles, stacking models, and preparing models for industry deployment using sparse matrices, customized transformers, and pipelines. By the end of the book, you’ll be able to build high-performing machine learning models using XGBoost with minimal errors and maximum speed.
Table of Contents (15 chapters)
Section 1: Bagging and Boosting
Section 2: XGBoost
Section 3: Advanced XGBoost

Who this book is for

This book is for data science professionals and enthusiasts, data analysts, and developers who want to build fast and accurate machine learning models that scale with big data. Proficiency in Python along with a basic understanding of linear algebra will help you to get the most out of this book.

What this book covers

Chapter 1, Machine Learning Landscape, presents XGBoost within the general context of machine learning by introducing linear regression and logistic regression before comparing results with XGBoost. pandas is introduced to preprocess raw data for machine learning by converting categorical columns and clearing null values in a variety of ways.

Chapter 2, Decision Trees in Depth, presents a detailed examination of decision tree hyperparameters that are used by XGBoost, along with a graphical and statistical analysis of variance and bias that highlights the importance of overfitting, a theme touched on throughout the book.

Chapter 3, Bagging with Random Forests, presents a general survey of random forests as an XGBoost competitor with a focus on bagging. Additional XGBoost hyperparameters shared with random forests such as n_esimtators and subsample are thoroughly covered.

Chapter 4, From Gradient Boosting to XGBoost, covers boosting fundamentals, building a booster from scratch in scikit-learn, fine-tuning new XGBoost hyperparameters such as eta, and comparing runtimes between gradient boosting and XGBoost to highlight XGBoost's impressive speed.

Chapter 5, XGBoost Unveiled, analyzes the mathematical derivations of XGBoost algorithms and features a historically relevant case study featuring XGBoost's role as the winning model in the Higgs Boson Kaggle Competition. Standard XGBoost parameters are discussed, base models are built, and the original Python API is covered.

Chapter 6, XGBoost Hyperparameters, covers all essential XGBoost hyperparameters, summarizes previous tree ensemble hyperparameters, and uses original grid search functions to fine-tune XGBoost models to optimize scores.

Chapter 7, Discovering Exoplanets with XGBoost, gives you the opportunity to discover exoplanets with XGBoost in a top-to-bottom case study. The pitfalls of imbalanced datasets are analyzed with the confusion matrix and classification report leading to different scoring metrics and the important XGBoost hyperparameter scale_pos_weight.

Chapter 8, XGBoost Alternative Base Learners, covers the full range of XGBoost boosters including gbtree, dart, and gblinear for regression and classification. Random forests are presented as base learners, and as XGBoost alternative models with the new XGBRFRegressor and XGBRFClassifier classes.

Chapter 9, XGBoost Kaggle Masters, presents tips and tricks that XGBoost Kaggle winners have used to win competitions such as advanced feature engineering, building non-correlated machine ensembles, and stacking.

Chapter 10, XGBoost Model Deployment, transforms raw data into XGBoost machine learning predictions through the use of customized transformers to handle mixed data and machine learning pipelines to make predictions on incoming data with a fine-tuned XGBoost model.