Giter Site home page Giter Site logo

shap4j-data-converter's Introduction

shap4j-data-converter

Data converter for shap4j, which converts tree ensemble models trained by XGBoost, LightGBM, CatBoost, scikit-learn and pyspark to .shap4j data files.

Getting started

Installation

 $ python setup.py install

Dump tree model through pickle

XGBoost

Here, we borrow the example in the shap documentation

import xgboost
import shap
import pickle

# train XGBoost model
X,y = shap.datasets.boston()
model = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)

with open("boston.pkl", "wb+") as f:
    pickle.dump(model, f)

Convert an existing .pkl file with command-line tool

We can use the shap4jconv program to convert the boston.pkl pickle file generated by the previous example to a .shap4j data file:

 $ shap4jconv boston.pkl

The command above generates the output file as boston.shap4j

Alternatively, you could specify the output file via the --output parameter:

 $ shap4jconv --output model.shap4j --overwrite boston.pkl

where the --overwrite parameter allows shap4jconv to overwrite an existing file.

Convert .pkl file programatically

You can also use shap4j-data-converter in your Python program by simply importing the Shap4jDataConverter class from the shap4jconv package, for example:

from shap4jconv import Shap4jDataConverter

converter = Shap4jDataConverter()
converter.convert("boston.pkl", output_file="dumped_boston.pkl", overwrite=True)

Use .shap4j data file in Java

See the Java example of shap4j for how to integrate SHAP into your JVM projects using the data files generated above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.