Reference articles on history, science, culture and more
Encyclopedia

Nearest centroid classifier

Classification model in machine learning

Image credit is listed at the end of this article.

In machine learning, a nearest centroid classifier or nearest prototype classifier is a classification model that assigns to observations the label of the class of training samples whose mean (centroid) is closest to the observation. When applied to text classification using word vectors containing tf*idf weights to represent documents, the nearest centroid classifier is known as the Rocchio classifier because of its similarity to the Rocchio algorithm for relevance feedback.

An extended version of the nearest centroid classifier has found applications in the medical domain, specifically classification of tumors.

01Algorithm

Training

Given labeled training samples \textstyle \{({\vec {x}}_{1},y_{1}),\dots ,({\vec {x}}_{n},y_{n})\} with class labels y_{i}\in \mathbf {Y}, compute the per-class centroids \textstyle {\vec {\mu }}_{\ell }={\frac {1}{|C_{\ell }|}}{\underset {i\in C_{\ell }}{\sum }}{\vec {x}}_{i} where C_{\ell } is the set of indices of samples belonging to class \ell \in \mathbf {Y}.

Prediction

The class assigned to an observation {\vec {x}} is {\hat {y}}={\arg \min }_{\ell \in \mathbf {Y} }\|{\vec {\mu }}_{\ell }-{\vec {x}}\|.

Watch videos about Nearest centroid classifierExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Nearest centroid classifier, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Images, from Wikimedia Commons:

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.