Skip to main content

entropy

Function entropy 

Source
pub fn entropy<S>(y: &ArrayBase<S, Ix1>) -> f64
where S: Data<Elem = f64>,
Expand description

Calculates the entropy of a label set.

Entropy quantifies the impurity or randomness in a dataset and is used by decision tree algorithms to evaluate split quality.

§Parameters

  • y - Class labels stored in a 1D array

§Returns

  • f64 - Entropy value of the dataset (0.0 for homogeneous data)

§Examples

use ndarray::array;
use rustyml::math::entropy;

let labels = array![0.0, 1.0, 1.0, 0.0];
let ent = entropy(&labels);
// For two classes with equal frequency, entropy = 1.0
assert!((ent - 1.0).abs() < 1e-6);