# Metoda k-średnich (k-means)

EN: **k-means clustering** · id `kmeans`

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Uczenie maszynowe](https://aiatlasgraph.com/t/ml.md) › [Uczenie nienadzorowane](https://aiatlasgraph.com/t/unsupervised.md) › [Klasteryzacja](https://aiatlasgraph.com/t/clustering.md) › Metoda k-średnich (k-means)

## Description

- PL: Dzieli dane na z góry zadaną liczbę k grup wokół środków, przesuwając je iteracyjnie. Dobra dla zwartych grup podobnej wielkości.
- EN: Splits data into a preset number k of groups around centroids that are moved iteratively. Works well for compact groups of similar size.

## In one sentence

- PL: To dzielenie danych na wybraną wcześniej liczbę grup skupionych wokół swoich środków.
- EN: This divides data into a preset number of groups around their centres.

## Problem it solves

- PL: Chcesz podzielić wiele przykładów na określoną liczbę grup, ale nie znasz jeszcze ich członków.
- EN: You want to divide many examples into a set number of groups but do not yet know their members.

## What it does

- PL: Przypisuje przykłady do najbliższych środków, przelicza środki z członków grup i powtarza te kroki, poprawiając podział.
- EN: It assigns examples to their nearest centres, recalculates centres from group members and repeats these steps to refine the partition.

## Everyday example

- PL: Dzielisz klientów na ustaloną liczbę grup według częstotliwości zakupów i wydatków, a potem sprawdzasz, czym grupy się różnią.
- EN: You divide customers into a preset number of groups using purchase frequency and spending, then examine how the groups differ.

## This concerns you if you…

- PL: znasz liczbę grup, które chcesz otrzymać
- PL: twoje dane tworzą dość zwarte skupiska podobnych przypadków
- EN: know how many groups you want
- EN: have data forming fairly compact groups of similar cases

## Keywords

k-means++ · centroid updates · inertia · elbow method · MiniBatchKMeans

## How it works

- PL: Próbki przypisuje się do najbliższych centroidów, a następnie centroidy aktualizuje jako średnie swoich grup. Naprzemienne kroki zmniejszają sumę kwadratowych odległości przy ustalonej liczbie klastrów.
- EN: Samples are assigned to nearest centroids, which are updated to their groups' means. Alternating steps reduce squared-distance totals for a fixed cluster count.

## Limits

- PL: Wynik zależy od inicjalizacji i skali cech. Metoda faworyzuje zwarte grupy, jest wrażliwa na odstające punkty i nie gwarantuje minimum globalnego.
- EN: Results depend on initialisation and feature scales. The method favours compact groups, is sensitive to outliers and does not guarantee a global minimum.

## Key terms

- PL: **centroid**: Średnia współrzędnych punktów przypisanych do klastra.
- PL: **inercja**: Suma kwadratowych odległości próbek od przypisanych centroidów.
- EN: **centroid**: The mean coordinates of points assigned to a cluster.
- EN: **inertia**: The sum of squared distances from samples to assigned centroids.

## Know first

- [Algebra liniowa: wektory i macierze (Linear algebra: vectors and matrices)](https://aiatlasgraph.com/t/linearalgebra.md)
- [Spadek gradientu i optymalizacja ciągła (Gradient descent and continuous optimisation)](https://aiatlasgraph.com/t/mathoptimization.md)

## Examples

- PL: wybór k (metoda łokcia) · k-means++
- EN: choosing k (elbow method) · k-means++

## Related topics

Untyped, symmetric "see also" links.

- [Algorytm EM i modele mieszanin (Expectation-maximisation and mixture models)](https://aiatlasgraph.com/t/emmixtures.md)

## Sources

- [scikit-learn — 2.3 Clustering](<https://scikit-learn.org/stable/modules/clustering.html>) `sklearn-clustering` · by scikit-learn developers

---

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