A data transaction model fairness test method, system, device and medium

CN123012484APending Publication Date: 2026-10-30GUANGXI POWER GRID CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611040372.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-14
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0005]因此,本发明提供了一种数据交易模型公平性测试方法、系统、设备及介质解决现有的公平性测试方法只关注当前梯度信息且未考虑样本与决策边界间的关联关系,导致迭代过程容易陷入相同的搜索路径,降低全局搜索阶段对样本空间中个体歧视样本的搜索效率的问题

Benefits of technology

在每次属性更新后,若生成的样本被判定为个体歧视样本,则增加对应目标属性的成功次数和总次数;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123012484A_ABST
    Figure CN123012484A_ABST
Patent Text Reader

Abstract

The application discloses a data transaction model fairness test method, system, device and medium, comprising: constructing a mapping relationship of model input to output Gini value; maximizing the Gini value of the model output through gradient search to generate a group of diversified individual discrimination samples; more individual discrimination samples for testing model fairness are iteratively generated by searching neighbor samples of the individual discrimination samples; the multi-armed bandit algorithm is used to select the minimum gradient search or the maximum historical value as the search strategy of the current iteration to generate the individual discrimination samples. The application aims at the problem that the existing method only focuses on the current gradient information, leading to the iteration process being easy to fall into the same search path, and uses the target model output Gini value to construct the gradient search guide strategy, guiding the global search process to search the individual discrimination samples in the direction of the decision boundary, and enhancing the diversity of the generated individual discrimination samples.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data transaction security technology, and in particular to a method, system, device and medium for testing the fairness of data transaction models. Background Technology

[0002] With the widespread application of deep learning in public sectors such as data trading, models are highly susceptible to inheriting biases from training data and making unethical discriminatory decisions. Therefore, introducing fairness testing is crucial. However, due to the low interpretability of model decisions and the hidden nature of biases in the sample space, existing fairness testing methods mainly detect biases by generating individual discrimination samples. There is an urgent need to improve the comprehensiveness of the test by enhancing the diversity of samples.

[0003] While current mainstream fairness testing methods employ a gradient search strategy that combines global search with local generation, they still have significant limitations: on the one hand, over-reliance on current gradient information can easily lead to a single search path and repeated sample generation; on the other hand, gradient guidance strategies lack consideration of the relationship between samples and decision boundaries, resulting in low efficiency of global search and difficulty in comprehensively and efficiently covering the biased decision-making behavior of the model. Summary of the Invention

[0004] In view of the aforementioned existing problems, the present invention is proposed.

[0005] Therefore, this invention provides a data transaction model fairness testing method, system, device, and medium to address the problem that existing fairness testing methods only focus on the current gradient information and do not consider the correlation between samples and decision boundaries, which makes it easy for the iterative process to fall into the same search path and reduces the search efficiency of individual discriminatory samples in the sample space during the global search stage.

