How can cluster assignments be used as features in a downstream supervised model, and what leakage risks arise?
Last updated
Encode clusters as one-hot IDs, distances to centroids (
KMeans.transform), or GMM soft memberships (predict_proba). This mainly helps linear models capture local nonlinear structure.Leakage arises from fitting clusters on the full dataset (test rows shape centroids), including the target in clustering inputs, non-out-of-fold target encoding, using future data, or transductive methods causing train/serve skew.
Avoid it by putting the clusterer inside a
Pipelineso it is re-fit per CV fold. Use inductive methods (k-means, GMM) for scoring and respect time splits.