class PositronicBrain::Classifier::Fisher

Public Instance Methods

classify(item, options={}) click to toggle source
# File lib/positronic_brain/classifier/fisher.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
fisher_score(item, category) click to toggle source
# File lib/positronic_brain/classifier/fisher.rb, line 28
def fisher_score(item, category)
  prod = category_given_item_product category, item, weighted: true
  return 0.0 if prod == 0.0

  features_count = extract_features!(item).count
  Distribution::ChiSquare.q_chi2 2*features_count, -2*Math.log(prod)
end
Also aliased as: score
fisher_scores(item) click to toggle source
# File lib/positronic_brain/classifier/fisher.rb, line 20
def fisher_scores(item)
  categories.map do |category|
    score = fisher_score item, category
    [category, score]
  end
end
Also aliased as: scores
score(item, category)
Alias for: fisher_score
scores(item)
Alias for: fisher_scores