[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution: In a first aspect, the present invention provides a method for testing the fairness of a data transaction model, comprising: Obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. A global iterative search is performed on the seed sample set to calculate the Gini value gradient of the model to be tested, and the attribute values ​​of the seed samples are updated according to the Gini value gradient until a sample whose prediction output has changed is found, and the sample is recorded as the initial discrimination sample. The initial discrimination sample is used as the starting point to perform local iterative generation. In each iteration, the multi-armed slot machine algorithm is used to dynamically select the path search strategy between the gradient search strategy and the historical experience strategy, and the attribute values ​​of the initial discrimination sample are updated according to the selected strategy to generate new individual discrimination samples. Based on the individual discrimination sample set consisting of all the new individual discrimination samples generated iteratively, a fairness test is performed on the model to be tested, and the fairness test results are obtained.

[0007] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the step of clustering the original test sample set and extracting seed samples from each cluster in a round-robin manner to form a seed sample set includes: The original test sample set is clustered using a clustering algorithm based on the protected and unprotected attributes to obtain multiple clusters; Calculate the sample density of each cluster and determine the sampling quantity of each cluster based on the sample density; According to the sampling quantity, samples are randomly drawn from each cluster in a round-robin manner, and the drawn samples are combined to form the seed sample set.

[0008] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the step of calculating the Gini value gradient of the model under test and guiding the attribute value update of the seed sample based on the Gini value gradient includes: Construct a fairness loss function based on the Gini index, calculate the gradient of the predicted output of the model under test for samples in the seed sample set with respect to the attribute values ​​of the seed samples, and obtain the Gini value gradient; The selection probability corresponding to each attribute is calculated based on the Gini value gradient, and the target update attribute is determined from the attributes of the seed sample according to the selection probability. The attribute value update direction is determined based on the gradient sign corresponding to the target update attribute, and the attribute value of the target update attribute is updated according to the attribute value update direction.

[0009] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the step of dynamically selecting a path search strategy between a gradient search strategy and a historical experience strategy using a multi-armed slot machine algorithm includes: Generate a random number; In response to the random number being less than a preset strategy selection threshold, a gradient search strategy is selected as the path search strategy for the current iteration. In response to the random number being greater than or equal to the strategy selection threshold, a historical experience strategy is selected as the path search strategy for the current iteration.

[0010] The beneficial effects of this preferred technical solution are that by establishing a mechanism through a dynamic switching strategy of state parameter thresholds and by combining success rate and diversity contribution for weighted reward calculation, a dynamic balance between exploration and utilization is achieved, effectively avoiding the search path from getting stuck in local optima, thereby significantly improving the diversity of generated individual discrimination samples and global search efficiency.

[0011] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the step of updating the attribute values ​​of the initial discriminatory sample according to the selected strategy includes: In response to the path search strategy being the gradient search strategy, the gradient of the Gini value output by the model under test with respect to each non-protected attribute of the current initial sample is calculated. The absolute value of the gradient of each non-protected attribute is back-normalized to obtain the selection probability corresponding to each attribute. The target attribute is then selected and updated according to the selection probability. In response to the path search strategy being the historical experience strategy, the historical success rate of each non-protected attribute in historical iterations is obtained, and the target attribute is selected for updating according to the historical success rate. The historical success rate is calculated as the ratio of the total number of times the attribute was selected in the historical iterations to the number of times it was successfully used to classify the updated sample as an individual discrimination sample. After each attribute update, if the generated sample is determined to be an individual discrimination sample, the success count and total count for the corresponding target attribute will be increased. If the sample is not identified as an individual discrimination sample, only the total number of times the corresponding target attribute is increased; The historical success rate of the attribute is updated based on the ratio of the updated number of successes to the total number of successes.

[0012] The beneficial effects of this preferred technical solution are that by combining local gradient reverse perturbation with historical similar sample offset update, it achieves complementarity between deterministic exploration and empirical guidance, effectively broadens the sample search space, and further enhances the diversity of generated individual discrimination samples.

[0013] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the step of searching until a sample in which the predicted output changes, and recording the sample as the initial discrimination sample, includes: During the iteration process, similar samples corresponding to the current seed sample are constructed. The similar sample refers to a sample that has all the same non-protected attribute values ​​as the current seed sample and at least one protected attribute value is different. If the current seed sample differs from the predicted output of the model to be tested from the similar sample, then it is determined that a sample whose predicted output has changed has been found, and the current seed sample is recorded as the initial discrimination sample.

[0014] As a preferred embodiment of the data transaction model fairness testing method described in this invention, the fairness testing of the model to be tested, based on the individual discrimination sample set composed of all new individual discrimination samples generated iteratively, includes: The total number of samples in the individual discrimination sample set and the number of samples that caused the model under test to produce discriminatory prediction results are counted. Calculate the individual discrimination coverage rate index based on the total number of samples and the sample size; The individual discrimination coverage rate index is compared with a preset fairness threshold. If the individual discrimination coverage rate index exceeds the preset fairness threshold, the model under test is determined to have failed the fairness test.

[0015] Secondly, the present invention provides a data transaction model fairness testing system, comprising: The clustering and seed selection module is used to obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. The global search module is used to perform a global iterative search on the seed sample set, calculate the Gini value gradient of the output of the model to be tested, and guide the attribute value update of the seed samples according to the Gini value gradient until a sample whose prediction output has changed is found, and the sample is recorded as the initial discrimination sample. The local generation module is used to perform local iterative generation starting from the initial discrimination sample. In each iteration, the multi-armed slot machine algorithm is used to dynamically select the path search strategy between the gradient search strategy and the historical experience strategy, and the attribute values ​​of the initial discrimination sample are updated according to the selected strategy to generate new individual discrimination samples. The fairness testing module is used to perform fairness testing on the model under test based on the individual discrimination sample set consisting of all new individual discrimination samples generated iteratively, and obtain the fairness test results.

[0016] Thirdly, the present invention provides a computer device, comprising: Memory, used to store programs; A processor for executing the computer-executable instructions, which, when executed by the processor, implement the steps of the data transaction model fairness testing method.

[0017] Fourthly, the present invention provides a computer-readable storage medium, comprising: when the program is executed by a processor, the step of implementing the data transaction model fairness testing method.

[0018] The beneficial effects of this invention are as follows: By constructing a fairness loss function based on the Gini index, calculating the gradient of the Gini value output by the model under test, and guiding the update of seed sample attribute values ​​based on this gradient, this invention achieves directional approximation of the model decision boundary, effectively improving the search efficiency of initial discriminatory samples; by using a multi-armed slot machine algorithm to dynamically select a path search strategy between gradient search strategy and historical experience strategy, and combining success rate and diversity contribution to calculate the cumulative reward value to determine the optimal path, this invention achieves a dynamic balance between exploration and utilization during the search process, avoiding the search path from getting trapped in local optima; by performing perturbation updates along the opposite direction of the local gradient or offset updates to highly similar historical reference samples according to the selected strategy, this invention achieves complementarity between deterministic exploration and empirical guidance, significantly broadening the sample search space and enhancing the diversity of generated individual discriminatory samples. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein: Figure 1 A basic flowchart of a data transaction model fairness testing method provided in one embodiment of the present invention is shown below; Figure 2 A flowchart illustrating a data transaction model fairness testing method provided in one embodiment of the present invention; Figure 3 A timing diagram of a data transaction model fairness testing method provided in one embodiment of the present invention. Detailed Implementation

[0020] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0021] Example 1, referring to Figure 1 As an embodiment of the present invention, a method for testing the fairness of a data transaction model is provided, comprising: S100: Obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. S200: Perform a global iterative search on the seed sample set, calculate the Gini value gradient of the model to be tested, and guide the attribute value update of the seed samples according to the Gini value gradient until a sample whose prediction output has changed is found, and record the sample as the initial discrimination sample. S300: Using the initial discrimination sample as a starting point, perform local iterative generation. In each iteration, use the multi-armed slot machine algorithm to dynamically select a path search strategy between gradient search strategy and historical experience strategy, and update the attribute values ​​of the initial discrimination sample according to the selected strategy to generate new individual discrimination samples. S400: Based on the individual discrimination sample set consisting of all new individual discrimination samples generated iteratively, the fairness test is performed on the model to be tested, and the fairness test results are obtained.

