Class: Rumale::EvaluationMeasure::NormalizedMutualInformation

Inherits:
Object
  • Object
show all
Includes:
Base::Evaluator
Defined in:
rumale-evaluation_measure/lib/rumale/evaluation_measure/normalized_mutual_information.rb

Overview

NormalizedMutualInformation is a class that calculates the normalized mutual information.

Reference

  • Manning, C D., Raghavan, P., and Schutze, H., “Introduction to Information Retrieval,” Cambridge University Press., 2008.

  • Vinh, N X., Epps, J., and Bailey, J., “Information Theoretic Measures for Clusterings Comparison: Variants, Properties, Normalization and Correction for Chance,” J. Machine Learning Research, vol. 11, pp. 2837–1854, 2010.

Examples:

require 'rumale/evaluation_measure/normalized_mutual_information'

evaluator = Rumale::EvaluationMeasure::NormalizedMutualInformation.new
puts evaluator.score(ground_truth, predicted)

Instance Method Summary collapse

Instance Method Details

#score(y_true, y_pred) ⇒ Float

Calculate noramlzied mutual information

Parameters:

  • y_true (Numo::Int32)

    (shape: [n_samples]) Ground truth labels.

  • y_pred (Numo::Int32)

    (shape: [n_samples]) Predicted cluster labels.

Returns:

  • (Float)

    Normalized mutual information



27
28
29
30
31
32
33
34
35
36
37
38
# File 'rumale-evaluation_measure/lib/rumale/evaluation_measure/normalized_mutual_information.rb', line 27

def score(y_true, y_pred)
  # calculate entropies.
  class_entropy = entropy(y_true)
  return 0.0 if class_entropy.zero?

  cluster_entropy = entropy(y_pred)
  return 0.0 if cluster_entropy.zero?

  # calculate mutual information.
  mi = MutualInformation.new
  mi.score(y_true, y_pred) / Math.sqrt(class_entropy * cluster_entropy)
end