adjusted_rand_index

Function adjusted_rand_index 

Source
pub fn adjusted_rand_index<F>(
    labels_true: ArrayView1<'_, i32>,
    labels_pred: ArrayView1<'_, i32>,
) -> Result<F>
where F: Float + FromPrimitive + Debug + 'static,
Expand description

Adjusted Rand Index for comparing two clusterings.

The Adjusted Rand Index (ARI) is a measure of the similarity between two data clusterings, adjusted for chance. It has a value between -1 and 1, where:

  • 1 indicates perfect agreement
  • 0 indicates agreement no better than random chance
  • Negative values indicate agreement worse than random chance

§Arguments

  • labels_true - Ground truth cluster labels
  • labels_pred - Predicted cluster labels

§Returns

The Adjusted Rand Index score

§Example

use scirs2_core::ndarray::Array1;
use scirs2_cluster::metrics::adjusted_rand_index;

let labels_true = Array1::from_vec(vec![0, 0, 1, 1, 2, 2]);
let labels_pred = Array1::from_vec(vec![0, 0, 2, 2, 1, 1]);

let ari: f64 = adjusted_rand_index(labels_true.view(), labels_pred.view()).unwrap();
assert!(ari > 0.0);  // Should be positive for similar clusterings