Formula Used
d(x,y) = √Σ(xᵢ − yᵢ)²
d(x,y) = Σ|xᵢ − yᵢ|
d(x,y) = [Σ|xᵢ − yᵢ|ᵖ]¹ᐟᵖ
wᵢ = 1 / dᵢᵖ
Choose the class with maximum neighbour vote.
ŷ = Σ(wᵢyᵢ) / Σwᵢ
How to Use
- Choose classification, regression, or automatic detection.
- Paste training data with features and one target column.
- Enter query points using matching feature columns.
- Select K, distance, scaling, and weighting options.
- Choose a validation method and K search range.
- Submit the form and inspect every nearest neighbour.
- Copy results or export CSV and PDF reports.
Example Data
| ID | Feature 1 | Feature 2 | Target |
|---|---|---|---|
| 1 | 1.0 | 1.2 | Class A |
| 2 | 1.3 | 1.0 | Class A |
| 3 | 4.8 | 5.1 | Class B |
| 4 | 5.2 | 4.9 | Class B |
KNN Guidance
KNN predicts from nearby observations. It stores training data directly. Scaling often prevents large units dominating distance.
Small K values follow local patterns. Large K values smooth predictions. Validation helps balance bias and variance.
Classification uses neighbour votes. Regression combines nearby target values. Weighted methods emphasize closer observations.
KNN can model nonlinear boundaries. It may slow on large datasets. Dimensionality reduction can improve performance.
Frequently Asked Questions
What does K mean?
K is the number of neighbours used for prediction.
How should I choose K?
Compare several values through cross-validation and select stronger performance.
Why is scaling important?
Scaling prevents large numeric ranges from dominating distance calculations.
Can KNN perform regression?
Yes. It averages or weights nearby numeric target values.
Which distance metric works best?
The best metric depends on feature meaning and distribution.
What causes classification ties?
Equal class votes can occur, especially with even K.
How are probabilities estimated?
The calculator divides each class vote by total votes.
Can I predict several rows?
Yes. Add multiple query rows for batch prediction.
Does KNN train a model?
KNN stores examples and calculates distances during each prediction.