Training vs Inference
Step 1 of 11
examples4
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