Translate a real question into model inputs, targets, training data, and predictions.

ML foundations: features, labels, and inference

Learning objectives

  • Turn a prediction question into features and a label.
  • Distinguish training from inference.
  • Identify data that should not be used as a feature.
  • Build a tiny dataset with scikit-learn.

A prediction question

Suppose we want to predict whether a robot should stop. A row is one observation:

distance_cm speed_cm_s obstacle_ahead
35 10 false
12 8 true

distance_cm and speed_cm_s are features. obstacle_ahead is the label we want to predict. During training, the model sees examples with labels. During inference, it receives only features and produces a prediction.

Build feature and label arrays

import numpy as np

features = np.array([
    [35, 10],
    [12, 8],
    [50, 5],
    [15, 12],
])
labels = np.array([0, 1, 0, 1])

print(features.shape)
print(labels.shape)
(4, 2)
(4,)

There are four observations and two features. The label array has one target for each observation.

Avoid leakage

Do not use information that would only become available after the event. For example, using emergency_stop_triggered to predict whether an emergency stop should happen would reveal the answer instead of learning a useful signal.

Practice

Define features and labels for one of these questions:

  1. Predict the energy use of a classroom.
  2. Classify whether an email is spam.
  3. Predict whether a plant needs water.

Write down what is known before the prediction and what must not be used.

Checkpoint

Explain why the number of feature rows must equal the number of labels. Give one example of a feature that could accidentally leak the target.

Next step

Continue to baselines and train/test splits.