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 background colour at every pixel is that predicted probability — deep blue means "confidently class 0", deep red means "confidently class 1", and the pale seam between them is the actual decision boundary the classifier draws in feature space. The bright contour line marks exactly where the probability equals your chosen threshold.
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 boundary into gentler curves; k=1 makes sharp, jagged, overfit boundaries that wrap single points.
- Class separation — pulls the two Gaussian blobs apart or together and changes how achievable a high AUC is.
- Decision threshold — slides the boundary contour and instantly recolours which points count as correctly classified (dimmed) versus misclassified (bright yellow ring).
- Planted points — click the canvas to drop your own point of the selected class anywhere; both classifiers retrain on the enlarged sample so you can watch a single outlier bend a k-NN boundary sharply while barely nudging the logistic-regression line.