Learn

Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Lesson 3 of 10 in this unit

Understand Neural Networks · ORIGINAL LEARN AI LESSON

Predict a class probability.

Train a two-feature probability model, inspect its gradients and compare estimates with outcomes before choosing an action threshold.

By the end: Explain sigmoid and cross-entropy, distinguish probability fitting from threshold selection, and interpret calibration bins with their sample counts.

Start with the exampleJump to the experimentRead the explanation
Prerequisites and path options

Why learn this? Separate fitting a class probability from choosing the threshold used to take action.

01 · TRY

Start with something concrete.

A model estimates a 70% chance that an example belongs to class 1. That probability is not yet an action. Fit a small model, inspect its numerical calculation, then see which decisions change when the threshold changes.

Try the interactive model
02 · PREDICT
Before you experiment

You change only the decision threshold. Which quantity stays unchanged?

You change only the decision threshold. Which quantity stays unchanged?
03 · EXPERIMENT

Change one thing. Watch what follows.

Loading this browser experiment…

04 · UNDERSTAND
READ & CONNECT

Understand what changed.

Back to the experiment

A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.

Same learning goal in both modes: Explain sigmoid and cross-entropy, distinguish probability fitting from threshold selection, and interpret calibration bins with their sample counts.

The idea in everyday terms

Logistic regression first combines inputs into a score, then uses sigmoid to turn it into a number between zero and one. Training adjusts the weights so the probabilities better match the training labels. Its cross-entropy loss gives a larger penalty when the model assigns little probability to the correct label. A threshold separately decides when to act.

What to watch in the experiment

Train the model, then move only the threshold. The probabilities and calibration bins should stay the same while the decisions and error costs change. Compare predicted probabilities with observed frequencies rather than treating a confident output as a verified fact.

What this does not establish

The data are synthetic and the development set is repeatedly exposed. Empty calibration bins have no observed frequency, and a threshold cannot repair poorly fitted probabilities.

Open the full worked examples, calculations and limitations

This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.

Predict a chance before choosing an action

A system might estimate a 70% chance that a request needs attention. That estimate is different from deciding to act. A team with costly misses may act at a lower threshold; another with limited review capacity may need a different policy. First learn how a probability estimate is fitted, then inspect the consequences of its action rule.

This lesson uses two unitless numerical measurements and synthetic binary labels. Binary means the label is either 0 or 1. No real service outcomes are implied. The fixed training and validation inputs are disjoint, but every visit to validation is development practice.

Keep the weighted sum, change the output

Linear regression predicts an unrestricted number. A class probability should lie between 0 and 1. Logistic regression first calculates a weighted sum, called a logit, then applies a sigmoid to map that sum into a probability estimate.

For example, weights 1 and −1, inputs 2 and 1, and bias 0 produce z = 1 × 2 − 1 × 1 + 0 = 1. The sigmoid converts 1 into approximately 0.731. That means an estimated 73.1% chance of label 1 under the model, not a guarantee that this particular outcome will be 1.

z=w1x1+w2x2+b,p=11+exp⁡(−z)z=w_1x_1+w_2x_2+b,\qquad p=\frac{1}{1+\exp(-z)}

x₁ and x₂ are the two input measurements; w₁ and w₂ are their learned weights; b is the learned bias; and z is the weighted sum. p is the estimated probability of label 1. The inputs in this lab are unitless, so the weighted sum is also unitless. exp is the exponential function with base e, approximately 2.718. The calculator in the workbench evaluates it for you.

At z = 0, exp(0) = 1, so p = 1 / 2 = 0.5. Positive logits give p above 0.5; negative logits give p below 0.5. Logistic regression is linear in its logit, even though its probability output bends smoothly. For two features, a fixed non-endpoint threshold gives a straight boundary when at least one weight is nonzero.

Fit probabilities with cross-entropy

A good probability-fitting objective should penalize confident wrong predictions more than uncertain ones. Binary cross-entropy uses the probability assigned to the observed outcome. If the true label is 1, predicting p = 0.8 gives loss −ln(0.8) ≈ 0.223; predicting p = 0.2 gives loss −ln(0.2) ≈ 1.609. If the true label is 0, the relevant probability is 1 − p instead.

L=−1n∑i=1n[yiln⁡pi+(1−yi)ln⁡(1−pi)]L=-\frac{1}{n}\sum_{i=1}^{n}\left[y_i\ln p_i+(1-y_i)\ln(1-p_i)\right]

