Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rokibulhassan
Copy link

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

@igrigorik
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants