Module: Idhja22::Dataset::TreeMethods
- Included in:
- Idhja22::Dataset
- Defined in:
- lib/idhja22/dataset/tree_methods.rb
Instance Method Summary collapse
Instance Method Details
#entropy ⇒ Object
16 17 18 19 20 |
# File 'lib/idhja22/dataset/tree_methods.rb', line 16 def entropy total = self.size return 1.0 if total < Idhja22.config.min_dataset_size category_counts.values.inject(0.0) { |ent, count| prop = count.to_f/total.to_f; ent-prop*Math.log(prop,2) } end |
#partition(attr_label) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/idhja22/dataset/tree_methods.rb', line 4 def partition(attr_label) groups = Hash.new([]) data.each do |datum| groups[datum[attr_label]] += [datum] end output = Hash.new groups.each do |value, data| output[value] = Dataset.new(data, attribute_labels, category_label) end return output end |