OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

SHAP Summary with PLOTLY

  • Thread starter Thread starter Julia Julchen
  • Start date Start date
J

Julia Julchen

Guest
I want to recreate the SHAP Summary Plot with the help of the plotly library.

I found this beautiful post: https://community.plotly.com/t/shap-like-bee-swarm-plots/68015 But I have no idea how the dataframe

df = pd.read_csv('Shap_FI.csv')

was created.

This is the endresult:

Code:
import pandas as pd
import plotly.express as px

df = pd.read_csv('Shap_FI.csv')

#values = df.iloc[:,2:].columns
values = df.iloc[:,2:].abs().mean(axis=0).sort_values().index
df_plot = pd.melt(df, id_vars=['transaction_id', 'predictions'], value_vars=values, var_name='Feature', value_name='SHAP')

fig = px.strip(df_plot, x='SHAP', y='Feature', color='predictions', stripmode='overlay', height=4000, width=1000)
fig.update_layout(xaxis=dict(showgrid=True, gridcolor='WhiteSmoke', zerolinecolor='Gainsboro'),
              yaxis=dict(showgrid=True, gridcolor='WhiteSmoke', zerolinecolor='Gainsboro')
)
fig.update_layout(plot_bgcolor='white')

fig = (
    fig
    # Make it so there is no gap between the supporting boxes
    .update_layout(boxgap=0)
    # Increase the jitter so it reaches the sides of the boxes
    .update_traces(jitter=1)
)

fig.write_html('plotly_beeswarm_test.html')
fig.show()

I am struggeling with the colour coding: Red and blue.In this post "Is there a way to recreate the Shap Values plot with plotly?" Is there a way to recreate the Shap Values plot with plotly? the colour code were just mapped to the classes which is not my goal.

And I do not understand this: transaction_id
<p>I want to recreate the SHAP Summary Plot with the help of the plotly library.</p>
<p>I found this beautiful post: <a href="https://community.plotly.com/t/shap-like-bee-swarm-plots/68015" rel="nofollow noreferrer">https://community.plotly.com/t/shap-like-bee-swarm-plots/68015</a>
But I have no idea how the dataframe</p>
<p><code>df = pd.read_csv('Shap_FI.csv') </code></p>
<p>was created.</p>
<p>This is the endresult:</p>
<pre><code>import pandas as pd
import plotly.express as px

df = pd.read_csv('Shap_FI.csv')

#values = df.iloc[:,2:].columns
values = df.iloc[:,2:].abs().mean(axis=0).sort_values().index
df_plot = pd.melt(df, id_vars=['transaction_id', 'predictions'], value_vars=values, var_name='Feature', value_name='SHAP')

fig = px.strip(df_plot, x='SHAP', y='Feature', color='predictions', stripmode='overlay', height=4000, width=1000)
fig.update_layout(xaxis=dict(showgrid=True, gridcolor='WhiteSmoke', zerolinecolor='Gainsboro'),
yaxis=dict(showgrid=True, gridcolor='WhiteSmoke', zerolinecolor='Gainsboro')
)
fig.update_layout(plot_bgcolor='white')

fig = (
fig
# Make it so there is no gap between the supporting boxes
.update_layout(boxgap=0)
# Increase the jitter so it reaches the sides of the boxes
.update_traces(jitter=1)
)

fig.write_html('plotly_beeswarm_test.html')
fig.show()

</code></pre>
<p>I am struggeling with the colour coding: Red and blue.In this post "Is there a way to recreate the Shap Values plot with plotly?" <a href="https://stackoverflow.com/questions...-to-recreate-the-shap-values-plot-with-plotly">Is there a way to recreate the Shap Values plot with plotly?</a> the colour code were just mapped to the classes which is not my goal.</p>
<p>And I do not understand this: transaction_id</p>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
Top