DecisionTree无法使用csv中的数据预测我的数据并在decisiontree中读取它

时间:2018-03-02 03:42:38

标签: ruby csv

我正在尝试使用decisiontree,从csv文件中获取数据,但似乎代码无法预测我的数据,事件他们可以读取我的csv文件,
decision = dec_tree.predict(data)不起作用..

require 'rubygems'
require 'decisiontree'
require 'csv'

attributes = ['Doc','PhPagi','PhSore','Kec','score']    
training = []
csv = CSV.read ('/Users/reynard/Desktop/Ruby/test.csv')
csv.each do |row|
training << row.map{|convert| convert.to_f }
end

puts training.inspect

dec_tree = DecisionTree::ID3Tree.new(attributes, training, 2, :discrete)
dec_tree.train

如何使用csv

中的数据预测此数据集
data = [26.0, 7.8, 8.0, 35.0] 

puts data.inspect

decision = dec_tree.predict(data)

puts "predicted: #{decision}"


if decision == 0
  puts "Water Condition Very BAD"
elsif decision == 1
  puts "Water Condition BAD "
elsif decision == 2
  puts "Water Condition Not so Good"    
elsif decision == 3
  puts "Water Contion Normal"
elsif decision == 4
  puts "Water Contion Good"
elsif decision == 5 
  puts " Water Contion Very Good"
else
  puts "dont understand"
end

0 个答案:

没有答案