liveBook · Manning

Centroid

As explained in Outlier Detection in Python

A cluster center is a representative location or point associated with a cluster and used to measure observations' proximity to that cluster.

A centroid, or cluster center, is a representative location for a cluster. In outlier detection, distance from that center provides one way to judge how unusual a record is: points near it are generally less unusual than points farther away. This comparison is most useful when clustering captures meaningful groups in the data. section 3.2.3

A center is only one part of a cluster-based comparison:

  • Compare a point’s distance with other distances in its own cluster. Different clusters can have different normal ranges, so one global distance threshold may be misleading. section 3.2.3
  • Consider cluster size. A point in a small cluster may merit attention, but cluster size alone gives every point in that cluster the same score. section 7.8.1
  • Check whether a point belongs to any cluster at all. DBSCAN can flag unassigned points without calculating their distance to a center. section 3.2.3

For a center-based score, divide each point’s Mahalanobis distance to its cluster center by the average Mahalanobis distance within that cluster. The ratio expresses distance relative to what is typical locally, making scores more comparable across clusters with different densities. An optional, adjustable cluster-size contribution can then raise scores for small-cluster points. These scores still depend on obtaining useful clusters; poor clustering can produce poor results. section 7.8.1

Centers in synthetic-data generation

A fitted Gaussian mixture model can also use cluster centers to generate records. It selects a Gaussian center according to that cluster’s weight, then samples from the cluster’s multivariate Gaussian. Sampling this way tends to produce typical records; modifying cluster means or covariance matrices can instead produce distinctly different data. section 11.2.3

Figure 7.8 The results using outlier detection based on cluster size and Mahalanobis distance relative to the cluster. With a single cluster (left) it performs well, scoring highest the points on the margins. With multiple clusters (right), it also does well, scoring the very small cluster and the three global outliers the highest.

Compare the high-scoring points on a single cluster’s margins with the small cluster and global outliers in the multiple-cluster result. section 7.8.1

How Outlier Detection in Python covers it

How deep it goes
Explains center-relative and cluster-relative distance scoring, including an optional size adjustment, without deriving how centers are estimated.
Examples
Illustrates scoring with single- and multiple-cluster results and contrasts it with DBSCAN flags for unassigned points.
What it assumes
Assumes basic familiarity with clusters and distances while explaining why comparisons should account for differences between clusters.
What you can do after
Apply it via Gaussian mixture clustering and Mahalanobis distance to compare points with their own cluster’s typical distance.
How it connects
Connects cluster centers to clustering, Mahalanobis distance, Gaussian mixture models, and outlier detection.

Also explained in

Compare how 10 books explain centroid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.