pub fn class_counts<T: Clone + Ord>(labels: &Array1<T>) -> Vec<(T, usize)>Expand description
Count how many samples carry each label.
This is a quick way to see how balanced a dataset is before choosing between
train_test_split and stratified_split. This function returns counts in
sorted class order, matching the numbering label_encode assigns.
§Parameters
labels- The per-sample labels to count.
§Returns
Vec<(T, usize)>- Each distinct class and its sample count, sorted by class.
§Example
use dataset_ml::preprocessing::class_counts;
use ndarray::array;
let labels = array!["spam", "ham", "ham", "ham"];
assert_eq!(class_counts(&labels), vec![("ham", 3), ("spam", 1)]);