Created
May 29, 2013 07:43
-
-
Save vralex/5668612 to your computer and use it in GitHub Desktop.
Decision tree example using.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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