AllTopicsTodayAllTopicsToday
Notification
Font ResizerAa
  • Home
  • Tech
  • Investing & Finance
  • AI
  • Entertainment
  • Wellness
  • Gaming
  • Movies
Reading: Tutorial: Exploring SHAP-IQ Visualizations – MarkTechPost
Share
Font ResizerAa
AllTopicsTodayAllTopicsToday
  • Home
  • Blog
  • About Us
  • Contact
Search
  • Home
  • Tech
  • Investing & Finance
  • AI
  • Entertainment
  • Wellness
  • Gaming
  • Movies
Have an existing account? Sign In
Follow US
©AllTopicsToday 2025. All Rights Reserved.
AllTopicsToday > Blog > AI > Tutorial: Exploring SHAP-IQ Visualizations – MarkTechPost
Screenshot 2025 08 03 at 9.41.59 pm.png
AI

Tutorial: Exploring SHAP-IQ Visualizations – MarkTechPost

AllTopicsToday
Last updated: August 4, 2025 5:29 am
AllTopicsToday
Published: August 4, 2025
Share
SHARE

On this tutorial, we’ll discover the scope of SHAP-IQ visualizations that present perception into how machine studying fashions attain their predictions. These visuals assist to interrupt down the habits of complicated fashions into interpretable parts. This reforms each particular person contributions of options and contributions to particular predictions. See the total code right here.

Dependencies Set up

