Skip to content

Training vs Inference

Lesson 2 of 32 · 4 min

Training vs Inference

Step 1 of 11

Training fits parameters from labelled examples. Here are four of them.

The Idea

Training is the loop that adjusts parameters until predictions match labels. It is expensive and runs rarely. Inference is a single pass over frozen parameters to answer one input. Same model, two completely different cost profiles.

Real-World Example

A pianist preparing a concert. Months of rehearsal are slow, repeated and full of corrections. The performance itself runs once, in real time, at full speed, with no chance to redo a bar.

The Code

Your turn

What does this print?

data = [(2.0, "low"), (4.0, "low"), (10.0, "high"), (12.0, "high")]
low = [x for x, y in data if y == "low"]
high = [x for x, y in data if y == "high"]
threshold = (sum(low) / len(low) + sum(high) / len(high)) / 2

def predict(x):
  return "high" if x > threshold else "low"

print(threshold, predict(7.0))

Mini quiz

1 / 3

In a deployed system, which runs far more often?

Certification prepPreparing for Associate Data Practitioner? Try the free 50-question practice exam

ReferenceBig-O cheat sheetPatterns cheat sheet