decisiontree icon indicating copy to clipboard operation
decisiontree copied to clipboard

Follow Ruby Naming convention and Added an extra attributes accessor for training data

Open rokibulhassan opened this issue 10 years ago • 1 comments

I need the train data out of the box, so added an attributes accessor to access the train data in RuleSet Class, So that I can get the accuracy directly. For better understanding I can show u the code snippet

class Simple
  def initialize(attributes=nil, training=nil)
    @attributes = attributes || ['Temperature']
    @training = training ||[
        [36.6, 'healthy'],
        [37, 'sick'],
        [38, 'sick'],
        [36.7, 'healthy'],
        [40, 'sick'],
        [50, 'really sick']
    ]
  end

  def tree
    dec_tree = DecisionTree::ID3Tree.new(@attributes, @training, 'sick', :continuous)
    dec_tree.train
    rule_set = dec_tree.rule_set

    result = rule_set.rules.each { |r| r.accuracy(rule_set.train_data) }
    result.collect { |r| ap [r.conclusion, r.accuracy] }
  end
end

rokibulhassan avatar Feb 19 '16 10:02 rokibulhassan

Do you really need to call it with rule_set.train_data? Looking at the code, we memoize @accuracy so I think you can just cal r.accuracy and get the value computed during the earlier training pass.

igrigorik avatar Feb 20 '16 16:02 igrigorik