Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Error’d: You Talkin’ to Me?

      September 20, 2025

      The Psychology Of Trust In AI: A Guide To Measuring And Designing For User Confidence

      September 20, 2025

      This week in AI updates: OpenAI Codex updates, Claude integration in Xcode 26, and more (September 19, 2025)

      September 20, 2025

      Report: The major factors driving employee disengagement in 2025

      September 20, 2025

      Development Release: Zorin OS 18 Beta

      September 19, 2025

      Distribution Release: IPFire 2.29 Core 197

      September 19, 2025

      Development Release: Ubuntu 25.10 Beta

      September 18, 2025

      Development Release: Linux Mint 7 Beta “LMDE”

      September 18, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Performance Prediction System using Python Machine Learning (ML)

      September 21, 2025
      Recent

      Student Performance Prediction System using Python Machine Learning (ML)

      September 21, 2025

      The attack on the npm ecosystem continues

      September 20, 2025

      Feature Highlight

      September 20, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Hyprland Made Easy: Preconfigured Beautiful Distros

      September 20, 2025
      Recent

      Hyprland Made Easy: Preconfigured Beautiful Distros

      September 20, 2025

      Development Release: Zorin OS 18 Beta

      September 19, 2025

      Distribution Release: IPFire 2.29 Core 197

      September 19, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»How to Use the SHAP-IQ Package to Uncover and Visualize Feature Interactions in Machine Learning Models Using Shapley Interaction Indices (SII)

    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 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

    Installing the dependencies

    Copy CodeCopiedUse a different Browser
    !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

    Copy CodeCopiedUse a different Browser
    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

    Copy CodeCopiedUse a different Browser
    # 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

    Copy CodeCopiedUse a different Browser
    # 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

    Copy CodeCopiedUse a different Browser
    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

    Copy CodeCopiedUse a different Browser
    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

    Copy CodeCopiedUse a different Browser
    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

    Copy CodeCopiedUse a different Browser
    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.

    The post How to Use the SHAP-IQ Package to Uncover and Visualize Feature Interactions in Machine Learning Models Using Shapley Interaction Indices (SII) appeared first on MarkTechPost.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMIT Researchers Develop Methods to Control Transformer Sensitivity with Provable Lipschitz Bounds and Muon
    Next Article A Coding Guide to Build Intelligent Multi-Agent Systems with the PEER Pattern

    Related Posts

    Machine Learning

    How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    September 3, 2025
    Machine Learning

    Announcing the new cluster creation experience for Amazon SageMaker HyperPod

    September 3, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Apple Zero-Click Flaw in Messages Exploited to Spy on Journalists Using Paragon Spyware

    Development

    Senior Playstation Engineer’s tips for learning new tools and getting things done [Podcast #184]

    Development

    Rilasciato Incus 6.13: Gestore di Container e Macchine Virtuali

    Linux

    I love how Grounded 2 gets rid of tired survival game tools — it makes the game better, not easier

    News & Updates

    Highlights

    Top Cryptocurrency Trends to Watch in 2025

    May 30, 2025

    As the cryptocurrency market continues to mature, 2025 is poised to be a pivotal year, marked by innovation, adoption, and regulatory advancements. From decentralized finance (DeFi) to environmental sustainability, the crypto space is evolving in ways that could redefine the global financial ecosystem. Here are the top cryptocurrency trends to watch in 2025.1. Mainstream Institutional AdoptionThe integration of cryptocurrencies into mainstream financial systems is accelerating. By 2025, institutional adoption is expected to reach unprecedented levels, driven by:Central Bank Digital Currencies (CBDCs):
    Countries worldwide are developing CBDCs, signaling broader acceptance of blockchain technology in traditional finance.Crypto ETFs and Mutual Funds:
    Regulatory approvals are paving the way for crypto-focused exchange-traded funds (ETFs), making digital assets more accessible to institutional and retail investors.Corporate Integration:
    Companies are increasingly holding cryptocurrencies as treasury assets and accepting them as payment, normalizing their use in commerce.2. Expansion of Decentralized Finance (DeFi)DeFi platforms continue to disrupt traditional financial services, offering decentralized lending, borrowing, and trading options. Emerging trends in DeFi for 2025 include:Cross-Chain Interoperability:
    Enhanced protocols will enable seamless transactions between different blockchain networks, reducing fragmentation in the DeFi space.DeFi 2.0 Innovations:
    New financial products and models, such as tokenized insurance and decentralized credit scoring, will drive growth.Mainstream Accessibility:
    Simplified user interfaces and lower entry barriers will attract non-technical users to DeFi platforms.3. Rise of Layer-2 SolutionsScalability and transaction speed remain critical challenges for major blockchains like Ethereum. Layer-2 solutions, which operate on top of existing blockchains, are set to address these issues. Key developments include:Optimistic and ZK-Rollups:
    These technologies will significantly enhance throughput and reduce transaction costs.Integration with Web3:
    Layer-2 solutions will play a crucial role in enabling seamless decentralized applications (dApps).4. NFT Evolution and UtilityNon-fungible tokens (NFTs) have moved beyond art and collectibles, finding utility in:Gaming:
    Play-to-earn (P2E) models and metaverse integrations are driving demand for gaming-related NFTs.Digital Identity:
    NFTs are emerging as tools for digital identity verification, with potential applications in healthcare, education, and beyond.Tokenization of Real Assets:
    Real estate, luxury goods, and intellectual property are increasingly being tokenized, unlocking liquidity and democratizing ownership.5. Enhanced Regulatory ClarityThe regulatory landscape for cryptocurrencies is becoming clearer, as governments recognize their transformative potential. Expected regulatory trends for 2025 include:Global Standards:
    Collaboration between nations to create unified regulations for cryptocurrencies and blockchain technologies.Focus on Consumer Protection:
    Policies aimed at safeguarding investors while promoting innovation.Taxation Reforms:
    Simplified frameworks for crypto taxation to encourage compliance and transparency.6. Emphasis on SustainabilityEnvironmental concerns around cryptocurrency mining have led to a focus on sustainable practices. Innovations in 2025 include:Green Mining:
    Transition to renewable energy sources and more energy-efficient consensus mechanisms like Proof-of-Stake (PoS).Carbon Credits Integration:
    Cryptocurrencies linked to carbon credits could incentivize eco-friendly behaviors.Blockchain for Sustainability:
    Leveraging blockchain for tracking and verifying sustainability initiatives.7. Enhanced Security and Privacy FeaturesAs the crypto ecosystem grows, so does the need for robust security and privacy. Innovations to watch include:Quantum-Resistant Cryptography:
    Developing protocols to withstand potential threats from quantum computing.Privacy Coins Evolution:
    Enhanced privacy-focused cryptocurrencies offering better compliance with regulatory standards.Secure Wallets and Custodial Services:
    Advances in wallet technologies to prevent hacks and ensure user safety.8. Integration with Traditional FinanceThe lines between traditional and digital finance are blurring. By 2025, expect:Hybrid Financial Products:
    Solutions combining crypto and fiat features to offer the best of both worlds.Bank Partnerships:
    Collaboration between crypto platforms and traditional banks to offer seamless services.Crypto-Powered Credit Systems:
    Lending and credit scoring systems that incorporate blockchain transparency and efficiency.9. Metaverse and Web3 ExpansionCryptocurrencies are central to the development of the metaverse and Web3. Key trends include:Virtual Economies:
    Cryptos and tokens underpin virtual goods and services in the metaverse.Decentralized Internet:
    Blockchain-based Web3 initiatives promoting user sovereignty over data.Interoperable Digital Assets:
    Assets that work across multiple platforms and virtual worlds.10. Focus on Education and AwarenessAs crypto adoption grows, so does the need for public understanding. Educational initiatives in 2025 will emphasize:Financial Literacy Programs:
    Governments and private entities will invest in teaching crypto fundamentals.Developer Training:
    Upskilling tech talent to support blockchain innovations.Consumer Awareness Campaigns:
    Promoting safe practices and scam prevention.ConclusionThe cryptocurrency landscape in 2025 is shaping up to be dynamic and transformative. From institutional adoption to sustainability and technological advancements, these trends will play a pivotal role in defining the future of digital finance. As investors, businesses, and governments align with these developments, the potential for growth and innovation in the crypto sector is limitless.

    Microsoft Brings Teams VDI Optimization to Amazon WorkSpaces

    September 2, 2025

    CVE-2025-8817 – Linksys RE Series Stack-Based Buffer Overflow Vulnerability

    August 10, 2025

    Not Rumor Anymore: Persona 4 Revival Announced At Xbox Games Showcase 2025

    June 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.