Class: HybridForest::Trees::TreeGrowers::CARTGrower

Inherits:
Object
  • Object
show all
Defined in:
lib/hybridforest/trees/tree_growers/cart_grower.rb

Instance Method Summary collapse

Constructor Details

#initialize(feature_selector: RandomFeatureSubspace.new, impurity_metric: GiniImpurity.new) ⇒ CARTGrower

Returns a new instance of CARTGrower.



18
19
20
21
# File 'lib/hybridforest/trees/tree_growers/cart_grower.rb', line 18

def initialize(feature_selector: RandomFeatureSubspace.new, impurity_metric: GiniImpurity.new)
  @impurity_metric = impurity_metric
  @feature_selector = feature_selector
end

Instance Method Details

#grow_tree(instances) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/hybridforest/trees/tree_growers/cart_grower.rb', line 23

def grow_tree(instances)
  split = find_best_split(instances)
  if split.info_gain == 0
    LeafNode.new(instances)
  else
    branch(split.subsets, split.feature, split.value)
  end
end