You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raiseValueError("Input of int64 is currently not supported, as it could overflow the float64 used internally when computing Silhouette. Use diss.astype(numpy.float64) if that is acceptable and you have the necessary memory for this copy.")
raiseValueError("Input of int64 is currently not supported, as it could overflow the float64 used internally when computing Silhouette. Use diss.astype(numpy.float64) if that is acceptable and you have the necessary memory for this copy.")
642
647
raiseValueError("Input data not supported. Use a numpy array of floats.")
643
648
649
+
defmedoid_silhouette(diss, meds, samples=False):
650
+
"""Medoid Silhouette index for cluster evaluation.
651
+
652
+
The Medoid Silhouette is an approximation to the Silhouette index, that
653
+
uses the distance to the cluster medoids instead of the average distance
654
+
to the other cluster members. If every point is assigned to the nearest
655
+
medoid, the Medoid Silhouette of a point reduces to 1-a/b where a is the
656
+
distance to the nearest, and b the distance to the second nearest medoid.
657
+
If b is 0, the Medoid Silhouette is 1.
658
+
659
+
This function assumes you already have a distance matrix. It is not necessary
660
+
to compute a distance matrix to evaluate the medoid silhouette -- only the
661
+
distances between points and medoids are necessary. If you do not have a
662
+
distance matrix, simply compute the medoid Silhouette directly, by computing
663
+
(1) the N x k distance matrix to the medoids, (2) finding the two smallest values
664
+
for each data point, and (3) computing the average of 1-a/b on these (with 0/0 as 0).
665
+
This can be implemented in a few lines with numpy easily.
666
+
667
+
:param diss: square numpy array of dissimilarities
668
+
:type diss: ndarray
669
+
:param meds: medoid indexes (k distinct values in 0 to n-1)
670
+
:type meds: ndarray of int
671
+
:param samples: whether to return individual samples or not
672
+
:type samples: boolean
673
+
674
+
:return: tuple containing the average Medoid Silhouette and the individual samples
675
+
:rtype: (float, ndarray)
676
+
"""
677
+
importnumpyasnp, os
678
+
from .kmedoidsimport_medoid_silhouette_i32, _medoid_silhouette_f32, _medoid_silhouette_f64
raiseValueError("Input of int64 is currently not supported, as it could overflow the float64 used internally when computing Silhouette. Use diss.astype(numpy.float64) if that is acceptable and you have the necessary memory for this copy.")
695
+
raiseValueError("Input data not supported. Use a numpy array of floats.")
696
+
644
697
# This is a hack to make sklearn an optional dependency only:
0 commit comments