Both algorithms answer the same question — "what's the probability this point is class 1?" — from opposite directions. k-NN looks locally: it finds the k closest training points to a query and returns the fraction that belong to class 1, with no training step at all. Logistic Regression looks globally: it fits one straight decision line by gradient descent, squashing a weighted sum of the coordinates through a sigmoid so the output always reads as a probability.
k-NN: P(y=1|x) = (1/k) · Σ 1[yᵢ=1] over the k nearest xᵢ
LogReg: P(y=1|x) = σ(w·x + b), σ(z) = 1/(1+e⁻ᶻ)
w,b updated by w -= η·∇L(w,b) each epoch
The terrain's height at every point in the plane is that predicted probability — a literal probability surface. The translucent plane is the decision threshold: wherever it slices through the terrain marks the boundary the classifier draws in feature space. Raise the threshold and fewer points get called positive (higher precision, lower recall); lower it and the opposite happens.
The ROC curve sweeps that threshold from 0 to 1 and plots the true-positive rate against the false-positive rate at each value — the diagonal is a coin flip, and the curve's area (AUC, computed here by trapezoidal integration over the real scores) is the probability a random positive point outscores a random negative one, independent of any single threshold choice.
- k — larger k smooths the k-NN surface into gentler probability gradients; k=1 makes sharp, jagged, overfit boundaries around single points.
- Class separation — pulls the two Gaussian blobs apart or together and retrains logistic regression on the new sample, changing how achievable a high AUC is.
- Decision threshold — moves the sea-level plane and instantly recolours which spheres count as correctly classified (dimmed) versus misclassified (bright yellow ring).