• bitcoinBitcoin(BTC)$83,917.000.95%
  • ethereumEthereum(ETH)$2,695.941.71%
  • tetherTether(USDT)$1.00-0.01%
  • binancecoinBNB(BNB)$762.96-0.09%
  • rippleXRP(XRP)$1.501.47%
  • usd-coinUSDC(USDC)$1.000.01%
  • solanaSolana(SOL)$119.080.24%
  • tronTRON(TRX)$0.3346560.32%
  • zcashZcash(ZEC)$1,403.27-9.49%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.000.00%
  • HyperliquidHyperliquid(HYPE)$87.88-1.07%
  • dogecoinDogecoin(DOGE)$0.0944631.40%
  • chainlinkChainlink(LINK)$14.998.33%
  • moneroMonero(XMR)$544.922.02%
  • whitebitWhiteBIT Coin(WBT)$83.901.17%
  • USDSUSDS(USDS)$1.00-0.04%
  • cardanoCardano(ADA)$0.2475750.65%
  • RainRain(RAIN)$0.012473-0.65%
  • leo-tokenLEO Token(LEO)$9.02-0.62%
  • stellarStellar(XLM)$0.2266098.36%
  • bitcoin-cashBitcoin Cash(BCH)$309.280.33%
  • nearNEAR Protocol(NEAR)$4.72-8.72%
  • uniswapUniswap(UNI)$8.72-4.57%
  • litecoinLitecoin(LTC)$68.38-3.67%
  • CantonCanton(CC)$0.132185-3.73%
  • hedera-hashgraphHedera(HBAR)$0.11757220.74%
  • Ethena USDeEthena USDe(USDE)$1.00-0.01%
  • avalanche-2Avalanche(AVAX)$10.873.03%
  • suiSui(SUI)$1.14-5.49%
  • daiDai(DAI)$1.000.01%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.57-1.35%
  • USD1USD1(USD1)$1.00-0.02%
  • quant-networkQuant(QNT)$250.81-8.62%
  • BittensorBittensor(TAO)$305.20-0.06%
  • crypto-com-chainCronos(CRO)$0.0694627.70%
  • tether-goldTether Gold(XAUT)$4,147.34-0.78%
  • shiba-inuShiba Inu(SHIB)$0.000006-0.51%
  • Global DollarGlobal Dollar(USDG)$1.000.03%
  • BitwayBitway(BTW)$1.19-9.89%
  • paypal-usdPayPal USD(PYUSD)$1.00-0.02%
  • EthenaEthena(ENA)$0.252955-4.51%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • okbOKB(OKB)$119.492.16%
  • OndoOndo(ONDO)$0.52-10.44%
  • MemeCoreMemeCore(M)$1.10-6.68%
  • Circle USYCCircle USYC(USYC)$1.140.01%
  • aaveAave(AAVE)$155.283.91%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.150.03%
  • Pump.funPump.fun(PUMP)$0.004865-2.00%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

How to Use the SHAP-IQ Package to Uncover and Visualize Feature Interactions in Machine Learning Models Using Shapley Interaction Indices (SII)

August 2, 2025
in AI & Technology
Reading Time: 6 mins read
A A
How to Use the SHAP-IQ Package to Uncover and Visualize Feature Interactions in Machine Learning Models Using Shapley Interaction Indices (SII)
ShareShareShareShareShare

In this tutorial, we explore how to use the SHAP-IQ package to uncover and visualize feature interactions in machine learning models using Shapley Interaction Indices (SII), building on the foundation of traditional Shapley values.

Shapley values are great for explaining individual feature contributions in AI models but fail to capture feature interactions. Shapley interactions go a step further by separating individual effects from interactions, offering deeper insights—like how longitude and latitude together influence house prices. In this tutorial, we’ll get started with the shapiq package to compute and explore these Shapley interactions for any model. Check out the Full Codes here

YOU MAY ALSO LIKE

Alibaba Qwen Releases Qwen-Audio-3.1-Realtime: A Full-Duplex Voice Model Trained to Think, Act, and Decide When to Speak

How To Get Started With Shortcuts On Your MacBook

Installing the dependencies

!pip install shapiq overrides scikit-learn pandas numpy

Data Loading and Pre-processing

In this tutorial, we’ll use the Bike Sharing dataset from OpenML. After loading the data, we’ll split it into training and testing sets to prepare it for model training and evaluation. Check out the Full Codes here

import shapiq
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from sklearn.model_selection import train_test_split
import numpy as np

# Load data
X, y = shapiq.load_bike_sharing(to_numpy=True)

# Split into training and testing
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Model Training and Performance Evaluation

# Train model
model = RandomForestRegressor()
model.fit(X_train, y_train)

# Predict
y_pred = model.predict(X_test)

# Evaluate
mae = mean_absolute_error(y_test, y_pred)
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
r2 = r2_score(y_test, y_pred)

print(f"R² Score: {r2:.4f}")
print(f"Mean Absolute Error: {mae:.4f}")
print(f"Root Mean Squared Error: {rmse:.4f}")

Setting up an Explainer