[0022] It should be noted that the decision-making process of the data transaction model faces a series of challenges during its operation. Due to the model's low interpretability, testers find it difficult to effectively track and trace the biased decisions generated by the model. Furthermore, the model's decision bias in the sample space cannot be accurately mapped to sample groups with similar attributes, making fairness defects more subtle and difficult to detect. In addition, existing methods only focus on current gradient information, which can easily lead to the iteration process falling into the same search path, resulting in the repeated generation of individual discrimination samples and reducing the comprehensiveness of the test. Moreover, its gradient guidance strategy does not consider the correlation between samples and decision boundaries, requiring the path search process to explore additional samples, reducing the efficiency of the global search phase.

[0023] Therefore, existing fairness testing methods, which only focus on current gradient information and neglect the correlation between samples and the decision boundary, are prone to getting stuck on the same search path during the iterative process, reducing the efficiency of searching for individual-discriminatory samples in the global search phase. This paper addresses this issue by using the Gini value output by the model as a gradient search guide strategy through steps S100-S400, directing the global search process towards the decision boundary to search for individual-discriminatory samples. Furthermore, by combining gradient search with a multi-armed slot machine algorithm, a path selection strategy for the local generation process is constructed to balance historical search information and current gradient information. This improves the breadth of path search and the effectiveness of path selection, enhances the diversity of generated individual-discriminatory samples, and strengthens the comprehensiveness of model fairness testing.

[0024] Example 2, refer to Figures 2-3 As an embodiment of the present invention, based on the previous embodiment, a data transaction model fairness testing method is provided, including: In this embodiment of the application, step S100 involves clustering the original test sample set and extracting seed samples from each cluster in a round-robin manner to form a seed sample set, including: The original test sample set is clustered using a clustering algorithm based on the protected and unprotected attributes to obtain multiple clusters; Calculate the sample density of each cluster and determine the sampling quantity of each cluster based on the sample density; According to the sampling quantity, samples are randomly drawn from each cluster in a round-robin manner, and the drawn samples are combined to form the seed sample set.

[0025] In an optional implementation, the seed sample selection strategy in step S100 can also calculate the sample density or number proportion of each cluster, and determine and extract the corresponding number of seed samples based on the proportion.

[0026] In an optional implementation, the seed sample selection strategy in step S100 can also use the model to be tested to predict the original test sample set, calculate the prediction uncertainty of each sample, and directly select the sample with the highest uncertainty to form the seed sample set.

[0027] In this embodiment of the application, the specific execution logic of extracting seed samples from each cluster in step S100 by polling is as follows: according to the preset extraction quantity, the same number of samples are extracted from each cluster as seed samples in turn, and all clusters are traversed in a loop until the total number of extracted samples reaches the preset total number of seed samples, thus forming a seed sample set.

