Training point k nearest neighbors Query point โ†’ prediction
cross-section at Z = 0.0

K-Nearest Neighbors Regression (2D): Predicting by Local Averaging

Supervised learning splits into two jobs: classification (predict a category) and regression (predict a number). This simulator focuses on the regression side of k-nearest neighbors โ€” instead of voting on a class, it averages the target values of the k closest labeled points in a 2D feature plane (X, Z) to predict a continuous value at any query location. The top panel renders a live heatmap of the prediction (or the true function, or the pointwise error) across the whole plane with training points and the current neighborhood overlaid; the bottom panel slices through that surface at the query's Z value so you can watch the 1D fit hug the true curve tightly at low k and flatten out as k grows, with live readouts for the predicted value, the ground truth, the pointwise error, and the RMSE across the whole domain.