Machine Learning in Finance: Prediction, Validation and Overfitting
Table of Contents
A lender that predicts “no default” for every account can be right 98% of the time and still miss every default. Machine learning in finance is useful when it improves a specific forecast or decision over a simple benchmark using information available at the time. This guide compares regularized regression and tree ensembles, then works through a fictional credit example you can reproduce from the counts.
What Is Machine Learning in Finance?
In supervised learning, a model learns from past inputs, called features, and their known outcomes, called labels. Before choosing a model, write down what you want to predict, when you will make the prediction, and what action the forecast could change.
Another use of machine learning is cluster analysis, which can group similar assets without using an outcome label such as next month’s return. This guide focuses on learning from known outcomes to forecast new ones.[11]
“Which accounts should we send to a review team at month-end?” is a decision. “Will this account incur a charge-off in the next 90 days?” is a prediction that could inform it. The review team also needs a cutoff, a cost per review and a way to weigh missed events. The probability model supplies one part of that decision.
Prediction vs. Statistical Inference
Prediction
Will this account experience a charge-off in the next 90 days? Judge the forecast on subsequent accounts using scores recorded before those outcomes were known.
Statistical inference
How strongly is utilization associated with default risk in a specified population, given the model and its assumptions? Report the estimated association and its uncertainty.
To ask whether lowering a borrower’s utilization would reduce the risk of default is to ask a causal question. For instance, high utilization may reflect a cash shortfall that also raises default risk. A model can use utilization to forecast defaults without separating those two effects. A strong forecast, a large coefficient or a tree’s feature importance does not answer the intervention question. See causal inference in econometrics for the design needed to estimate an effect.[1]
Compare Simple Models and Tree Ensembles
Start with a constant that a real analyst could have computed at the time: the historical event rate for default, or a simple historical mean for a return. Give every challenger the same eligible data, prediction dates and scoring rule. A complex model earns its place by improving later results enough to justify its use.
| Model | What it does | What to check |
|---|---|---|
| Ridge (L2) | Penalizes the sum of squared coefficients. It shrinks large weights and can be useful when inputs overlap in what they measure. | Scale continuous features using training data and choose the penalty on later validation data. |
| Lasso (L1) | Penalizes the sum of absolute coefficient values. It can set some coefficients to zero and leave a shorter input list. | Check whether the selected features change across folds, especially when inputs are correlated. |
| Random forest | Combines many trees fitted with random samples and subsets of features at splits. Trees can pick up interactions, such as high utilization being more informative when payments are also late. | Test whether those interactions help on later data; check tree size and probability calibration. |
| Gradient boosted trees | Adds trees one at a time to improve the loss of the existing ensemble, such as a loss for probability forecasts. | Choose tree depth, learning rate and number of trees using earlier data. Keep the final test out of early stopping and other tuning. |
Ridge and lasso usually refer to penalized linear regression for continuous targets such as returns. For a yes-or-no target, apply the corresponding L2 or L1 penalty to logistic regression instead. The penalty constrains the fit; it does not fix future information in the predictors.[2] [3]
Overfitting means learning patterns specific to the training sample that don’t hold up on new data. A deep tree might isolate a handful of accounts that all defaulted in one quarter, even though their shared characteristics have little predictive value later. Shrinking coefficients or limiting tree depth can help; forward validation tells you whether either change improves the forecast.
Worked Example: A 90-Day Default Flag
Suppose a fictional U.S. lender wants to route existing accounts that are current on payments to a review queue. In this retrospective exercise, it scores one account per borrower, once, at the close (Eastern Time) of the first month-end at which the borrower is eligible. The exercise records would-be flags without changing anyone’s treatment.
Set the data clock
Use only values available to the lender at the scoring cutoff. Label the account 1 if its first charge-off occurs in the next 90 calendar days and 0 if no charge-off occurs and the full window is observed. Charge-off is the exercise’s proxy for default. Assume each label becomes usable five calendar days after the 90-day window closes, even if a charge-off is visible sooner. For a March 31, 2025 snapshot, the window is April 1 through June 29, and the finalized label is available July 4. An account with incomplete follow-up cannot be labeled 0 just because there is no event record.
Fit on old accounts; choose a cutoff on later ones
For a model simple enough to reproduce by hand, group accounts using two conditions fixed in advance: utilization of at least 80% and at least one payment marked late in the prior six months. Both conditions place an account in high, exactly one in middle, and neither in low. Estimate each group’s probability from its training charge-off rate. The table supplies all the fictional counts.
| Sample by snapshot date | High | Middle | Low |
|---|---|---|---|
| Train: Jan. 2021–Aug. 2023 | 40 / 200 | 24 / 400 | 34 / 3,400 |
| Validate: Jan.–Aug. 2024 | 12 / 60 | 6 / 100 | 6 / 840 |
| Test: 2025 | 10 / 50 | 0 / 20 | 10 / 930 |
Training counts use only labels available before January 1, 2024. Validation counts use only labels available before January 1, 2025. In both periods, August 31 is the last eligible month-end: its label is available December 4, while September 30 labels are unavailable until January 3. A snapshot from October 31, 2023 has a window through January 29, 2024, and a label available February 3, so it cannot enter that fit. The locked test uses the full 2025 snapshot cohort; all its labels are available before the April 6, 2026 readout.
The fixed model scores are 40 / 200 = 20%, 24 / 400 = 6% and 34 / 3,400 = 1%. The constant benchmark predicts (40 + 24 + 34) / 4,000 = 2.45% for everyone. Keep these probabilities unchanged for validation and test. The benchmark’s operating policy sends nobody to review, which is also what its 2.45% probability implies at either cutoff below.
On validation data, compare reviews at a score of at least 5% or at least 10%, and the no-review benchmark. Suppose a review costs $100 whether or not the account later charges off, and each missed charge-off incurs a $1,000 penalty in this exercise. The evaluation adds those costs; it does not assume a review prevents a charge-off.
- 5% cutoff: 160 reviews and 6 missed charge-offs. 160 × $100 + 6 × $1,000 = $22,000.
- 10% cutoff: 60 reviews and 12 misses. 60 × $100 + 12 × $1,000 = $18,000.
- No review: 24 misses. 24 × $1,000 = $24,000.
Freeze the 10% rule before inspecting the 2025 test. Fitting the probabilities on the training period and choosing the cutoff on the validation period are different uses of data.
Score the reserved test once
The 10% rule reviews the 50 high-group accounts, including 10 that charge off. It misses the other 10 charge-offs among the 950 unflagged accounts. That means 40 false alarms and 940 correctly unflagged accounts.
Accuracy: (10 + 940) / 1,000 = 95%, versus (1,000 − 20) / 1,000 = 98% for no review. The model’s recall, the share of charge-offs flagged, is 10 / 20 = 50%. Its precision, the charge-off rate among reviews, is 10 / 50 = 20%.
Assigned cost: 50 × $100 + 10 × $1,000 = $15,000, versus 20 × $1,000 = $20,000 for no review. If review cost were $200, both rules would cost $20,000 on the same accounts with the cutoff held fixed.
To grade the probabilities before turning them into decisions, use the Brier score: the mean of (predicted probability − outcome)2, with outcome 1 or 0. For the model, the high, middle and low groups contribute 10 × 0.802 + 40 × 0.202, 20 × 0.062, and 10 × 0.992 + 920 × 0.012. Their sum divided by 1,000 is 0.017965. Scoring the constant 2.45% against the same 20 events and 980 non-events gives (20 × 0.97552 + 980 × 0.02452) / 1,000 = 0.01962025. Lower is better. The middle group had zero events in just 20 cases, so this score and the lower assigned cost don’t establish reliable calibration or actual savings.[6]
How to Evaluate a Financial Model Over Time
- Build the dataset as of each prediction. Keep an observation date, its actual availability date and the ending and availability dates for the label. Use only the universe, fields and values accessible when the decision would have been made.
- Walk forward through several windows. Fit on the eligible past, score the next period, and repeat. An expanding window keeps older history; a rolling window drops it. Use the same forecast dates and label rules for every model. In a panel of many loans or stocks for each date, keep that date’s rows together. If the intended use is forecasting unseen borrowers, prevent borrower overlap as well.[4]
- Enforce label availability and purge overlaps. A row can start before the holdout while its outcome is still in the future. Two five-day returns computed four trading days apart even share a daily return. In a split, purge training rows whose outcome windows overlap held-out outcome windows. Separately exclude any training label still unavailable at the fit date, even when its outcome window has ended.[5]
- Use an embargo where the design needs it. In purged cross-validation that trains on both sides of a held-out block, an embargo also drops nearby training rows after that block. For example, their trailing features could still use prices from the held-out period. That split still trains on later dates; use past-only walk-forward folds to replay an actual historical decision. A row-count gap, such as
TimeSeriesSplit(gap=...), does not inspect label intervals or calendar time.[4] [5] - Lock selections before testing. Fit imputation, scaling and feature selection inside each training fold. Use earlier validation to choose model settings and thresholds; fit any calibrator on separate eligible predictions out of sample for the base model. With nested validation, repeat selection inside each outer training window before predicting its next period. Keep a final test for assessment, and log any later redesign so the next assessment uses new data.[4] [6]
Real example of a data vintage: The U.S. Bureau of Economic Analysis estimated on July 30, 2020 that second-quarter real GDP had decreased at a 32.9% annual rate. Its August 27 release revised that decrease to 31.7%. An August 3 forecast could have used the 32.9% release; using the later number would leak future information. A vintage database such as the St. Louis Fed’s ALFRED helps reconstruct what was public on a given date. If you score mid-session, check release times as well. See alternative data in investing for a different example of checking a predictor’s availability.[7]
Common Mistakes
- Shuffling the financial panel. Mixed dates can let the fit use later regimes, repeated accounts or nearly identical outcome windows. Split by the time at which predictions would have been made.
- Building the universe from today’s survivors. Include companies that later delisted when they were eligible for the historical decision. Use outcome data that account for what happened to their positions.
- Using a future action as an input. The charge-off code and a collections action logged after scoring can predict the label only because they report what happened later.
- Counting only the winning backtest. If you try dozens of cutoff dates, feature sets and models, the best apparent result may reflect luck. Log the variants and reserve data the selection process has not seen.[9]
Limits of Financial Prediction
The toy test contains only 20 charge-offs. Catching one more changes recall by 1 / 20 = 5 percentage points. Report event counts, performance across time blocks and uncertainty that accounts for shared dates or borrowers. A rule can weaken when the economy, customers or lending policy changes.
In a historical study of U.S. stock returns, Gu, Kelly and Xiu found that models capturing nonlinear interactions could improve forecasts. Shallower models performed better than deeper ones in their comparisons, and the authors pointed to the small signal relative to return noise. The result does not establish a best model for the next market regime. In a lending application, compare observed and predicted rates as labels mature, review decision costs and capacity, and define when deterioration calls for a model review. See model risk management for the governance behind that process.[8]
Forecast quality is different from tradable return. Lower forecast error does not tell you what portfolio you could have held. A trading test needs a rule that turns forecasts into positions, executable entry and exit times, and a comparison against a relevant benchmark after fees, bid-ask spreads, market impact and any borrowing costs that apply. Compare risk and turnover too. The credit example’s $5,000 difference is a change in an assumed scoring cost, so it gives no evidence of a trading return or savings from an actual review program.[10]
Frequently Asked Questions
Sources
- Galit Shmueli, “To Explain or to Predict?” (Statistical Science, 2010), sections 1–2. Author manuscript.
- scikit-learn, Linear Models, sections on ridge, lasso and logistic regression.
- scikit-learn, Ensembles, sections on gradient boosting and random forests.
- scikit-learn, Cross Validation of Time Series Data, TimeSeriesSplit and Nested versus Non-nested Cross-validation.
- Marcos López de Prado, Advances in Financial Machine Learning (Wiley, 2018), chapter 7, sections 7.4.1–7.4.2.
- scikit-learn, Data Leakage and Probability Calibration.
- U.S. Bureau of Economic Analysis, second-quarter 2020 GDP advance estimate, July 30 and second estimate, August 27; Federal Reserve Bank of St. Louis, FRED and ALFRED real-time periods.
- Shihao Gu, Bryan Kelly and Dacheng Xiu, “Empirical Asset Pricing via Machine Learning” (Review of Financial Studies, 2020). Open research manuscript.
- Campbell R. Harvey, Yan Liu and Heqing Zhu, “… and the Cross-Section of Expected Returns” (Review of Financial Studies, 2016).
- Feifei Li, Tzee-Man Chow, Alex Pickard and Yadwinder Garg, “Transaction Costs of Factor-Investing Strategies” (Financial Analysts Journal, 2019).
- scikit-learn, Clustering, section 2.3.
Disclaimer
This article is for education. The default rule, account counts and costs are hypothetical and do not establish a lending policy, a regulatory definition of default or an investment recommendation.
