Unit 3.4 · about 2 h
147 / 324XGBoost, LightGBM and CatBoost configuration
Graduating from one API to the family means reading any booster config on sight. The names rhyme across libraries but the defaults do not, and that gap is where silent misconfiguration lives.
- explain
You can now
- Map depth, learning rate, row and column sampling, L2 and early stopping across XGBoost, LightGBM, CatBoost and sklearn HGBT without mixing up names.
- State the defaults that bite and set one equivalent configuration in each library from memory.
Covers
- XGBoost, LightGBM and CatBoost configuration literacy
Study, in this order
6 steps
- XGBoost tree-booster parametersXGBoost parameters and sklearn estimator interface
Parameters for Tree Booster:
etadefault 0.3,max_depth6,min_child_weight1,subsample1,colsample_bytree,bylevelandbynode1,lambda1,alpha0 - XGBoost sklearn interface and early stoppingXGBoost parameters and sklearn estimator interface
Early Stopping:
XGBClassifierwithtree_methodhist,early_stopping_roundswitheval_set, best iteration used automatically for prediction - LightGBM core and control parametersLightGBM parameters
learning_rate0.1,num_leaves31,max_depth-1 for no limit with leaf-wise growth,min_data_in_leaf20,feature_fraction1.0,bagging_fraction1.0 effective only withbagging_freqabove 0,lambda_l20.0, early stopping by callback orearly_stopping_round - CatBoost common parametersCatBoost common parameters and categorical features
depth6,learning_ratechosen automatically forLogloss,MultiClassandRMSEand 0.03 otherwise,l2_leaf_reg3.0,iterations1000,SymmetricTreegrow_policy,subsample0.8 under the defaultMVSbootstrap on CPU (Bayesianfor multiclass),rsmfor columns per split,boosting_typeOrderedversusPlain,use_best_modelwitheval_set,one_hot_max_size2 - sklearn histogram gradient boosting as the local baselinescikit-learn - neighbors, SVMs, trees and ensembles
1.11.1.1 Histogram-Based Gradient Boosting with Usage:
max_iter100 replacesn_estimators,max_bins255,max_leaf_nodes31,early_stoppingautoabove 10000 rows - HoML Chapter 6: histogram boosting with native categoriesHands-On Machine Learning with Scikit-Learn and PyTorch - nonlinear classical models
Book Chapter 6: Histogram-Based Gradient Boosting (printed pp. 214-215). Notebook 06 cells:
HistGradientBoostingRegressorwithcategorical_features=[0]: binned training with a native categorical slot
Focus on
- Learn the name map, in XGBoost, LightGBM and CatBoost order: step size is
eta,learning_rateandlearning_rate; rows aresubsample,bagging_fractionandsubsample; columns arecolsample_bytreeper tree,feature_fractionper tree andrsmper split (aliascolsample_bylevel); L2 islambda,lambda_l2andl2_leaf_reg. - Defaults that bite: XGBoost
eta0.3 against LightGBM 0.1, CatBoost 1000iterationswith a rate it picks itself for the common losses, LightGBM bagging off untilbagging_freqpasses 0, LightGBM growing leaf-wise tonum_leaves31 with no depth limit (max_depth-1), and CatBoost symmetric trees atdepth6. - Early stopping differs per library: XGBoost takes
early_stopping_roundswitheval_setand predicts from the best iteration, LightGBM takesearly_stopping_roundor theearly_stoppingcallback with a validation set, CatBoost takeseval_setwithuse_best_model, and HGBT stops by itself only above 10000 rows. - Categorical handling differs too: CatBoost takes raw categories with ordered target statistics and one-hot encodes only features with at most
one_hot_max_sizevalues (2 by default), LightGBM takes integer-codedcategorical_featurecolumns, and XGBoost takes pandascategorycolumns withenable_categorical=Trueon thehistorapproxtree method.
Reproduce closed-book
max_iter 200, learning_rate 0.05, max_depth 4, l2_regularization 1.0, early_stopping=True, random_state 0) on make_moons(n_samples=2000, noise=0.25, random_state=0): it runs all 200 iterations because its internal validation score is still improving, and scores 0.955 on the data it was fit on (sklearn 1.9.1).Traps
num_leaves31 withmax_depth4 cannot grow 31 leaves: depth caps the tree at 16 leaves, so set both consistently instead of copying the default.bagging_fraction0.8 alone changes nothing in LightGBM. Bagging stays off untilbagging_freqis set above 0.- Copying
n_estimators100 into CatBoost without setting the learning rate silently swaps the shrinkage regime, since CatBoost defaults to 1000iterationswith an automatic rate.
Practice
The section mini-project covers this: configured XGBoost, LightGBM and CatBoost runs with early stopping compared under fixed splits in the family-choice defense.
Self-test
-
What are the default step sizes in XGBoost, LightGBM and CatBoost?
XGBoosteta0.3 and LightGBMlearning_rate0.1. CatBoost picks the rate automatically forLogloss,MultiClassandRMSE, from the iteration count, and uses 0.03 otherwise. -
Name the row-sampling parameter in each of the three libraries and any enabling switch.
XGBoostsubsample; LightGBMbagging_fraction, which needsbagging_freqabove 0; CatBoostsubsample, 0.8 under the defaultMVSbootstrap on CPU, while multiclass defaults to theBayesianbootstrap. -
Should low-cardinality string columns be one-hot encoded for CatBoost?
No. Pass them as categorical features and let ordered target statistics handle them; CatBoost one-hot encodes only features with at mostone_hot_max_sizevalues, 2 by default. -
When does sklearn HGBT stop early without an explicit validation set?
Withearly_stoppingauto, which is the default, it reserves validation internally on data above 10000 rows. Smaller data runs the fullmax_iterunless validation is passed.
Completion criterion
Stop when
You write all four configurations from memory with correct names, state each default you overrode, and your HGBT run matches the reference iteration count and accuracy.
Mark passed, then open 3.5 Only mark this when you can do it without notes.Leads to
- 5.8 Permutation importance and partial dependence Explain the configured booster with model-agnostic tools.
- 5.7 Learning curves, error taxonomies and slices Diagnose the early-stopped runs with learning curves.
Comes after
- 3.3 AdaBoost and gradient boostingConfigure the production implementations of this loop.
Resources for this unit
- Hands-On Machine Learning with Scikit-Learn and PyTorch - nonlinear classical models Read Chapters 3, 5 and 6 and the online Appendix C notebook as the first pass through performance measures, trees, ensembles and SVMs, running notebooks 03, 05 and 06 alongside. Vary depth, estimators, learning rate, k, C and RBF width under fixed splits.
- scikit-learn - neighbors, SVMs, trees and ensembles Check official estimator constraints, complexity, preprocessing needs, missing-value behavior and probability caveats. Do not use library calls as the mechanism implementation.
- XGBoost parameters and sklearn estimator interface Read the tree-booster parameter list for
eta, depth, sampling and regularization names and defaults, and the sklearn page for early stopping witheval_set. - LightGBM parameters Read
learning_rate,num_leaves,max_depth,min_data_in_leaf,feature_fraction,bagging_fractionwithbagging_freq,lambda_l2and early stopping defaults. - CatBoost common parameters and categorical features Read
iterations,learning_rate,l2_leaf_reg,depth,grow_policy,subsample,rsm,boosting_type,use_best_modelandone_hot_max_sizedefaults, plus native categorical handling.
Also in this section
- ISLP - tree-based methods and support vector machines Use Chapters 8 and 9 with their Python labs for the statistical account of trees, bagging, random forests, boosting and SVMs that the notebooks leave implicit, and for model-choice and feature-importance arguments.
- Deep-ML - tree, ensemble and kernel problems Use 138 Best Gini-Based Split, 20 Decision Tree Learning, 307 Bagging Classifier, 21 Pegasos Kernel SVM and 280 RBF Kernel as unit checks after the local implementation passes. Their tests were read in review; each card states what they pin, including tie and update-order conventions.
- Probabilistic Machine Learning, Chapter 16: exemplar-based methods Read Sections 16.1 to 16.1.3 for the KNN decision rule, the curse of dimensionality with the growing-hypercube example, and the speed section on k-d trees, hashing and approximate search.