[0028] In addition, the process of constructing the seed sample set also includes a pre-screening step for individual discrimination samples: traversing all combinations of the values ​​of the protective attributes of the seed sample to generate a set of similar samples corresponding to the seed sample, wherein the similar samples are samples that have all the same non-protective attribute values ​​as the seed sample and at least one protective attribute value is different; if the current seed sample has the aforementioned similar samples and the similar samples are different from the predicted output of the model to be tested by the current seed sample, then the current seed sample is directly determined as an individual discrimination sample and added to the individual discrimination sample set, without needing to enter the subsequent iterative search process.

[0029] In this embodiment of the application, step S200, which calculates the Gini value gradient of the model to be tested and guides the update of the attribute values ​​of the seed sample based on the Gini value gradient, includes: Construct a fairness loss function based on the Gini index, calculate the gradient of the predicted output of the model under test for samples in the seed sample set with respect to the attribute values ​​of the seed samples, and obtain the Gini value gradient; The selection probability corresponding to each attribute is calculated based on the Gini value gradient, and the target update attribute is determined from the attributes of the seed sample according to the selection probability. The attribute value update direction is determined based on the gradient sign corresponding to the target update attribute, and the attribute value of the target update attribute is updated according to the attribute value update direction.

[0030] In an alternative implementation, the guiding function for the global search in step S200 may also construct a loss function based on other fairness metrics (such as statistical parity difference or chance equality difference) and calculate the gradient of the metric with respect to the sample attributes to guide the global search.

[0031] In an alternative implementation, the guiding function of the global search in step S200 can also be constructed as an adversarial loss function aimed at maximizing the difference between the current sample and its similar samples in the model output, and the attribute value update of the seed sample can be guided by gradient ascent.

[0032] Specifically, when updating the attribute values ​​of seed samples based on the Gini value gradient, the gradient of the Gini value output by the model under test with respect to each non-protected attribute of the current seed sample is first calculated. Then, from all the non-protected attributes of the current seed sample, non-protected attributes whose current values ​​do not exceed a preset value range and can continue to be updated are selected to form a first list of updatable non-protected attributes. For each attribute in the first list of updatable non-protected attributes, normalization is performed according to its corresponding absolute gradient value to obtain the first attribute selection probability of that attribute. The larger the absolute gradient value, the higher the first attribute selection probability. A first target attribute is extracted from the first list of updatable non-protected attributes according to the first attribute selection probability. The update direction is determined according to the gradient sign of the first target attribute, and the attribute value of the first target attribute is updated according to a preset update step size to generate a new sample for the next iteration.

[0033] In this embodiment of the application, step S300, which uses a multi-armed slot machine algorithm to dynamically select a path search strategy between a gradient search strategy and a historical experience strategy, includes: Obtain the state parameters during the current iteration process and determine whether the state parameters exceed the preset strategy switching threshold; In response to the fact that the policy switching threshold has not been exceeded, an operation to update gradient information is performed to establish the current gradient search policy; In response to exceeding the policy switching threshold, the historical selection value is calculated to establish the current historical experience policy; The established gradient search strategy and the historical experience strategy are respectively mapped to the two arms of the multi-armed slot machine algorithm; Calculate the cumulative reward value for each arm within a preset time window. The cumulative reward value is obtained by weighted summation based on the success rate and diversity contribution of generating the new individual discrimination sample. The selection priority of each arm is calculated based on the confidence upper bound algorithm, and the arm with the highest selection priority is selected as the path search strategy for the current iteration.

[0034] In an optional implementation, the strategy selection algorithm in the local generation in step S300 may also employ algorithms such as Thompson sampling or confidence upper bound (UCB) to dynamically calculate the selection probability based on the historical rewards of each strategy in order to select the path search strategy.

[0035] In an alternative implementation, the policy selection algorithm in the local generation in step S300 can also train a lightweight reinforcement learning agent to adaptively output and select the optimal path search policy based on the current sample attributes and historical search states.

[0036] In this embodiment of the application, the specific implementation of the path search strategy selection using the multi-armed slot machine algorithm in step S300 is as follows: Generate a random number; If the random number is less than the preset strategy selection threshold, then the gradient search strategy is selected as the path search strategy for the current iteration. If the random number is greater than or equal to the strategy selection threshold, then the historical experience strategy is selected as the path search strategy for the current iteration.

