shap4j-parent

Java wrapper of the SHAP library (https://github.com/slundberg/shap)

License

License

GroupId

GroupId

io.github.xydrolase
ArtifactId

ArtifactId

shap4j-parent
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

pom
Description

Description

shap4j-parent
Java wrapper of the SHAP library (https://github.com/slundberg/shap)
Project URL

Project URL

https://github.com/xydrolase/shap4j
Project Organization

Project Organization

io.github.xydrolase
Source Code Management

Source Code Management

https://github.com/xydrolase/shap4j

Download shap4j-parent

Filename Size
shap4j-parent-0.0.2.pom 8 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.xydrolase/shap4j-parent/ -->
<dependency>
    <groupId>io.github.xydrolase</groupId>
    <artifactId>shap4j-parent</artifactId>
    <version>0.0.2</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.xydrolase/shap4j-parent/
implementation 'io.github.xydrolase:shap4j-parent:0.0.2'
// https://jarcasting.com/artifacts/io.github.xydrolase/shap4j-parent/
implementation ("io.github.xydrolase:shap4j-parent:0.0.2")
'io.github.xydrolase:shap4j-parent:pom:0.0.2'
<dependency org="io.github.xydrolase" name="shap4j-parent" rev="0.0.2">
  <artifact name="shap4j-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.xydrolase', module='shap4j-parent', version='0.0.2')
)
libraryDependencies += "io.github.xydrolase" % "shap4j-parent" % "0.0.2"
[io.github.xydrolase/shap4j-parent "0.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • shap4j
  • platform

shap4j

Build Status javadoc

Java interface for the SHAP (SHapley Additive exPlanations) library for tree ensembles (TreeExplainer). Note that shap4j is not a pure Java port of SHAP. Rather, it utilizes JavaCPP to provide a Java-Native Interface (JNI) on top of the fast C++ implementation of TreeExplainer. In this sense, shap4j leverages the same underlying native code that powers the Python version of TreeExplainer, to ensure validity and efficiency.

Current supported platforms:

  • macosx-x86_64
  • linux-x86_64

Use cases

shap4j enables lean SHAP integration in JVM projects, i.e. a project can import shap4j as the sole dependency, without having to depend on heavier third-party tree ensemble libraries, e.g. xgboost4j.

Tree ensemble model conversion

In order for shap4j to explain a tree ensemble model, that model must be provided in a .shap4j data file, which can be generated from model dumps (pickle files) of XGBoost/LightGBM/CatBoost/sklearn using the companion Python library shap4j-data-converter.

Usage

Maven

<dependency>
  <groupId>io.github.xydrolase</groupId>
  <artifactId>shap4j-platform</artifactId>
  <version>0.0.2</version>
</dependency>

SBT

libraryDependencies += "io.github.xydrolase" % "shap4j-platform" % "0.0.2"

Example usage

package examples;

import java.nio.file.Files;
import java.io.File;
import shap4j.TreeExplainer;

class ExampleApp {
    public static void main(String[] args) throws Exception {
        byte[] data = Files.readAllBytes(new File("boston.shap4j").toPath());
        TreeExplainer explainer = new TreeExplainer(data);
        double[] x = {
                6.320e-03, 1.800e+01, 2.310e+00, 0.000e+00, 5.380e-01, 6.575e+00,
                6.520e+01, 4.090e+00, 1.000e+00, 2.960e+02, 1.530e+01, 3.969e+02,
                4.980e+00
        };
        double[] shapValues = explainer.shapValues(x, false);

        System.out.println("SHAP values: " + Arrays.toString(shapValues));
    }
}

The data file boston.shap4j can be found here. Or, you can follow the examples in shap4j-data-converter to generate it yourself.

API Docs

Versions

Version
0.0.2
0.0.1