Class: Basset::NaiveBayes::FeatureCount
- Inherits:
-
Object
- Object
- Basset::NaiveBayes::FeatureCount
- Defined in:
- lib/basset/naive_bayes.rb
Overview
A class to store feature counts
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_count_for_class(count, classification) ⇒ Object
- #count ⇒ Object
- #count_for_class(classification) ⇒ Object
-
#initialize(feature_name = nil, classification = nil, count = 0) ⇒ FeatureCount
constructor
A new instance of FeatureCount.
- #inspect(opts = {:verbose=>false}) ⇒ Object
Constructor Details
#initialize(feature_name = nil, classification = nil, count = 0) ⇒ FeatureCount
Returns a new instance of FeatureCount.
120 121 122 123 |
# File 'lib/basset/naive_bayes.rb', line 120 def initialize(feature_name=nil, classification=nil, count=0) @name, @classes = feature_name, {} add_count_for_class(count, classification) if classification end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
118 119 120 |
# File 'lib/basset/naive_bayes.rb', line 118 def classes @classes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
118 119 120 |
# File 'lib/basset/naive_bayes.rb', line 118 def name @name end |
Instance Method Details
#==(other) ⇒ Object
139 140 141 |
# File 'lib/basset/naive_bayes.rb', line 139 def ==(other) other.kind_of?(FeatureCount) && other.classes == @classes && other.name == @name end |
#add_count_for_class(count, classification) ⇒ Object
125 126 127 128 |
# File 'lib/basset/naive_bayes.rb', line 125 def add_count_for_class(count, classification) @classes[classification] ||= 0 @classes[classification] += count end |
#count ⇒ Object
135 136 137 |
# File 'lib/basset/naive_bayes.rb', line 135 def count @classes.values.sum end |
#count_for_class(classification) ⇒ Object
130 131 132 133 |
# File 'lib/basset/naive_bayes.rb', line 130 def count_for_class(classification) #@classes[classification] || 1 um, what? @classes[classification] || 0 end |
#inspect(opts = {:verbose=>false}) ⇒ Object
143 144 145 146 |
# File 'lib/basset/naive_bayes.rb', line 143 def inspect(opts={:verbose=>false}) return super if opts[:verbose] "#<FeatureCount for ``" + @name.to_s + "''" + " --> " + @classes.inspect + " > " end |