💳 Loan Default Predictor — Gradient Boosted Trees Live
Watch a real gradient boosting ensemble grow shallow decision trees live, each one fitting the residual errors of the last, genuinely reducing simulated loan-default prediction loss with every boosting round.
About Gradient Boosted Trees for Loan Default Prediction
Gradient boosting builds a strong classifier out of many weak ones. Starting from a single constant (the log-odds of the base default rate), the algorithm repeatedly fits a shallow decision tree to the pseudo-residuals — for logistic loss, simply the difference between the true label and the current predicted probability — and adds that tree's scaled-down prediction to a running score. Each tree only needs to explain what the ensemble so far got wrong, so the training loss decreases with every round even though every individual tree is deliberately weak and shallow.
This simulation generates synthetic loan applicants with realistic risk factors (income, credit history length, debt-to-income ratio, credit utilization, recent late payments, employment length) combined into a true default probability plus irreducible noise, exactly as in real lending data. A genuine CART-style regression tree is grown at every boosting round by exhaustively searching every feature and threshold for the split that most reduces squared error on the residuals, and each leaf's output is refined with a Newton-Raphson step. Adjust the learning rate, number of trees and tree depth and watch training and held-out validation log-loss evolve live.
Frequently Asked Questions
What is gradient boosting, in plain terms?
Gradient boosting builds a strong predictive model as a sum of many weak models, usually shallow decision trees, added one at a time. Instead of each tree trying to predict the label directly, every new tree is trained to fit the mistakes (residual errors) left behind by the ensemble built so far. Each tree's contribution is scaled down by a learning rate before being added, so the ensemble improves gradually and does not overfit to any single tree's quirks.
How does gradient boosting work for binary classification like loan default?
The model maintains a running log-odds score F(x) for every borrower. At each round it computes the negative gradient of the log-loss with respect to F, which for logistic loss works out to simply y − p, the difference between the true label (0 or 1) and the current predicted probability p = sigmoid(F(x)). A shallow regression tree is fit to these residuals, and each leaf's output value is refined with a Newton-Raphson step using the leaf's residual sum divided by its sum of p(1−p), which approximates the second derivative of the loss. The tree's predictions, scaled by the learning rate, are then added to F for every borrower, and the cycle repeats.
How does the tree decide where to split?
At each node the algorithm scans every candidate feature (income, credit history length, debt-to-income ratio, credit utilization, recent late payments, employment length) and every possible threshold between adjacent sorted values, computing how much the split would reduce the total squared error of the residuals in that node compared to leaving it unsplit. The split with the largest error reduction (subject to a minimum-samples-per-leaf constraint) is chosen, and the process repeats recursively in the resulting child nodes until the maximum tree depth is reached.
Why does the training loss keep decreasing but the validation loss can level off or rise?
Each new tree is fit specifically to reduce the residual error on the training set, so training log-loss decreases almost monotonically as trees are added. The validation set was never used to fit any tree, so its loss only improves as long as the patterns the trees are learning genuinely generalize. Once the ensemble starts fitting noise specific to the training borrowers rather than the true default-risk relationship, validation loss stops improving or creeps back up — this gap is the classic signature of overfitting, and is exactly why boosting round count, tree depth and learning rate are tuned against a held-out validation set rather than the training set itself.
What does the learning rate control, and why not just use a large one?
The learning rate scales down how much of each new tree's fitted correction is actually added to the running prediction. A small learning rate (e.g. 0.05) means many trees are needed to reach a good fit, but each one only nudges the model slightly, which tends to generalize better and reduces the risk of any single noisy tree throwing the ensemble off course. A large learning rate (close to 1.0) lets the model fit the training data very quickly, often in just a handful of rounds, but it is far more prone to overshooting and overfitting, since early trees lock in large corrections before later trees can smooth them out.
Why use shallow trees of depth 1-3 instead of one big deep tree?
A single deep tree can memorize the training set almost perfectly by carving it into tiny, homogeneous regions, which generalizes poorly. Gradient boosting instead uses many shallow, high-bias, low-variance trees (often called "stumps" at depth 1) and lets the boosting process itself supply the complexity, one small correction at a time. A depth-1 stump can only ever capture a single feature interaction per tree, but summed over dozens or hundreds of boosting rounds, the ensemble can represent very complex, high-order feature interactions while each individual tree stays simple and resistant to overfitting.
How is this different from a random forest?
A random forest builds many deep trees independently and in parallel on bootstrapped samples of the data, then averages their predictions — this reduces variance (noise) but each tree is trained without knowledge of the others' errors. Gradient boosting builds trees sequentially, and every new tree is explicitly trained to correct the specific errors the current ensemble is making. This sequential error-correction is what lets boosting often reach lower bias and higher accuracy than a forest of comparable size, at the cost of being more sensitive to the learning rate and number of rounds, and more prone to overfitting if left unchecked.
What features actually predict loan default risk in this simulation?
The synthetic borrower generator bakes in realistic relationships used by real credit-risk models: higher income and longer employment history reduce default risk, while a higher debt-to-income ratio, higher credit-card utilization, and more late payments in the past two years increase it; a longer credit history also modestly reduces risk by giving more track record to assess. These relationships are combined into a true log-odds of default plus irreducible random noise, then a coin flip weighted by that probability generates the observed default label — so even a perfect model cannot reach zero loss, exactly as in real lending data.
What is the AUC score shown in the stats panel?
AUC (area under the ROC curve) measures how well the model ranks borrowers who actually defaulted above those who did not, regardless of any particular probability threshold. An AUC of 0.5 means the model ranks pairs no better than a coin flip; an AUC of 1.0 means every defaulter is ranked above every non-defaulter. It is computed here directly from its rank-based definition: for every defaulter/non-defaulter pair in the validation set, count whether the defaulter received a higher predicted probability, and average over all pairs.
Watch a real gradient boosting ensemble grow shallow decision trees live, each one fitting the residual errors of the last, genuinely reducing simulated loan-default prediction loss with every boosting round.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install