Class: HybridForest::Trees::TreeGrowers::ID3Grower
- Inherits:
-
Object
- Object
- HybridForest::Trees::TreeGrowers::ID3Grower
- Includes:
- Observable
- Defined in:
- lib/hybridforest/trees/tree_growers/id3_grower.rb
Instance Method Summary collapse
- #grow_tree(instances, parent_instances = nil) ⇒ Object
-
#initialize(feature_selector: MaxOneSplitPerFeature.new, impurity_metric: Entropy.new) ⇒ ID3Grower
constructor
A new instance of ID3Grower.
Constructor Details
#initialize(feature_selector: MaxOneSplitPerFeature.new, impurity_metric: Entropy.new) ⇒ ID3Grower
Returns a new instance of ID3Grower.
24 25 26 27 28 |
# File 'lib/hybridforest/trees/tree_growers/id3_grower.rb', line 24 def initialize(feature_selector: MaxOneSplitPerFeature.new, impurity_metric: Entropy.new) @impurity_metric = impurity_metric @feature_selector = feature_selector add_observer(@feature_selector) end |
Instance Method Details
#grow_tree(instances, parent_instances = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hybridforest/trees/tree_growers/id3_grower.rb', line 30 def grow_tree(instances, parent_instances = nil) features = remaining_features(instances) if instances.count == 0 LeafNode.new(parent_instances) elsif instances.pure? || features.count == 0 LeafNode.new(instances) else try_to_split_dataset(instances, features) end end |