Confusion Matrix Rates, Sigmoid Forward Pass, and Activation Choice
Machine LearningModel answerLast updated
Work through a screening-style ML set: pick the confusion matrix matching target TPR/FPR, hand-compute a sigmoid neuron, and justify activation choices per layer.
Three short fundamentals problems of the kind that show up in timed ML screens. Show your arithmetic.
1) Matching a target TPR and FPR
Four binary-classification confusion matrices are proposed. In each, rows are actual and columns are predicted.
| Option | TP | FN | FP | TN |
|---|---|---|---|---|
| A | 80 | 20 | 10 | 90 |
| B | 45 | 5 | 45 | 5 |
| C | 50 | 50 | 5 | 95 |
| D | 90 | 10 | 30 | 70 |
A model is required to hit TPR (recall) = 0.80 and FPR = 0.10 simultaneously.
Question: Which option(s) meet both targets? Briefly say what operating point each of the other options represents.
2) Forward pass of one sigmoid unit
A neuron computes
[ z = w^\top x + b, \qquad \hat{y} = \sigma(z) = \frac{1}{1+e^{-z}} ]
with (w = [0.5,,-1.0]), (x = [2.0,,1.0]), (b = 0).
Question: Compute (z) and (\hat{y}) to three decimal places, and state the value of the derivative (\sigma'(z)) at this point.
3) Choosing activations
The candidate set is sigmoid, tanh, ReLU, Leaky ReLU, softmax.
- Which activation belongs in the output layer for multi-class, single-label classification?
- Give two independent reasons ReLU-style nonlinearities are standard in hidden layers of deep nets.
- Name one characteristic failure of sigmoid/tanh in deep hidden layers and explain the mechanism.
Hints
Hint 1
For part 1, each rate is computed inside a single actual-class row: TPR uses the positive row, FPR uses the negative row. Never divide by the grand total.
Hint 2
For part 2, watch the sign of the second weight — the dot product largely cancels. Then use σ(0) and recall σ'(z) = σ(z)(1 − σ(z)).
Hint 3
For part 3, structure your answer as output layer / hidden layer / failure mode, and justify each with the shape of the derivative rather than a slogan.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Part 1 — TPR and FPR
Definitions. TPR = TP / (TP + FN): the share of actual positives that are caught. FPR = FP / (FP + TN): the share of actual negatives that are wrongly flagged. Both are conditional on the true class, which is exactly why they can be traded against each other by moving the decision threshold while the underlying model stays fixed.
| Option | TPR = TP/(TP+FN) | FPR = FP/(FP+TN) | Verdict |
|---|---|---|---|
| A | 80/100 = 0.80 | 10/100 = 0.10 | matches both |
| B | 45/50 = 0.90 | 45/50 = 0.90 | no |
| C | 50/100 = 0.50 | 5/100 = 0.05 | no |
| D | 90/100 = 0.90 | 30/100 = 0.30 | no |
Answer: only Option A.
Reading the others correctly matters as much as the arithmetic. Option B has TPR equal to FPR, so it lies on the ROC diagonal — its decisions carry no information beyond a coin flip biased toward "positive" 90% of the time. Option C is a strict threshold: it almost never raises a false alarm but misses half the positives. Option D is a permissive threshold: it catches nearly everything at the price of a 30% false-alarm rate. C and D are plausibly the same underlying scorer at two different cutoffs, and which one you would ship depends on the relative cost of a miss versus a false alarm.
Frequent errors. Dividing FP by the total sample size (or reporting 1 − precision) instead of conditioning on actual negatives. Confusing FPR with FNR, which is simply 1 − TPR. Reading the table column-first when the problem states rows are actual.
Part 2 — The sigmoid unit
Pre-activation:
z = (0.5)(2.0) + (−1.0)(1.0) + 0 = 1.0 − 1.0 = 0.000
Output:
ŷ = σ(0) = 1/(1 + e⁰) = 1/(1+1) = 0.500
Derivative: σ'(z) = σ(z)(1 − σ(z)) = 0.5 × 0.5 = 0.250, which is the maximum possible slope of the sigmoid. So the unit is sitting exactly on its decision boundary and simultaneously at its most gradient-friendly point — a useful thing to notice, since it links directly to part 3.
Common slips. Losing the minus sign on the second weight (gives z = 2, ŷ ≈ 0.881). Writing the sigmoid as 1/(1+e^{z}), which flips the curve. Rounding intermediate terms instead of only the final answer.
Part 3 — Activation selection
Output layer for multi-class, single-label
Softmax, (\text{softmax}(z)_i = e^{z_i}/\sum_j e^{z_j}). It maps the logit vector to a distribution over mutually exclusive classes: all entries positive, sum to one, which is exactly the structure the likelihood assumes. Paired with categorical cross-entropy the gradient with respect to the logits collapses to ŷ − y, which is why the combination is the default.
Draw the boundaries explicitly: multi-label problems (classes not exclusive) use an independent sigmoid per class with binary cross-entropy, and plain binary classification is the K = 2 special case of softmax.
Why ReLU-style units dominate hidden layers
Any two of these, argued from the derivative rather than asserted:
- No saturation on the positive side. ReLU(z) = max(0, z) has derivative exactly 1 for z > 0. Backprop multiplies one Jacobian per layer; a factor of 1 leaves the gradient magnitude intact, so signal survives many layers.
- Cheap. Forward is a comparison, backward is a 0/1 mask — no exponentials, unlike sigmoid and tanh.
- Sparse, selective activations. Units with negative pre-activation output exactly zero, so only a subset of the layer is active, which tends to yield more disentangled features and cheaper downstream computation.
- Piecewise linear. Optimization behaves like a well-conditioned linear problem locally; the network is still globally nonlinear and remains a universal approximator.
Known weakness worth naming: dying ReLU. A unit whose pre-activation is negative for every input in the data distribution receives exactly zero gradient and stops updating forever. Leaky ReLU (slope α ≈ 0.01 on the negative side), PReLU, ELU and GELU all retain a small nonzero gradient there to prevent this.
The characteristic failure of sigmoid/tanh in deep hidden layers
Vanishing gradients, driven by saturation.
- σ'(z) = σ(z)(1 − σ(z)) peaks at 0.25 at z = 0 and decays toward 0 as |z| grows.
- tanh'(z) = 1 − tanh²(z) peaks at 1 but also collapses to 0 for large |z|.
- Backpropagation multiplies one such factor per layer. With sigmoid and ten layers, the worst-case shrink is 0.25¹⁰ ≈ 10⁻⁶; early layers receive essentially no signal and train far more slowly than late ones.
- Once a unit saturates, its derivative is near zero, so it cannot escape on its own — the layer becomes effectively frozen.
A secondary issue: sigmoid outputs are confined to (0, 1) and therefore not zero-centered, so the gradients on a layer's incoming weights share a sign and updates zig-zag. Tanh fixes the centering but still saturates.
Where sigmoid and tanh remain correct choices: output layers (probabilities), and gates inside recurrent cells such as LSTM and GRU, where a squashed value in (0, 1) is exactly the semantics needed.
What strong answers show
- Correct conditioning in part 1 — FPR is measured within actual negatives — plus a one-line reading of each decoy's operating point.
- Clean, sign-correct arithmetic in part 2 with rounding deferred to the end, and the observation that σ'(0) is the maximum.
- Mechanistic reasoning in part 3: derivative magnitudes multiplied through layers, not just the phrase "ReLU avoids vanishing gradients", plus the softmax/sigmoid boundary case, the dying-ReLU remedy, and where sigmoid/tanh still belong.