Semi-supervised K-means

Machine Learning
Introduced by
Wagstaff, K. et al. (constrained); Basu, S. et al. (seeded)
Year
2001–2002
Type
Semi-supervised clustering
Family
Machine learning

What does it do?

Semi-supervised K-means extends standard K-means by adding partial supervision, either a small set of labeled seed points or pairwise must-link and cannot-link constraints, to guide cluster formation.

It sits between unsupervised clustering and supervised classification, and is aimed at settings where some labels or constraints are available but a full labeled dataset is not.

The intuition behind the method

Standard K-means groups points by geometric proximity alone, which can produce clusters that do not match domain categories. Semi-supervised K-means adds a small amount of guidance: a few points with known group membership (seeds), or rules such as 'these two points belong together' or 'these two must be separated'. These rules are respected during assignment, so the clusters remain distance-based but are pushed toward partitions that agree with the supplied knowledge. Because the guidance is sparse, the method is most useful when labels are scarce, and it does not require the labeling effort of a fully supervised classifier.

History

Constrained K-means was introduced by Wagstaff et al. at ICML 2001, who used background knowledge in the form of must-link and cannot-link constraints. Basu, Banerjee, and Mooney reported seeded clustering at ICML 2002, in which labeled seed points initialize the centroids. Both papers are standard references for semi-supervised clustering with K-means.

When to use it

Use semi-supervised K-means when most of the data is unlabeled, a small number of labels or pairwise constraints can be obtained, and standard K-means yields clusters that conflict with known categories. It suits problems where the clusters are roughly convex in the chosen feature space, such as grouping documents represented as numeric vectors or segmenting customers on standardized attributes. Do not use it when no supervision is available, since plain K-means is then simpler. Avoid it when clusters are strongly non-convex or irregular, where density-based methods such as DBSCAN are generally more appropriate. Also avoid it when the constraints are noisy or may contradict each other, because an infeasible set prevents the assignment step from completing. If enough labeled data exists for a supervised classifier, a classifier is the more direct choice.

Limitations and considerations

  • Inherits the K-means assumption of convex, roughly spherical clusters of similar spread, and performs poorly on elongated or irregularly shaped groups.
  • The number of clusters K must be specified in advance; neither the seeds nor the constraints determine it.
  • Infeasible or contradictory constraints, such as a must-link chain that connects a pair also linked by a cannot-link, make a valid assignment impossible and stop the procedure.
  • Unrepresentative seeds or noisy constraints can bias the centroids and may yield results worse than unsupervised K-means.
  • Sensitive to feature scale: without standardization, dimensions with large variance dominate the distance calculation and therefore the assignments.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Needs only a small amount of supervision, such as a few seed labels or pairwise constraints, to steer the clusters toward known structure.
  • Accepts more than one supervision format: class-level seeds, must-link constraints, cannot-link constraints, or a mixture.
  • The assignment rule stays distance-based, so centroids remain interpretable and the effect of the supplied constraints can be inspected directly.
  • A seeded starting configuration can begin closer to the target structure than a random start, which may reduce the number of iterations needed, although this depends on how representative the seeds are.
  • The core iteration is that of standard K-means, so it remains practical on large datasets; the extra cost comes from checking constraints at each assignment.

Applications

  • Clustering text documents using a few manually labeled documents per topic as seeds.
  • Customer segmentation in which a small sample of customers with known segment membership anchors the initial clusters.
  • Grouping items where domain experts can state that particular pairs must be together or apart, such as images judged similar by annotators.
  • Trajectory or movement analysis where known pairs of trips are assumed to share a travel mode, expressed as must-link constraints.

How it works

How it works

1

Before clustering, the analyst supplies supervision in one of two forms: (1) seed labels, a subset of data points with known cluster assignments, or (2) pairwise constraints, consisting of must-link pairs (points that belong in the same cluster) and cannot-link pairs (points that must be placed in different clusters). The supervision encodes domain knowledge without requiring a fully labeled dataset.

2

In the seeded variant, the labeled seed points of each class are averaged to give that class's initial centroid, so the starting configuration reflects known structure rather than a random draw. In the constrained variant, the initial centroids are chosen at random, and the constraints are enforced from the first assignment onward. The choice of initialization should be reported with the results, since it affects which solution is reached.

