class PositronicBrain::Classifier::NaiveBayes

Public Instance Methods

bayes_score(item, category) click to toggle source
# File lib/positronic_brain/classifier/naive_bayes.rb, line 28
def bayes_score(item, category)
  item_given_category_product(item, category, weighted: true)*prob_category(category)
end
Also aliased as: score
bayes_scores(item) click to toggle source
# File lib/positronic_brain/classifier/naive_bayes.rb, line 20
def bayes_scores(item)
  categories.map do |category|
    score = bayes_score item, category
    [category, score]
  end
end
Also aliased as: scores
classify(item, options={}) click to toggle source
# File lib/positronic_brain/classifier/naive_bayes.rb, line 4
def classify(item, options={})
  best_category = options[:default] || @default_category
  best_score    = options[:minimum] || @minimum_score || 0.0

  scores = scores item

  scores.each do |category, score|
    if score > best_score
      best_category = category
      best_score    = score
    end
  end

  [best_category, best_score]
end
score(item, category)
Alias for: bayes_score
scores(item)
Alias for: bayes_scores