Find a course

Module 1: The Machine Learning Workflow and DataLesson 1 of 1114 min

What Machine Learning Is and How Projects Work

Frame problems as regression, classification or clustering, learn the core vocabulary, and follow the steps of a real machine learning project.

Step 1 of 12Learn

Programs that write their own rules

A bike-sharing company wants to know how many bikes will be rented at each station tomorrow, so trucks can move bikes to where they will be needed. A programmer could try writing rules: more rentals on warm days, fewer when it rains, a spike at 8 a.m. near train stations, a dip on holidays. But how much does a 5°F rise matter on a Sunday in March near a university? The interactions multiply faster than anyone can write them down.

Machine learning (ML) flips the approach. Instead of writing the rules, you collect examples, in this case two years of hourly rentals along with weather, time, day of week and holidays, and let an algorithm find the function that maps those inputs to the output. A classic definition, from computer scientist Tom Mitchell, says a program learns from experience E with respect to a task T and a performance measure P if its performance at T, measured by P, improves with E. Here, T is predicting rentals, E is the historical data and P might be the average error in bikes per hour.

The core vocabulary:

  • Each row of data is an example (or observation).
  • The input columns are features, usually written x. Temperature, hour and holiday are features.
  • The value to predict is the label or target, written y.
  • The model is a function f with adjustable parameters. Training chooses parameters so that f(x) is close to y on the examples.
  • Settings you pick before training, such as how complex the model may be, are hyperparameters.

The goal is never to fit the past perfectly. It is to generalize: to make good predictions on data the model has not seen.

Step 2 of 12Practice · Diagram

The main families of machine learning

Most problems in this course fit one branch of this tree. Tap a node for an example.

Predicting how many bikes a station will rent tomorrow belongs to which leaf?

Tap the shape that answers the question, then press Check.

The main families of machine learningHierarchy diagram: Machine learning, Supervised, Unsupervised, Reinforcement, Regression, Classification, Clustering, Dimensionality reduction.Machine learningSupervisedRegressionClassificationUnsupervisedClusteringDimensionality reductionReinforcement
Machine learning
Supervised

Learns from examples that come with the right answer (labels).

Unsupervised

Finds structure in data that has no labels.

Reinforcement

An agent learns by trial and reward, like a game-playing program.

Regression

Predicts a number: rentals, prices, temperatures.

Classification

Predicts a category: spam or not, fraud or not.

Clustering

Groups similar items, such as customer segments.

Dimensionality reduction

Compresses many features into a few, as PCA does.

Step 3 of 12Practice · Sort into groups

Classify each problem by the type of machine learning task.

Tap an item, then tap its group (or drag it there).

Step 4 of 12Learn

The workflow, step by step

Real ML projects follow a fairly standard sequence. Skipping steps is the most common reason projects fail, usually not choosing the wrong algorithm.

  1. Define the problem and the metric. What decision will the prediction support? What does success mean in numbers? For the bike company: mean absolute error under 3 bikes per station-hour, so trucks rarely arrive with too few bikes.
  2. Collect data. Gather examples that represent the situations the model will face. Two years of rentals covers seasons; one month would not.
  3. Explore and clean. Plot distributions, look for missing values, impossible entries (a temperature of 900°F) and duplicates.
  4. Engineer features. Turn raw data into useful inputs: extract hour of day and weekday from a timestamp, encode categories, scale numbers.
  5. Split the data into training, validation and test sets before fitting anything.
  6. Train baseline and candidate models. Always start with a simple baseline, such as "predict the average for that hour and station." A fancy model that cannot beat a simple baseline is not worth deploying.
  7. Evaluate and tune on validation data; compare models fairly.
  8. Test once on the held-out test set for an honest final estimate.
  9. Deploy and monitor. Track performance in production, because the world changes.

The loop is iterative. Evaluation often sends you back to collect more data or engineer better features. Practitioners commonly report that most of their time goes to steps 2 to 4, the data work, rather than to modeling.

Step 5 of 12Practice · Put in order

Put the stages of a machine learning project in the usual order.

Drag the items, or use the arrow buttons, to put them in order.

  1. Train a baseline and candidate models
  2. Tune models on validation data
  3. Deploy and monitor
  4. Collect and explore the data
  5. Define the problem and success metric
  6. Evaluate once on the test set
  7. Engineer features and split the data

Step 6 of 12Diagram

The workflow is a loop, not a line

After deployment, monitoring sends you back to earlier stages. Tap a stage.

The workflow is a loop, not a lineCycle diagram: Define problem and metric → Collect and explore data → Features and split → Baseline and models → Tune and evaluate → Deploy and monitor.Monitor and improveDefine problemand metricCollect andexplore dataFeatures andsplitBaseline andmodelsTune and evaluateDeploy andmonitor

Tap a shape with to see more.

Define problem and metric

What decision does the prediction support, and what number means success?

Collect and explore data
Features and split

Split before fitting anything on the data, to avoid leakage.

Baseline and models

Always beat a simple baseline first.

Tune and evaluate
Deploy and monitor

Drift or new needs send you back to data collection or even the problem definition.

Step 7 of 12Learn

Choosing a baseline and a metric

Two decisions made at the start shape everything that follows.

The metric. Machine learning optimizes whatever you measure, so measure what matters. For regression, common choices are:

  • Mean absolute error (MAE): the average size of the errors, in the target's units. "On average we are off by 2.4 bikes." Easy to explain.
  • Mean squared error (MSE) and its square root RMSE: square the errors before averaging, so large errors count much more. Use it when big misses are especially costly.
  • R²: the share of the variance in the target explained by the model; 1 is perfect, 0 is no better than predicting the mean.

For classification you'll meet accuracy, precision, recall and F1 later in the course.

The baseline. A baseline is the simplest reasonable prediction, and it tells you whether ML is adding value at all. For regression, predict the mean or median of the training targets, or last week's value. For classification, predict the most common class.

Example: a model predicting daily sales has an MAE of 40 units. Sounds good? If simply predicting "same as the same weekday last week" gives an MAE of 42, the model adds almost nothing and may not justify its complexity. If the baseline MAE is 120, the model is a large improvement.

A useful habit is to write down the baseline score before training anything. It anchors every later result and protects you from celebrating a model that only looks impressive.

Step 8 of 12Practice · Chart

Same MAE, very different RMSE

Model A misses by 3 on each of five days. Model B is perfect four days and misses by 15 once. Both have an MAE of 3.

Tap the metric that exposes Model B's one big miss.

Tap the bar that answers the question, then press Check.

Same MAE, very different RMSEBar chart with 2 categories: MAE: Model A (3,3,3,3,3) 3, Model B (0,0,0,0,15) 3; RMSE: Model A (3,3,3,3,3) 3, Model B (0,0,0,0,15) 6.71.02468Error (units)MAERMSE3336.71
Computed from the two error lists shown. RMSE of B = square root of (225 / 5) = 6.71.
Same MAE, very different RMSE
ItemModel A (3,3,3,3,3)Model B (0,0,0,0,15)
MAE33
RMSE36.71

Step 9 of 12Practice · Work it out

A model's predictions for four days are 10, 12, 9 and 15 units; actual sales were 12, 12, 6 and 14. What is the mean absolute error (MAE)?

Step 10 of 12Note

Step 11 of 12Practice · Select all that apply

A hospital wants to predict which patients will be readmitted within 30 days. Which are sensible first steps? Select all that apply.

Select all that apply.

Step 12 of 12Practice · Choose one

Your new model predicts daily website visitors with an MAE of 300. Simply predicting yesterday's visitor count gives an MAE of 310. What is the best conclusion?