Class: HybridForest::Trees::Entropy
- Inherits:
-
Object
- Object
- HybridForest::Trees::Entropy
- Includes:
- Impurity
- Defined in:
- lib/hybridforest/trees/impurity_metrics/entropy.rb
Instance Method Summary collapse
Methods included from Impurity
#information_gain, #weighted_impurity
Instance Method Details
#compute(instances) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/hybridforest/trees/impurity_metrics/entropy.rb', line 10 def compute(instances) instance_count = instances.count label_counts = instances.count_labels label_counts.values.sum do |label_count| label_probability = label_count.to_f / instance_count label_surprise = Math.log2(1 / label_probability) label_probability * label_surprise end end |