Relative Content

Tag Archive for pythonscikit-learnhierarchical-clusteringconnectivity

Key word argument “connectivity” in sklearn AgglomerativeClustering does not work as expected

In my Python code, I have a set of objects that I want to cluster based on a given distance matrix. However, there are some objects that should never end up in the same cluster. The number of clusters is chosen so that the problem is solvable. I want to use the AgglomerativeClustering class from the sklearn library. I set the distances of the incompatible objects to 1, which in some cases did not prevent them from ending up in the same cluster. I also tried to pass a connectivity matrix to AgglomerativeClustering via the keyword “connectivity”. This does not work in all cases. Below is a boiled down problem.