Intermediate 25 min

Test the trained model

After training, weight and bias are just numbers sitting in memory. Inference means running the forward pass without updates.

import math

def sigmoid(x):
    return 1 / (1 + math.exp(-x))

# Example values after training (yours may differ slightly)
weight = 1.2
bias = -2.1

def predict(study_hours):
    raw_output = study_hours * weight + bias
    probability = sigmoid(raw_output)
    label = "Pass" if probability >= 0.5 else "Fail"
    return label, probability

print(predict(1.5))   # likely Fail, prob maybe ~0.2
print(predict(3.5))   # likely Pass, prob maybe ~0.8

Different answers at 1.5 vs 3.5 hours happen because the learned line separates fail-like hours from pass-like hours. The probability tells you how far from the 0.5 cliff—not how “confident the AI feels.”

Why probabilities differ

study_hoursTypical behavior
1.5Below the region where training saw passes → lower prob
2.5Near the boundary → prob ~0.5–0.6
3.5In the pass region from training → higher prob

The model only knows patterns in four points. Guessing for 10 hours is extrapolation—it might look confident, but the data never taught that.

Exercise — predict 2.5 hours

print(predict(2.5))

Question: Is the model unsure? Why?

Answer

If probability is near 0.5, yes—small nudges to weight or hours flip the label. That is what a decision boundary looks like in miniature.

Exercise — add a data point

Add (5, 1) to the dataset and retrain.

Question: Does the model become more confident on high hour counts?

Answer

Often yes for hours near 4–5, because another pass example pulls the boundary. Always verify by printing probabilities—not just Pass/Fail.

Live runner — your predict function

Plug in weights from your last training run on page 4.

🐍 Python Predict with trained weights
📟 Console Output
Run code to see output...

Mid-tutorial quiz

Three questions—good time to pause and check the story so far.

Key takeaways

  1. After training, prediction is forward pass only—no weight updates.
  2. Probability near 0.5 means the example sits near the decision boundary.
  3. Tiny data means fragile extrapolation—be skeptical outside the training range.

Next: add sleep hours as a second input and watch the formula grow one term.