Class: PositronicBrain::Classifier::Fisher
- Defined in:
- lib/positronic_brain/classifier/fisher.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #classify(item, options = {}) ⇒ Object
- #fisher_score(item, category) ⇒ Object (also: #score)
- #fisher_scores(item) ⇒ Object (also: #scores)
Methods inherited from Base
#category_given_item_product, #extract_features, #initialize, #item_given_category_product, #normalized_prob_category_given_feature, #prob_category, #prob_category_given_feature, #prob_feature_given_category, #train
Methods inherited from Base
#dump_path, #initialize, initialize_persistence, #inspect, persistence, persistence_class, persistence_options
Constructor Details
This class inherits a constructor from PositronicBrain::Classifier::Base
Instance Method Details
#classify(item, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/positronic_brain/classifier/fisher.rb', line 4 def classify(item, ={}) best_category = [:default] || @default_category best_score = [: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) ⇒ Object Also known as: score
28 29 30 31 32 33 34 |
# 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 |
#fisher_scores(item) ⇒ Object Also known as: scores
20 21 22 23 24 25 |
# 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 |