! Pip Set up Shapiq Overrides Scikit-LearnPandas Numpy Seaborn
Importing sklearn.ensemble from sklearn.metrics from randomforestregressor from sklearn.model_selection from sklearn.model_selection from r2_score from tqdm.asyncio from Tqdm import TQDM import Shapiq print (f “shapiq model: {shapiq .__version}”

Importing a dataset

This tutorial makes use of an MPG (mile per gallon) dataset. This hundreds straight from the Seaborn Library. This dataset accommodates details about numerous automotive fashions, together with options equivalent to horsepower, weight, and origin. See the total code right here.

SNS df = sns.load_dataset(“mpg”) import seaborn as df

Processing datasets

Utilizing label encoding, it converts categorical columns to numerical codecs, making them appropriate for mannequin coaching.

Import pandas as pd in sklearn.preprocessing labellencoder # drop line df = df.dropna() with lacking values[:, “origin”] = le.fit_transform(df[“origin”])DF[‘origin’]. Distinctive ()
For i, the label of the enumeration (le.classes_): print(f “{label}→{i}”)

Break up the info into coaching and check subsets

#Options and Goal x = df.drop (column=[“mpg”, “name”])y = df[“mpg”]

feature_names = x.columns.tolist() x_data, y_data = x.values, y.values #traintest cut up x_train, x_test, y_train, y_test = train_test_split (x_data, y_data, test_size = 0.2, random_state=42)

Mannequin Coaching

Prepare random forest regression on resolution timber (N_ESTIMATORS = 10) with most depths of 10 and 10. A hard and fast RANDOM_STATE ensures repeatability.

#Prepare mannequin = randomforestregressor(random_state = 42, max_depth = 10, n_estimators = 10) mannequin.match(x_train, y_train)

Mannequin analysis

#MSE = MEAN_SQUARED_ERROR(Y_TEST, MODEL.PREDICT(X_TEST)) R2 = R2_SCORE(Y_TEST, MODEL.PREDICT(X_TEST)) Printing (F “Imply Error: {MSE:.2F}”) Printing (F “R2 Rating: {R2:.2F}”)

Native Occasion Description

Choose a selected check occasion (utilizing instance_id = 7) to research how the mannequin reached the prediction. Prints the true, predicted, and have values for this occasion. See the total code right here.

#Choose the native occasion defined and instance_id = 7 x_explain = x_test[instance_id]
y_true = y_test[instance_id]
y_pred = mannequin.predict(x_explain.reshape(1,-1))[0]
print(f “occasion {instance_id}, true worth: {y_true}, predicted worth: {y_pred}”) i, function in enumerate (feature_names): print(f “{function}: {x_explain[i]} “)

Generates descriptions of a number of interplay orders

Use the Shapiq package deal to generate Shapley-based descriptions of various interplay orders. Particularly, calculate the next:

Order 1 (commonplace Shapley worth): Particular person function contribution order 2 (pairwise interplay): Perform pair mixture impact order n (full interplay): All interactions as much as the full variety of options

#Create descriptions for numerous orders future_names = listing(x.columns)[int, shapiq.InteractionValues] = {} About ordering tqdm[1, 2, n_features]): index = “k-sii” if order>1 else “sv”# can be mechanically set by the explanator = shapiq.treeexplainer(mannequin = mannequin, max_order = order, index = index) si_order.[order] =explaider.clarify(x = x_explain)si_order

1. Energy Chart

Forceplots are highly effective visualization instruments that enable you perceive how machine studying fashions have reached a specific prediction. It shows baseline predictions (i.e., the anticipated values of the earlier mannequin earlier than trying on the function) and exhibits how every function makes the prediction greater or decrease.

On this plot:

Pink bars symbolize options or interactions that enhance prediction. A blue bar represents one thing that reduces it. The size of every bar corresponds to the scale of its impact.

When utilizing Shapley’s interplay values, the pressure plot can visualize interactions between features in addition to particular person contributions. That is significantly insightful when decoding complicated fashions. It’s because it visually breaks down how the mixtures of options work collectively to have an effect on the result. See the total code right here.

sv = si_order[1] # Get SVSI = SI_ORDER[2] #2- Get sii mi = si_order[n_features] #Moebius transformation sv.plot_force(feature_names = feature_names, present = true)si.plot_force(feature_names = feature_names, present = true)mi.plot_force(feature_names = feature_names, present = true)

From the primary plot, we will see that the bottom worth is 23.5. Options equivalent to weight, cylinder, horsepower, and displacement have a optimistic impact on prediction and push it above the baseline. In the meantime, mannequin 12 months and acceleration have a adverse influence, pulling forecasts down.

2. Waterfall Chart

Like pressure plots, waterfall plots are one other frequent option to visualize Shapley values initially launched within the Shap library. Varied options point out greater or decrease predictions in comparison with baseline. One of many key advantages of waterfall plots is that it mechanically group options which have very small influence on the “different” classes, making the chart cleaner and simpler to know. See the total code right here.

sv.plot_waterfall(feature_names = feature_names, present = true) si.plot_waterfall(feature_names = feature_names, present = true) mi.plot_waterfall(feature_names = feature_names, present = true)

3. Community Plot

The community plot exhibits how options work together utilizing one Shapley interplay. The node measurement displays the influence of particular person options, whereas the sting width and shade point out the energy and orientation of the interplay. It’s particularly helpful when coping with many options, revealing complicated interactions that less complicated plots could miss. See the total code right here.

si.plot_network(feature_names = feature_names, present = true) mi.plot_network(feature_names = feature_names, present = true)

4. Si graph plot

SI graph plots prolong the community plot by visualizing all greater order interactions as hyperedges connecting a number of features. Node measurement signifies the affect of particular person options, whereas edge width, shade, and transparency mirror the depth and orientation of the interplay. This supplies a complete view of how options collaboratively have an effect on mannequin predictions. See the total code right here.

#Since it’s plotted contained in the node, we abbreviate the operate identify. Abbrev_feature_names=shapiq.plot.utils.abbreviate_feature_names sv.plot_si_graph(feature_names = abbrev_feature_names, present = present = size_factor = 2.5, nadeize_size_size_size_sizex plot_original_nodes = true, )si.plot_si_graph(feature_names = abbrev_feature_names, present = true, size_factor = 2.5, node_size_scaling = 1.5, plot_original_nodes = true, )mi.plot_si_graph size_factor = 2.5, node_size_scaling = 1.5, plot_original_nodes = true,)

5. Barplot

The bar plot is tailor-made to the worldwide description. Different plots can be utilized regionally and globally, however bar plots summarise the general significance of options (or function interactions) by exhibiting imply absolute Shapley (or interactions) values for all cases. In Shapiq, we spotlight the traits that the interplay contributes most on common. See the total code right here.

Description= []
explainer =shapiq.treeexplainer(mannequin = mannequin, max_order = 2, index = “k-sii”) for tqdm (vary (20)): x_explain = x_test[instance_id]
si = explader.clarify(x = x_explain)contrisations.append(si)shapiq.plot.bar_plot(contressations, feature_names = feature_names, present = true)

“Distance” and “Horsepower” are essentially the most influential options general. That’s, it has the strongest private affect on mannequin prediction. That is evident from the excessive imply absolute Shapley interplay values within the bar plot.

Moreover, trying on the secondary interplay (i.e. how the 2 features work together), the mix “horsepower x weight” and “distance x horsepower” point out necessary joint results. Their mixed attributions are roughly 1.4, indicating that these interactions play an necessary position in shaping mannequin predictions past people who contribute individually to mannequin predictions. This highlights the existence of nonlinear relations between features inside the mannequin.

See the total code right here. For tutorials, code and notebooks, please go to our GitHub web page. Additionally, be at liberty to observe us on Twitter. Do not forget to hitch 100K+ ML SubredDit and subscribe to our publication.

I’m a civil engineering graduate (2022) from Jamia Milia Islamia, New Delhi, and have a powerful curiosity in information science, significantly neural networks and purposes in quite a lot of fields.

Discussing Decision Trees: What Makes a Good Split?
Can AI Save Indian Farmers?
China Unveils World’s First AI Hospital: 14 Virtual Doctors Ready to Treat Thousands Daily
AI May Soon Help You Understand What Your Pet Is Trying to Say
Wix and Alibaba Unite to Serve SMBs
TAGGED:ExploringMarkTechPostSHAPIQTutorialVisualizations
Share This Article
Facebook Email Print
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow US

Find US on Social Medias
FacebookLike
XFollow
YoutubeSubscribe
TelegramFollow

Weekly Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Popular News
The institute dr hendricks.jpg
Movies

Stephen King Sci-Fi Series Continues Streaming Chart Dominance After Nearly 3 Weeks

AllTopicsToday
AllTopicsToday
August 1, 2025
Best MacBooks We’ve Tested (August 2025)
How Couples’ Relationship Feedback Loops Improve Mental Health
6 Best Crypto Exchanges of 2025
Run Ollama Models Locally and make them Accessible via Public API
- Advertisement -
Ad space (1)

Categories

  • Tech
  • Investing & Finance
  • AI
  • Entertainment
  • Wellness
  • Gaming
  • Movies

About US

We believe in the power of information to empower decisions, fuel curiosity, and spark innovation.
Quick Links
  • Home
  • Blog
  • About Us
  • Contact
Important Links
  • About Us
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • Contact

Subscribe US

Subscribe to our newsletter to get our newest articles instantly!

©AllTopicsToday 2025. All Rights Reserved.
1 2
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?