Sha256: c68345ec856251dbea51b05ced7fc9f1d753299c29739cf2f1b501ff188518b0

Contents?: true

Size: 970 Bytes

Versions: 11

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

require 'svmkit/validation'
require 'svmkit/evaluation_measure/purity'

module SVMKit
  module Base
    # Module for all clustering algorithms in SVMKit.
    module ClusterAnalyzer
      # An abstract method for analyzing clusters and predicting cluster indices.
      def fit_predict
        raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
      end

      # Calculate purity of clustering result.
      #
      # @param x [Numo::DFloat] (shape: [n_samples, n_features]) Testing data.
      # @param y [Numo::Int32] (shape: [n_samples]) True labels for testing data.
      # @return [Float] Purity
      def score(x, y)
        SVMKit::Validation.check_sample_array(x)
        SVMKit::Validation.check_label_array(y)
        SVMKit::Validation.check_sample_label_size(x, y)
        evaluator = SVMKit::EvaluationMeasure::Purity.new
        evaluator.score(y, fit_predict(x))
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
svmkit-0.7.3 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.7.2 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.7.1 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.7.0 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.6.3 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.6.2 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.6.1 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.6.0 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.5.2 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.5.1 lib/svmkit/base/cluster_analyzer.rb
svmkit-0.5.0 lib/svmkit/base/cluster_analyzer.rb