[0037] In this embodiment of the application, step S300, which updates the attribute values ​​of the initial discriminatory sample according to the selected strategy, includes: In response to the path search strategy being the gradient search strategy, the gradient of the Gini value output by the model under test with respect to each unprotected attribute of the current initial sample is calculated to obtain the second list of updatable unprotected attributes corresponding to the current initial sample; for each attribute in the second list of updatable unprotected attributes, inverse normalization is performed according to its corresponding absolute gradient value to obtain the second attribute selection probability of that attribute; wherein, the larger the absolute gradient value, the lower the second attribute selection probability; a second target attribute is extracted from the second list of updatable unprotected attributes according to the second attribute selection probability, the update direction is determined according to the gradient sign of the second target attribute, and the attribute value of the second target attribute is updated; In response to the path search strategy being the historical experience strategy, a second list of updatable unprotected attributes corresponding to the current initial sample is obtained. For each unprotected attribute in the second list of updatable unprotected attributes, the total number of times it has been selected in all completed iterations, and the number of times it has been successfully selected and the resulting new sample has been identified as an individual discrimination sample, are recorded. The historical success rate of the attribute is obtained based on the ratio of the number of successful selections to the total number of selections. For each attribute in the second list of updatable unprotected attributes, its historical success rate is normalized to obtain the third attribute selection probability. The higher the historical success rate, the higher the third attribute selection probability. A third target attribute is extracted from the second list of updatable unprotected attributes according to the third attribute selection probability. The update direction is determined based on the gradient sign of the third target attribute, and the attribute value of the third target attribute is updated.

[0038] After each attribute update, if the generated sample is determined to be a discriminatory sample, the success count and total count of the corresponding target attribute are increased; if it is not determined to be a discriminatory sample, only the total count of the corresponding target attribute is increased; and the historical success rate of the attribute is updated based on the ratio of the updated success count to the total count. Furthermore, after a single iteration of the initial sample, a reward value reset step is included: if the total count of the target attribute reaches a preset upper limit, or if the newly generated sample fails to be determined to be a discriminatory sample in a consecutive preset number of iterations, the reward value (i.e., the historical success rate) of the corresponding target attribute is reset to a preset initial value.

[0039] In an optional implementation, the attribute selection method in the historical experience strategy in step S300 can also use the exponentially weighted moving average (EWMA) algorithm to calculate the recent success rate of each attribute and dynamically update the selection probability of the attribute accordingly.

[0040] In an optional implementation, the attribute selection method in the historical experience strategy in step S300 can also adopt a context-based multi-armed slot machine algorithm, which dynamically calculates the selection probability of each attribute by combining the attribute value of the current sample with the historical reward.

[0041] In this embodiment of the application, step S300, which continues until a sample whose prediction output has changed is found and is recorded as the initial discrimination sample, includes: During the iteration process, similar samples corresponding to the current seed sample are constructed. The similar sample refers to a sample that has all the same non-protected attribute values ​​as the current seed sample and at least one protected attribute value is different. If the current seed sample differs from the predicted output of the model to be tested from the similar sample, then it is determined that a sample whose predicted output has changed has been found, and the current seed sample is recorded as the initial discrimination sample.

[0042] In this embodiment of the application, step S300 is as follows: Figure 2 As shown, after each modification of the protected attribute using gradient information, a consistency check is performed: the modified sample is input into the model under test, and its predicted output is compared with that before the modification. If they are consistent, it indicates that discrimination has not been triggered or the model is in a safe zone, and subsequent iterations continue or the sample is added to the locally generated sample list. If they are inconsistent, a set of discriminatory samples with model fairness defects has been identified. During the iteration process, intermediate samples that have undergone attribute modification but have not yet been confirmed as final discriminatory samples are added to the locally generated sample list as context or basis for subsequent multi-armed slot machine algorithm strategy selection.

[0043] In this embodiment of the application, step S400, based on the individual discrimination sample set composed of all the new individual discrimination samples generated iteratively, performs a fairness test on the model to be tested, including: The total number of samples in the individual discrimination sample set and the number of samples that caused the model under test to produce discriminatory prediction results are counted. Calculate the individual discrimination coverage rate index based on the total number of samples and the sample size; The individual discrimination coverage rate index is compared with a preset fairness threshold. If the individual discrimination coverage rate index exceeds the preset fairness threshold, the model under test is determined to have failed the fairness test.

[0044] Example 3, referring to Tables 1-2, is an embodiment of the present invention. This embodiment provides a method and system for assisting deep brain stimulation surgery and treatment based on digital twin technology. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through specific implementation methods and implementation effects.

