Module: Rumale::Base::ClusterAnalyzer

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:

  • (NotImplementedError)


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:

  • x (Numo::DFloat)

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

  • y (Numo::Int32)

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

Returns:

  • (Float)

    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