8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/test_commie.rb', line 8
def self.candidate
require "decisiontree"
print "Rank >> "
rank = gets.chomp.to_i
print "Politics >> "
politics = gets.chomp
print "Candidacy >> "
candidacy = gets.chomp
puts " "
labels = ["rank", "person", "politics", "candidacy"]
training = [
[7, "Person", "Libertarian", "UnCandidate"],
[6, "Person", "Centrist", "No Candidate"],
[5, "Person", "Mutualist", "Likely Not A Candidate"],
[4, "Person", "Mutualist", "Possibly A Candidate"],
[4, "Person", "Syndicalist", "Possibly A Candidate"],
[3, "Person", "Socialist", "Likely A Candidate"],
[2, "Person", "Communist", "Definite Candidate"],
[1, "Person", "Left Communist", "Worrying"],
]
dec_tree = DecisionTree::ID3Tree.new(labels, training, "UnCandidate", rank: :discrete, person: :discrete, politics: :discrete, candidacy: :discrete)
dec_tree.train
test = [rank, "Person", politics, labels]
decision = dec_tree.predict(test)
actuality = test.last
puts "Predicted: #{decision}"
end
|