Method: RCPNetwork::DanglingModifiers.predict_from_data

Defined in:
lib/RCP_Network.rb

.predict_from_dataObject

Main decision tree



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/RCP_Network.rb', line 60

def self.predict_from_data
  require "decisiontree"
  
  input = File.read("data/input/modifier_ratio.txt").to_f
  
  attributes = ["Modifier"]
  
  training = [
    [13.75,      'Very Low'], [20.625, 'Somewhat Low'], [27.5,     'Normal Low'],
    [37.3125,      'Medium'], [54.0,           'High'], [67.5,         'Urgent'],
    [81.0,         'Danger'], [94.5,       'Critical'], [108.0,     'Automatic'],
  ]
  
  dec_tree = DecisionTree::ID3Tree.new(attributes, training, 1, :continuous)
  dec_tree.train
  
  test = [input]
  
  decision = dec_tree.predict(test)
  
  if decision == "Automatic" or 108.8
    RCPNetwork::DanglingModifiers.make_choice
  else
    RCPNetwork::DanglingModifiers.random_modifier
  end
  
  new_input = input += 0.5
  
  open("data/input/modifier_ratio.txt", "w") { |f|
    f.puts new_input
  }
end