[0045] The specific details of this embodiment are as follows: I. Experimental Environment The hardware and software environment configuration for this experiment is as follows: The experiment was conducted on a computer with the following specifications: AMD Ryzen 9-5900HX, CPU 3.30GHz, 32GB RAM, GeForce RTX 3080 GPU, and Windows 11 64-bit operating system.

[0046] The dataset used in the experiment is the BankMarketing dataset, which records marketing activities of Portuguese banking institutions. The goal of this dataset is to predict whether customers will subscribe to the bank's term deposits. It contains 45,211 samples, of which customers who subscribe to term deposits represent 11.5% of the total sample. The dataset includes 17 categories of personal information, such as age, employment, marital status, whether they have a mortgage, and whether they have personal loans. It also includes one protected attribute: age.

[0047] The experiment used a deep neural network to build the target model on the dataset. The target model achieved an accuracy of 89.14% on the Bank Marketing test set. The specific network structure of the model is shown in Table 1.

[0048] Table 1. Structure of the deep neural network model used in this method

[0049] II. Experimental Procedure Step 1: Input the original test sample set into the model to be tested. Cluster the original test sample set to obtain multiple clusters. Seed samples are then extracted from each cluster in a round-robin manner to form a seed sample set. Specifically, the input Bank Marketing test set is clustered using the K-Means clustering algorithm, with four clusters. Following a preset extraction quantity, the same number of samples are extracted from each cluster as seed samples, and this process is repeated across all clusters until the total number of extracted samples reaches the preset total number of seed samples. In this embodiment, 250 seed samples are extracted from each cluster, totaling 1000 seed samples, as input samples for the global gradient search to ensure seed sample diversity.

[0050] Step 2: Generate individual discrimination samples using global gradient search. Perform an iterative search on each seed sample in the seed sample set, setting the maximum number of iterations to 100 and the update step size to 1. Traverse all combinations of protective attribute values ​​for the seed samples, generating a set of similar samples that have all the same non-protective attribute values ​​as the current seed sample but differ in at least one protective attribute (i.e., age). If a similar sample differs from the predicted output of the model under test from the current seed sample, the current seed sample is determined to be an individual discrimination sample, added to the individual discrimination sample set, and the current iteration terminates. If no bias is detected, calculate the gradient of the Gini value output by the model under test with respect to each non-protective attribute of the current seed sample. Based on the preset value range of each non-protective attribute, select non-protective attributes whose current values ​​do not exceed the preset value range and can be continuously updated, forming a first list of updatable non-protective attributes. For each non-protective attribute in the list, normalize it according to its corresponding absolute gradient value to obtain the first attribute selection probability of that non-protective attribute (the larger the absolute gradient value, the higher the first attribute selection probability). Based on the probability of the first attribute selection, a non-protected attribute is chosen as the first target attribute according to the probability. The update direction is determined according to its gradient sign. The attribute value of the target attribute is updated according to the preset update step size, and a new sample is generated to enter the next iteration. When all seed samples have completed the iteration or the maximum number of iterations has been reached, the global search stops. After deduplication of the generated individual discrimination sample set, it is output to the local generation module.

[0051] Step 3: The local generation module uses a multi-strategy path search to generate new samples. Individual discrimination samples from the individual discrimination sample set are used as initial samples, and the initial values ​​of each initial sample are recorded. The successful update count and total update count for each non-protected attribute are initialized, and a strategy selection threshold of 0.5 is set to balance gradient search and historical experience strategies. In each iteration, the second list of updatable non-protected attributes and their updatable directions for the current initial sample are obtained. A multi-armed slot machine algorithm is used to select the path search strategy for the current iteration by comparing a generated random number with the threshold of 0.5: if the random number is less than 0.5, a gradient search strategy is used, calculating the gradient of the Gini value output by the model under test with respect to each non-protected attribute of the current initial sample, and calculating the second attribute selection probability in reverse based on the absolute value of the gradient corresponding to each non-protected attribute in the second list of updatable non-protected attributes (the larger the absolute value of the gradient, the lower the second attribute selection probability); if the random number is greater than or equal to 0.5, a historical experience strategy is used, calculating the third attribute selection probability based on the historical success rate of each non-protected attribute in the second list of updatable non-protected attributes (the higher the historical success rate, the higher the third attribute selection probability). Based on the path search strategy selected in the current iteration, a target attribute is chosen probabilistically, and the update direction is determined according to the gradient sign of the selected target attribute before updating the attribute value. If the updated sample is identified as a discriminatory sample, the sample is retained and added to the discriminatory sample set, and the success count, total count, and reward value of the corresponding target attribute are updated. If the updated sample is not identified as a discriminatory sample, the total count and reward value of the corresponding target attribute are updated, and the current sample is reset to its initial value. When the corresponding target attribute meets the reward value reset condition, its reward value is reset to the preset initial value. After all iterations are completed, the generated discriminatory sample set is deduplicated and output, and the final discriminatory sample set is used as the fairness defect sample set of the model to be tested.

