Giter Club home page Giter Club logo

dynamic-shap-plots's Introduction

Dynamic SHAP Plots

This project enables interactive plotting of the visualizations from the SHAP project. The plots show the relative importances of the feature variables in a dataset when making predictions on the target variable.

The core functions to calculate the SHAP values are taken from the SHAP library, and modified to return the matplotlib figure objects instead of plotting them. The file dynamic_shap_plots.py binds them all together to produce the interactive visualizations with the Plotly library.

Requirements:

shap
plotly
pandas
sklearn
matplotlib
xgboost
iml
scipy
numpy

This package has been built and tested on Windows 10 with Python 3.5. Slight modifications may be needed in case of errors when using in Linux or Mac OS.

Some dynamic SHAP visualizations in Jupyter notebook:

1. Summary Plot:

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from dynamic_shap_plots import summary_plot_plotly_fig as sum_plot
import warnings
warnings.filterwarnings('ignore')

plotly_fig = sum_plot(r'path\to\dataset.csv', target='target column')

init_notebook_mode(connected=True)
iplot(plotly_fig, show_link=False)

To save the figure:

plot(plotly_fig, show_link=False, filename=r'path\to\save\figure.html')

2. Dependence Plot:

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from dynamic_shap_plots import dependence_plot_to_plotly_fig as dep_plot
from shap_plots import shap_summary_plot, shap_dependence_plot
import warnings
warnings.filterwarnings('ignore')

lis, features = dep_plot(r'path\to\dataset.csv', target='target column', max_display=20)

init_notebook_mode(connected=True)
for i in range(len(lis)):
  iplot(lis[i], show_link=False)

Alternately, you can also plot for specific features:

>>> features.index('Q2FC - Timeliness of billing notices/statements')
15
>>> iplot(lis[15], show_link=False)

3. Interaction Plot:

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from dynamic_shap_plots import dependence_plot_to_plotly_fig as dep_plot
from dynamic_shap_plots import interaction_plot_to_plotly_fig as int_plot
from shap_plots import shap_summary_plot, shap_dependence_plot
import warnings
warnings.filterwarnings('ignore')

lis, features = int_plot(r'path\to\dataset.csv', target='target column', max_display=20)

init_notebook_mode(connected=True)
for i in range(len(lis)):
  iplot(lis[i], show_link=False)

Alternately, you can also plot for specific features:

>>> features.index('QCF - Caring company')
262
>>> iplot(lis[262], show_link=False)

dynamic-shap-plots's People

Contributors

prashantsaikia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.