← WritingMachine Learning

Financial machine learning from zero, part 1: the vocabulary, the traps, and the metrics that matter

2026-09-05 · 22 min read

machine-learningcredit-riskfraudamlmetricspytorchbeginnersseries

This is post one of a series on financial machine learning for people who know some Python, have used a banking app or applied for a loan or glanced at a stock chart, and have never trained a model on financial data. Every code example in the posts that follow will be in PyTorch. This post has no code at all. It is the ground the rest of the series stands on.

My background is the banking side of this field: building credit-scoring models that decide who gets a loan, fraud models that decide which card transactions to block, and the anti-money laundering (AML) analytics pipelines that decide which accounts an investigator looks at next. Those three problems are the spine of this series. Market prediction, the thing most "ML for finance" content is about, appears as a supporting track, because it teaches a few lessons about time and noise that banking models need too.

In every one of these settings I have watched models that looked excellent in development quietly fail in production. The cause was almost never the algorithm. It was something in this post.

Why this series

Most machine learning tutorials assume the data is i.i.d., short for independent and identically distributed: each example is drawn from the same unchanging process and does not depend on the ones before it. Financial data violates both halves. A customer's transactions this month depend on last month's. The borrowers who applied for loans in 2019 were not facing the economy of 2021, and the fraudsters of 2021 had learned from every model deployed against them in 2019.

Three more realities follow. Labels are noisy: whether a borrower defaults depends partly on things no feature captures, and whether a transaction is labelled fraud depends on whether the customer noticed. Leakage is common: it is astonishingly easy to let the outcome, or the future, into today's features without noticing. And accuracy is often the wrong score: a fraud model that flags nothing is 99.9 percent accurate.

This series starts from those realities instead of bolting them on at the end. The code will be PyTorch because research-style finance work needs three things it does well: models you can shape freely rather than pick from a menu, custom loss functions that encode what you actually care about (a loss is the quantity a model minimises during training), such as the asymmetric cost of a missed default versus a declined good customer, and a short path from a research idea to a running prototype. You will not need a GPU for anything in this series.

What machine learning is, in a bank

A traditional decision rule is written by hand. "If a card is used in two countries within an hour, block it." "If debt payments exceed 50 percent of income, decline." A human chose the signal, the threshold, and the action. The rule does exactly what it says, forever, whether or not customers and fraudsters still behave that way.

Machine learning replaces the hand-written rule with a procedure that finds patterns in historical data. You supply examples of inputs and outcomes, past applications and whether they defaulted, past transactions and whether they were disputed, and the algorithm adjusts a model until its outputs match the outcomes as well as it can. The model may discover that the two-country rule matters only for new cards, or not at all. The human's job shifts from writing rules to choosing the data, the target, the model family, and the way success is measured.

Finance is harder than classic machine learning for four reasons that recur throughout the series. Non-stationarity: the relationships change over time. The economy moves, products change, and fraud is adversarial, meaning the people generating the positive class adapt to whatever you deploy. Low signal-to-noise: defaults, fraud, and laundering are rare events buried in millions of ordinary records, and in markets the predictable part of a daily return is a sliver of the random part. Asymmetric costs: a missed fraud and a wrongly blocked card are both errors, and they cost different amounts to different people. Market models have their own version in transaction costs. Look-ahead bias: using information that was not available at the time of the decision, which inflates every development result and vanishes in production.

The three types of machine learning, mapped to finance

Supervised learning

You have inputs and the correct answer for each, and the model learns the mapping. This is most of applied finance ML.

Examples: credit scoring, which estimates a borrower's probability of default, the chance they fail to repay, from income, repayment history, and existing debt; fraud detection, which scores each card transaction on how likely it is to be unauthorised, using the amount, the merchant, and how far and how fast the card has moved since its last use; and, on the market track, forecasting next-month volatility, the size of price swings.

What good looks like: predictions better than a naive baseline on data the model never saw, by a margin large enough to matter after costs. For default and fraud, good means catching most of the rare bad cases without flagging too many good ones, with probabilities a lender can price from. A credit model that ranks borrowers correctly but says 2 percent when the true default rate is 6 percent loses money on every loan it approves.

