You have data on past outcomes (which customers churned, which transactions were fraudulent, which loans defaulted) and you want to predict the next ones. XGBoost (Chen and Guestrin, 2016) is a boosted-tree method for this kind of task, and the report pairs its predictions with SHAP values (Lundberg and Lee, 2017), which show how each feature moved a prediction. Upload a CSV and get a classification report.
Worked Example (Simulated): Can Boosted Trees Spot Positives in Made-Up Data?
Question: Can boosted trees spot a positive result in a small made-up set?
Inputs: Made-up data, seed 24. The script builds 600 rows and 6 features (4 carry signal) with a 70/30 class split built in. It sets aside 180 test rows, and each class has the same share in both sets.
Method: The script uses scikit-learn gradient boosting, a tool for boosted trees (Friedman, 2001). It uses 80 trees, a learning rate of 0.05, and max depth of 2. It scores test rows at the default class cutoff. It also gives ROC AUC, a score for how well the model ranks cases.
from sklearn.datasets import make_classification
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import (accuracy_score, precision_score, recall_score,
roc_auc_score, confusion_matrix)
SEED = 24
X, y = make_classification(
n_samples=600,
n_features=6,
n_informative=4,
n_redundant=0,
n_clusters_per_class=2,
weights=[0.70, 0.30],
class_sep=0.9,
random_state=SEED,
)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.30, stratify=y, random_state=SEED
)
model = GradientBoostingClassifier(
n_estimators=80, learning_rate=0.05, max_depth=2, random_state=SEED
)
model.fit(X_train, y_train)
pred = model.predict(X_test)
score = model.predict_proba(X_test)[:, 1]
print(f"Simulated data, seed {SEED}")
print(f"Rows: {len(y)}; features: {X.shape[1]}; test rows: {len(y_test)}")
print("Split: stratified; test fraction: 0.30")
print("Model: GradientBoostingClassifier; trees: 80; learning rate: 0.05; "
"max depth: 2")
print(f"Test positive share: {y_test.mean():.3f}")
print(f"Accuracy: {accuracy_score(y_test, pred):.3f}")
print(f"Precision: {precision_score(y_test, pred):.3f}")
print(f"Recall: {recall_score(y_test, pred):.3f}")
print(f"ROC AUC: {roc_auc_score(y_test, score):.3f}")
print("Confusion matrix (rows=true 0/1, cols=predicted 0/1):")
print(confusion_matrix(y_test, pred, labels=[0, 1]))
Printed output:
Simulated data, seed 24
Rows: 600; features: 6; test rows: 180
Split: stratified; test fraction: 0.30
Model: GradientBoostingClassifier; trees: 80; learning rate: 0.05; max depth: 2
Test positive share: 0.300
Accuracy: 0.856
Precision: 0.889
Recall: 0.593
ROC AUC: 0.897
Confusion matrix (rows=true 0/1, cols=predicted 0/1):
[[122 4]
[ 22 32]]
Result: This example uses scikit-learn gradient boosting, not the XGBoost package. The test set's positive share is 0.300 (54 of 180 rows), so always saying "negative" would score 0.700 accuracy; the model's 0.856 is above that. The miss to name is recall, 0.593: of 54 real positives, the model found 32 and missed 22. Precision, the share of positive calls that were right, is 0.889 (32 of 36). ROC AUC is 0.897. Accuracy alone hides the missed cases.
Limit: The data are made up, with the class split built in. These results do not show how the model works on real loan, fraud, or customer data. This is a scikit-learn model, not XGBoost, and the script does not run SHAP.
Sources
- Chen T, Guestrin C (2016). XGBoost: a scalable tree boosting system. Proceedings of the 22nd ACM SIGKDD Conference.
- Friedman J (2001). Greedy function approximation: a gradient boosting machine. Annals of Statistics.
- Lundberg S, Lee S-I (2017). A unified approach to interpreting model predictions. Advances in Neural Information Processing Systems 30.
What Is XGBoost?
XGBoost, eXtreme Gradient Boosting, builds trees in order. Later trees aim to cut past errors. The first tree makes rough predictions, the second tree studies the errors and corrects them, and so on. The combined ensemble of many trees is often more accurate than a single tree.
The "gradient" part refers to how XGBoost decides what counts as a mistake. It uses gradient descent, the same optimization technique behind neural networks, to find the direction that reduces prediction error the fastest. Each tree is trained not on the original data, but on the residual errors from all previous trees. This sequential, error-correcting approach is what makes gradient boosting so powerful compared to methods that train trees independently.
XGBoost adds speed and regularization to earlier boosting algorithms. It uses techniques like column subsampling (only looking at a random subset of features per tree), built-in handling of missing values, and L1/L2 regularization to prevent overfitting. Chen and Guestrin (2016) describe these engineering details.
Critically, raw prediction accuracy is only half the story. A model that says "this customer will churn" is useful, but a model that also shows which inputs pushed the score up, such as falling usage or support tickets, is easier to act on. The report pairs XGBoost with SHAP (SHapley Additive exPlanations), which assigns each feature a contribution to a prediction, so you can see how the inputs shaped a score.
When to Use XGBoost
XGBoost excels at classification problems where you need to predict a binary outcome from structured tabular data. The most common business applications fall into a few categories.
Credit scoring and risk assessment. Banks and lenders use XGBoost to predict which loan applicants will default. The model learns from historical loan performance (payment history, credit utilization, income, employment tenure) and scores new applications. SHAP values can show how input parts shaped a score. Whether that meets a rule depends on the rule and the full decision process.
Churn prediction. Subscription businesses use XGBoost to identify customers likely to cancel. The model picks up on patterns like declining login frequency, reduced feature usage, or support ticket spikes. Because SHAP shows the top drivers for each at-risk customer, the retention team knows whether to offer a discount, fix a product issue, or reach out with onboarding help.
Demand forecasting. Retailers and supply chain teams predict which products will sell above or below target. Features might include price, seasonality, promotional calendar, and competitor pricing. XGBoost handles the nonlinear interactions between these variables, for example, a discount during peak season might behave very differently than the same discount in a slow month, without requiring you to specify those interactions manually.
Fraud detection. Payment processors flag suspicious transactions using XGBoost trained on transaction amount, merchant category, time of day, geographic distance from the cardholder's home, and velocity of recent transactions. The model can pick up combinations of signals that simple rules miss, and SHAP values show which inputs moved a flagged score.
The common thread is structured data with a clear binary outcome. If your data lives in a spreadsheet or database table and you want to predict yes/no, high/low, or pass/fail, compare XGBoost with a simple base model, such as logistic regression.
What Data Do You Need?
You need a CSV with at least two columns: one binary outcome column (the thing you want to predict) and one or more predictor columns (the features the model learns from). Map your outcome column. This should contain two distinct values like 0/1, yes/no, true/false, or high/low. Then map one or more predictor columns. These can be numeric (revenue, count, duration) or categorical (region, product type, channel).
The module supports multiple predictors. Map predictor_1 as required, then add predictor_2, predictor_3, and so on for additional features. More relevant predictors can improve the model, and feature importance shows which columns the model relied on.
No row count fits every task. Check how many cases of each class are in the train and test sets (the default split holds out 30% for testing), and ask if the test results are clear enough for the choice at hand. If your outcome is imbalanced (say, only 5% of transactions are fraudulent) the model still works, but you should pay more attention to the precision-recall tradeoff than raw accuracy. The report's confusion matrix and ROC curve make this clear.
You can also tune the model's behavior through optional parameters. Advanced users can adjust the number of boosting rounds (n_rounds), tree depth (max_depth), learning rate, subsampling fraction, column sampling rate, classification threshold, and whether to use early stopping. Early stopping monitors held-out performance and halts training when additional rounds stop improving results, which can limit overfitting.
How to Read the Report
The report walks you through the full modeling pipeline, from data preparation to actionable insights. Here is what each section tells you.
Analysis Overview. A snapshot of the classification task: how many rows were used, what the outcome variable is, how many predictors were included, and the class distribution. Check this first to confirm the model is answering the right question with the right data.
Data Pipeline. Shows the preprocessing steps: how missing values were handled, how categorical variables were encoded, and how the data was split into training and test sets. This matters for reproducibility. You need to know exactly what transformations were applied before the model saw the data.
Model Configuration. Lists the hyperparameters used: number of boosting rounds, max tree depth, learning rate, subsample ratio, and column sampling rate. If you want to re-run with different settings, this card tells you exactly what the current run used.
Feature Importance (Gain). A bar chart ranking features by their total gain: how much each feature reduces prediction error across all trees. This is XGBoost's internal measure of feature usefulness. High-gain features are the ones the model relies on most. This is fast to compute but can be biased toward high-cardinality features, which is why the report also includes SHAP importance.
SHAP Feature Importance. A summary plot showing the magnitude and direction of each feature's contribution to predictions. Unlike gain-based importance, SHAP values are additive attributions based on Shapley values from game theory (Lundberg and Lee, 2017). You can see not just which features matter, but how they matter, whether higher values of a feature push predictions toward the positive or negative class. This is the section to show stakeholders who want to understand the "why" behind the model.
Learning Curves. Plots of training and held-out error across boosting rounds. These tell you whether the model has converged and whether it is overfitting. If training error keeps dropping but held-out error plateaus or rises, the model is memorizing noise in the training data. Early stopping helps prevent this, and the learning curves show exactly where it kicked in.
ROC Curve. The Receiver Operating Characteristic curve plots the true positive rate against the false positive rate at every classification threshold. ROC AUC, the area under this curve, sums up the curve across cutoffs. An AUC of 0.5 means the model ranks no better than random guessing. Read it with precision and recall at the chosen cutoff, and weigh the cost of false alarms and missed cases too. The ROC curve also helps you choose the right threshold, if false positives are expensive (like incorrectly flagging legitimate transactions), you can move the threshold to trade recall for precision.
Confusion Matrix. A 2x2 grid showing true positives, true negatives, false positives, and false negatives on the held-out test set. This is where you see the concrete impact of the model's predictions. How many churners did it catch? How many non-churners did it incorrectly flag? The confusion matrix makes the cost of errors tangible and helps you judge whether the model is good enough for your use.
Model Performance Metrics. Accuracy, precision, recall, F1 score, and AUC in a single table. Accuracy tells you overall correctness, but it can be misleading with imbalanced classes (a model that predicts "no fraud" for every transaction scores high accuracy when few transactions are fraudulent, as the baseline in the example above shows). Precision tells you what fraction of positive predictions were correct. Recall tells you what fraction of actual positives the model caught. F1 balances the two. Look at all of them together, not just accuracy.
Executive Summary. AI-generated insights that synthesize the technical results into business language. Which features drive the outcome? How reliable is the model? What should you do with these findings? This section is designed for stakeholders who want the conclusion without wading through charts and metrics.
When to Use Something Else
If your goal is to understand the statistical relationship between a single predictor and an outcome (and you need p-values, confidence intervals, and odds ratios) use logistic regression instead. Logistic regression is interpretable by design and is the standard in fields where regulatory or academic conventions demand simple, transparent models. XGBoost may score higher on accuracy, but logistic regression tells a cleaner story when you have a small number of well-understood predictors.
If you want a strong ensemble model but prefer something easier to tune, consider a random forest. Random forests train trees independently (in parallel) rather than sequentially, which makes them often easier to tune. The tradeoff is that a well-tuned boosted model can score higher on some datasets.
For very large-scale datasets (millions of rows, hundreds of features), LightGBM is worth considering. It uses histogram-based splitting and leaf-wise tree growth, which can change training speed on big data. If training time is your bottleneck, it may be worth comparing.
If your data has spatial structure (images), sequential structure (text, time series), or you need to learn feature representations from raw data rather than engineered columns, neural networks are the better tool. XGBoost assumes your features are already meaningful columns in a table. It does not learn hierarchical representations the way deep learning does. For structured tabular data, boosted trees are a common choice, but for unstructured data they are usually the wrong tool.
The R Code Behind the Analysis
Every report names its method and includes the R code that produced it, so you can reproduce, audit and cite it. The method code is fixed, not rewritten for each run, so the same data gives the same analysis every time.
The analysis uses the xgboost package for model training and prediction: SHAP values are computed using the SHAPforxgboost package. The ROC curve and AUC come from the pROC package, and the confusion matrix from caret. Data preprocessing uses dplyr and base R. Every step (from train/test split to threshold selection to metric computation) is visible in the code tab of your report, so you or a data scientist can check what was done and reproduce it independently.
Your turn
Bring your own data and the question you actually need answered.
MCP AnalyticsData science by email Send us your data and your question, and we will reply. ds@mcpanalytics.ai