Machine learning models · Phase 1 · Lesson 3

Data, features, targets and loss

Trace one example from raw data to features, prediction, target and loss.

This is one focused step in the 60-lesson course. Use the retrieval check before moving on.

Lesson goal

Trace one example from raw data to features, prediction, target and loss.

The core idea

A loss function is the ruler used during training. Change the ruler and the model is pushed towards a different behaviour.

Mental model

Picture it this way. A loss function is the ruler used during training. Change the ruler and the model is pushed towards a different behaviour. The important question is what assumption this picture makes, and whether that assumption fits the data.

Mathematical core

For regression, mean squared error is mean((y - y_hat)^2). For binary classification, log loss penalises confident wrong probabilities much more than uncertain ones.

Worked example

A cancellation model might use tenure and recent usage as features, predict a probability, compare it with the observed cancellation label, then add the example's loss to the training objective.

When to use it

It earns a place when

  • Use explicit targets and losses whenever you can state what a correct prediction means.
  • You can evaluate it against a credible baseline.
  • Its output fits the decision and data constraints.

Do not make it the default when

  • Do not confuse a metric used for reporting with the loss used to fit the model. They can be related without being identical.
  • A simpler model has not been tested.
  • The data or target definition is still unclear.

Failure modes

Watch for this. A loss can reward the wrong behaviour if the target is noisy, the labels are biased or the objective ignores the cost of errors.

When a result looks surprisingly good, inspect the split, target timing, error slices and data-generating process before celebrating.

Practice

Use this as a small experiment rather than a recipe to copy blindly. Change one thing, record the result and explain the change.

Do this. Create a tiny table with three rows. Pick one target, write three predictions and calculate which row should receive the largest squared error.

Retrieval check

Answer from memory first. The buttons reveal feedback, but the durable step is explaining why.

1. What is a feature?

2. Why square regression errors in mean squared error?

3. What does log loss punish especially strongly?

Transfer prompt. Describe one real problem where this model or idea would be a sensible candidate. Name the target, the main risk and the metric you would inspect.

Primary source

Google ML Crash Course. Use the source for the deeper treatment after you can explain the lesson's core idea without looking.