Function engram::metrics::pearson_correlation
source · pub fn pearson_correlation(x: &[f64], y: &[f64]) -> f64
Expand description
Calculate the Pearson correlation coefficient between two vectors. Formula:
n * sum(x * y) - sum(x) * sum(y)
--------------------------------
sqrt((n * sum(x^2) - sum(x)^2) * (n * sum(y^2) - sum(y)^2))
§Examples
use engram::metrics::pearson_correlation;
let a = [1.0, 2.0, 3.0, 4.0, 5.0];
let b = [1.0, 2.1, 2.9, 3.9, 5.1];
let pc = pearson_correlation(&a, &b);