n is the number of training examples. For row i, yᵢ is its observed 0/1 label and pᵢ is its predicted probability of label 1. ln is the natural logarithm, the inverse of exp. The expression selects the log probability of the observed class, negates it and averages over examples. Loss is dimensionless; with natural logarithms it can be expressed in nats. You do not need to calculate logarithms by hand to run the guided experiment.

The implementation evaluates an equivalent stable expression directly from the logit. It does not take log(0) when a displayed sigmoid probability rounds to zero or one. Display precision and mathematical certainty are different things.

Change all parameters from the same model

Gradient descent changes parameters to reduce training loss. The learning rate sets the size of a step. For a single row, each weight’s contribution is (p − y) × its input; the bias contribution is p − y. Average these contributions across the training set.

For a worked example, start with zero weights and bias. With inputs (2, −1) and label 1, p = 0.5, so p − y = −0.5. The three gradient contributions are −1, +0.5 and −0.5. At learning rate 0.1, subtracting rate × gradient gives weight changes +0.1 and −0.05, and bias change +0.05. All contributions use the original zero-parameter model before any update is applied.

The lab’s one-CPU-update control uses the average over all 64 training rows, so it need not equal that one-row worked example. The optional update table shows the actual averages. The 100-update button performs the same simultaneous updates in a worker. Training is bounded at 1,000 accepted updates; cancellation retains the preceding accepted model.

Compare frequencies, not individual promises

A probability estimate of 0.8 does not promise an individual success. Calibration asks whether predictions near 0.8 are accompanied by about 80% positive outcomes over suitable repeated cases. Group the validation predictions into intervals, then compare each bin’s mean estimate with its observed positive fraction.

If five predictions average 0.8 and three observed outcomes are positive, the measured fraction is 3 / 5 = 0.6. That mismatch deserves investigation, but five cases cannot establish a stable calibration error. Empty bins have no observed fraction; they are not evidence of zero probability. Wider bins can also hide differences within them.

The lab’s plot uses identical zero-to-one axes and a diagonal showing equality of those two summaries. Every dot has a corresponding row with counts. The diagonal is not a confidence interval. Repeatedly choosing a model using these bins makes them development evidence; use appropriate new data for a final calibration claim.

Choose a threshold with consequences in mind

Predict label 1 when p is at least the selected threshold. Equality counts as positive. Moving that threshold changes the confusion counts, precision, recall and assumed error costs. It does not change weights, probability estimates, cross-entropy or the probability-bin table.

Try this before training: zero parameters give p = 0.5 everywhere. At threshold 0.5 every case is positive; at 0.55 every case is negative. The probabilities are identical in both experiments. This separates fitting the estimate from deciding how to use it.

After training, compare thresholds under different costs. A low numerical cost under the lab’s fixed assumptions is not automatically a deployable policy. Capacity, affected users, changing populations and unreliable cost estimates may matter. Use the decision-threshold lesson and cumulative decision project to develop that reasoning.

Know what the synthetic demonstration establishes

Training and validation labels are fixed seeded draws from sigmoid(−0.2 + 1.3x₁ − 1.1x₂). The trainer receives sampled training labels, not the generating probabilities or validation labels. Finite samples produce uncertainty even though the generating model belongs to this model family. This example does not show that real relationships are linear, that fitted probabilities are automatically calibrated, or that classroom performance transfers to a real service.

Use the downloaded experiment to explain a changed probability, an unchanged probability after a threshold move, a calibration-bin count and a limitation. Engineering and decision prompts are practice; independently reviewed artifacts and learner pilots remain pending.

05 · APPLY
Check your understanding

Ten predictions average probability 0.8, and six outcomes are positive. What is justified?

Ten predictions average probability 0.8, and six outcomes are positive. What is justified?
06 · CONTINUE

Take this idea with you.

Fit probabilities using training evidence, assess them against suitable outcomes, then choose an action rule with explicit costs. Neither a sigmoid nor a low training loss guarantees calibration or useful decisions.

My Learning
Explore related topics and the topic map

How this topic connects

Explore this topic on the interactive map

Use these connections to review a foundation or choose where to go next. You can open any topic without completing the others.

What it builds on

  • Linear regression

    Estimate a numerical outcome and inspect its errors before assuming a straight-line relationship is adequate.

  • Decision thresholds

    Choose when to act on a prediction by comparing the consequences of different kinds of error.

  • Probability and averages

    Combine outcomes with their frequencies or probabilities, keeping the denominator explicit when interpreting this lesson’s evidence.

You are herePredict a class probability

Train a two-feature probability model, inspect its gradients and compare estimates with outcomes before choosing an action threshold.

What it enables