[0052] Step 4, Fairness Testing. The final individual discrimination sample set is used as the fairness defect sample set of the model under test. The model under test is then subjected to fairness testing to obtain the corresponding fairness test results.

[0053] III. Experimental Results This experiment compared the method of the present invention with the comparative methods ADF (a method for searching for individual discrimination samples in the sample space using adversarial sample generation) and EIDIG (a method that introduces a momentum term and uses the sample output value as the guiding function for gradient search). The test results are shown in Table 2.

[0054] Table 2 Comparative experimental results of the present invention, ADF method, and EIDIG method

[0055] Analysis of the test results shows that, based on the fairness testing method of the data trading model for enhancing the diversity of individual discrimination samples, after performing 100 fuzzy mutations on 1000 samples, the number of test samples generated increased by 155.55% and 44.72% compared to the ADF and EIDIG methods, respectively; the total fuzzy mutation time was shortened by 45.27% and 32.54% compared to the ADF and EIDIG methods, respectively; and the number of sample types generated increased by 111.01% and 25.68% compared to the ADF and EIDIG methods, respectively. The experimental results fully verify that the method of this invention is significantly superior to existing comparative methods in terms of the number, efficiency, and sample diversity of individual discrimination samples generated.

[0056] Example 4 is an embodiment of the present invention. This embodiment differs from the first embodiment in that it provides a data transaction model fairness testing system.

[0057] It should be noted that the technical solution of the data transaction model fairness testing system and the technical solution of the data transaction model fairness testing method described above belong to the same concept. For details not described in detail in the technical solution of the data transaction model fairness testing system in this embodiment, please refer to the description of the technical solution of the data transaction model fairness testing method described above.

[0058] This embodiment provides a data transaction model fairness testing system, comprising: The clustering and seed selection module is used to obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. The global search module is used to perform a global iterative search on the seed sample set, calculate the Gini value gradient of the output of the model to be tested, and guide the attribute value update of the seed samples according to the Gini value gradient until a sample whose prediction output has changed is found, and the sample is recorded as the initial discrimination sample. The local generation module is used to perform local iterative generation starting from the initial discrimination sample. In each iteration, the multi-armed slot machine algorithm is used to dynamically select the path search strategy between the gradient search strategy and the historical experience strategy, and the attribute values ​​of the initial discrimination sample are updated according to the selected strategy to generate new individual discrimination samples. The fairness testing module is used to perform fairness testing on the model under test based on the individual discrimination sample set consisting of all new individual discrimination samples generated iteratively, and obtain the fairness test results.

[0059] This embodiment also provides a computer device applicable to a data transaction model fairness testing method, including: The system includes a memory and a processor. The memory stores computer-executable instructions, and the processor executes these instructions to implement a data transaction model fairness testing method as proposed in the above embodiments.

[0060] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, it implements a data transaction model fairness testing method as proposed in the above embodiments.

[0061] The storage medium proposed in this embodiment and the method for implementing a fairness test of a data transaction model proposed in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0062] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.

[0063] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for testing the fairness of a data transaction model, characterized in that, include: Obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. A global iterative search is performed on the seed sample set to calculate the Gini value gradient of the model to be tested, and the attribute values ​​of the seed samples are updated according to the Gini value gradient until a sample whose prediction output has changed is found, and the sample is recorded as the initial discrimination sample. The initial discrimination sample is used as the starting point to perform local iterative generation. In each iteration, the multi-armed slot machine algorithm is used to dynamically select the path search strategy between the gradient search strategy and the historical experience strategy, and the attribute values ​​of the initial discrimination sample are updated according to the selected strategy to generate new individual discrimination samples. Based on the individual discrimination sample set consisting of all the new individual discrimination samples generated iteratively, a fairness test is performed on the model to be tested, and the fairness test results are obtained.

2. The data transaction model fairness testing method as described in claim 1, characterized in that: The process of clustering the original test sample set and extracting seed samples from each cluster in a round-robin manner to form a seed sample set includes: The original test sample set is clustered using a clustering algorithm based on the protected and unprotected attributes to obtain multiple clusters; Calculate the sample density of each cluster and determine the sampling quantity of each cluster based on the sample density; According to the sampling quantity, samples are randomly drawn from each cluster in a round-robin manner, and the drawn samples are combined to form the seed sample set.

