Lesson 1 of 7, about 20 minutes
The machine learning workflow
Machine learning projects succeed or fail long before any code is written. In this lesson you'll learn the workflow professionals follow, so every model you build starts on the right foot.
The seven steps
- Frame the problem. What decision will the model help with? What exactly will it predict? How will we know it's useful?
- Get the data. What examples exist? Do they include the answer (label) you want to predict?
- Explore and clean. Understand the data, fix errors, handle missing values.
- Prepare features. Turn raw data into numbers a model can use.
- Train models. Start simple, then try stronger models.
- Evaluate honestly. Test on data the model hasn't seen, using metrics that match the business goal.
- Deploy and monitor. Put the model to work, and check it keeps performing as the world changes.
In practice you loop back often. Evaluation might show you need better data, which sends you back to step 2.
Framing: the most important step
Vague: "Use AI to improve our SACCO."
Well framed: "When a member applies for a loan, predict the probability they'll be more than 30 days late on repayment, using their savings and repayment history. Loan officers will use the score to decide which applications need a closer review. Success means catching at least 70% of future late payers while flagging no more than 25% of all applicants."
A well-framed problem tells you the label, the features available at prediction time, how the prediction will be used, and the success measure.
Regression or classification?
| Type | Predicts | Examples |
|---|---|---|
| Regression | A number | Rent, sales next month, crop yield, delivery time |
| Classification | A category | Will default or not, spam or not, which product a customer will buy |
| Clustering (unsupervised) | Groups, with no labels | Customer segments, similar products |
The data leakage trap
Only use features you'd actually have at the moment of prediction. If you're predicting loan default at application time, you can't use "number of reminder SMS sent", because those are only sent after the customer is already late. Including it makes the model look brilliant in testing and useless in real life. This mistake is called data leakage, and it's very common.
Start with a baseline
Before building anything clever, ask: what's the simplest possible prediction? For rent, it might be "predict the average rent for every house." For loan default, "predict nobody defaults." Your model must clearly beat the baseline to be worth using.
Your toolkit
We'll use scikit-learn, which is already installed in Colab. Its models all follow the same pattern, so once you learn one, you know them all:
from sklearn.linear_model import LinearRegression
model = LinearRegression() # 1. choose a model
model.fit(X_train, y_train) # 2. train on features X and labels y
preds = model.predict(X_test) # 3. predict on new data
Try it. Frame two ML problems from your own field using the SACCO example as a template. For each, state: the label, 4 features available at prediction time, how the prediction will be used, the success measure, and a baseline.
Key takeaways
- Follow the workflow: frame, data, clean, features, train, evaluate, deploy.
- Framing defines the label, features, use and success measure.
- Avoid data leakage and always compare against a simple baseline.
Enjoyed this? Create a free account, then unlock all 7 lessons, the exam and the certificate for US$82.
Unlock the full course