pub fn fold_stability<F, S1, S2, D>(
x: &ArrayBase<S1, Ix2>,
labels: &ArrayBase<S2, D>,
n_folds: Option<usize>,
fold_size: Option<f64>,
random_seed: Option<u64>,
) -> Result<F>Expand description
Calculate fold stability of a clustering algorithm
Measures how stable a clustering is when applied to different subsets of data. Higher values indicate more robust clustering.
§Arguments
x- Array of shape (n_samples, n_features) - The datalabels- Array of shape (n_samples,) - Predicted cluster labelsn_folds- Number of folds to split the data into (default: 5)fold_size- Fraction of data to include in each fold (default: 0.8)random_seed- Optional seed for reproducibility
§Returns
- Fold stability index (between 0 and 1)
§Examples
use scirs2_core::ndarray::{array, Array2};
use scirs2_metrics::clustering::validation::fold_stability;
let x = Array2::from_shape_vec((10, 2), vec![
1.0, 2.0, 1.5, 1.8, 1.2, 2.2, 1.3, 2.1, 1.4, 1.9,
5.0, 6.0, 5.2, 5.8, 5.5, 6.2, 5.3, 6.1, 5.4, 5.9,
]).unwrap();
let labels = array![0, 0, 0, 0, 0, 1, 1, 1, 1, 1];
let stability = fold_stability(&x, &labels, None, None, None).unwrap();