3. The data transaction model fairness testing method as described in claim 1 or 2, characterized in that: The calculation of the Gini value gradient of the model under test, and the subsequent updating of the attribute values ​​of the seed samples based on the Gini value gradient, includes: Construct a fairness loss function based on the Gini index, calculate the gradient of the predicted output of the model under test for samples in the seed sample set with respect to the attribute values ​​of the seed samples, and obtain the Gini value gradient; The selection probability corresponding to each attribute is calculated based on the Gini value gradient, and the target update attribute is determined from the attributes of the seed sample according to the selection probability. The attribute value update direction is determined based on the gradient sign corresponding to the target update attribute, and the attribute value of the target update attribute is updated according to the attribute value update direction.

4. The data transaction model fairness testing method as described in claim 3, characterized in that: The method of dynamically selecting a path search strategy between gradient search strategy and historical experience strategy using the multi-armed slot machine algorithm includes: Generate a random number; In response to the random number being less than a preset strategy selection threshold, a gradient search strategy is selected as the path search strategy for the current iteration. In response to the random number being greater than or equal to the strategy selection threshold, a historical experience strategy is selected as the path search strategy for the current iteration.

5. The data transaction model fairness testing method as described in claim 4, characterized in that: The step of updating the attribute values ​​of the initial discriminatory sample according to the selected strategy includes: In response to the path search strategy being the gradient search strategy, the gradient of the Gini value output by the model under test with respect to each non-protected attribute of the current initial sample is calculated. The absolute value of the gradient of each non-protected attribute is back-normalized to obtain the selection probability corresponding to each attribute. The target attribute is then selected and updated according to the selection probability. In response to the path search strategy being the historical experience strategy, the historical success rate of each non-protected attribute in historical iterations is obtained, and the target attribute is selected for updating according to the historical success rate. The historical success rate is calculated as the ratio of the total number of times the attribute was selected in the historical iterations to the number of times it was successfully used to classify the updated sample as an individual discrimination sample. After each attribute update, in response to the generated sample being judged as an individual discrimination sample, the success count and total count of the corresponding target attribute are increased; For samples that are not identified as individual discrimination samples, only the total number of times the corresponding target attribute is increased; The historical success rate of the attribute is updated based on the ratio of the updated number of successes to the total number of successes.

6. The data transaction model fairness testing method as described in claim 5, characterized in that: The process of searching until a sample whose prediction output changes, and recording that sample as the initial discrimination sample, includes: During the iteration process, similar samples corresponding to the current seed sample are constructed. The similar sample refers to a sample that has all the same non-protected attribute values ​​as the current seed sample and at least one protected attribute value is different. In response to the difference between the current seed sample and the predicted output of the similar sample by the model to be tested, it is determined that a sample whose predicted output has changed has been found, and the current seed sample is recorded as the initial discrimination sample.

7. The data transaction model fairness testing method as described in claim 6, characterized in that: The individual discrimination sample set, composed of all new individual discrimination samples generated iteratively, is used to conduct fairness tests on the model to be tested, including: The total number of samples in the individual discrimination sample set and the number of samples that caused the model under test to produce discriminatory prediction results are counted. Calculate the individual discrimination coverage rate index based on the total number of samples and the sample size; The individual discrimination coverage rate index is compared with a preset fairness threshold. If the individual discrimination coverage rate index exceeds the preset fairness threshold, the model under test is determined to have failed the fairness test.

8. A data transaction model fairness testing system, using the method described in any one of claims 1-7, characterized in that, include: The clustering and seed selection module is used to obtain the original test sample set of the data transaction model to be tested, perform clustering processing on the original test sample set, and extract seed samples from each cluster in a round-robin manner to form a seed sample set. The global search module is used to perform a global iterative search on the seed sample set, calculate the Gini value gradient of the output of the model to be tested, and guide the attribute value update of the seed samples according to the Gini value gradient until a sample whose prediction output has changed is found, and the sample is recorded as the initial discrimination sample. The local generation module is used to perform local iterative generation starting from the initial discrimination sample. In each iteration, the multi-armed slot machine algorithm is used to dynamically select the path search strategy between the gradient search strategy and the historical experience strategy, and the attribute values ​​of the initial discrimination sample are updated according to the selected strategy to generate new individual discrimination samples. The fairness testing module is used to perform fairness testing on the model under test based on the individual discrimination sample set consisting of all new individual discrimination samples generated iteratively, and obtain the fairness test results.

9. A computer device, characterized in that, include: Memory, used to store programs; A processor for loading the program to perform the steps of the method as claimed in any one of claims 1-7.

10. A computer-readable storage medium storing a program, characterized in that, When the program is executed by a processor, it implements the steps of the method as described in any one of claims 1-7.