Class: RandomForest
- Inherits:
-
Object
- Object
- RandomForest
- Defined in:
- lib/random_forest.rb
Instance Method Summary collapse
- #decisions_count(features) ⇒ Object
-
#initialize(xml) ⇒ RandomForest
constructor
A new instance of RandomForest.
- #predict(features) ⇒ Object
Constructor Details
#initialize(xml) ⇒ RandomForest
5 6 7 8 9 10 |
# File 'lib/random_forest.rb', line 5 def initialize(xml) xml_trees = xml.xpath('PMML/MiningModel/Segmentation/Segment') @decision_trees = xml_trees.collect{ |xml_tree| DecisionTree.new(xml_tree) } end |
Instance Method Details
#decisions_count(features) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/random_forest.rb', line 12 def decisions_count(features) decisions = @decision_trees.collect { |decision_tree| decision_tree.decide(features) } decisions.inject(Hash.new(0)) { |h, e| h[e] += 1 ; h } end |
#predict(features) ⇒ Object
19 20 21 |
# File 'lib/random_forest.rb', line 19 def predict(features) decisions_count(features).max_by {|_, v| v }[0] end |