rust_shap 0.1.0

A lightweight Rust implementation of Kernel SHAP
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! Small utility functions that correspond to helper routines in shap/utils/_general.py

/// compute n choose r as f64; used by kernel weighting
pub fn combination(n: usize, r: usize) -> f64 {
    if r > n { return 0.0; }
    let r = if r > n - r { n - r } else { r };
    let mut num = 1f64;
    let mut den = 1f64;
    for i in 0..r {
        num *= (n - i) as f64;
        den *= (i + 1) as f64;
    }
    num / den
}