1. The playground
The data are two rings: class 1 is inside, class 0 is outside. Blue points are class 0, green points are class 1. White rings mark validation points. Red rings mark points the current model gets wrong.
Choose Linear, Quadratic, Neural net, kNN, or Tree. Linear, quadratic, and neural models use Train or Step; kNN and trees refit instantly. The background is the model's probability: blue leans class 0, green leans class 1. The pink line is the boundary where p = 0.5. Use Move points to drag a point, or Add class 0 / Add class 1 to click in a new training point.
Every boundary, probability, loss, and accuracy on this page is computed from the training data. Nothing is pre-drawn. Changing the data or the model resets the walk, so each comparison starts from zero.
2. What to notice
- Linear. A straight boundary cannot put the inner ring on one side and the outer ring on the other. Training accuracy stalls well below 100% because some points stay on the wrong side.
- Quadratic. The extra x² and y² features let the boundary curve into a circle or ellipse. Training accuracy can jump to 100% quickly.
- Neural net. Eight tanh hidden units learn their own features. The boundary can curve without a hand-written x² or y² feature, but training is slower and noisier than the quadratic model.
- kNN. The background is the fraction of the k nearest training points in class 1. Small k follows individual points; larger k smooths the boundary.
- Tree. The plane is cut into axis-aligned rectangles. A shallow tree underfits; a deeper tree can carve a small region around individual points.
- Train vs validation. The two scores do not have to agree. A perfect training score with a lower validation score is a warning about overfitting or an unrepresentative split.
- Wrong points. Red rings show examples on the wrong side of p = 0.5. Adding a point or dragging one changes the data and resets the boundary.
- Confidence. The shading is not a second boundary. It shows how far the probability is from 0.5, not whether the model is correct.
3. The model
Linear and Quadratic modes are logistic classifiers on a feature map φ:
The sigmoid turns the score into a probability:
Linear mode uses φ(x, y) = [x, y]. Quadratic mode uses:
The model is still linear in its weights. The curvature comes from the features. Neural net mode replaces the hand-written features with eight tanh hidden units:
The hidden weights and the output weights are trained together by backpropagation. Training minimizes the mean cross-entropy with full-batch gradient descent:
kNN predicts from the fraction of the k nearest training points in class 1:
A tree predicts the majority class in the leaf reached by the point. The tree is grown by choosing splits that reduce weighted Gini impurity:
Accuracy is measured after thresholding at 0.5:
The parametric models use a fixed learning rate of 0.5 for linear/quadratic and 1.0 for the neural model, plus a small L2 penalty of 0.001. kNN uses the k slider and the tree uses the depth slider; both are non-parametric and have no gradient-descent loop.
4. The data
The default set has 28 points: 14 inner (class 1) and 14 outer (class 0). Each class contributes 10 training points and 4 validation points. The rings are generated with a seeded random number generator, so the same seed gives the same data; New data changes the seed.
This is a deliberately small, two-dimensional simulation. Real classifiers have more features, more points, and noisier labels. The same ideas apply: choose a representation, fit parameters, and check held-out data.
The parametric models use full-batch gradient descent, not mini-batches. kNN and trees fit directly from the data. The boundary and accuracy are the lesson, not the engineering of a production training loop.
5. Related lessons
These lessons build the classifiers, the feature map, the neural network, kNN, trees, and the generalization check from the beginning.