# Metoda k najbliższych sąsiadów (k-NN)

EN: **k-nearest neighbours** · id `knn`

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Uczenie maszynowe](https://aiatlasgraph.com/t/ml.md) › [Uczenie nadzorowane](https://aiatlasgraph.com/t/supervised.md) › Metoda k najbliższych sąsiadów (k-NN)

## Description

- PL: Model bez treningu parametrów: odpowiedź dla nowego przykładu wynika z k najbardziej podobnych przykładów w danych. Ta sama idea stoi za wyszukiwaniem wektorowym.
- EN: A model with no parameter training: the answer for a new example comes from the k most similar examples in the data. The same idea underlies vector search.

## In one sentence

- PL: To przewidywanie odpowiedzi przez porównanie nowego przypadku z najbardziej podobnymi znanymi przykładami.
- EN: This predicts an answer by comparing a new case with the most similar known examples.

## Problem it solves

- PL: Masz opisane przykłady, ale potrzebujesz odpowiedzi dla nowego przypadku bez budowania skomplikowanych reguł.
- EN: You have labelled examples but need an answer for a new case without building complicated rules.

## What it does

- PL: Wybiera podobne przykłady według ustalonej miary i korzysta z ich głosów lub średniej, zamiast uczyć wewnętrzne ustawienia modelu.
- EN: It selects similar examples using a chosen measure and uses their votes or average instead of learning internal model parameters.

## Everyday example

- PL: Szacujesz czas naprawy sprzętu z opisanych wcześniejszych napraw urządzeń o najbardziej podobnych cechach i usterkach.
- EN: You estimate equipment repair time using recorded repairs of devices with the most similar features and faults.

## This concerns you if you…

- PL: masz opisane przypadki podobne do nowych zadań
- PL: chcesz przewidywać przez porównanie zamiast wyuczone reguły
- EN: have labelled cases similar to new tasks
- EN: want predictions based on comparisons rather than learned rules

## Keywords

distance metrics · neighbor voting · distance weighting · KD-tree · BallTree

## How it works

- PL: Miara odległości wybiera najbliższe przykłady zapisane w zbiorze treningowym. Głosowanie ich etykiet daje klasyfikację, a uśrednienie wartości daje regresję, opcjonalnie z wagami zależnymi od odległości.
- EN: A distance measure selects the closest stored training examples. Voting over labels gives classification, while averaging values gives regression, optionally weighting by distance.

## Limits

- PL: Wynik zależy od skali cech, metryki i liczby sąsiadów. Wysoki wymiar osłabia informację odległości, a duży zbiór zwiększa koszt przechowywania i zapytań.
- EN: Results depend on feature scales, metrics and neighbour counts. High dimensions weaken distance information, while large datasets increase storage and query costs.

## Key terms

- PL: **metryka odległości**: Reguła mierząca różnicę między reprezentacjami przykładów.
- PL: **ważenie sąsiadów**: Zmiana wpływu przykładów w zależności od ich odległości od zapytania.
- EN: **distance metric**: A rule measuring differences between example representations.
- EN: **neighbour weighting**: Adjusting examples' influence according to their distance from a query.

## Know first

- [Algebra liniowa: wektory i macierze (Linear algebra: vectors and matrices)](https://aiatlasgraph.com/t/linearalgebra.md)

## Examples

- PL: miara odległości · wybór k · głosowanie sąsiadów
- EN: distance metric · choosing k · neighbour voting

## Related topics

Untyped, symmetric "see also" links.

- [Bazy wektorowe (Vector databases)](https://aiatlasgraph.com/t/vectordb.md)

## Sources

- [scikit-learn User Guide (version 1.9.1)](<https://scikit-learn.org/stable/user_guide.html>) `sklearn-user-guide` · by scikit-learn developers

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/knn · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
