xgboost
Skill15 starsChanged 44 days agoMITView on GitHub
Expert XGBoost assistance covering extreme gradient boosting, tree pruners, DMatrix, GPU hist tree method, and early stopping. Use when training high-accuracy tabular models for competitions and production.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- service-meshSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 120
Use native xgb.train with early_stopping:
- Very specific: line 154
Use deprecated gpu_hist tree method.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
XGBoost
XGBoost is an optimized distributed gradient boosting library designed for high efficiency, speed, and predictive accuracy on tabular datasets.
When to Use
- Tabular Data Competitions & Industry Production: High-performance gradient boosted decision trees for classification and regression.
- GPU-Accelerated Tree Building: Training massive datasets on NVIDIA GPUs with
tree_method="hist"anddevice="cuda". - Handling Missing Values & Sparsity: Automatic direction assignment for missing values without manual imputation.
- Monotonic Feature Constraints: Enforcing domain-specific rules (e.g., higher credit score must never increase interest rate).
Quick Start
import xgboost as xgb
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# Scikit-learn compatible API with GPU histogram support
model = xgb.XGBClassifier(
n_estimators=100,
learning_rate=0.05,
max_depth=6,
tree_method="hist", # Ultra-fast histogram method
device="cuda" if xgb.rabit.get_rank() >= 0 else "cpu"
)
model.fit(X_train, y_train)
accuracy = model.score(X_test, y_test)
print(f"XGBoost Test Accuracy: {accuracy:.4f}")Core Concepts
High-Performance XGBClassifier with Early Stopping
Training XGBoost using Scikit-Learn API with GPU acceleration:
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
import pandas as pd
import numpy as np
# Sample dataset
X = pd.DataFrame(np.random.randn(20000, 10), columns=[f"feat_{i}" for i in range(10)])
y = (X["feat_0"] + X["feat_1"] * 2 > 0.5).astype(int)
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)
# Configure modern XGBoost 2.x classifier
clf = xgb.XGBClassifier(
n_estimators=1000,
learning_rate=0.03,
max_depth=6,
subsample=0.8,
colsample_bytree=0.8,
tree_method="hist",
device="cuda" if xgb.rabit.is_distributed() else "cpu",
early_stopping_rounds=30,
eval_metric="auc",
random_state=42
)
clf.fit(
X_train, y_train,
eval_set=[(X_val, y_val)],
verbose=50
)
preds = clf.predict_proba(X_val)[:, 1]
print(f"Validation AUC: {roc_auc_score(y_val, preds):.4f}")Enforcing Monotonic Constraints
Ensuring predictions strictly increase or decrease with specific features:
# Feature 0 must have positive monotonic relationship (+1), Feature 1 negative (-1)
monotonic_rules = (1, -1, 0, 0, 0, 0, 0, 0, 0, 0)
constrained_clf = xgb.XGBClassifier(
monotone_constraints=monotonic_rules,
tree_method="hist",
n_estimators=100
)
constrained_clf.fit(X_train, y_train)Saving Model in Universal JSON Format
Exporting trained model for portable cross-platform serving:
# Save model in standard JSON format (recommended for XGBoost 2.x)
clf.save_model("xgboost_model.json")
# Load model in production service
loaded_clf = xgb.XGBClassifier()
loaded_clf.load_model("xgboost_model.json")Common Patterns
DMatrix Native Training with Early Stopping Callback
Problem: Preventing overfitting without training hundreds of redundant trees after validation loss plateaus.
Solution:
Use native xgb.train with early_stopping:
dtrain = xgb.DMatrix(X_train, label=y_train)
dval = xgb.DMatrix(X_test, label=y_test)
params = {
"objective": "binary:logistic",
"eval_metric": "logloss",
"tree_method": "hist"
}
evals = [(dtrain, "train"), (dval, "val")]
bst = xgb.train(
params,
dtrain,
num_boost_round=1000,
evals=evals,
callbacks=[xgb.callback.EarlyStopping(rounds=50, save_best=True)],
verbose_eval=50
)Best Practices
Do:
- Target XGBoost 2.x with
tree_method="hist"anddevice="cuda"for extreme training speedups. - Save models in the native
.jsonformat (model.save_model("model.json")) rather than binary pickle files. - Set
early_stopping_roundsin constructor parameters to prevent overfitting on validation data. - Utilize
monotone_constraintswhen business or regulatory logic demands monotonic behavior.
Don't:
- Use deprecated
gpu_histtree method; in modern XGBoost usetree_method="hist"withdevice="cuda". - Perform manual one-hot encoding on high-cardinality categoricals; use
enable_categorical=True. - Tune hyperparameters without early stopping active; it wastes compute on overfitted trees.
Troubleshooting
| Error | Cause | Solution |
XGBoostError: Invalid device ordinal | Requesting GPU when no CUDA device is present or wrong GPU ID. | Set device="cpu" or verify GPU with nvidia-smi. |
DataFrame columns must be the same as when the model was trained | Inference DataFrame features do not match training order/names. | Align inference DataFrame columns: df = df[model.feature_names_in_]. |
Overfitting on training set | Trees too deep or learning rate too high. | Decrease max_depth (e.g. 4-6) and tune regularization reg_alpha and reg_lambda. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