We set up a TabularExplainer using the shapiq package to compute Shapley interaction values based on the k-SII (k-order Shapley Interaction Index) method. By specifying max_order=4, we allow the explainer to consider interactions of up to 4 features simultaneously, enabling deeper insights into how groups of features collectively impact model predictions. Check out the Full Codes here

# set up an explainer with k-SII interaction values up to order 4
explainer = shapiq.TabularExplainer(
    model=model,
    data=X,
    index="k-SII",
    max_order=4
)

Explaining a Local Instance

We select a specific test instance (index 100) to generate local explanations. The code prints the true and predicted values for this instance, followed by a breakdown of its feature values. This helps us understand the exact inputs passed to the model and sets the context for interpreting the Shapley interaction explanations that follow. Check out the Full Codes here

from tqdm.asyncio import tqdm
# create explanations for different orders
feature_names = list(df[0].columns)  # get the feature names
n_features = len(feature_names)

# select a local instance to be explained
instance_id = 100
x_explain = X_test[instance_id]
y_true = y_test[instance_id]
y_pred = model.predict(x_explain.reshape(1, -1))[0]
print(f"Instance {instance_id}, True Value: {y_true}, Predicted Value: {y_pred}")
for i, feature in enumerate(feature_names):
    print(f"{feature}: {x_explain[i]}")

Analyzing Interaction Values

We use the explainer.explain() method to compute Shapley interaction values for a specific data instance (X[100]) with a budget of 256 model evaluations. This returns an InteractionValues object, which captures how individual features and their combinations influence the model’s output. The max_order=4 means we consider interactions involving up to 4 features. Check out the Full Codes here

interaction_values = explainer.explain(X[100], budget=256)
# analyse interaction values
print(interaction_values)

First-Order Interaction Values

To keep things simple, we compute first-order interaction values—i.e., standard Shapley values that capture only individual feature contributions (no interactions).

By setting max_order=1 in the TreeExplainer, we’re saying:

“Tell me how much each feature individually contributes to the prediction, without considering any interaction effects.”

These values are known as standard Shapley values. For each feature, it estimates the average marginal contribution to the prediction across all possible permutations of feature inclusion. Check out the Full Codes here

feature_names = list(df[0].columns)
explainer = shapiq.TreeExplainer(model=model, max_order=1, index="SV")
si_order = explainer.explain(x=x_explain)
si_order

Plotting a Waterfall chart

A Waterfall chart visually breaks down a model’s prediction into individual feature contributions. It starts from the baseline prediction and adds/subtracts each feature’s Shapley value to reach the final predicted output.

In our case, we’ll use the output of TreeExplainer with max_order=1 (i.e., individual contributions only) to visualize the contribution of each feature. Check out the Full Codes here

si_order.plot_waterfall(feature_names=feature_names, show=True)

In our case, the baseline value (i.e., the model’s expected output without any feature information) is 190.717.

As we add the contributions from individual features (order-1 Shapley values), we can observe how each one pushes the prediction up or pulls it down:

  • Features like Weather and Humidity have a positive contribution, increasing the prediction above the baseline.
  • Features like Temperature and Year have a strong negative impact, pulling the prediction down by −35.4 and −45, respectively.

Overall, the Waterfall chart helps us understand which features are driving the prediction, and in which direction—providing valuable insight into the model’s decision-making.


Check out the Full Codes here. Feel free to check out our GitHub Page for Tutorials, Codes and Notebooks. Also, feel free to follow us on Twitter and don’t forget to join our 100k+ ML SubReddit and Subscribe to our Newsletter.


I am a Civil Engineering Graduate (2022) from Jamia Millia Islamia, New Delhi, and I have a keen interest in Data Science, especially Neural Networks and their application in various areas.

Credit: Source link

ShareTweetSendSharePin

Related Posts

Alibaba Qwen Releases Qwen-Audio-3.1-Realtime: A Full-Duplex Voice Model Trained to Think, Act, and Decide When to Speak
AI & Technology

Alibaba Qwen Releases Qwen-Audio-3.1-Realtime: A Full-Duplex Voice Model Trained to Think, Act, and Decide When to Speak

September 29, 2026
How To Get Started With Shortcuts On Your MacBook
AI & Technology

How To Get Started With Shortcuts On Your MacBook

September 29, 2026
The Warning Signs That Your iPhone Battery Needs To Be Replaced
AI & Technology

The Warning Signs That Your iPhone Battery Needs To Be Replaced

September 28, 2026
How To Improve Your Android Phone’s Battery Life
AI & Technology

How To Improve Your Android Phone’s Battery Life

September 28, 2026
Next Post
Darksiders 4 was not on my 2025 bingo card

Darksiders 4 was not on my 2025 bingo card

Leave a Reply Cancel reply

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

Search

No Result
View All Result
Orange: The Market Is Underestimating This European Telecom Giant (Rating Upgrade) (ORANY)

Orange: The Market Is Underestimating This European Telecom Giant (Rating Upgrade) (ORANY)

September 23, 2026
100-pound bear falls out of tree after tranquilization

100-pound bear falls out of tree after tranquilization

September 25, 2026
‘Simpsons’ writer Dan Greaney launches presidential bid

‘Simpsons’ writer Dan Greaney launches presidential bid

September 26, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!