Module: Rumale::Base::ClusterAnalyzer

Included in:
Clustering::DBSCAN, Clustering::KMeans
Defined in:
lib/rumale/base/cluster_analyzer.rb

Overview

Module for all clustering algorithms in Rumale.

Instance Method Summary collapse

Instance Method Details

#fit_predictObject

An abstract method for analyzing clusters and predicting cluster indices.

Raises:



13
14
15
# File 'lib/rumale/base/cluster_analyzer.rb', line 13

def fit_predict
  raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end

#score(x, y) ⇒ Float

Calculate purity of clustering result.

Parameters:

  • (shape: [n_samples, n_features]) Testing data.

  • (shape: [n_samples]) True labels for testing data.

Returns:

  • Purity



22
23
24
25
26
27
28
# File 'lib/rumale/base/cluster_analyzer.rb', line 22

def score(x, y)
  check_sample_array(x)
  check_label_array(y)
  check_sample_label_size(x, y)
  evaluator = Rumale::EvaluationMeasure::Purity.new
  evaluator.score(y, fit_predict(x))
end