3

The data points are processed in random order. Each point is assigned to its nearest centroid, as in standard K-means, provided the choice does not violate a constraint with points already assigned: a must-link partner must be in the same cluster, and a cannot-link partner must not be. If the nearest centroid is ruled out, the next-nearest admissible centroid is used. If a point has no admissible cluster, the constraints cannot be satisfied consistently at that point. The procedure then terminates, and the clusters from the last iteration with a feasible assignment are typically reported. Because the outcome can depend on processing order and on the initial centroids, the procedure is a heuristic and does not guarantee a global optimum.

4

After assignment, each centroid is recomputed as the mean of all points currently assigned to it, including the seed points. The centroid therefore reflects the full cluster membership rather than only the supervised points. For a fixed assignment, the mean is the centroid that minimises the within-cluster sum of squared distances, the objective that standard K-means seeks to reduce.

Formula
\mu_k = \frac{1}{|C_k|}\sum_{x_i \in C_k} x_i
5

Assignment and centroid-update steps alternate until memberships stop changing or a maximum iteration count is reached. Whether seed points keep their supplied labels during later iterations depends on the variant and its implementation, so this should be checked before interpreting the output. Because a single run can terminate early on an infeasible point or depend on its starting configuration, the method is usually run several times from different seeds or initializations, and the best feasible solution is reported. The output should also be checked against the supplied constraints for violations.

Common pitfalls

  • Providing seeds for only some of the clusters while leaving others with no supervision, which pulls centroids toward the labeled groups and can leave the unlabeled structure poorly represented.
  • Clustering unstandardized features, so that a variable with a large numeric scale overshadows informative variables measured on smaller scales.
  • Entering constraints without checking feasibility, then assuming all of them are satisfied when the algorithm has in fact been unable to complete an assignment.
  • Setting K equal to the number of seed classes without considering that the data may contain additional latent clusters.
  • Judging quality only against the seed labels, which were used to guide the clustering, rather than against held-out labeled points or expert review.

Frequently asked questions

How many labeled points or constraints do I need?

There is no fixed number. The benefit depends on how accurate the supervision is and how well it covers each cluster. Seeds or constraints that cover only some clusters can bias the result, so it is worth checking that every expected group has some supervision before relying on the output.

What if my constraints are contradictory?

Contradictory or infeasible constraints can make a valid assignment impossible. When this happens, the procedure terminates and the clusters from the last feasible iteration are typically reported, so the output may not satisfy all constraints. Before running, check that no chain of must-link pairs connects two points that are also linked by a cannot-link constraint. If the constraints may be noisy, verify the most doubtful ones before running, since a single contradictory pair can prevent a complete assignment.

How do I choose the right K?

The silhouette coefficient, the elbow heuristic on within-cluster sum of squares, and the gap statistic can all be applied. If seed classes are available, K is at least the number of seed classes, but the data may contain additional latent clusters. Try values of K above the seed count and assess the results both quantitatively and by inspecting the clusters.

Is seeded K-means better than constrained K-means?

They encode different kinds of knowledge. Seeded K-means suits cases where a few labeled examples per class are available. Constrained K-means suits cases where you can identify pairs of points that belong together or apart without knowing their absolute cluster labels. Which performs better depends on the form and accuracy of the available supervision, so neither should be assumed superior in general.

Can I use this with text or high-dimensional data?

Yes, but reducing dimensionality before clustering, for example with PCA, or with TF-IDF followed by SVD for text, is generally advisable. In very high dimensions, Euclidean distances can become similar for all pairs of points, which weakens the distance-based assignment step regardless of the supervision used.

Related methods

Sources

  1. Wagstaff, K., Cardie, C., Rogers, S., & Schroedl, S. (2001). Constrained K-means Clustering with Background Knowledge. In Proceedings of the 18th International Conference on Machine Learning (ICML 2001), pp. 577–584.

    Open publication reference
  2. Basu, S., Banerjee, A., & Mooney, R. J. (2002). Semi-supervised Clustering by Seeding. In Proceedings of the 19th International Conference on Machine Learning (ICML 2002), pp. 27–34.

    Open publication reference
  3. 2015_Book_DataMining, p. 226–227