K-Nearest Neighbors Regression (2D): Predicting by Local Averaging
Interactive 2D k-nearest neighbors regression: drag a query point across a flat feature plane and watch a live heatmap of the k-NN prediction, a cross-section curve, and neighbor-connector lines show how averaging nearby labels goes from noisy to over-smoothed as you tune k, distance weighting and label noise.
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.
Interactive 2D k-nearest neighbors regression: drag a query point across a flat feature plane and watch a live heatmap of the k-NN prediction, a cross-section curve, and neighbor-connector lines show how averaging nearby labels goes from noisy to over-smoothed as you tune k, distance weighting and label noise.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install