I'm computing silhouette_score from sklearn.metrics library in python, for hierarchical clustering. I'm computing this metric for few cuts of the tree (few options of number of clusters, K). For some cuts of the tree, the silhouette_score returns nan result. Why?
here is my code:
dist_matrixis the distance matrix nXn (symmetric)
tree- one option for cut of the tree (using
metric- precomputed as the distance matrix is already calculated based on some distance metric I calculated.
NaN result only happens for large amount of clusters (large K).here is the error I'm getting:
> /usr/local/lib64/python3.6/site-packages/sklearn/metrics/cluster/unsupervised.py:205: > RuntimeWarning: > > invalid value encountered in true_divide
Any idea why? Thanks