IInvest Like the Best
← All frameworks
Innovation

The ML Experiment Pipeline (Features → Labels → Train/Test/Validation)

From raw data to a trustworthy model without secretly cheating yourself.

Difficulty
Advanced
Time to result
~weeks to results
Steps
7
Confidence
90%

This is the disciplined, repeatable process Jeremiah Lowin walks through for building any supervised machine learning model, using an email spam classifier as the running example. It covers turning raw inputs into fixed-shape numerical features (feature engineering), defining labels for the model to learn from, and then carefully partitioning data into training, validation, and test sets so that performance estimates are never contaminated by information the model has already seen. The framework's core insight is that the entire exercise is a discipline of avoiding self-deception: every stage introduces a new way to accidentally leak the answer into the process, and the structure exists specifically to prevent that. It is especially critical in finance, where non-stationary, noisy data makes it easy to believe a model is smarter than it actually is.

Origin

Lowin developed this mental checklist over a career moving from academic statistics into hedge fund risk management and then building ML systems, having personally seen models that appeared successful but had actually learned spurious correlations.

Core principles

  • 01Never let a model be evaluated on data it learned from.
  • 02Feature engineering determines what the model is even capable of learning.
  • 03The validation set is for tuning; the test set is for truth — using it more than once for tuning defeats its purpose.
  • 04In time series, split chronologically, never randomly, to prevent the model from learning the future.

How to run it

  1. 1

    Define and encode your features

    Convert raw inputs (e.g., email text) into a fixed-length, consistent numerical representation such as a bag-of-words vector so every observation has the same shape.

    Pro tip If two observations can vary wildly in raw size (a 100-word vs. 1,000-word email), you need a representation that normalizes that difference.

  2. 2

    Engineer features for model compatibility

    Transform inputs mathematically or qualitatively so they're amenable to the model, e.g., converting exponentially distributed data (like GDP) into linear space before modeling.

    Pro tip Always ask whether a variable's distribution needs to be reshaped before it goes into the model.

  3. 3

    Define your labels carefully

    For supervised learning, decide exactly what answer you are training the model to produce. In finance this is unusually hard — a 'good trade' has no single obvious definition.

    Pro tip Treat label definition as feature engineering on the output side; time spent here pays off more than tuning the model itself.

    Watch out A poorly defined label (e.g., naive total return) can make the entire exercise unsolvable regardless of model sophistication.

  4. 4

    Split into training, validation, and test sets

    Use the training set for the model to learn the correlation structure repeatedly. Hold back a validation set for tuning decisions, and a completely separate test set for final, one-time evaluation.

    Watch out If you're working with time series, split by time (train on earlier years, test on later ones) rather than randomly across the whole dataset, or the model will learn from the future.

  5. 5

    Train the model

    Let the model iterate on the training data, discovering a correlation structure between inputs and the labeled outputs, typically via an optimization process like gradient descent.

    Watch out Watch for overfitting — the model can learn something that looks correct in training but is actually a spurious artifact of how the data was collected.

  6. 6

    Tune hyperparameters against the validation set

    Systematically test different model configurations (number of neurons, tree depth, number of factors) against the validation set, treating it as a scientific hypothesis test rather than random trial and error.

    Pro tip Do this in a controlled, hypothesis-driven way rather than throwing configurations at the wall.

    Watch out Using the same validation set repeatedly effectively folds it into training — don't mistake validation performance for true out-of-sample performance.

  7. 7

    Run the final out-of-sample test once

    Only after tuning is fully complete, evaluate the model exactly once on the untouched test set to get an honest read on real-world performance.

In the wild

Spam vs. Not-Spam Email Classifier

Lowin walks through building a classifier using bag-of-words features and the sending domain, labeling training emails as spam or not spam, then validating and testing the model on unseen emails to avoid the model 'caching' answers.

→ Illustrates each stage of the pipeline concretely, showing how features, labels, and held-out data work together.

The Tank-Detection Overfitting Story

An AI trained to spot tanks in satellite images performed perfectly in testing but failed completely in production; it turned out all training images of tanks happened to be taken at night, so the model had actually just learned to detect darkness.

→ A now-classic cautionary tale illustrating how a model can appear successful while having learned a spurious correlation.

Common mistakes

Letting the model 'cheat' on the test set

Repeatedly using the test set to guide tuning decisions effectively makes it part of training, invalidating it as a measure of true out-of-sample performance.

Splitting time series data randomly

Randomly shuffling a time series before splitting lets the model learn correlations from the future, producing results that look great in testing but can't work in live deployment.

Learning a spurious correlation instead of the real signal

As in the tank/night-time example, a model can achieve excellent apparent accuracy by picking up on an incidental artifact in the data rather than the actual phenomenon you intended it to learn.

Is it for you?

Not ideal for

Situations where you have very little data or where labels cannot be defined with any precision (e.g., ill-posed problems).

From the transcript

“we can't ask it to tell us what it learned with the same data that it learned from, we need to test it on new…”

Jeremiah

“The validation set serves as your halfway test set”

Jeremiah

“you want to train through some year, you want to test from that year forward”

Jeremiah

From the episode

Jeremiah Lowin – Machine Learning in Investing – [Invest Like the Best, EP.105]

→