A method for calculating SHAP values of a machine learning model and related apparatuses
By mapping feature subsets of machine learning models to quantum Hamiltonians for parallel solution and combining Monte Carlo sampling, the problem of high computational complexity of SHAP values under high-dimensional data is solved, achieving efficient and accurate interpretation of feature contributions.
Patent Information
- Application Number
- CN202610800288.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-04
- Publication Date
- 2026-07-21
AI Technical Summary
Existing methods for calculating SHAP values in machine learning models have excessively high computational complexity in high-dimensional data, making them unscalable for practical applications.
A quadratic unconstrained binary optimization matrix is used to map the quantum Hamiltonian. The ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. The SHAP value is calculated by combining Monte Carlo sampling, which reduces computational complexity and improves accuracy.
It significantly reduces the computational complexity of SHAP values from exponential to polynomial, improving computational accuracy and efficiency, and is suitable for interpreting high-dimensional features.
Smart Images

Figure CN122433932A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of interpretable machine learning technology, and in particular to a method and apparatus for calculating the SHAP value of a machine learning model. Background Technology
[0002] As the complexity of machine learning models increases, model interpretability has become a core issue of common concern in academia and industry. SHAP (SHapley Additive exPlanations), a game theory-based model interpretation method, is used to quantify the contribution of features to the prediction results of machine learning models, providing global and local interpretability for black-box models. By calculating the average contribution of a feature across all possible values, it fairly distributes the "gain" of the model's predictions to each feature.
[0003] The traditional method of accurately calculating SHAP values requires traversing all feature subsets, resulting in an exponential time complexity (O( )). (), where M is the number of features. When M < 15, direct enumeration is acceptable; however, when M > 20, the number of subsets exceeds 10. 6 The computational cost is increasing exponentially, making it impossible to scale to high-dimensional data in practical applications. For example, for a model with 50 features, accurate computation requires processing over 10... 15 The combination of these features far exceeds the processing capabilities of existing computers.
[0004] This demonstrates that the existing methods for calculating SHAP values in machine learning models have high computational complexity. Summary of the Invention
[0005] In view of the above problems, this application provides a method and related apparatus for calculating the SHAP value of a machine learning model, so as to reduce computational complexity. The specific solution is as follows: The first aspect of this application provides a method for calculating the SHAP value of a machine learning model, including: Determine the objective function set for each feature subset corresponding to the machine learning model; the objective function set is used to characterize the mapping relationship between each feature subset and the model's prediction performance. Perform a quadratic unconstrained binary optimization on the objective function set to obtain the quadratic unconstrained binary optimization matrix; The quadratic unconstrained binary optimization matrix is mapped to a quantum Hamiltonian. The ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. The objective function corresponding to the ground state of the quantum Hamiltonian is taken as the key objective function. The feature subset corresponding to the key objective function is the high-contribution feature subset of the machine learning model. Monte Carlo sampling is used to calculate the SHAP value of each feature in the feature subset corresponding to the key objective function; Core features are determined based on the SHAP values of each feature, and key decision-making information corresponding to the business scenario to which the machine learning model belongs is generated based on the core features.
[0006] In one possible implementation, the objective function set for each feature subset corresponding to the machine learning model is determined, including: Obtain the feature set of the machine learning model; Determine the baseline predictions of the machine learning model; Determine the predicted values for each feature subset in the feature set, excluding any single feature; Calculate the difference between the predicted value and the baseline predicted value for each feature subset, and use the difference as the model prediction performance value for each feature subset; Construct a set of objective functions that represent the mapping relationship between each feature subset and the model's predicted performance value.
[0007] In one possible implementation, a quadratic unconstrained binary optimization is performed on the objective function set to obtain a quadratic unconstrained binary optimization matrix, including: Each individual feature and each subset of features in the objective function set is converted into a binary variable and a combination of binary variables, respectively. The binary variables are used to represent the marginal contribution information of a single feature, and the combination of binary variables is used to represent the collaborative contribution information of the combined indicators. A quadratic unconstrained binary optimization matrix is generated based on binary variables and combinations of binary variables.
[0008] In one possible implementation, feasible quantum gate sequences include cost Hamiltonian layers and hybrid Hamiltonian layers; The quadratic unconstrained binary optimization matrix is mapped to a quantum Hamiltonian. The ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. The objective function corresponding to the ground state of the quantum Hamiltonian is taken as the key objective function, including: The quadratic unconstrained binary optimization matrix is converted into a quantum Hamiltonian, and the qubits in the quantum Hamiltonian are initialized to obtain a quantum superposition state. The quantum Hamiltonian is decomposed into a cost Hamiltonian layer and a hybrid Hamiltonian layer, and quantum circuits are constructed based on the cost Hamiltonian layer and the hybrid Hamiltonian layer. The final quantum state of quantum superposition is calculated in parallel using quantum circuits; Calculate the energy value of the final quantum state, and take the final quantum state with an energy value lower than the preset energy threshold as the ground state. The objective function corresponding to the ground state is the key objective function.
[0009] In one possible implementation, Monte Carlo sampling is used to calculate the SHAP values of each feature in the feature subset corresponding to the key objective function, including: Determine the high-contribution feature subset based on the key objective function; The first weight value is determined based on the energy value of the high-contribution feature subset; Calculate the SHAP value of each feature based on the first weight value.
[0010] In one possible implementation, Monte Carlo sampling is used to calculate the SHAP values of each feature in the feature subset corresponding to the key objective function, including: Determine the high-contribution feature subset based on the key objective function; Generate a neighboring feature subset of the high-contribution feature subset; The second weight value is determined based on the high-contribution feature subset and the neighboring feature subset; Calculate the SHAP value of each feature based on the second weight value.
[0011] A second aspect of this application provides a device for calculating the SHAP value of a machine learning model, comprising: The determining unit is used to determine the objective function set for each feature subset corresponding to the machine learning model; the objective function set is used to characterize the mapping relationship between each feature subset and the model's prediction performance. The processing unit is used to perform a quadratic unconstrained binary optimization on the objective function set to obtain a quadratic unconstrained binary optimization matrix. The filtering unit is used to map the quadratic unconstrained binary optimization matrix to a quantum Hamiltonian, solve the ground state of the quantum Hamiltonian in parallel using an executable quantum gate sequence, and take the objective function corresponding to the ground state of the quantum Hamiltonian as the key objective function; the feature subset corresponding to the key objective function is the high contribution feature subset of the machine learning model. The computational unit is used to calculate the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling; The application unit is used to determine the core features based on the SHAP values of each feature, and to generate key decision information corresponding to the business scenario to which the machine learning model belongs based on the core features.
[0012] A third aspect of this application provides a computer program product, including computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the SHAP value calculation method of the machine learning model of the first aspect or any implementation thereof.
[0013] A fourth aspect of this application provides a device for calculating the SHAP value of a machine learning model, comprising at least one processor and a memory connected to the processor, wherein: Memory is used to store computer programs; The processor is used to execute computer programs to enable the SHAP value calculation device of the machine learning model to implement the SHAP value calculation method of the machine learning model of the first aspect or any implementation thereof described above.
[0014] The fifth aspect of this application provides a computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to perform a method for calculating the SHAP value of a machine learning model of the first aspect or any implementation thereof.
[0015] Using the above technical solution, the SHAP value calculation method and related apparatus for machine learning models provided in this application first determine the mapping relationship between each feature subset corresponding to the machine learning model and the model's prediction effect as the objective function set. A quadratic unconstrained binary optimization process is then performed on the objective function set to obtain a quadratic unconstrained binary optimization matrix. This process transforms the feature subset selection problem into a combinatorial optimization problem using the quadratic unconstrained binary optimization matrix. Next, the above matrix is mapped to a quantum Hamiltonian, and the ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. This process employs a quantum optimization algorithm to search for high-contribution feature subsets of the machine learning model in parallel within the quantum state space. The search space is polynomial-level, significantly reducing the computational complexity of the SHAP value. Monte Carlo sampling is performed based on the high-contribution feature subsets to increase the effective sampling ratio of Monte Carlo sampling, further improving the computational accuracy of the SHAP value. Finally, core features are determined based on the SHAP values of each feature, and key decision information corresponding to the business scenario to which the machine learning model belongs is generated based on these core features. Attached Figure Description
[0016] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0017] Figure 1 A flowchart illustrating a method for calculating the SHAP value of the machine learning model provided in this application; Figure 2 A schematic diagram of a SHAP value calculation device for the machine learning model provided in this application; Figure 3 A schematic diagram of the structure of the SHAP value calculation device for the machine learning model provided in this application. Detailed Implementation
[0018] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0019] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0020] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0021] Existing methods for calculating the SHAP value of machine learning models include not only the exact calculation methods mentioned above, but also approximate calculation methods, such as Monte Carlo sampling, TreeSHAP, and kernel approximation methods.
[0022] Among them, the Monte Carlo sampling method estimates the expected value of Shapley by randomly sampling a subset of features. Its computational complexity is directly related to the number of samplings, but due to the limited sampling efficiency, it may lead to high variance due to insufficient sample size, making it difficult to guarantee the estimation accuracy. TreeSHAP optimizes tree models (such as decision trees and random forests) by using the splitting rules of the tree structure to quickly calculate feature contributions. Its computational complexity is linearly related to the tree depth. This SHAP value can significantly improve computational efficiency, but it depends on a specific model structure and cannot be applied to non-tree models such as neural networks, thus limiting its generalization ability. The kernel approximation method replaces the original Shapley equation with a linear model, transforming complex combinatorial optimization into an analytically solvable problem and significantly reducing the computational cost. However, the linear assumption may deviate from the theoretical properties of the Shapley value, leading to discrepancies between the interpreted results and the actual contributions.
[0023] In addition, there is existing research on the quantization of SHAP values, but existing quantum machine learning research focuses on accelerating model training and inference, and designs special algorithms for interpretability. It also lacks a quantized expression for the weighted summation of feature subsets. In other words, there is no mature system for calculating the SHAP value of machine learning models based on quantum computing in the existing technology.
[0024] In summary, among the existing methods for calculating the SHAP value of machine learning models, the exact calculation method has high exponential complexity, Monte Carlo sampling requires a balance between computational resources and accuracy, TreeSHAP is limited by the model type, and kernel approximation requires a balance between the degree of approximation and theoretical consistency.
[0025] To address the aforementioned issues, this application provides a method and apparatus for calculating the SHAP value of a machine learning model, thereby resolving the fundamental shortcomings of existing methods for calculating the SHAP value of machine learning models in terms of computational efficiency, scalability, and practicality.
[0026] Optional, see Figure 1 This application provides a flowchart illustrating a method for calculating the SHAP value of a machine learning model.
[0027] like Figure 1 As shown, the method for calculating the SHAP value of a machine learning model includes the following steps: Step 101: Determine the objective function set for each feature subset corresponding to the machine learning model; the objective function set is used to characterize the mapping relationship between each feature subset and the model's prediction performance.
[0028] It should be noted that machine learning models are any supervised or unsupervised learning models capable of generating predictive results, including but not limited to a wide range of types from linear regression to deep neural networks. Specifically, this includes supervised learning models, unsupervised models, deep learning models, and reinforcement learning models.
[0029] Supervised learning models include classification models and regression models.
[0030] Classification models include logistic regression, random forest, and support vector machine models: Logistic regression is used for binary classification problems, such as credit scoring. The SHAP value can be used to explain the contribution of features to the probability of default. For example, income may contribute +0.15, while debt ratio may contribute -0.10, indicating that higher income and lower debt ratio result in lower default risk. Random forest models are used for customer segmentation tasks. The SHAP value identifies key attributes, such as age and purchase frequency, by ranking features by importance, which can guide precise marketing strategies. Support vector machine models are used for text classification. The SHAP value is used to explain the contribution of keywords.
[0031] Regression models include linear regression models and gradient boosting tree models. Linear regression models can be applied to house price forecasting, and the SHAP value is used to quantify the strength of the influence of each factor on the price; gradient boosting tree models can be applied to sales forecasting, and the SHAP value is used to optimize inventory strategies.
[0032] Unsupervised learning models include clustering analysis models and dimensionality reduction models.
[0033] The clustering analysis models include K-Means and hierarchical clustering models. K-Means models can be used for user segmentation, and SHAP values are used to explain the clustering basis and assist in adjusting market strategies. Hierarchical clustering models can be used to cluster gene expression data, and SHAP values are used to identify key gene-driven sample groupings, supporting disease subtyping research.
[0034] Dimensionality reduction models include principal component analysis models, where SHAP values are used to explain the original variables that contribute the most to the principal components, thus improving the interpretability of the results.
[0035] Deep learning models include image recognition models and natural language processing models.
[0036] Image recognition models include convolutional neural network models and object detection models. Image recognition models can be applied to medical image diagnosis. SHAP values can be used to locate lesion areas using heatmaps and quantify pixel-level contributions. In object detection models, taking vehicle detection models as an example, SHAP values display key features such as "edge sharpness" and "color contrast," optimizing recognition efficiency in low-light scenes.
[0037] Natural language processing models include the Transformer model, which can be applied to sentiment analysis. The SHAP value visualizes the impact of keywords on sentiment through attention weights, thereby improving the transparency of text classification.
[0038] Taking the Q-Learning model as an example in reinforcement learning models, in game AI, SHAP analyzes the contribution of each state feature when the agent makes decisions, and optimizes the policy robustness.
[0039] Correspondingly, a feature subset of a machine learning model refers to all possible combinations of features other than that feature when evaluating the marginal contribution of a particular feature to the model's prediction. Each feature subset here includes the set of other feature combinations corresponding to each individual feature.
[0040] Optionally, first determine the feature set of the machine learning model, then determine the baseline prediction value of the machine learning model, calculate the prediction value of each feature subset except for a single feature, calculate the difference between the prediction value of each feature subset and the baseline prediction value, use the difference as the model prediction effect value of each feature subset, and construct the objective function set based on the mapping relationship between each feature subset and the model prediction effect value.
[0041] Specifically, we first define binary variables and objective functions based on each feature subset.
[0042] Let each feature be i, ,definition The value indicates whether the feature is selected; 1 indicates selected, and 0 indicates unselected.
[0043] Let the objective function be The objective function is mainly used to characterize the impact of each feature subset on the prediction performance of the machine learning model. It can be expressed as: = Machine learning model predictions on a subset of features - baseline predictions.
[0044] The baseline prediction is the output of the machine learning model when no features are involved in the prediction.
[0045] Step 102: Perform a quadratic unconstrained binary optimization on the objective function set to obtain the quadratic unconstrained binary optimization matrix.
[0046] It should be noted that the QUBO (Quadratic Unconstrained Binary Optimization Matrix) matrix is a mathematical representation tool for quadratic unconstrained binary optimization problems, used to transform complex combinatorial optimization problems into a unified quadratic form.
[0047] Optionally, each individual feature in the objective function set is converted into a binary variable, each subset of features is converted into a combination of binary variables, and a quadratic unconstrained binary optimization matrix is generated based on the binary variables and the combinations of binary variables.
[0048] Among them, binary variables are used to characterize the marginal contribution information of a single feature, and combinations of binary variables are used to characterize the collaborative contribution information of combined indicators.
[0049] For example, to transform the objective function into a quadratic unconstrained binary optimization matrix form, this matrix can be represented as:
[0050] in, The linear term represents the marginal contribution information of a single feature, and its calculation formula is as follows:
[0051] in, The quadratic term represents the collaborative contribution information between feature i and feature j, and its calculation formula is:
[0052] It should be noted that, assuming the number of features in the feature set of the machine learning model is n, if the SHAP value is calculated by iterating through the features, the machine learning model will require 2^n iterations. n The number of model calls is reduced to only a few after constructing the quadratic unconstrained binary optimization matrix. .
[0053] Step 103: Map the quadratic unconstrained binary optimization matrix to a quantum Hamiltonian, solve the ground state of the quantum Hamiltonian in parallel using an executable quantum gate sequence, and take the objective function corresponding to the ground state of the quantum Hamiltonian as the key objective function; the feature subset corresponding to the key objective function is the high contribution feature subset of the machine learning model.
[0054] In this step, QAOA (Quantum Approximate Optimization Algorithm) is used to select a subset of high-contribution features from the QUBO matrix. This algorithm can quickly find the subset of features that have the greatest impact on the prediction results of the machine learning model, compressing the search space from exponential to polynomial level.
[0055] Optionally, the quadratic unconstrained binary optimization matrix is converted into a quantum Hamiltonian. The qubits in the quantum Hamiltonian are initialized to obtain a quantum superposition state. The quantum Hamiltonian is decomposed into a cost Hamiltonian layer and a hybrid Hamiltonian layer. A quantum circuit is constructed based on the cost Hamiltonian layer and the hybrid Hamiltonian layer. The final quantum state of the quantum superposition state is calculated in parallel based on the quantum circuit. The energy value of the final quantum state is calculated. The final quantum state with an energy value lower than a preset energy threshold is taken as the ground state. The objective function corresponding to the ground state is the key objective function.
[0056] It should be noted that the process of converting a quadratic unconstrained binary optimization matrix into a quantum Hamiltonian is essentially converting the feature subset selection problem into quantum language. This process mainly involves decomposing linear and quadratic terms from the quadratic unconstrained binary optimization matrix, and then using these linear and quadratic terms to form the quantum Hamiltonian. The linear terms represent the marginal contribution information of a single feature, while the quadratic terms represent the collaborative contribution information of combined indices.
[0057] Then, the qubits in the quantum Hamiltonian are initialized to obtain a quantum superposition state. The quantum superposition state puts all qubits in a superposition state of "simultaneous selection / non-selection". Based on this quantum superposition state, all feature subsets can be explored in parallel.
[0058] Simultaneously, the quantum Hamiltonian is decomposed into an executable quantum gate sequence, which includes a cost Hamiltonian layer and a hybrid Hamiltonian layer. A quantum circuit is constructed based on these cost and hybrid Hamiltonian layers. The cost and hybrid Hamiltonian layers are alternately applied in the quantum circuit for time evolution, with parameters continuously adjusted to minimize energy. The evolution of the cost Hamiltonian layer represents a low-energy state evolution, while the evolution of the hybrid Hamiltonian layer breaks local minima and performs a global search. The initial superposition state evolves through the parameterized quantum gate sequence to obtain the final quantum state. The energy value of the final quantum state is calculated, and the final quantum state (binary vector) with the lowest energy is taken as the ground state (optimal solution). The feature subset corresponding to the lowest energy binary vector is the optimal subset.
[0059] It should be noted that the key objective function is the final quantum state with the lowest energy or each final quantum state with an energy value lower than a preset energy threshold.
[0060] In summary, this step is a process of approximating the ground state through a parameterized executable sequence of quantum gates. Essentially, it utilizes the parallelism of quantum superposition states and the dynamic mitigation of hybrid Hamiltonians, combined with classical optimization to achieve a global search.
[0061] For example, we will introduce the two core steps of quantum circuit configuration and quantum solution.
[0062] Quantum circuit configuration mainly includes parameterization circuit, initial state preparation, evolution operation, and classical optimizer selection.
[0063] The parameterization circuit is mainly used to construct a QAOA quantum circuit, which includes alternating Hamiltonian evolution layers.
[0064] The quantum superposition state prepared from the initial state is a uniform superposition state, which can be expressed by the following formula: ; in, The quantum state initially prepared by quantum qubits is a quantum superposition state; n represents the number of qubits involved in the computation. This is the quantum representation of the classical binary state, corresponding to different combinations of qubit states.
[0065] Evolutionary operations are mainly used and .in, The problem Hamiltonian corresponding to the cost Hamiltonian layer is the QUBO matrix; This is the driving Hamiltonian corresponding to the hybrid Hamiltonian layer, which is used to implement global search.
[0066] Finally, select classic optimizers such as ADAM optimizer and adjust the parameters. .in, Used for regulation The corresponding evolution step size or intensity; Used for regulation The corresponding evolution step size or intensity.
[0067] The quantum solution process mainly includes problem encoding, quantum state evolution, and measurement and sampling.
[0068] The problem encoding mainly involves mapping the QUBO matrix Q to a Hamiltonian: ,in, Let the Pauli-Z operator be the i-th qubit; Let $\mathbf{j}$ be the Pauli-Z operator on the $j$-th qubit; $i$ be the $i$-th qubit; $Q$ is the QUBO matrix, which is the core representation of the classical optimization problem; and $\mathbf{j}$ is the element. This represents the weights of variables and the interactions between variables in a coding problem.
[0069] After configuring the quantum circuit and solving the quantum problem, the binary vector with the lowest energy is selected as the optimal subset. Alternatively, the top-K high-probability solutions, such as the top 1000 feature subsets, are retained as candidate feature subsets to facilitate subsequent Monte Carlo sampling.
[0070] Step 104: Calculate the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling.
[0071] It should be noted that Monte Carlo sampling is a technique for solving mathematical problems through random simulation. It can generate samples through methods such as direct sampling, rejection sampling, or importance sampling, and finally calculate the expected value, integral value, or distribution parameter based on the samples.
[0072] In this application, the Monte Carlo sampling is performed on a subset of high-contribution features of the machine learning model selected from the quadratic unconstrained binary optimization matrix using a quantum approximation optimization algorithm. This significantly increases the proportion of effective sampling and further improves the calculation accuracy of the SHAP value.
[0073] Optionally, a subset of high-contribution features is determined based on the key objective function, a first weight value is determined based on the energy value of the subset of high-contribution features, and the SHAP value of each feature is calculated based on the first weight value.
[0074] Specifically, based on the correlation objective function selected in the previous step, a subset of high-contribution features is determined. The first weight value is calculated based on the objective function value (also known as the energy value) of each subset of high-contribution features. Finally, the SHAP value of each feature of the machine learning model is calculated based on the first weight value.
[0075] For example, based on the high-contribution feature subset The weights are calculated based on the corresponding objective function values. The weight calculation formula is as follows: ; in, For feature subset energy, This refers to the temperature parameter.
[0076] This specific embodiment also provides another specific implementation of this step: Optionally, a high-contribution feature subset is determined based on the key objective function, a neighboring feature subset of the high-contribution feature subset is generated, a second weight value is determined based on the high-contribution feature subset and the neighboring feature subset, and the SHAP value of each feature is calculated based on the second weight value.
[0077] This process is a local extended sampling in Monte Carlo sampling.
[0078] Specifically, a neighborhood search is first performed on the high-contribution feature subset to generate its neighboring feature subset. The neighboring feature subset can be obtained by adding or deleting one or two features from the high-contribution feature subset. This process is to expand the sampling pool.
[0079] Then, the predicted values of the neighboring feature subsets are calculated. Based on the predicted values of the neighboring feature subsets and the objective function values of the high-contribution feature subsets, a second weight value is calculated. Finally, the SHAP value of each feature is calculated based on the second weight value. In addition, Monte Carlo sampling can also employ importance sampling, which can be implemented as follows: For each feature i, its SHAP value can be calculated using the following formula:
[0080] in, is the feature subset that does not contain i; N is the set of all features; This is the predicted value of the model when "features in subset S are used only".
[0081] The formula for calculating the unbiased sampling weights can be: ; in, The SHAP theoretical weights corresponding to subset S are used to assign weights to the "contribution difference" between different subsets during calculation.
[0082] Since importance sampling was performed, to ensure that the weights are reasonable and approximately unbiased, the correction formula for the importance sampling weights can be as follows: ; in, The corrected sampling weights make the sampling process closer to "unbiased," ensuring the accuracy of the final SHAP value calculation. The original weights for QAOA sampling are the sampling distribution of the quantum approximation optimization algorithm.
[0083] W is the normalization factor, and its calculation formula can be as follows: W = .
[0084] Finally, Monte Carlo sampling is performed to estimate the SHAP value of each feature. This process utilizes a QAOA-guided sampling distribution to efficiently compute the feature SHAP value.
[0085] For example, for each feature i, its SHAP value can be: ; in, A subset of samples guided by QAOA; is the SHAP value of feature i; M is the number of samples in the Monte Carlo simulation; In the m-th sampling, a subset that is randomly generated and does not contain participant i; To assign to a subset The weights; It is a set function; For marginal contribution.
[0086] Step 105: Determine the core features based on the SHAP values of each feature, and generate key decision information corresponding to the business scenario to which the machine learning model belongs based on the core features.
[0087] Optionally, features whose SHAP values meet the core feature threshold are selected as core features, and key decision information of the business scenario to which the machine learning model belongs is generated based on the core features.
[0088] It should be noted that this application uses quantum optimization algorithms to selectively screen key subsets. Specifically, QAOA searches for high-contribution subsets in parallel in the quantum state space, compressing the search space from exponential to polynomial level, significantly reducing the number of samples, overcoming the "curse of dimensionality", reducing the complexity to polynomial level, and making the interpretation of high-dimensional features possible.
[0089] This application quantifies the importance of feature interactions using the QUBO matrix, guiding sampling to focus on high-contribution regions, reducing the number of model calls, lowering estimation variance and resource consumption, and specifically guiding QAOA to output Top-K high-energy subsets, thereby significantly increasing the effective sampling ratio.
[0090] This application is the first to combine QAOA with the SHAP framework to construct an end-to-end quantum-classical hybrid interpretation system, filling a gap in the application of quantum computing in the field of interpretability.
[0091] In summary, the SHAP value calculation method for the machine learning model provided in this application first determines the mapping relationship between each feature subset corresponding to the machine learning model and the model's prediction effect as the objective function set. A quadratic unconstrained binary optimization process is then performed on the objective function set to obtain a quadratic unconstrained binary optimization matrix. This process transforms the feature subset selection problem into a combinatorial optimization problem using the quadratic unconstrained binary optimization matrix. Next, the above matrix is mapped to a quantum Hamiltonian, and the ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. This process employs a quantum optimization algorithm to search for high-contribution feature subsets of the machine learning model in parallel within the quantum state space. The search space is polynomial-level, significantly reducing the computational complexity of the SHAP value. Monte Carlo sampling is performed based on the high-contribution feature subsets to increase the effective sampling ratio of Monte Carlo sampling, further improving the computational accuracy of the SHAP value. Finally, core features are determined based on the SHAP values of each feature, and key decision information corresponding to the business scenario to which the machine learning model belongs is generated based on these core features.
[0092] For example, taking a wealth management institution's intelligent screening system for funds of funds as an example, the specific implementation process of the SHAP value calculation method provided in this application is introduced.
[0093] The fund intelligent screening system includes 12 core indicators: Sharpe ratio, maximum drawdown, fund manager tenure, industry concentration, etc., which are used to evaluate 500 candidate funds.
[0094] Understandably, traditional SHAP value calculation requires calling a model. This approach cannot meet the real-time inventory adjustment requirements. Using quantum software simulation as an example, after adopting a quantum acceleration scheme, the number of model calls is reduced to O(n²)~144.
[0095] Step 1: Construct the QUBO matrix for fund evaluation.
[0096] 1.1. Define variables and objective function.
[0097] The binary variable is: (Sharpe ratio > 1.5 in the past 3 years) (Maximum drawdown < 15%)... (Heavy weighting in the technology sector > 30%)
[0098] The baseline predicted value is: empty subset (all) When the value is 0, the model gives a fund comprehensive score of 60 points (CSI 500 benchmark). The objective function is: F(x) = the fund score of the model based on the subset x, specifically 60.
[0099] 1.2. Calculate the interaction contribution parameters.
[0100] Linear terms For: marginal improvement of a single indicator.
[0101] Example: only (Fund manager's tenure > 5 years) Activation score 68→=68-60=8.
[0102] Quadratic terms For: the synergistic effect between indicators.
[0103] Example: Activate simultaneously (Annualized volatility <10%) and The score is 77 when institutional holdings account for more than 40%.
[0104] =77-(single) 65+ individual (70-60)=77-75=2.
[0105] The QUBO matrix contains 12×12=144 parameters, covering all single and dual indicator combinations.
[0106] 1.3. Efficiency optimization.
[0107] The traditional method requires calling the model 4096 times, while this solution only requires 12×13 / 2=78 times. Specifically, the triangle traversal method can be used.
[0108] Step 2: QAOA quantum screening core indicator combination.
[0109] 2.1. Quantum software simulation configuration.
[0110] Parameterized circuit design using a 12-qubit superconducting quantum processor to meet 12 performance indicators: The initial state is prepared using the Hadamard gate: ^ 12; in, The quantum state obtained after a single qubit undergoes a Hadamard gate operation; ; The symbol for the tensor product (also called the direct product) of quantum states; 12 represents 12 tensors. The states are combined together through tensor product operations.
[0111] The alternating layer structure is configured with 4 layers of QAOA loops to balance accuracy and hardware noise.
[0112] Hamiltonian encoding is: , .
[0113] The optimization process specifically employs a quantum-classical hybrid training method, with the ADAM optimizer iterating 200 times.
[0114] 2.2. Quantum solution results.
[0115] The measured high-frequency index combination is as follows: Its optimal solution is: x=[1,1,0,0,1,0,0,0,0,0,0,1] (Sharpe ratio, maximum drawdown, institutional holdings ratio, technology sector) Analysis of the energy spectrum: The top 5% subset (approximately 200) covers 80% of the fund score variance.
[0116] Step 3: Construct an indicator space sampling strategy.
[0117] 3.1. Construction of a quantum-classical hybrid sampling cell.
[0118] QAOA guided sampling includes energy weighting and local perturbation spreading. The formula for energy weighting can be: ; It is used for adaptive temperature regulation.
[0119] For example, the optimal subset can be represented as: -32→ ; This process requires handling the number field.
[0120] Local perturbation expansion: For each quantum solution, apply a ±2 index perturbation (e.g., delete x). 12 In the technology sector, x6's ESG rating is increased to >AA.
[0121] Finally, multiple expanded samples are generated for dynamic validation and model scoring.
[0122] 3.2 Importance sampling correction.
[0123] The sampling correction formula can be specifically as follows: ; Correcting importance sampling can prevent overfitting of quantum solutions.
[0124] The corrected weight formula can be as follows: ; Where M is the normalization factor.
[0125] Step 4: SHAP value-driven fund attribution.
[0126] 4.1. Dynamic Monte Carlo sampling.
[0127] Sampling was performed in the QAOA sample.
[0128] 4.2. SHAP value parsing.
[0129] The specific contributions of the key indicators are as follows: A Sharpe ratio > 1.5 has a SHAP value of 9.7, which is economically interpreted as a core discriminant factor for risk-adjusted returns; The SHAP value for funds with a size of 2-5 billion is -2.1, which can be explained economically as a liquidity discount for medium-sized funds. The SHAP value of the heavily invested technology sector is 6.3, which can be explained by economics as the double-edged sword effect of industry beta exposure. The SHAP value for managers with tenures of more than 5 years is 5.8, which can be economically explained by the fact that the experience premium is significantly amplified in a bear market.
[0130] The above describes a method for calculating the SHAP value of a machine learning model according to an embodiment of this application. The following describes an apparatus for performing the above method for calculating the SHAP value of a machine learning model.
[0131] Please see Figure 2 , Figure 2 A schematic diagram of a SHAP value calculation device for the machine learning model provided in this application. Figure 2 As shown, the device includes: The system comprises: a determination unit 10, a processing unit 20, a filtering unit 30, a calculation unit 40, and an application unit 50; wherein: The determining unit 10 is used to determine the objective function set for each feature subset corresponding to the machine learning model; the objective function set is used to characterize the mapping relationship between each feature subset and the model prediction effect. Processing unit 20 is used to perform quadratic unconstrained binary optimization on the objective function set to obtain a quadratic unconstrained binary optimization matrix; The screening unit 30 is used to map the quadratic unconstrained binary optimization matrix to a quantum Hamiltonian, solve the ground state of the quantum Hamiltonian in parallel using an executable quantum gate sequence, and take the objective function corresponding to the ground state of the quantum Hamiltonian as the key objective function; the feature subset corresponding to the key objective function is the high contribution feature subset of the machine learning model. The computing unit 40 is used to calculate the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling; Application unit 50 is used to determine core features based on the SHAP values of each feature, and to generate key decision information corresponding to the business scenario to which the machine learning model belongs based on the core features.
[0132] In one embodiment, the determining unit 10 is specifically used for: Obtain the feature set of the machine learning model; Determine the baseline predictions of the machine learning model; Determine the predicted values for each feature subset in the feature set, excluding any single feature; Calculate the difference between the predicted value and the baseline predicted value for each feature subset, and use the difference as the model prediction performance value for each feature subset; Construct a set of objective functions that represent the mapping relationship between each feature subset and the model's predicted performance value.
[0133] In one possible implementation, a quadratic unconstrained binary optimization is performed on the objective function set. In one embodiment, the processing unit 20 is specifically used for: Each individual feature and each subset of features in the objective function set is converted into a binary variable and a combination of binary variables, respectively. The binary variables are used to represent the marginal contribution information of a single feature, and the combination of binary variables is used to represent the collaborative contribution information of the combined indicators. A quadratic unconstrained binary optimization matrix is generated based on binary variables and combinations of binary variables.
[0134] In one embodiment, the feasible executable quantum gate sequence in the screening unit 30 includes a cost Hamiltonian layer and a hybrid Hamiltonian layer. The screening unit 30 is specifically used for: The quadratic unconstrained binary optimization matrix is converted into a quantum Hamiltonian, and the qubits in the quantum Hamiltonian are initialized to obtain a quantum superposition state. The quantum Hamiltonian is decomposed into a cost Hamiltonian layer and a hybrid Hamiltonian layer, and quantum circuits are constructed based on the cost Hamiltonian layer and the hybrid Hamiltonian layer. The final quantum state of quantum superposition is calculated in parallel using quantum circuits; Calculate the energy value of the final quantum state, and take the final quantum state with an energy value lower than the preset energy threshold as the ground state. The objective function corresponding to the ground state is the key objective function.
[0135] In one embodiment, the calculation unit 40 is specifically used for: Determine the high-contribution feature subset based on the key objective function; The first weight value is determined based on the energy value of the high-contribution feature subset; Calculate the SHAP value of each feature based on the first weight value.
[0136] In one embodiment, the calculation unit 40 is specifically used for: Determine the high-contribution feature subset based on the key objective function; Generate a neighboring feature subset of the high-contribution feature subset; The second weight value is determined based on the high-contribution feature subset and the neighboring feature subset; Calculate the SHAP value of each feature based on the second weight value.
[0137] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement the SHAP value calculation method of any machine learning model provided in this application.
[0138] This application also provides a device for calculating the SHAP value of a machine learning model in its embodiments. (See reference) Figure 3 The diagram illustrates a structural schematic of a SHAP value calculation device suitable for implementing the machine learning model provided in this application. The SHAP value calculation device for the machine learning model in this embodiment may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 3 The illustrated SHAP value calculation device for the machine learning model is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0139] like Figure 3As shown, the SHAP value calculation device for the machine learning model may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. When the SHAP value calculation device for the machine learning model is powered on, RAM 603 also stores various programs and data required for the operation of the SHAP value calculation device. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.
[0140] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 608 including, for example, memory card, hard disk, etc.; and communication devices 609. Communication device 609 allows the machine learning model's SHAP value calculation device to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 3 A device for calculating SHAP values using a machine learning model with various apparatuses is shown; however, it should be understood that implementation or possession of all the apparatuses shown is not required. More or fewer apparatuses may be implemented alternatively.
[0141] This application also provides a computer storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the SHAP value calculation method of any machine learning model provided in this application.
[0142] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0143] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0144] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0145] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A method for calculating the SHAP value of a machine learning model, characterized in that, include: Determine the objective function set for each feature subset corresponding to the machine learning model; The objective function set is used to characterize the mapping relationship between each feature subset and the model prediction effect; Perform a quadratic unconstrained binary optimization on the objective function set to obtain a quadratic unconstrained binary optimization matrix; The quadratic unconstrained binary optimization matrix is mapped to a quantum Hamiltonian, and the ground state of the quantum Hamiltonian is solved in parallel using an executable quantum gate sequence. The objective function corresponding to the ground state of the quantum Hamiltonian is taken as the key objective function. The feature subset corresponding to the key objective function is the high-contribution feature subset of the machine learning model. The SHAP value of each feature in the feature subset corresponding to the key objective function is calculated using Monte Carlo sampling; Based on the SHAP values of each feature, core features are determined, and key decision information corresponding to the business scenario to which the machine learning model belongs is generated based on the core features.
2. The method for calculating the SHAP value of a machine learning model according to claim 1, characterized in that, The determination of the objective function set for each feature subset corresponding to the machine learning model includes: Obtain the feature set of the machine learning model; Determine the baseline prediction value of the machine learning model; Determine the predicted value of each feature subset in the feature set, excluding any single feature; The difference between the predicted value of each feature subset and the baseline predicted value is calculated, and the difference is used as the model prediction effect value of each feature subset. Construct a set of objective functions that characterize the mapping relationship between each feature subset and the model's predicted performance value.
3. The method for calculating the SHAP value of a machine learning model according to claim 1, characterized in that, The step of performing a quadratic unconstrained binary optimization on the objective function set to obtain a quadratic unconstrained binary optimization matrix includes: Each individual feature and each subset of features in the objective function set is converted into a binary variable and a combination of binary variables, respectively; the binary variables are used to characterize the marginal contribution information of the individual feature; the combination of binary variables is used to characterize the collaborative contribution information of the combined indicators. The quadratic unconstrained binary optimization matrix is generated based on the binary variables and combinations of binary variables.
4. The method for calculating the SHAP value of a machine learning model according to claim 1, characterized in that, The feasible executable quantum gate sequence includes cost Hamiltonian layers and hybrid Hamiltonian layers; The process of mapping the quadratic unconstrained binary optimization matrix to a quantum Hamiltonian, solving for the ground state of the quantum Hamiltonian in parallel using an executable quantum gate sequence, and using the objective function corresponding to the ground state of the quantum Hamiltonian as the key objective function includes: The quadratic unconstrained binary optimization matrix is converted into the quantum Hamiltonian, and the qubits in the quantum Hamiltonian are initialized to obtain the quantum superposition state. The quantum Hamiltonian is decomposed into the cost Hamiltonian layer and the hybrid Hamiltonian layer, and a quantum circuit is constructed based on the cost Hamiltonian layer and the hybrid Hamiltonian layer; The final quantum state of the quantum superposition state is calculated in parallel based on the quantum circuit. Calculate the energy value of the final quantum state, and take the final quantum state with the energy value lower than the preset energy threshold as the ground state. The objective function corresponding to the ground state is the key objective function.
5. The method for calculating the SHAP value of a machine learning model according to claim 4, characterized in that, The calculation of the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling includes: The high-contribution feature subset is determined based on the key objective function; The first weight value is determined based on the energy value of the high-contribution feature subset; The SHAP value of each feature is calculated based on the first weight value.
6. The method for calculating the SHAP value of a machine learning model according to claim 1, characterized in that, The calculation of the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling includes: The high-contribution feature subset is determined based on the key objective function; Generate a neighboring feature subset of the high-contribution feature subset; A second weight value is determined based on the high-contribution feature subset and the neighboring feature subset; The SHAP value of each feature is calculated based on the second weight value.
7. A device for calculating the SHAP value of a machine learning model, characterized in that, include: The determining unit is used to determine the objective function set for each feature subset corresponding to the machine learning model; The objective function set is used to characterize the mapping relationship between each feature subset and the model prediction effect; The processing unit is used to perform a quadratic unconstrained binary optimization on the objective function set to obtain a quadratic unconstrained binary optimization matrix; The filtering unit is used to map the quadratic unconstrained binary optimization matrix into a quantum Hamiltonian, solve the ground state of the quantum Hamiltonian in parallel using an executable quantum gate sequence, and take the objective function corresponding to the ground state of the quantum Hamiltonian as the key objective function; the feature subset corresponding to the key objective function is the high contribution feature subset of the machine learning model. The computing unit is used to calculate the SHAP value of each feature in the feature subset corresponding to the key objective function using Monte Carlo sampling; The application unit is used to determine core features based on the SHAP values of each feature, and to generate key decision information corresponding to the business scenario to which the machine learning model belongs based on the core features.
8. A computer program product, characterized in that, Includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the SHAP value calculation method of the machine learning model as described in any one of claims 1 to 6.
9. A device for calculating the SHAP value of a machine learning model, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the SHAP value calculation device of the machine learning model can implement the SHAP value calculation method of the machine learning model as described in any one of claims 1 to 6.
10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the SHAP value calculation method of the machine learning model as described in any one of claims 1 to 6.