Skip to content

Instantly share code, notes, and snippets.

@vralex
Created May 29, 2013 07:43
Show Gist options
  • Save vralex/5668612 to your computer and use it in GitHub Desktop.
Save vralex/5668612 to your computer and use it in GitHub Desktop.
Decision tree example using.
#!/usr/bin/ruby
require 'rubygems'
require 'decisiontree'
attributes = ['Temperature']
training = [
[36.6, 'healthy'],
[37, 'sick'],
[38, 'sick'],
[36.7, 'healthy'],
[40, 'sick'],
[50, 'really sick'],
]
dec_tree = DecisionTree::ID3Tree.new(attributes, training, 'sick', :continuous)
dec_tree.train
test = [37, 'sick']
decision = dec_tree.predict(test)
puts "Predicted: #{decision} ... True decision: #{test.last}";
# Graph the tree, save to 'tree.png'
dec_tree.graph("tree")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment