Anti-fact sample interpretation method, system and device and storage medium

By constructing counterfactual samples and explaining the decision-making process of the machine learning model, the problem of insufficient model interpretability in the existing technology is solved, and the causal understanding and interpretability enhancement of the criminal recidivism risk prediction model are achieved.

CN118657224APending Publication Date: 2024-09-17HUNAN NORMAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410848031.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-27
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

The lack of interpretability of existing machine learning models, especially in areas where understanding the model's decision-making process is required, has led to questions about model reliability and understandability.

Method used

By constructing counterfactual samples and using the characteristics of the perturbed original samples to generate counterfactual samples that comply with causal constraints, and then explain the decision-making process of the prediction model, specific methods include setting counterfactual optimization features, generating biased initial populations, optimizing loss functions, and iterating Counterfactual samples are generated, and the final counterfactual samples are screened to demonstrate causal relationships.

Benefits of technology

The interpretability of the model is enhanced, allowing users to understand the causal relationship between input features and output results, thereby reducing the risk of recidivism.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657224A
    Figure CN118657224A
Patent Text Reader

Abstract

The invention belongs to the field of artificial intelligence, and particularly relates to an anti-fact sample interpretation method, system and device and a storage medium, and the method comprises the steps: obtaining an original sample and an output result of the original sample, and setting anti-fact optimization features; generating a biased initial population according to the original sample and a preset algorithm; based on the feature constraint condition and the anti-fact optimization feature, optimizing the initial function of the prediction model to obtain an anti-fact optimization loss function; performing evolutionary iteration on the biased initial population based on the original sample, the anti-fact optimization loss function and the prediction model to obtain an anti-fact sample conforming to causal constraints, and performing screening to obtain a final anti-fact sample; and comparing the final anti-fact sample with an original sample to obtain a causal relationship between the input characteristics of the prediction model and an output result. The method has the effect of explaining the causal relationship between the input features and the output results of the prediction model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence, and specifically relates to a counterfactual sample interpretation method, system, device and storage medium. Background Art

[0002] In recent years, with the rapid development of artificial intelligence technology, machine learning (ML) has been widely used in many fields and has achieved excellent results, such as bankruptcy prediction, fault diagnosis, and medical diagnosis. Some studies have pointed out that due to the "black box" characteristics of most ML models, humans cannot understand the decision-making process inside the model. Therefore, in some fields that require interpretability, the reliability and understandability of ML have gradually been questioned. In order to enhance the interpretability of ML models, research on interpretable ML has gradually gained attention.

[0003] In the related technologies, the research on the interpretability of black boxes mainly includes Kentaro et al., who combined the Mahalanobis distance and the local outlier factor from the perspective of data rationality and proposed a new objective optimization function, trying to determine whether the generated counterfactual samples conform to the original data distribution to further generate explanations that conform to the distribution of the data set. Peyman et al. proposed an explanation framework called CARE from the perspective of recourse, which makes the generated explanations more sound and operational by considering various data attributes and user requirements. Mothilal et al. introduced the deterministic point process (DPP) to measure diversity and proposed a counterfactual explanation method that can generate a variety of different counterfactual samples to solve the problem that traditional methods only generate one counterfactual sample. Or it is a counterfactual explanation method based on feature weighting, which effectively applies the feature weights estimated by the SHAP method to the search process of counterfactual samples. Grath et al. proposed that feature importance can be estimated using variance analysis or K nearest neighbor algorithm.

[0004] For the above-mentioned related technologies, most studies focus on optimizing the original loss function or introducing various constraints to improve the loss function. Such methods usually involve weighted combination of different optimization objectives in the loss function to form a single comprehensive optimization objective, in the hope of optimizing the quality of counterfactual samples from multiple different perspectives. However, researchers cannot reasonably determine the weight of each optimization objective in the loss function and can only set the weight based on past experience, resulting in inaccurate interpretability of the model. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a counterfactual sample interpretation method, system, device and storage medium, which can reasonably explain the decision-making process of the prediction model.

[0006] A counterfactual sample explanation method, comprising:

[0007] Obtaining an original sample and an output result after the original sample is input into a prediction model, wherein the input features of the prediction model are the features of the original sample;

[0008] Setting a counterfactual optimization feature, wherein the counterfactual optimization feature is a feature of the disturbed original sample;

[0009] Generate a biased initial population according to the original sample and a preset algorithm;

[0010] Set feature constraints;

[0011] Based on the feature constraint and the counterfactual optimization feature, optimizing the initial function of the prediction model to obtain the counterfactual optimization loss function;

[0012] Based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function and the prediction model, the biased initial population is evolved iteratively to obtain a counterfactual sample that meets the causal constraint;

[0013] Screening out the counterfactual sample that is closest to the original sample and meets the causal constraint to obtain a final counterfactual sample;

[0014] The final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and the output results of the prediction model.

[0015] The prediction model is used to develop and evaluate the recidivism risk prediction model. The original samples are cases of recidivism of criminals who have committed crimes. The cases include the characteristics of the original samples such as gender, race, age, number of crimes, and degree of crime. The preset algorithm is the KD-Tree algorithm.

[0016] The counterfactual sample explanation method is to construct a counterfactual sample that is related to the original sample but has some different features, so as to obtain the causal relationship between the input features and output results of the prediction model, thereby explaining why the prediction model made the decision and enhancing the interpretability of the model.

[0017] Specifically, the output result is the probability of a criminal who committed a crime in the past committing a crime again. The causal relationship between the input features and the output results of the crime recidivism risk prediction model is that when one of the input features is changed, it is known how the output result changes.

[0018] By constructing counterfactual samples, we can understand the causal relationship between the input features and output results of the crime recidivism risk prediction model, thereby providing explainability for the output results of the crime recidivism risk prediction model. According to this causal relationship, we can reduce the probability of recidivism by interfering with the corresponding input features.

[0019] Specifically, a counterfactual sample explanation method includes:

[0020] Obtaining an original sample of patients who have committed crimes again and the output result after the original sample is input into a development and evaluation model for predicting the risk of criminal recidivism, wherein the input features of the development and evaluation model for predicting the risk of criminal recidivism are the features of the original sample, and the features of the original sample include the number of past crimes, gender, race, age stage and degree of crime;

[0021] Setting a counterfactual optimization feature, wherein the counterfactual optimization feature is a feature of one or more original samples of the disturbance, wherein the features of the original samples include the number of past crimes, gender, race, age stage, and degree of crime;

[0022] Generate a biased initial population according to the original sample and the counterfactual optimization target;

[0023] Setting feature constraints, wherein the feature constraints include a first constraint and a second constraint, wherein the first constraint includes that gender and race cannot be changed and age cannot be reduced, and the second constraint includes a prediction output loss term, proximity, sparsity, and rationality of data distribution;

[0024] Based on the feature constraint and the counterfactual optimization feature, an initial function for developing and evaluating a crime recidivism risk prediction model is optimized to obtain the counterfactual optimization loss function;

[0025] Based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function and the prediction model, the biased initial population is evolved iteratively to obtain a counterfactual sample that meets the causal constraint;

[0026] Screening out the counterfactual sample that is closest to the original sample to obtain a final counterfactual sample;

[0027] The final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and output results of the crime recidivism risk prediction model.

[0028] Optionally, generating a biased initial population according to the original sample and a preset algorithm includes:

[0029] The original samples are input into a preset algorithm to obtain samples that are close to the original samples in latent space but have opposite prediction results as biased initial populations, and the preset algorithm is a KD-Tree algorithm.

[0030] Optionally, the setting of feature constraint conditions includes:

[0031] Analyzing the variability and invariability of various characteristics of the original sample;

[0032] Taking the mutability and immutability as the first constraint condition;

[0033] Obtaining a second constraint condition of the initial function;

[0034] The first constraint condition and the second constraint condition are set as feature constraints.

[0035] Optionally, the second constraint condition includes prediction output loss term, proximity, sparsity and data distribution rationality

[0036] The initial function of the prediction model is optimized based on the feature constraint condition and the counterfactual optimization feature to obtain the counterfactual optimization loss function, which includes:

[0037] The initial function is:

[0038]

[0039] in, represents the counterfactual sample, x i represents the original sample, λ is the empirical weight under multiple iterative experiments, represents the expected prediction result, d(.,.) is a distance function used to measure the original sample x i With the counterfactual sample x * The distance between is the output result of the counterfactual sample;

[0040] The optimized counterfactual optimization loss function is:

[0041]

[0042] Among them, hinge_yloss(.) is the prediction output loss term, dist(.) is the proximity, II(.) is the sparsity, RIM(.) is the relative influence index, lof(.) is the rationality of data distribution, and x represents the parameter to be optimized.

[0043] Optionally, the step of screening out the counterfactual sample closest to the original sample to obtain the final counterfactual sample includes:

[0044] The similarity between the original sample and the counterfactual sample is calculated, and the counterfactual sample with the highest similarity is selected as the final counterfactual sample.

[0045] Before comparing the final counterfactual sample with the original sample to obtain the causal relationship between the input feature and the output result of the prediction model, the method includes:

[0046] Determining whether the counterfactual sample conforms to the data distribution of the original sample;

[0047] If the counterfactual sample conforms to the data distribution of the original sample, then the final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and the output results of the prediction model;

[0048] If the counterfactual sample does not conform to the data distribution of the original sample, the counterfactual sample is regenerated

[0049] A counterfactual sample explanation system, comprising:

[0050] An acquisition module is used to acquire original samples of reoffending patients who have committed crimes and output results after the original samples are input into a development and evaluation model for predicting the risk of criminal reoffending, wherein the input features of the development and evaluation model for predicting the risk of criminal reoffending are features of the original samples, and the features of the original samples include the number of past crimes, gender, race, age stage and degree of crime;

[0051] A first setting module is used to set a counterfactual optimization feature, where the counterfactual optimization feature is a feature of one or more original samples of the disturbance, where the features of the original samples include the number of past crimes, gender, race, age stage, and degree of crime;

[0052] A first generation module, configured to generate a biased initial population according to the original sample and the counterfactual optimization target;

[0053] The second setting module is used to set feature constraint conditions;

[0054] An optimization module, configured to optimize an initial function for developing and evaluating a crime recidivism risk prediction model based on the feature constraint and the counterfactual optimization feature, to obtain the counterfactual optimization loss function;

[0055] A second generation module is used to iterate the evolution of the biased initial population based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function and the prediction model to obtain a counterfactual sample that meets the causal constraint;

[0056] A screening module, used to screen out the counterfactual sample that is closest to the original sample to obtain a final counterfactual sample;

[0057] The explanation module is used to compare the final counterfactual sample with the original sample to obtain the causal relationship between the input features and output results of the crime recidivism risk prediction model.

[0058] A terminal device includes a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor loads and executes the computer program, a counterfactual sample interpretation method is adopted.

[0059] A computer-readable storage medium stores a computer program, which, when loaded and executed by a processor, adopts a counterfactual sample interpretation method.

[0060] The beneficial effects of the present invention are as follows: in the process of generating counterfactual samples for the crime recidivism risk prediction model, causal relationships are used as constraints to ensure that the generated counterfactual samples meet the preset causal constraints, and the prediction results obtained by inputting the counterfactual samples into the crime recidivism risk prediction model are compared with the prediction results of the original samples to enhance the user's understanding of the causal relationship between the input features and output results of the crime recidivism risk prediction model, enhance the interpretability of the model, and by utilizing the causal relationship, the probability of criminals committing crimes again in the future can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 This is a system flow chart of a counterfactual sample interpretation method of the present invention. DETAILED DESCRIPTION

[0062] A counterfactual sample explanation method, such as Figure 1 As shown, the present invention includes:

[0063] S100, obtaining the original samples of the crime recidivism risk prediction model and the output results obtained by inputting the original samples into the crime recidivism risk prediction model.

[0064] S110, setting a counterfactual optimization feature, where the counterfactual optimization feature is a feature of one or more original samples that are disturbed, and the disturbance is to change one or more features of the original sample, and the remaining features remain unchanged.

[0065] Specifically, a prediction model refers to a mathematical model that uses historical data, relationships between variables, statistical methods, machine learning algorithms and other technologies to predict future events, trends or results. Through the prediction model and the original sample, the prediction model will output the prediction results.

[0066] In this embodiment, a prediction model is used to develop and evaluate the risk of criminal recidivism. The features used in the model are the number of past crimes (priors_count), gender (sex), race (race), age (age_cat) and degree of crime (c_charge_degree, where M represents a minor crime and F represents a serious crime). The original sample is a fact sample including the above features. The fact sample can be a real case, and the output result is the probability of the criminal committing a crime again in the future. The number of features in the original sample is greater than or equal to the number of counterfactual optimization features.

[0067] The prediction model can be a criminal recidivism risk prediction model or a diabetic patient diagnosis prediction model. The development and evaluation of the criminal recidivism risk prediction model is a model for predicting the recidivism of criminals who have committed crimes. The model includes five input features: the number of crimes, gender, race, age stage and degree of crime; the diabetic patient diagnosis prediction model predicts whether the patient has diabetes through the specific diagnostic measurement of the data set, and its input feature is the treatment method used to treat diabetic prisoners. The counterfactual optimization feature is obtained by perturbing the original sample. Perturbation refers to changing one or more features of the original sample, and the remaining features remain unchanged to obtain the counterfactual optimization feature. The original sample for the development and evaluation of the criminal recidivism risk prediction model is: gender is male, race is a certain race, age stage is young adult, past crime is serious, and the number of crimes is high. Then a counterfactual sample can be to change the gender in the case to female, race to non-certain race, age to middle-aged, past crime is light, and the number of crimes is high.

[0068] The prediction result is the result output by the prediction model. For example, when developing and evaluating the crime recidivism risk prediction model as a prediction model, the prediction result is the crime rate of people who have committed crimes in the future. When the prediction model is a diabetes patient diagnosis prediction model, the prediction result is to predict whether the patient has diabetes through a specific diagnosis, and its counterfactual sample is what treatment makes the patient change from diabetes to non-diabetes. Different prediction models have different prediction results. The prediction results vary according to different prediction models.

[0069] S120: Generate a biased initial population based on the original sample and a preset algorithm.

[0070] Specifically, the biased initial population is samples that are close to the original samples in the latent space but have opposite prediction results.

[0071] The counterfactual optimization feature is the prediction result of one or more target features that the user wants to obtain according to the user's needs. For example, if the user wants to know the crime situation when the gender is male, then all the original samples of males who have committed crimes are filtered out.

[0072] The biased initial population is a sample generated by a preset algorithm that is close to the original sample latent space but has the opposite prediction result. The preset algorithm is the KD-Tree algorithm.

[0073] S130. Set feature constraint conditions.

[0074] S140. Based on the feature constraint condition and the feature constraint condition counterfactual optimization feature, the initial function of the prediction model is optimized to obtain the feature constraint condition counterfactual optimization loss function.

[0075] Specifically, the feature constraint condition is that when changing certain features of the original sample, the changed features cannot violate the objective laws of the real world and the constraints when evaluating the model performance. Not every feature should be changed during the optimization process. Only counterfactual samples that comply with the realistic causal constraints are operational. Therefore, it is necessary to analyze the features of each data set and the feature constraints that these features should follow and convert them into equality or inequality constraints. For example, gender and race are generally immutable. The counterfactual optimization loss function comprehensively considers multiple constraints that affect the quality of counterfactual results and uses them as part of multi-objective optimization, effectively avoiding the problem of not fully considering the weights of various constraints and the possible conflicts between them. The counterfactual optimization loss function is equivalent to the optimization problem of the minimum and maximum values. The counterfactual optimization loss function includes multiple constraints, including prediction output loss, proximity, sparsity, rationality of data distribution, and whether the features can change the imposed causal constraints. It is worth noting that in order to ensure that the generated counterfactual samples follow the causal relationship (objective facts), we use causal constraints as one of the constraints for multi-objective optimization.

[0076] The initial function is a function for single-objective optimization, and multiple optimization objectives are directly superimposed into a comprehensive single optimization objective for optimization.

[0077] S150, based on the original samples, counterfactual optimization features, counterfactual optimization loss function and prediction model, the biased initial population is evolved and iterated to obtain counterfactual samples that meet the causal constraints.

[0078] Specifically, after the biased initial population, counterfactual optimization features, and causal constraints are set, a series of counterfactual samples that meet the causal constraints are generated through evolutionary iterations (selection, crossover, mutation), and finally the counterfactual samples whose predicted results are changed and are closest to the original samples are further screened out as the final results.

[0079] Specifically, since changing the prediction result is the result of changing one or more input features in the prediction model, by changing the prediction result and comparing it with the prediction result, the change of the corresponding feature to the prediction model can be obtained. For example, if the age increases and the crime rate decreases, we can know how the crime rate changes when the age changes in the prediction model, which enhances the interpretability of the prediction model.

[0080] S160. Filter out the counterfactual sample that is closest to the original sample to obtain the final counterfactual sample.

[0081] Specifically, since there may be more than one counterfactual sample generated, the similarity between the original sample and the counterfactual sample is calculated, and the counterfactual sample with the highest similarity is selected as the final counterfactual sample with feature constraints. The similarity can be calculated using Euclidean distance or cosine similarity.

[0082] S170. Compare the final counterfactual sample with the original sample to obtain the causal relationship between the input features and output results of the prediction model.

[0083] Specifically, the counterfactual samples are input into the prediction model to obtain the prediction results. By statistically analyzing the causal relationship between the counterfactual samples and the original samples, the changes in the corresponding features for the prediction model can be obtained. For example, if the age increases and the crime rate decreases, we can know how the crime rate changes when the age changes in the prediction model, which enhances the interpretability of the prediction model.

[0084] In one implementation of this embodiment, the step of generating a biased initial population according to the original sample and the preset algorithm includes:

[0085] S200, inputting the original sample into a preset algorithm, and obtaining samples that are close to the original sample in latent space but have opposite prediction results as a biased initial population.

[0086] Specifically, the biased initial population counterfactual interpretation is to generate a series of samples similar to the original samples but with opposite prediction results based on specific original samples, so as to provide modification suggestions for the original samples. In fact, excellent counterfactual samples should maintain a certain proximity with the original samples in the latent space to ensure their rationality. Based on the above reasons, the preset algorithm adopts the KD-Tree algorithm in this embodiment to generate a set of samples with adjacent latent space but opposite prediction results for each original sample as a biased initial population. This biased initialization helps to focus on the area close to the original sample, providing a more accurate set of counterfactual samples, so that the algorithm accelerates the convergence speed and enhances the stability of the algorithm.

[0087] In order to adapt the algorithm to different data types, this paper sets appropriate crossover and mutation operators for continuous features and categorical features. Specifically, for numerical features, the strategy of simulated binary crossover recombinator (SBX) and polynomial mutator (PM) is used for crossover and mutation operations. For categorical features, the uniform crossover recombinator (UX) and random selection mutator are used to deal with different types of feature data.

[0088] Specifically, samples of the same race and gender are selected from the original samples, and then the selected samples are feature recombined to obtain new samples as the biased initial population. Being close to the target feature usually refers to selecting samples from the original data set that are similar or close to the target feature in some key features. Feature recombining is to extract the features of each sample in the original sample and combine them with other samples. For example, a sample has ABC3 features. Feature A of the first sample, feature B of the second sample, and feature C of the third sample are combined to obtain a new sample. The combination is continued until the quantity requirement is met to obtain a biased initial population.

[0089] In one implementation of this embodiment, the step feature constraint condition setting feature constraint condition includes:

[0090] S300, analyzing the variability and invariability of each feature of the original sample of feature constraint conditions.

[0091] S310. Taking the variability and immutability of the feature constraint as the first constraint of the feature constraint.

[0092] S320, obtaining the second constraint of the initial function of the characteristic constraint.

[0093] S330: Set the first feature constraint condition and the second feature constraint condition as feature constraints.

[0094] Specifically, the variability and immutability of each feature of the original sample means that when some features are disturbed, due to the particularity of the features, the objective laws of real life cannot be violated when making changes. Therefore, some features cannot be changed or can be changed conditionally, for example, age cannot be reduced, and gender generally cannot be changed.

[0095] Specifically, the first constraint is expressed in the form of an equation or inequality in the form of a mathematical formula. For example, age can only increase in the real world, and the age characteristics of the counterfactual sample are Can only be greater than or equal to the age feature x of the original sample i , so the causal constraint on age can be set as an inequality:

[0096] In one implementation of this embodiment, the second constraint of the step feature constraint includes a prediction output loss term, proximity, sparsity, and data distribution rationality.

[0097] Specifically, realistic causal constraints are those that cannot be changed in real life, such as a person's gender, race, and age cannot be reduced. It is necessary to impose feature constraints on these features, so that they will not be changed or will be changed conditionally.

[0098] Specifically, the initial function is a function optimized for a single objective, and multiple optimization objectives are directly superimposed into a comprehensive single optimization objective for optimization. However, the research method of directly integrating multiple optimization objectives into a single optimization objective may conflict, and the weight of each objective item cannot be reasonably determined. Therefore, in order to avoid the above-mentioned problems, we convert it into a multi-objective optimization problem, and add four explicit constraints and one implicit constraint to balance various objectives and requirements from multiple different perspectives. Specifically, the four explicit constraints are the prediction output loss, proximity, sparsity, and rationality of data distribution (the second constraint), and the implicit constraint is a causal constraint (the first constraint). These constraints are jointly optimized as multiple optimization objectives or constraints of the multi-objective optimization algorithm.

[0099] Prediction output loss term: This constraint term reflects the difference between the predicted value of the counterfactual sample and the expected prediction. In previous studies, there are various choices for this constraint term. For example, L1-loss, L2-loss or cross entropy loss functions, etc. Although these loss functions can measure the quality of counterfactual samples well, they have low tolerance for correctly classified samples. Counterfactual interpretation requires that counterfactual samples are generated based on slight perturbations of the original samples. Therefore, it is only necessary for the predicted expectation of the counterfactual sample to exceed the conventional threshold (usually 0.5), and it is not necessarily required to reach the optimal expectation (0 or 1). Previous studies have also pointed out that optimizing the counterfactual prediction expectation to 0 or 1 may cause large changes to the counterfactual samples.

[0100] Compared with the loss functions mentioned above, the hinge loss function may be able to better measure the quality of counterfactual samples. The reason is that the hinge loss function allows a certain error between the predicted value and the expected value of the counterfactual sample. Loss will only occur when the error exceeds the tolerance threshold. When the error is less than the tolerance threshold, no loss will occur, that is, no penalty will be imposed on the correctly predicted counterfactual samples. Due to the existence of tolerance, the optimization algorithm can be more tolerant when facing marginal confidence samples, avoiding major changes in counterfactual samples caused by excessive pursuit of absolute accuracy. When the counterfactual explanation requires a small perturbation to the sample, the tolerance of the hinge loss function allows the model to make more flexible judgments on these samples when making decisions. Therefore, the hinge loss is used to measure the loss of the predicted output.

[0101] hinge_yloss=max(0,1–y*y * ).

[0102] Where y represents the correct class label (0 is represented as -1, 1 is represented as 1), and y* is the predicted output probability of the counterfactual sample.

[0103] Proximity refers to the property of keeping any original sample close to the counterfactual sample in the feature space by making a small perturbation to it, but the generated counterfactual sample prediction result is the same as the expectation or the reverse of the original sample prediction result. Generally speaking, the proximity of the counterfactual sample to the original sample is a measure of the similarity or distance between the original sample and the counterfactual sample. The proximity is quantified as the inverse weighted Euclidean distance:

[0104]

[0105] Among them, w j represents the inverse of the weight estimated by the AcME method, f i is the weight coefficient estimated by the AcME method, x ij Represents the original sample x i The jth feature of . Represents a counterfactual sample The jth feature of .

[0106] Since counterfactual explanations usually involve minimal optimization problems, when using weighted Euclidean distance to measure the distance between counterfactual samples and original samples, we perform inverse weighting on the feature weights. Specifically, we take the inverse of the weight coefficient of each feature, as shown in the above formula w i =1 / f i The purpose of this process is to ensure that the weights of each feature have the correct effect on the distance calculation in the optimization problem. After this step, the w of the important features iwill become smaller, while the w of unimportant features i will become larger, so that the model will be more inclined to select counterfactual samples generated based on important feature perturbations when performing the minimum optimization problem, thereby obtaining a compact and explainable intervention effect. In addition, the lower the value of this indicator, the closer the distance between the counterfactual sample and the original sample is, and vice versa, the farther the distance between the counterfactual sample and the original sample is. Therefore, the smaller the indicator, the better.

[0107] The sparsity in counterfactual explanations measures how many feature values ​​in the counterfactual sample are different from those in the original sample. The sparsity depends on the size of the feature difference between the counterfactual sample and the original sample. Intuitively, counterfactual samples with few feature changes (low sparsity) may be easier to implement and easier to be accepted by users, while counterfactual samples with many feature changes (high sparsity) are not only difficult to implement but also difficult for users to accept. Therefore, sparsity is often used as one of the constraints of counterfactual explanations, and an indicator function is used for statistics, as shown in the following formula:

[0108]

[0109] However, most of the current studies have only counted the number of changed features in terms of sparsity, and have not explored in depth whether the magnitude of the change in features (especially continuous features) has an impact on counterfactual interpretations, that is, ignoring the magnitude and degree of impact of each feature change. Although this method can provide quantitative information about feature changes, it cannot capture the specific degree of impact of each feature on model predictions, nor can it provide a more detailed explanation for continuous features. Therefore, in the basis of sparsity evaluation, it is necessary to consider further indicators and methods to more comprehensively understand the impact of feature changes on the model. For the above reasons, this paper proposes a relative impact metric (RIM). Specifically, when feature x ij When it is a continuous feature, we first calculate its relative change difference, and then process the result by absolute value, because we are concerned about the magnitude of feature change rather than the direction. Then, the absolute change value is combined with the inverse weight w j Multiply them together to get the final relative impact index RIM of the feature i Similarly, in order to ensure fairness for the classification features that have been processed by one-hot, the directly corresponding inverse weight w iIt is regarded as an importance indicator of the magnitude of change. The smaller the value of this indicator, the smaller the relative impact of the feature change on the model output, that is, the smaller the impact of perturbing the feature. In general, based on the indicator function, this indicator further quantifies the magnitude of feature change and feature weights (especially continuous features), so that the contribution of features to model output can be analyzed in more detail, providing a deeper understanding of counterfactual interpretations. In the minimization process of multi-objective optimization, the relative impact measurement caused by feature changes will also encourage the model framework to choose which counterfactual samples to introduce small-scale perturbations of more important features, thereby further improving the comprehensibility of counterfactual samples.

[0110] The relative influence index formula is:

[0111]

[0112] Among them, d real_count The number of features that represent the actual change in the continuous feature, d real_cat The number of features that represent actual variation in categorical features.

[0113] Plausibility: Plausibility means that the generated counterfactual samples should conform to the distribution or data manifold of the input dataset as much as possible, which means that the counterfactual samples should have a reasonable distribution in the given feature space and be as similar as possible to the real samples. In other words, the counterfactual samples should be reasonable, not outliers. The density-based LOF method is used as a measure of the plausibility of counterfactual samples.

[0114] LOF is implemented based on local density. By comparing the local density and reachable distance of a given data point and its neighboring points, it identifies the degree of dispersion of the data point and its neighboring points, thereby determining whether it is an outlier. Therefore, measuring whether a counterfactual sample is feasible is not only related to the distance of the neighboring points of the point, but also closely related to their density. This process involves the Kth reachable distance - rd k (o,p), local reachable density——lrd k (p), LOF k (p)——local outlier factor and other concepts, the specific definitions are as follows:

[0115] rd k (o,p)=max{d k (o),d(o,p)}.

[0116] where d k (o) represents the kth distance of the neighboring point o, and d(o,p) represents the distance from data point o to data point p.

[0117]

[0118] N k (p) refers to the kth neighborhood of data point p, specifically the set of points within the kth distance of point p, including points on the kth distance, which is mainly used to characterize the density of data point p. From the formula, we can see that when the density of point p and its neighboring points is lower, the reachable distance between them is more likely to be the distance between two larger points, so the lrd is smaller. Conversely, when the density of point p and its neighboring points is higher, their reachable distance is more likely to be the smaller kth distance of each other, and the final lrd value is larger.

[0119]

[0120] The above formula shows the kth local outlier factor of data point p, which is calculated by k (p) The average reachable density of all points in the neighborhood except point p is compared with the local reachable density of point p. When the ratio is greater than 1, it indicates that the density of point p is less than the density of its neighboring points, and point p is very likely to be an outlier. Conversely, the more the ratio is less than or equal to 1, the more the density of point p is greater than the density of its neighboring points, indicating that point p is an interior point.

[0121] The LOF algorithm implemented by the scikit-learn library is used to estimate whether each counterfactual sample is an outlier. Specifically, if the counterfactual sample is an outlier, the LOF prediction is -1, otherwise it is +1.

[0122] In one implementation of this embodiment, step S140 optimizes the initial function based on the feature constraint and the optimization target to obtain the counterfactual optimization loss function including:

[0123] The initial function is:

[0124]

[0125] in, represents the counterfactual sample, x i represents the original sample, λ is the empirical weight under multiple iterative experiments, represents the expected prediction result, d(.,.) is a distance function used to measure the original sample x i With the counterfactual sample x * The distance between is the output result of the counterfactual sample;

[0126] The optimized counterfactual optimization loss function is:

[0127]

[0128] Among them, hinge_yloss(.) is the prediction output loss term, dist(.) is the proximity, II(.) is the sparsity, RIM(.) is the relative influence index, lof(.) is the rationality of data distribution, and x represents the parameter to be optimized, that is, the counterfactual optimization feature.

[0129] Specifically, the initial population plays a vital role in the algorithm, which affects the global search capability and convergence speed of the algorithm. Evolutionary algorithms, as a type of heuristic algorithm, simulate the biological evolution process in nature, genetics, crossover and mutation operations to find the optimal solution or near-optimal solution to the problem. Since this type of heuristic algorithm has the characteristics of multi-point and multi-directional search during the search, there can be multiple solutions. When looking for a solution, the features of the solution to be obtained are determined by counterfactual optimization features, and then constraints are imposed by counterfactual optimization loss functions, and the convergence speed and global search capability are accelerated by the initial population.

[0130] In one implementation of this embodiment, the step of comparing the final counterfactual sample with the original sample to obtain the causal relationship between the input features and the output results of the prediction model includes:

[0131] S400, determining whether the counterfactual sample conforms to the data distribution of the original sample.

[0132] S410: If the counterfactual sample is consistent with the data distribution of the original sample, the final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and the output results of the prediction model.

[0133] S420: If the counterfactual sample does not conform to the data distribution of the original sample, then the counterfactual sample is regenerated.

[0134] Specifically, the purpose of judging whether the counterfactual sample conforms to the data distribution of the original sample is to ensure that the counterfactual sample maintains similar characteristics to the original sample in certain features. The data distribution of the original sample refers to the distribution of the values ​​of the original sample on each feature, including the mean, variance, and distribution shape. By ensuring that the data distribution of the counterfactual sample is similar to that of the original sample, the counterfactual sample can be made more representative and more reliable in tasks such as model training, analysis, or evaluation. Judging whether the counterfactual sample conforms to the data distribution of the original sample can be based on statistical methods or visualization methods.

[0135] By comparing the prediction results of the original sample output by the prediction model with the prediction results of the final counterfactual sample output by the prediction model, we can find out how the prediction results of the prediction model change when the features change.

[0136] For example, for developing and evaluating models for predicting the risk of criminal recidivism, this dataset is a dataset for developing and evaluating models for predicting the risk of criminal recidivism. This dataset has a total of 7214 samples. Based on previous studies, we used the number of previous crimes (priors_count), gender (sex), race (race), age stage (age_cat), and degree of crime (c_charge_degree, where M represents minor crimes and F represents serious crimes) for modeling. The task of our machine learning model is to make bail decisions based on the prediction results to identify which bail applicants are likely to re-offend in the next two years. By analyzing counterfactual samples, we aim to determine what intervention measures may help reduce the recidivism rate (i.e., perturb those who were originally predicted to re-offend so that their prediction results become non-offenders), so as to provide targeted suggestions for future decisions. In this paper, our research goal is to explore what measures can be taken to change the predicted results of individuals applying for bail from possible crimes to possible non-crimes in the next two years through counterfactual samples. Assuming that we interfere with race so that the crime rate decreases in the next two years, we can know which race will have a lower crime rate in the future.

[0137] Another example is the study of diabetes and digestive and kidney diseases, which includes 768 samples, each with 8 numerical features, and all patients are women of a certain race over the age of 21. The specific diagnostic measurements of this data set are used to predict whether the patient has diabetes. In addition, by analyzing the generated counterfactual samples, it is explored what kind of treatment behavior can transform the predicted results of patients with diabetes initially into non-diabetic patients, so as to provide treatment recommendations, including controlling the disease and slowing down the course of the disease.

[0138] Through this application document, we can understand why the prediction model outputs the result, provide suggestions for people's decision-making, and enhance the interpretability of the model.

[0139] A counterfactual sample explanation system, comprising:

[0140] An acquisition module is used to acquire original samples of reoffending patients who have committed crimes and output results after the original samples are input into a development and evaluation model for predicting the risk of criminal reoffending, wherein the input features of the development and evaluation model for predicting the risk of criminal reoffending are features of the original samples, and the features of the original samples include the number of past crimes, gender, race, age stage and degree of crime;

[0141] A first setting module is used to set a counterfactual optimization feature, where the counterfactual optimization feature is a feature of one or more original samples of the disturbance, where the features of the original samples include the number of past crimes, gender, race, age stage, and degree of crime;

[0142] A first generation module, configured to generate a biased initial population according to the original sample and the counterfactual optimization target;

[0143] The second setting module is used to set feature constraint conditions;

[0144] An optimization module, configured to optimize an initial function for developing and evaluating a crime recidivism risk prediction model based on the feature constraint and the counterfactual optimization feature, to obtain the counterfactual optimization loss function;

[0145] A second generation module is used to iterate the evolution of the biased initial population based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function and the prediction model to obtain a counterfactual sample that meets the causal constraint;

[0146] A screening module, used to screen out the counterfactual sample that is closest to the original sample to obtain a final counterfactual sample;

[0147] The explanation module is used to compare the final counterfactual sample with the original sample to obtain the causal relationship between the input features and output results of the crime recidivism risk prediction model.

[0148] An embodiment of the present application also discloses a terminal device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor loads and executes the computer program, a counterfactual sample interpretation method is adopted.

[0149] The terminal device may be a computer device such as a desktop computer, a laptop computer or a cloud server, and the terminal device includes but is not limited to a processor and a memory. For example, the terminal device may also include input and output devices, a network access device and a bus.

[0150] Among them, the processor can adopt a central processing unit (CPU). Of course, according to actual usage, other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. can also be adopted. The general-purpose processor can adopt a microprocessor or any conventional processor, etc., and this application does not impose any restrictions on this.

[0151] Among them, the memory can be an internal storage unit of the terminal device, such as a hard disk or memory of the terminal device, or it can be an external storage device of the terminal device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital card (SD) or a flash memory card (FC) equipped on the terminal device, etc., and the memory can also be a combination of an internal storage unit and an external storage device of the terminal device. The memory is used to store computer programs and other programs and data required by the terminal device. The memory can also be used to temporarily store data that has been output or is to be output, and this application does not impose any restrictions on this.

[0152] Among them, through this terminal device, a counterfactual sample interpretation method in the above embodiment is stored in the memory of the terminal device, and is loaded and executed on the processor of the terminal device for easy use.

[0153] An embodiment of the present application further discloses a computer-readable storage medium, and the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, a counterfactual sample interpretation method in the above embodiment is adopted.

[0154] Among them, the computer program can be stored in a computer-readable medium, the computer program includes computer program code, the computer program code can be in the form of source code, object code, executable file or certain middleware, etc. The computer-readable medium includes any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the computer-readable medium includes but is not limited to the above-mentioned components.

[0155] Among them, through this computer-readable storage medium, a counterfactual sample interpretation method in the above embodiment is stored in a computer-readable storage medium, and is loaded and executed on a processor to facilitate the storage and application of the above method.

[0156] A person skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of protection of the present application is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present application as above, which are not provided in detail for the sake of simplicity.

[0157] One or more embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the present application. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application should be included in the protection scope of the present application.

Claims

1. A counterfactual sample explanation method, characterized in that: include: Obtaining an original sample of patients who have committed crimes again and the output result after the original sample is input into a development and evaluation model for predicting the risk of criminal recidivism, wherein the input features of the development and evaluation model for predicting the risk of criminal recidivism are the features of the original sample, and the features of the original sample include the number of past crimes, gender, race, age stage and degree of crime; Setting a counterfactual optimization feature, wherein the counterfactual optimization feature is a feature of one or more original samples of the disturbance, wherein the features of the original samples include the number of past crimes, gender, race, age stage, and degree of crime; Generate a biased initial population according to the original sample and the counterfactual optimization target; Set feature constraints; Based on the feature constraint and the counterfactual optimization feature, an initial function for developing and evaluating a crime recidivism risk prediction model is optimized to obtain the counterfactual optimization loss function; Based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function, and the development and evaluation of the crime recidivism risk prediction model, the biased initial population is evolved iteratively to obtain a counterfactual sample that meets the causal constraint; Screening out the counterfactual sample that is closest to the original sample to obtain a final counterfactual sample; The final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and output results of the crime recidivism risk prediction model.

2. The counterfactual sample explanation method according to claim 1, characterized in that: The generating of the biased initial population according to the original sample and the preset algorithm comprises: The original samples are input into a preset algorithm to obtain samples that are close to the original samples in latent space but have opposite prediction results as biased initial populations, and the preset algorithm is a KD-Tree algorithm.

3. The counterfactual sample explanation method according to claim 1, characterized in that: The setting feature constraint conditions include: Analyzing the variability and invariability of various characteristics of the original sample; Taking said mutability and immutability as a first constraint; Obtaining the second constraint of the initial function for developing and evaluating the criminal recidivism risk prediction model; The first constraint condition and the second constraint condition are used as the feature constraint conditions.

4. The counterfactual sample explanation method according to claim 3, characterized in that: The second constraint condition includes prediction output loss term, proximity, sparsity and data distribution rationality.

5. The counterfactual sample explanation method according to claim 1, characterized in that: The initial function of developing and evaluating the crime recidivism risk prediction model is optimized based on the feature constraint condition and the counterfactual optimization feature to obtain the counterfactual optimization loss function, which includes: The initial function is: in, represents the counterfactual sample, x i represents the original sample, λ is the empirical weight under multiple iterative experiments, represents the expected prediction result, d(.,.) is a distance function used to measure the original sample x i With the counterfactual sample x * The distance between is the output result of the counterfactual sample; The optimized counterfactual optimization loss function is: Among them, hinge_yloss(.) is the prediction output loss term, dist(.) is the proximity, II(.) is the sparsity, RIM(.) is the relative influence index, lof(.) is the rationality of data distribution, and x represents the parameter to be optimized.

6. The counterfactual sample explanation method according to claim 1, characterized in that: The method of screening out the counterfactual sample closest to the original sample to obtain the final counterfactual sample includes: The similarity between the original sample and the counterfactual sample is calculated, and the counterfactual sample with the highest similarity is selected as the final counterfactual sample.

7. The counterfactual sample explanation method according to claim 1, characterized in that: The method of comparing the final counterfactual sample with the original sample to obtain the causal relationship between the input features and the output results of the crime recidivism risk prediction model for developing and evaluating the crime recidivism risk prediction model includes: Determining whether the counterfactual sample conforms to the data distribution of the original sample; If the counterfactual sample is consistent with the data distribution of the original sample, then the final counterfactual sample is compared with the original sample to obtain the causal relationship between the input features and the output results of the crime recidivism risk prediction model for development and evaluation; If the counterfactual sample does not conform to the data distribution of the original sample, the counterfactual sample is regenerated.

8. A counterfactual sample explanation system, characterized in that: include: An acquisition module is used to acquire original samples of reoffending patients who have committed crimes and output results after the original samples are input into a development and evaluation model for predicting the risk of criminal reoffending, wherein the input features of the development and evaluation model for predicting the risk of criminal reoffending are features of the original samples, and the features of the original samples include the number of past crimes, gender, race, age stage and degree of crime; A first setting module is used to set a counterfactual optimization feature, where the counterfactual optimization feature is a feature of one or more original samples of the disturbance, where the features of the original samples include the number of past crimes, gender, race, age stage, and degree of crime; A first generation module, configured to generate a biased initial population according to the original sample and the counterfactual optimization target; The second setting module is used to set feature constraint conditions; An optimization module, configured to optimize an initial function for developing and evaluating a crime recidivism risk prediction model based on the feature constraint and the counterfactual optimization feature, to obtain the counterfactual optimization loss function; A second generation module is used to iterate the evolution of the biased initial population based on the original sample, the counterfactual optimization feature, the counterfactual optimization loss function, and the development and evaluation of the crime recidivism risk prediction model to obtain a counterfactual sample that meets the causal constraint; A screening module, used to screen out the counterfactual sample that is closest to the original sample to obtain a final counterfactual sample; An explanation module is used to compare the final counterfactual sample with the original sample to obtain the causal relationship between the input features and output results for developing and evaluating the crime recidivism risk prediction model.

9. A terminal device, comprising a memory and a processor, characterized in that: The memory stores a computer program that can be run on the processor, and when the processor loads and executes the computer program, the interpretation method according to any one of claims 1 to 7 is adopted.

10. A computer-readable storage medium having a computer program stored therein, characterized in that: When the computer program is loaded and executed by a processor, the interpretation method according to any one of claims 1 to 7 is adopted.