tslearn icon indicating copy to clipboard operation
tslearn copied to clipboard

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

Open AliyaAbl opened this issue 2 years ago • 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,

AliyaAbl avatar Apr 06 '22 07:04 AliyaAbl

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

GillesVandewiele avatar Apr 06 '22 09:04 GillesVandewiele

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.

MichaelKarpe avatar Oct 07 '22 21:10 MichaelKarpe

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.

MichaelKarpe avatar Oct 07 '22 21:10 MichaelKarpe