Your First Machine Learning Project: 7 Steps That Work

⚡ TL;DR: Load, explore, split, preprocess, train, evaluate, ship — in that order. The split comes before any preprocessing, and the test set is touched once. Get the order right and everything else is detail.

Every other post on this site covers one piece. This one puts them in order, so you can work through a real dataset start to finish without wondering what comes next.

End-to-end machine learning project pipeline in seven steps, highlighting that the train test split must come before preprocessing
The order matters more than any individual step. Preprocessing before the split is the mistake that quietly inflates every score you report.

Step 1 — Frame the question first

Before any code: what are you predicting, and what does a useful answer look like? “Predict house prices” is a regression problem. “Will this customer churn” is classification. The answer decides your model and your metrics.

Also decide what “good enough” means now, not after you see the results. It is remarkably easy to move the goalposts to wherever your model happened to land.

Step 2 — Load and explore

Open the data in pandas and run the five commands: shape, head(), info(), describe(), isna().sum().

✅ What you are looking for: how many rows and columns; which columns have gaps; whether numeric columns were read as text; how skewed things are; and — for classification — whether the classes are wildly imbalanced. Ten minutes here saves hours later.

Step 3 — Split, before anything else

This is the step beginners get out of order, and it is the one that matters most.

⚠️ Split now, not after cleaning

If you scale, impute or encode using the whole dataset and split afterwards, information from your test rows has shaped your training data. Your evaluation is no longer honest — and the failure is invisible, because everything still runs.

Split first. Everything that learns from data gets fitted on the training portion only.

Step 4 — Preprocess, fitted on training data

In order: fill the gaps, encode the categories, deal with outliers, then scale. This is also where feature engineering earns its keep — usually more than any model choice you make later.

Wrap it all in a scikit-learn Pipeline. It is not tidiness for its own sake: a pipeline makes it structurally impossible to leak, because every step is refitted inside each cross-validation fold automatically.

Step 5 — Train a baseline first

🧪 Start deliberately stupid

Your first model should be something trivial: predict the mean for every row, or always predict the majority class.

That number is your floor. If a neural network beats it by two points, the neural network is not working — and without the baseline you would have called 88% a success.

Then fit something simple and real: linear or logistic regression, or a decision tree. Only then reach for anything complicated.

Step 6 — Evaluate honestly

Use cross-validation on your training data to compare options, and report the spread as well as the mean.

Pick metrics that match the problem: RMSE or MAE for regression; the confusion matrix and precision and recall for classification. Accuracy alone is rarely enough and is actively misleading on imbalanced data.

Compare training against validation scores to see whether you are overfitting or underfitting, and fix whichever you have before doing anything else.

Step 7 — Test once, then ship

When everything is settled, evaluate on the test set. Once. That number is what you report.

If it is much worse than your cross-validation scores, you have overfit to your own decisions — and the honest response is to say so, not to go back and tune further against the test set.

Before it goes anywhere near real users, check performance per group, not just overall. Then see deploying your first model.

A realistic sense of where the time goes

StageShare of effortWhat beginners expect
Understanding the problem~15%Skipped entirely
Cleaning and features~60%A quick preliminary
Modelling~15%The whole job
Evaluating and writing up~10%An afterthought

Good first datasets

Pick something small and well-understood so you are learning the process, not fighting the data. The Titanic dataset covers missing values and categorical encoding. California Housing is a clean regression problem that ships with scikit-learn. Palmer Penguins is a friendlier replacement for the Iris dataset.

Whichever you choose, write up what you did and what you found. Explaining your reasoning is what turns a tutorial you followed into something you actually understand.

🔑 Key Takeaways

  • Split before you preprocess. Everything that learns from data is fitted on training data only.
  • Always build a trivial baseline first, so you know what “good” actually means.
  • Use a pipeline — it makes leakage structurally impossible.
  • Touch the test set once, at the very end.
  • Expect to spend most of your time on data, not on models.

Further reading

scikit-learn’s introductory tutorial follows this same order in code, and its pipeline documentation shows how to bundle preprocessing and model into one object.

Where to go next

Scroll to Top