tslearn-team/tslearn

Question - is there a feature where I can specify the minimum number of elements in a cluster?

AliyaAbl opened this issue · 3 comments

I am using this library on a spike sorting project and would like to cluster neurons regarding their behavior after a given stimulus. The problem is, that some neurons are clustered into very small groups, even though their behavior is quite similar to other clusters. Is there a way to specify the minimum number of neurons in each cluster?

Thanks in advance,

You could try hierarchical clustering with DTW and barycenters perhaps and use a post-processing algorithm on the produced dendrogram.

This repository proposes size-constrained k-means clustering by formulating the cluster assignment step as a minimum-cost flow problem.

One possible approach could be to replace the euclidian_distance by tslearn cdist_dtw in the previously mentioned repository.

Extending the tslearn.clustering.kmeans module with size-constrained clustering would be a more interesting solution, maybe leading the path to implementing other kinds of constrained clustering in tslearn. This is less straightforward, of course.

You could try hierarchical clustering with DTW and barycenters perhaps and use a post-processing algorithm on the produced dendrogram.

A time-series BisectingKMeans (as now existing in scikit-learn >= 1.1.0) could also be helpful with this approach.