Merge branch 'dvisockas-master'

This commit is contained in:
Ilya Grigorik
2015-11-23 16:37:29 -08:00
3 changed files with 6 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ include DecisionTree
# Read in the training data # Read in the training data
training = [] training = []
attributes = nil
File.open('data/continuous-training.txt', 'r').each_line do |line| File.open('data/continuous-training.txt', 'r').each_line do |line|
data = line.strip.chomp('.').split(',') data = line.strip.chomp('.').split(',')
attributes ||= data attributes ||= data

View File

@@ -5,6 +5,8 @@ require 'decisiontree'
# Read in the training data # Read in the training data
training = [] training = []
attributes = nil
File.open('data/discrete-training.txt', 'r').each_line do |line| File.open('data/discrete-training.txt', 'r').each_line do |line|
data = line.strip.split(',') data = line.strip.split(',')
attributes ||= data attributes ||= data
@@ -45,7 +47,7 @@ File.open('data/discrete-test.txt', 'r').each_line do |line|
v v
end end
end end
training.push(test_data) test.push(test_data)
end end
# Let the tree predict the output and compare it to the true specified value # Let the tree predict the output and compare it to the true specified value

View File

@@ -190,7 +190,7 @@ module DecisionTree
end end
label_text = "#{key} ''" label_text = "#{key} ''"
if type(attr[0].attribute) == :continuous if type(attr[0].attribute) == :continuous
label_text.gsub!("''", attr[0].threshold) label_text.gsub!("''", attr[0].threshold.to_s)
end end
[parent_text, child_text, label_text] [parent_text, child_text, label_text]