Class: HybridForest::Trees::GiniImpurity
- Inherits:
-
Object
- Object
- HybridForest::Trees::GiniImpurity
- Includes:
- Impurity
- Defined in:
- lib/hybridforest/trees/impurity_metrics/gini_impurity.rb
Instance Method Summary collapse
Methods included from Impurity
#information_gain, #weighted_impurity
Instance Method Details
#compute(instances) ⇒ Object
10 11 12 13 14 |
# File 'lib/hybridforest/trees/impurity_metrics/gini_impurity.rb', line 10 def compute(instances) total_count = instances.count.to_f label_counts = instances.count_labels.each_value 1 - label_counts.sum { |count| (count / total_count)**2 } end |