Class: Clusterer::WeightNormalizedComplementBayes

Inherits:
ComplementBayes show all
Includes:
WeightNormalized
Defined in:
lib/clusterer/bayes.rb

Overview

Based on the description given in “Tackling the Poor Assumptions of Naive Bayes Text Classifiers” by Jason D. M. Rennie, Lawrence Shih, Jaime Teevan and David R. Karger, ICML - 2003

An improved complement bayes, the authors claim that this algorithm performs better, then the ComplementBayes. The weights are normalized, before using this algorithm.

Instance Attribute Summary

Attributes inherited from Bayes

#categories

Instance Method Summary collapse

Methods included from WeightNormalized

#initialize, #train, #untrain

Methods inherited from ComplementBayes

#train, #untrain

Methods inherited from Bayes

#classify, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Clusterer::Bayes

Instance Method Details

#distribution(document) ⇒ Object



234
235
236
237
238
239
240
# File 'lib/clusterer/bayes.rb', line 234

def distribution(document)
  self.class.superclass.superclass.instance_method(:distribution).bind(self).call do |cl,ind|
    we, sum = weighted_likelihood(cl), 0.0
    document.each {|term,freq| sum += freq * (we[term] || 0)}
    -sum
  end
end