xgboost-lightgbm

Industry-standard gradient boosting libraries for tabular data and structured datasets. XGBoost and LightGBM excel at classification and regression tasks on tables, CSVs, and databases. Use when working with tabular machine learning, gradient boosting trees, Kaggle competitions, feature importance a

By tondevrel · 433 installs

npx skills add tondevrel/scientific-agent-skills --skill xgboost-lightgbm

Source repository · Upstream listing

XGBoost & LightGBM Gradient Boosting for Tabular Data XGBoost (eXtreme Gradient Boosting) and LightGBM (Light Gradient Boosting Machine) are the de facto standard libraries for machine learning on tabular/structured data. They consistently win Kaggle competitions and are widely used in industry for their speed, accuracy, and robustness. When to Use Classification or regression on tabular data (CSVs, databases, spreadsheets). Kaggle competitions or data science competitions on structured data. Feature importance analysis and feature selection. Handling missing values automatically (no need to impute). Working with imbalanced datasets (built in class weighting). Need for fast training on large datasets (millions of rows). Hyperparameter tuning with cross validation. Ranking tasks (learning to rank algorithms). When you need interpretable feature importances. Production ML systems requiring fast inference on tabular data. Reference Documentation XGBoost Official : https://xgboost.readthedocs.io/ XGBoost GitHub : https://github.com/dmlc/xgboost LightGBM Official : https://lightgbm.readthedocs.io/ LightGBM GitHub : https://github.com/microsoft/LightGBM Search patterns : xgboost.XGBClassifier , lightgbm.LGBMRegressor , xgboost.train , lightgbm.cv Core Principles Gradient Boosting Trees Both libraries build an ensemble of decision trees sequentially, where each new tree corrects errors from previous trees. This creates highly accurate models that capture complex non linear patterns. Speed vs Accuracy Trade offs XGBoost : Slower but often slightly more accurate. Better for smaller datasets (<100k rows). LightGBM : Faster, especially on large datasets (millions of rows). Uses histogram based learning. Regularization Both include L1/L2 regularization (alpha, lambda parameters) to prevent overfitting. This is crucial when you have many features. Handling Categorical Features LightGBM has native categorical feature support. XGBoost requires encoding (label encoding or one hot). Quick Reference Installation Standard Imports Basic Pattern Classification with XGBoost Basic Pattern Regression with LightGBM Critical Rules ✅ DO Use Early Stopping Always use early stopping with a validation set to prevent overfitting and save training time. Start with Defaults Both libraries have excellent default parameters. Start there before tuning. Monitor Training Use eval set parameter to track validation metrics during training. Handle Imbalance For imbalanced classes, use scale pos weight (XGBoost) or class weight (LightGBM). Feature Engineering Create interaction features, polynomial features, aggregations boosting excels with rich feature sets. Use Native API for Advanced Control For complex tasks, use xgb.train() or lgb.train() instead of sklearn wrappers. Save Models Properly Use .save model() and .load model() methods, not pickle (more robust). Check Feature Importance Always examine feature importances to understand your model and detect data leakage. ❌ DON'T Don't Forget to Normalize Target For regression, if target has wide range, consider log transform or standardization. Don't Ignore Tree Depth max depth (XGBoost) or num leaves (LightGBM) are critical. Too deep = overfit. Don't Use Default Learning Rate for Large Datasets Reduce learning rate to 0.01 0.05 for datasets 1M rows. Don't Mix Up Parameters XGBoost uses max depth , LightGBM uses num leaves . They're different! Don't One Hot Encode for LightGBM Use categorical feature parameter instead for better performance. Don't Skip Cross Validation Always CV before trusting a single train/test split. Anti Patterns (NEVER) XGBoost Fundamentals Scikit learn Style API Native XGBoost API (More Control) Cross Validation LightGBM Fundamentals Scikit learn Style API Native LightGBM API Categorical Features (LightGBM's Superpower) Hyperparameter Tuning Key Parameters to Tune Learning Rate ( learning rate or eta ) Lower = more accurate but slower Start: 0.1, then try 0.05, 0.01 Lower learning rate requires more n estimators Tree Complexity XGBoost: max depth (3 10) LightGBM: num leaves (20 100) Higher = more complex, risk of overfit Sampling Ratios subsample / bagging fraction : 0.5 1.0 colsample bytree / feature fraction : 0.5 1.0 Lower values add regularization Regularization reg alpha (L1): 0 10 reg lambda (L2): 0 10 Higher values prevent overfit Grid Search with Cross Validation Optuna for Advanced Tuning Feature Importance and Interpretability Feature Importance SHAP Values (Advanced Interpretability) Practical Workflows 1. Kaggle Style Competition Pipeline 2. Imbalanced Classification 3. Multi Class Classification 4. Time Series with Boosting 5. Model Stacking (Ensemble) Performance Optimization GPU Acceleration Memory Optimization Parallel Training Common Pitfalls and Solutions The "Overfitting on Validation Set" Problem When you tune hyperparameters based on validation performance, you're indirectly overfitting to the validation set. The "Categorical Encoding" Dilemma XGBoost doesn't handle categorical features natively (but LightGBM does). The "Learning Rate vs Trees" Trade off Lower learning rate needs more trees but gives better results. The "max depth vs num leaves" Confusion XGBoost uses max depth , LightGBM uses num leaves . They're related but different! The "Data Leakage" Detection Feature importance can reveal data leakage. XGBoost and LightGBM have revolutionized machine learning on tabular data. Their combination of speed, accuracy, and interpretability makes them the go to choice for structured data problems. Master these libraries, and you'll have a powerful tool for the vast majority of real world ML tasks.