cluster_stability

Function cluster_stability 

Source
pub fn cluster_stability<F, S1, S2, D>(
    x: &ArrayBase<S1, Ix2>,
    labels: &ArrayBase<S2, D>,
    n_runs: Option<usize>,
    perturbation_scale: Option<F>,
    random_seed: Option<u64>,
) -> Result<F>
where F: Float + NumCast + Debug + ScalarOperand + AddAssign + DivAssign, S1: Data<Elem = F>, S2: Data<Elem = usize>, D: Dimension,
Expand description

Calculate Cluster Stability index

Measures the stability of clustering by comparing multiple runs with perturbed data. Higher values indicate more stable clustering.

§Arguments

  • x - Array of shape (n_samples, n_features) - The data
  • labels - Array of shape (n_samples,) - Predicted cluster labels
  • n_runs - Number of bootstrap samples to generate (default: 10)
  • perturbation_scale - Scale of Gaussian noise to add (default: 0.1)
  • random_seed - Optional seed for reproducibility

§Returns

  • Stability index (between 0 and 1)

§Examples

use scirs2_core::ndarray::{array, Array2};
use scirs2_metrics::clustering::validation::cluster_stability;

let x = Array2::from_shape_vec((6, 2), vec![
    1.0, 2.0, 1.5, 1.8, 1.2, 2.2,
    5.0, 6.0, 5.2, 5.8, 5.5, 6.2,
]).unwrap();

let labels = array![0, 0, 0, 1, 1, 1];

let stability = cluster_stability(&x, &labels, None, None, None).unwrap();