Class: Rumale::EvaluationMeasure::DaviesBouldinScore
- Inherits:
-
Object
- Object
- Rumale::EvaluationMeasure::DaviesBouldinScore
- Defined in:
- rumale-evaluation_measure/lib/rumale/evaluation_measure/davies_bouldin_score.rb
Overview
DaviesBouldinScore is a class that calculates the Davies-Bouldin score.
Reference
-
Davies, D L., and Bouldin, D W., “A Cluster Separation Measure,” IEEE Trans. Pattern Analysis and Machine Intelligence, Vol. PAMI-1, No. 2, pp. 224–227, 1979.
Instance Method Summary collapse
-
#score(x, y) ⇒ Float
Calculates the Davies-Bouldin score.
Instance Method Details
#score(x, y) ⇒ Float
Calculates the Davies-Bouldin score.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'rumale-evaluation_measure/lib/rumale/evaluation_measure/davies_bouldin_score.rb', line 24 def score(x, y) labels = y.to_a.uniq.sort n_clusters = labels.size n_dimensions = x.shape[1] dist_cluster = Numo::DFloat.zeros(n_clusters) centroids = Numo::DFloat.zeros(n_clusters, n_dimensions) n_clusters.times do |n| cls_samples = x[y.eq(labels[n]), true] cls_centroid = cls_samples.mean(0) centroids[n, true] = cls_centroid dist_cluster[n] = Rumale::PairwiseMetric.euclidean_distance(cls_samples, cls_centroid.(0)).mean end dist_centroid = Rumale::PairwiseMetric.euclidean_distance(centroids) dist_centroid[dist_centroid.eq(0)] = Float::INFINITY dist_mat = (dist_cluster.(1) + dist_cluster) / dist_centroid dist_mat[dist_mat.diag_indices] = -Float::INFINITY dist_mat.max(0).mean end |