Unsupervised learning

You have inputs and no answers. The model finds structure.

AML is where unsupervised methods earn their living. Money laundering has very few confirmed labels, because a suspicious activity report filed by the bank rarely comes back with a verdict. So an AML analytics pipeline typically combines hand-written rules (cash deposits just under the reporting threshold, rapid movement of funds through a new account) with anomaly scores that rank accounts by how unusual their behaviour is relative to a peer group, and hands the top of that list to human investigators. The same anomaly-detection idea is how fraud detection begins on a new product before any disputes exist. Other uses: segmenting customers by behaviour, and on the market track, clustering trading days into regimes such as calm, volatile, and crisis.

What good looks like: groups a human recognises that stay stable when you re-run on a different period. Metrics such as the silhouette score or the Davies-Bouldin index measure how cleanly separated clusters are, but the real test is operational. In AML, good means the investigators' queue contains more genuine cases per hundred alerts than it did before, and the same tool can retire alerts nobody would ever act on.

Reinforcement learning

An agent takes actions, receives rewards, and learns a policy that maximises reward over time.

Examples in banking are still emerging: deciding which delinquent customers to contact first in collections, or how to adjust credit limits over a customer's life. In markets it is used for trade execution, breaking a large order into pieces to minimise market impact.

What good looks like: lower cost or higher recovery than a simple policy, measured on customers or orders the agent did not train on. I mention reinforcement learning for completeness. It is powerful, data-hungry, and easy to fool with a badly designed simulator. It will appear late in this series, if at all.

Vocabulary you will see in every model notebook

Ideas that destroy beginner finance models

A random 80/20 split is dangerous on time-ordered data

The textbook approach shuffles all rows and holds out 20 percent. On financial data this puts a customer's March transactions in training and their April ones in test, or loans from the same month of the same economy on both sides. Adjacent records share most of their information, so the model appears to generalise when it is really interpolating between neighbours it has already seen. Always split by time, always leave a gap.

Late labels and the base rate

Because a default label takes a year to mature, the most recent year of loans has no labels yet, and a model trained on the loans that do have labels has learned from an older economy. Retraining schedules have to respect that lag. Fraud labels depend on customers noticing and disputing, so undisputed fraud is silently labelled legitimate, which teaches the model that some fraud patterns are fine.

Then there is the base rate, the share of positives in the data. Defaults might run at 2 percent, card fraud at a tenth of a percent, and confirmed money laundering far below that. At those rates a model that flags nothing looks superb on accuracy, and a fraud model that catches every fraud while blocking 5 percent of good transactions will be switched off within a week by the people who answer the customer calls. Every metric choice later in this post is shaped by that imbalance.

Look-ahead bias and survivorship bias

Look-ahead bias is using information before it was available: scoring a January application with a bureau report pulled in March. Survivorship bias is subtler in banking than in markets. You only observe defaults on the loans you approved. The applicants you declined have no label, so a model trained on approved loans has never seen the riskiest part of the population it will be asked to score. Market datasets have the same problem when they contain only companies that still exist today. Both make development results look better than anything achievable live.

High accuracy can still lose money

A fraud model that is right 99.9 percent of the time may be right on every legitimate transaction and wrong on every fraud. A credit model that is right on 97 percent of applicants may be wrong on exactly the 3 percent whose losses exceed the margin on all the rest, because a single default costs many times the profit on a good loan. On the market track the same thing appears as a model that calls direction correctly 70 percent of the time but is wrong on the few large moves that dominate the total. Accuracy sees neither cost nor magnitude.

Costs of acting on the prediction

Every prediction that becomes an action has a cost the model never saw. A blocked card means a call centre conversation and a customer who may leave. A declined application means lost interest income. An AML alert means an investigator's hour. Market strategies pay transaction costs and slippage, the gap between the price expected and the price obtained, and have limited capacity before their own trading destroys the edge. A development result that ignores the cost of acting is a fiction.

