# Assigning new observations into existing clusters made from a distance matrix

I am building a classification model (binary outcome) and would like to include an external cluster membership code as a predictor. For training the model, this is straight forward. When "scoring" new data with the model, it is less so.

• If the clustering was k-means and used euclidean distance, assigning the new data to its closest cluster (centroid) would be easy.
• But, how do you do this when you are using a distance matrix as input to the clustering algorithm? That is, what if you cannot compute some sort of centroid or other "aggregate representation" of a cluster?

Note: Once the classification model is built, the labeling and meaning of the clusters must remain static.

The question is general, but perhaps made more difficult in that I am looking at clustering time series data (using the dtw package with hclust) - so it seems that one possible solution to the general question ( i.e. to use a predictive model to map new data to the existing cluster assignments) is not possible.

Any experience with this?

• Once you run hclust, can't you calculate cluster centroids in the original space? If so, when scoring the the model, you should be able to use dtw to calculate distance between a given cluster centroid and a new data point. Apr 3, 2012 at 14:40
• @Yevgeny, for some reason I don't get emails when comments are made. In response to this, I don't know - why not make it an answer and let others decide? I suppose that one could average the values at each time point per cluster and use a distance matrix. Apr 4, 2012 at 17:23

Assuming that you can get/calculate centroids of the resulting clusters, one approach would be, when scoring the model for a particular time series, to use dtw to calculate distance between a given cluster's centroid and the time series, and then choose the closest cluster as an additional feature.