Velamuvi AIAcademy

Lesson 12 of 13 · Getting It Right

The ML Project Workflow

The steps of every machine learning project: define the problem, explore data, prepare features, set a baseline, train, evaluate, deploy and monitor.

  • 5 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • List the steps of a machine learning project in order
  • Explain why every project needs a baseline
  • Compare a model against a baseline in Python
  • Describe what happens after a model is deployed

The steps

Machine learning projects differ in data and models, but they follow the same path:

  1. Define the problem. What exactly will be predicted, for whom, and how will success be measured? (“Predict delivery time in minutes; success = average error under 5 minutes.”)
  2. Collect data. Gather examples with the right labels.
  3. Explore the data. Look at rows, ranges, missing values, odd outliers.
  4. Prepare the data. Clean it, encode categories, build features, split into training, validation and test sets.
  5. Set a baseline. The simplest reasonable prediction, as a yardstick.
  6. Train models. Start simple; try more complex models if needed.
  7. Evaluate. Compare on validation data; check the final choice once on the test set.
  8. Deploy. Put the model where it's used: an app, a website, a report.
  9. Monitor and improve. Watch real-world performance and retrain as things change.

It's rarely a straight line: exploring data often sends you back to redefine the problem, and evaluation often sends you back to collect more data.

Always start with a baseline

Try it yourselfPython
# Workflow step: always compare your model with a simple baseline.
# Delivery times (minutes) with the distance (km) for 10 past orders.
train = [(1.0, 14), (2.5, 19), (4.0, 25), (0.5, 12), (3.0, 22), (5.0, 29), (2.0, 18), (6.0, 33)]
test = [(1.5, 16), (4.5, 27)]

# Baseline: always predict the average delivery time
baseline = sum(t for _, t in train) / len(train)

# Model: a straight line from distance to time
n = len(train)
mx = sum(d for d, _ in train) / n
my = sum(t for _, t in train) / n
slope = sum((d - mx) * (t - my) for d, t in train) / sum((d - mx) ** 2 for d, _ in train)

def predict(distance):
    return my + slope * (distance - mx)

baseline_error = sum(abs(baseline - t) for _, t in test) / len(test)
model_error = sum(abs(predict(d) - t) for d, t in test) / len(test)
print(f"Baseline (always {baseline:.1f} min): average error {baseline_error:.1f} min")
print(f"Model ({slope:.1f} min per km):        average error {model_error:.1f} min")
print("Worth using the model?", "yes" if model_error < baseline_error else "no")

Always predicting 21.5 minutes would be off by 5.5 minutes on average. The model, which learned that each kilometre adds about 3.8 minutes, is off by only 0.2. Clearly worth it. If a model only matched the baseline, it wouldn't be worth the complexity of building, deploying and maintaining it.

After deployment

A deployed model needs looking after:

  • Monitor its predictions and, when the true answers arrive later, its errors.
  • Retrain on fresh data regularly, or when performance drops.
  • Collect feedback on mistakes and add them to the data.

Common mistakes

Practice exercise

Before training anything, measure a baseline. Any real model must beat this number.

Your solutionPython
train_prices = [200, 240, 260, 300]     # house prices (thousands) in the training set
test_prices = [230, 290]                # house prices in the test set

# Baseline model: predict the AVERAGE training price for every house.
# Print its mean absolute error on the test set, like: Baseline MAE: 12.5
Knowledge check

Why should every machine learning project measure a baseline?

Summary

  • Projects follow the same steps: define, collect, explore, prepare, baseline, train, evaluate, deploy, monitor.
  • Data work usually takes the most time.
  • A baseline shows whether a model adds real value.
  • After deployment, watch for data drift, monitor errors and retrain.

Next: the course project, predicting house prices from start to finish.

Finished reading? Tick it off to track your progress.