In-sample, out-of-sample, and walk-forward

In-sample results come from the data the model was fitted on. They are almost meaningless in finance. Out-of-sample results come from data the model never saw. Walk-forward validation repeats the process the way you would actually deploy: train on loans booked before a date, test on the next quarter's, roll forward, repeat. It is slower and it is the only honest picture of how a model would have behaved.

Metrics that actually matter in financial machine learning

This section is the reference you will come back to. Each table lists the metric, where it is used, what it measures, whether higher or lower is better, and the trap to watch.

Classification: default, fraud, suspicious activity

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
AccuracyApprove/decline, fraud/notShare of predictions that are correctContextIf 1% of loans default, predicting "no default" for everyone scores 99%. Accuracy lies on imbalanced data
PrecisionFraud and AML alertsOf the cases flagged positive, the share that were truly positiveHigherHigh precision means few false alarms; the cost of a wrong fraud block is an angry customer
RecallDefault and fraud screeningOf the true positives, the share the model caughtHigherHigh recall means few missed frauds; usually traded off against precision
F1Summarising imbalanced classificationHarmonic mean of precision and recallHigherOne number for the trade-off; hides which side is weak
ROC-AUCRanking risk across borrowersProbability a random positive is scored above a random negativeHigherLooks healthy even when positives are rare, because it rewards ranking the vast negative class correctly
Gini coefficientCredit scorecardsRanking power, equal to 2 × ROC-AUC − 1HigherThe number credit risk teams quote. A Gini of 0.5 is a decent retail scorecard; it inherits ROC-AUC's blindness to calibration
KS statisticCredit scorecardsLargest gap between the cumulative distributions of good and bad borrowers across the scoreHigherPoints to the single cut-off that best separates the groups, which is how approval thresholds get set
PR-AUCFraud, default, any rare eventArea under the precision-recall curveHigherThe honest one for imbalanced data. A no-skill PR-AUC equals the positive rate, so know that baseline
Log lossProbability outputsPenalises confident wrong predictionsLowerRewards calibrated probabilities, not just correct ordering
Population stability index (PSI)Monitoring deployed modelsHow far the distribution of scores, or of a feature, has drifted from the training populationLowerNot a quality metric but a drift alarm. A PSI above 0.25 on a scorecard usually triggers a review

Risk and calibration

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
Brier scoreDefault probabilities, event forecastsMean squared difference between predicted probability and the 0/1 outcomeLowerA model that says 80% should be right about 80% of the time. Brier checks that
Reliability (calibration curve)Any probability used for pricing or capitalWhether predicted probabilities match observed frequencies in each bucketCloser to the diagonalA model can rank borrowers perfectly and still say 5% when the truth is 15%. For pricing a loan, that gap is the whole problem

Business outcomes: what the bank feels

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
Bad rate at cut-offCredit approval policyShare of approved loans that default at the chosen score thresholdLowerThe number the business owns. Move the cut-off and the approval rate moves the other way
Approval rateCredit approval policyShare of applicants acceptedContextHigher grows the book and the losses together. Always report next to bad rate
Expected credit lossPricing and provisioningProbability of default × exposure × loss given default, summed over the bookLowerOnly as good as the calibration behind it
False positives per fraud caughtFraud thresholdsGood transactions blocked for each fraud stoppedLowerThe ratio the call centre feels. Ten to one is uncomfortable; one hundred to one is unusable
Alerts per confirmed caseAML tuningInvestigator alerts generated for each case that becomes a filed reportLowerRules-only systems commonly run above 95% false positives. This ratio is what the analytics are there to improve

