shap-rs 0.1.0

Native Rust implementations of model-agnostic, linear, and TreeSHAP explainers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use ndarray::{array, Array2, ArrayView2, Axis};
use shap_rs::{explainers::AutoExplainer, Background, Explainer, FnModel, Result};

fn main() -> Result<()> {
    let model = FnModel::new(|x: ArrayView2<'_, f64>| Ok(x.sum_axis(Axis(1)).insert_axis(Axis(1))));
    let background = Background::new(Array2::zeros((1, 3)))?;
    let explanation = AutoExplainer::new(model, background)
        .with_exact_threshold(2)
        .with_kernel_samples(32)
        .explain(array![[1.0, 2.0, 3.0]].view())?;
    println!("{:?}", explanation.values());
    Ok(())
}