Comments (10)
You can. If you look at the source of a Jupyter notebook with a visualization you will see that it prints out html with react (initjs()
dumps the library code. The python from the iml library (which I made separate in case other's wanted to use it) as this code in it:
return HTML("""
<div id='{id}'>{err_msg}</div>
<script>
if (window.IML) IML.ReactDom.render(
IML.React.createElement(IML.AdditiveForceVisualizer, {data}),
document.getElementById('{id}')
);
</script>""".format(err_msg=err_msg, data=json.dumps(self.data), id=id_generator()))
https://github.com/interpretable-ml/iml/blob/master/iml/visualizers.py
So I am sure you could co-opt that into any react interface you want.
from shap.
Hey, thanks, I did just that a few days ago. Took a look at the source code for the ForceVisualizer JSX, and used it as a component for the application. Then I passed the parameters from the server using the Visualizer Python class, and passed those parameters as props to the ForceVisualizer. Worked like a charm!
Thanks!
from shap.
from shap.
Hi guys,
I have exactly this same need to include an Explainer during a classification real-time system. It would be awesome if you could elaborate into the @JuanCorp 's solution. Is it posible to include the Explainer's visualisation into a non-react app (maybe a Angular front-end app) ?
@slundberg Thanks for your SHAP implementation and also the discussion you included in the paper!
from shap.
from shap.
Hey, thanks, I did just that a few days ago. Took a look at the source code for the ForceVisualizer JSX, and used it as a component for the application. Then I passed the parameters from the server using the Visualizer Python class, and passed those parameters as props to the ForceVisualizer. Worked like a charm!
Thanks!
Great that you managed to do that. Could you share how did you do it? I'm trying to use it as a React component but having troubles.
Maybe an example of how does your <AdditiveForceVisualizer ... >
does look like would help
from shap.
As above! Please write a documentation piece on how to integrate it with a react front-end! We're going to get it going soon so it would be great if there was something to lean on for help in integrating.
from shap.
@JuanCorp Can you please provide source code where you used parameters from shap.visualise and passed to forceVisualizer JSX in react ?
from shap.
Hello! What I did back in the day is look at the iml and shap source code and prepare the data just like the iml library expected. I think the interface has changed since then, so this approach may be wrong.
def _explicar_instancia(shap_values, feature_names=None,
data=None, out_names=["peso recomendacion"]):
if type(data) == np.ndarray:
data = data.flatten()
nans = np.argwhere(np.isnan(shap_values))
indexes = nans[:, 1]
shap_values = shap_values[:, ~np.isnan(shap_values).all(0)]
shap_values = shap_values[~np.isnan(shap_values).all(1)]
feature_names = [f for i, f in enumerate(
feature_names) if i not in indexes]
data = np.array([d for i, d in enumerate(data) if i not in indexes])
instance = iml.Instance(np.zeros((1, len(feature_names))), data)
exp = iml.AdditiveExplanation(
shap_values[0, -1],
np.sum(shap_values[0, :]),
shap_values[0, :-1],
None,
instance,
iml.IdentityLink(),
iml.Model(None, out_names),
iml.DenseData(np.zeros((1, len(feature_names))), feature_names)
)
visualizer = iml.AdditiveForceVisualizer(exp)
visualizer.data["labelMargin"] = 20
return visualizer.data
Since I don't think iml exists anymore, you'll have to take a look at how SHAP generates these visualizations today.
from shap.
And how did you consume this in React Project actually ? Can you give some guidance as per current Technology context , how do we go best about it. Basically there will be diff SHAP charts for every time user predicts , through API we can send those SHAP Visualization params to UI and but how does react consume it Actually. I tried to look at React D3 component but it dint seem to have native support for SHAP Charts.
@JuanCorp
from shap.
Related Issues (20)
- BUG: Error using Falcon for text-generation HOT 4
- BUG: Error when using DeepExplainer on LSTM Model HOT 1
- ENH: Partition Explainer for Video Models
- Does Feature/Column Order of dataset matter while calculating SHAP values? HOT 3
- When will the paddlepaddle framework be supported HOT 1
- BUG: LookupError: gradient registry has no entry for: shap_TensorListStack HOT 1
- BUG: shap summary plot for 3 group classification HOT 1
- ENH: Include directionality of feature association in beeswarm plot
- ENH: Support SeLU and activation function in Pytorch Deep Explainer
- BUG: tensorflow DeepExplainer SHAP explanations do not sum up to the model's output HOT 1
- Question: Using SHAP with GPT-4 via API HOT 1
- BUG: Warning: unrecognized nn.Module: Chomp1d HOT 2
- CI broken: mistralai Mistral-7B-v0.1 Tokenizer no longer accessible
- BUG: summary_plot ignores plot_type for TreeExplainer
- BUG: TypeError: waterfall() got an unexpected keyword argument 'features'
- BUG: Unexpected Interaction Plot Instead of Summary Plot in Multiclass SHAP Summary with XGBoost HOT 1
- BUG: Workflow failure on macOS when building 'lightgbm'
- ENH: expose raw feature categories in shap.plots.bar HOT 1
- ENH: Winter Values
- [Meta-issue] Release 0.45.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shap.