Prediction and regression: amounts, volatility, returns

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
MAE (mean absolute error)Loss-given-default, exposure and volatility forecastsAverage size of the error, in the units of the targetLowerRobust to outliers; treats a 1% miss and ten 0.1% misses the same
MSE (mean squared error)Default training loss for regressionAverage squared errorLowerPunishes large misses heavily; one crisis month can dominate
RMSE (root mean squared error)Reporting regression errorSquare root of MSE, back in target unitsLowerSame ranking as MSE, easier to read
MAPE (mean absolute percentage error)Balance and volume forecastsAverage error as a percentage of the actualLowerExplodes when the actual is near zero, so never use it on returns
Explanatory powerShare of the target's variance the model explainsHigherOn daily returns an R² near zero is normal, and 0.3 is a leakage alarm. On loss amounts, modest values are also the norm

Ranking and selection: which accounts to review, which names to buy

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
Precision at kAML and fraud review queuesOf the top k alerts, the share that were genuineHigherMatches how investigators work: they get through k cases a day, not the whole list
MAP and nDCGReview queues; top-k stock selectionRanking quality with more credit for true cases placed higherHigherBorrowed from search engines; useful whenever position in the list matters
Information coefficient (IC) and Rank ICCross-sectional stock signalsCorrelation (Pearson, or Spearman on ranks) between predicted and realised returns across assets on a dateHigherAn IC of 0.05 is a real edge in equities. Report the mean and its stability; Rank IC resists one huge winner

Strategy quality, market track only

MetricTypical use in financeWhat it measuresBetter whenOne-line intuition / trap
Sharpe ratioUniversal strategy scoreAverage excess return divided by its standard deviation, annualisedHigherEasy to inflate by overfitting the development window
Sortino and Calmar ratiosAsymmetric or drawdown-sensitive strategiesExcess return over downside deviation; annual return over maximum drawdownHigherVariants that stop penalising good volatility, or that let one bad month set the denominator
Maximum drawdownRisk of ruinLargest peak-to-trough loss over the periodLowerThe number that gets a strategy shut down. Always report next to Sharpe
Hit rateTrade-level diagnosticsShare of trades that made moneyContextA 40% hit rate with large winners beats 70% with large losers
TurnoverCost and capacityHow much of the portfolio is traded per periodContextHigher means higher costs and lower capacity; zero means the model is doing nothing

The cheat box

Lower is better: MAE, MSE, RMSE, MAPE, log loss, Brier score, PSI, bad rate, expected credit loss, false positives per fraud caught, alerts per confirmed case, maximum drawdown, Davies-Bouldin index, inertia, perplexity

Higher is better: precision, recall, F1, ROC-AUC, Gini, KS, PR-AUC, precision at k, MAP, nDCG, R², IC and Rank IC, Sharpe, Sortino, Calmar, silhouette score

Context-dependent: accuracy, approval rate, alert volume, hit rate, turnover, number of trades

A warning that deserves its own paragraph. Never approve a credit or fraud model on ROC-AUC or Gini alone, computed on the development sample. A ranking metric on the data you fitted measures how well you fit the past, and any sufficiently flexible model fits the past beautifully. Pair the ranking metric with a calibration check such as the Brier score, and with the operational number the business will feel, such as bad rate at the chosen cut-off or good customers declined per fraud caught. Compute all of them on a clean out-of-time window that neither the model nor you have touched. If the ranking is strong and the calibration is poor, or the numbers collapse out of time, suspect leakage before you suspect genius.

The market-track version of the same rule: never pick a strategy on Sharpe ratio alone computed on the training period. Pair a statistical metric such as Rank IC or log loss with an economic one such as Sharpe and maximum drawdown, on a clean out-of-sample window.

What this post does not do

There are no derivations here, no explanation of how gradient descent finds the parameters, no PyTorch, and no scorecard or backtest engine. Each of those is a post of its own, and each will be built in the open with the metrics above applied honestly. Treating them properly matters more than getting to them quickly.

What is next

The next three posts, all in PyTorch:

After that, fraud detection with late-arriving labels, the anomaly layer of an AML pipeline and how to measure it when almost nothing is labelled, and then a short market track: a return-prediction baseline and the ranking and strategy metrics applied honestly.

Before then, a question for you. Which finance metric do you trust least, and why? Mine is ROC-AUC quoted for a fraud model without the base rate next to it.

Summary to save

Share