A data poisoning detection method for KNN missing value filling model

Through the improved LOF algorithm and counter mechanism, toxic samples in the KNN missing value filling model are detected and removed, solving the problem of data poisoning attacks, improving the accuracy of the filling results and the quality of the data set, and enhancing the defense capabilities of the model .

CN118228131BActive Publication Date: 2024-09-17JINAN UNIVERSITY
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410650199.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-24
Publication Date
2024-09-17
Estimated Expiration
2044-05-24

AI Technical Summary

Technical Problem

The KNN missing value filling model is difficult to effectively detect and defend against data poisoning attacks, causing the model to learn incorrect information and output incorrect filling results, affecting the quality of the data set and the results of other tasks.

Method used

Using the improved local density abnormality factor (LOF) algorithm and counter mechanism, by calculating the local density abnormality factor of the missing sample, comparing the LOF values ​​of different samples, and judging and clearing the K neighbors of the target missing sample to detect and clear the data in the data set. Toxic samples.

Benefits of technology

Effectively defend against targeted data poisoning attacks, improve the accuracy of missing value filling and the quality of data sets, provide flexible detection intensity settings, and enhance the defense capabilities of the KNN model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118228131B
    Figure CN118228131B
Patent Text Reader

Abstract

The present invention discloses a data poisoning detection method for a KNN missing value filling model, which belongs to the technical field of machine learning and missing value filling, and includes: setting a threshold coefficient and calculating an abnormal threshold, and then using an improved local density abnormal factor algorithm to calculate the local density abnormal factors of different missing samples in a data set, and then updating the abnormal counter of each missing sample by comparing the local density abnormal factors of different missing samples, and then checking whether the abnormal counter of each missing sample is an abnormal threshold to determine the target missing sample that the attacker intends to attack, and finally clearing the K neighbors of the target missing sample to clear the poisonous samples in the data set. The detection method can select the detection strength by flexibly setting the threshold coefficient. It provides a reference basis for defending against targeted poisoning attacks for KNN models, and has practical significance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of machine learning and missing value filling, and in particular relates to a data poisoning detection method for a KNN missing value filling model. Background Art

[0002] In the era of big data, people are constantly exploring the huge value contained in data to obtain higher economic benefits. High-quality data sets, that is, data sets with high integrity, high validity and high accuracy, are the goals pursued by many practitioners in related industries. However, due to various reasons, some data items are generally missing in the acquired data. For example, due to frequent adjustments and changes in business, data does not exist in a static manner. This change causes historical data to be missing in some attribute columns. Therefore, people are eager to find a fast and accurate method to fill in missing values. Machine learning, as a powerful tool, especially the missing value filling model based on KNN, plays an important role in the field of missing value filling. Using this model for missing value filling has the advantages of high efficiency, good scalability and high accuracy.

[0003] However, in recent years, many research works have discovered potential security issues in the machine learning process, and targeted data poisoning is one of them. Targeted data poisoning is an attack method that acts on the machine learning training phase. Specifically, the attacker observes the data set and cleverly designs several poisonous samples to make the model learn wrong information, thereby outputting wrong prediction results for specific samples. This attack method does not directly affect the parameters of the machine learning model, but indirectly affects the machine learning model through the data set, so it is called data poisoning.

[0004] The missing value filling method based on KNN also faces this security risk, that is, the machine learning model will learn the wrong model from the toxic data, thus giving the wrong filling result. This is the result that users least want to see, because in missing value filling, accurate estimation of missing values ​​is crucial, and wrong filling results will affect the quality of the dataset and the results of other tasks using the dataset. Summary of the invention

[0005] In order to solve the above technical problems, the present invention proposes a data poisoning detection method for a KNN missing value filling model to solve the problems existing in the above prior art.

[0006] To achieve the above object, the present invention provides a data poisoning detection method for a KNN missing value filling model, comprising:

[0007] Obtain a data set to be tested, and search for missing samples in the data set to be tested;

[0008] Counting the length of the missing sample index array to obtain the number of missing samples;

[0009] Calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain LOF values ​​within a preset range of missing samples;

[0010] Compare the LOF values ​​of the preset range of the missing samples, and feed the comparison result back to the counter;

[0011] The element value in the counter is judged based on the parameter threshold coefficient to obtain the target missing sample detection result;

[0012] The poisonous samples inserted by the attacker are determined based on the target missing sample detection result.

[0013] Preferably, the process of calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain the LOF value of the preset range of missing samples includes:

[0014] Obtain the Euclidean distance from the data point p to the data point o in the missing sample;

[0015] Convert the Euclidean distance from the data point p to the data point o into the Kth distance from the data point p to the data point o;

[0016] Acquire a Kth distance neighborhood and a Kth reachable distance based on the Kth distance from the data point p to the data point o;

[0017] Obtaining an improved LRD value based on the Kth distance neighborhood and the Kth reachable distance;

[0018] The improved LRD value and the number of missing samples are calculated based on the improved LOF algorithm to obtain the LOF value of the preset range of missing samples.

[0019] Preferably, the expression for obtaining the Kth distance neighborhood is:

[0020] ;

[0021] ;

[0022] in, Defined as all points whose distance from point p is no greater than its Kth distance, is the number of points whose distance from point p is no greater than its Kth distance, For point p and point distance.

[0023] The expression of the Kth reachable distance is:

[0024]

[0025] in, is the Kth reachable distance from point p to point o, is the Kth distance of point o, is the distance between point p and point o.

[0026] Preferably, the expression for obtaining the improved LRD value based on the Kth distance neighborhood and the Kth reachable distance is:

[0027] ;

[0028] Among them, α is the smoothing coefficient, is the improved local reachability density of point p.

[0029] Preferably, the expression for obtaining the LOF value of the preset range of missing samples is:

[0030] ;

[0031] in, is the local outlier factor of point p.

[0032] Preferably, the process of comparing the LOF values ​​of the preset range of the missing samples and feeding back the comparison results to the counter includes: comparing the sample to be compared of the missing sample with other samples, and if the LOF value of the sample to be compared is smaller than the LOF value of the other samples, adding 1 to the counter corresponding to the sample to be compared.

[0033] Preferably, the process of determining the element value in the counter based on the parameter threshold coefficient to obtain the target missing sample detection result includes:

[0034] The elements in the counter are sorted to generate element values ​​in the counter. If the element value in the counter is greater than the product of the parameter threshold coefficient and the number of missing samples, the missing sample corresponding to the element value in the counter is determined to be the target missing sample, and the target missing sample detection result is output.

[0035] Preferably, the process of determining the poisonous sample inserted by the attacker based on the target missing sample detection result includes:

[0036] Get the K neighbors of each target missing sample in the target missing sample detection result;

[0037] The K neighbors of each target missing sample are judged as poisonous samples inserted by the attacker and deleted.

[0038] Compared with the prior art, the present invention has the following advantages and technical effects:

[0039] The present invention first sets the threshold coefficient and calculates the abnormal threshold, and then uses the improved local density abnormal factor algorithm to calculate the local density abnormal factors of different missing samples in the data set, and then updates the abnormal counter of each missing sample by comparing the local density abnormal factors of different missing samples, and then checks whether the abnormal counter of each missing sample is the abnormal threshold to determine the target missing sample that the attacker intends to attack, and finally removes the poisonous samples in the data set by removing the K neighbors of the target missing sample. The detection method can select the detection strength by flexibly setting the threshold coefficient. It provides a reference basis for defending against targeted poisoning attacks on KNN models, which has practical significance. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0041] Figure 1 This is a flow chart of a data poisoning detection method for a KNN missing value filling model according to an embodiment of the present invention;

[0042] Figure 2 Schematic diagram of an improved LOF according to an embodiment of the present invention. DETAILED DESCRIPTION

[0043] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0044] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0045] Embodiment 1

[0046] like Figure 1 As shown, this embodiment provides a data poisoning detection method for a KNN missing value filling model, including:

[0047] Obtain a data set to be tested, and search for missing samples in the data set to be tested;

[0048] Counting the length of the missing sample index array to obtain the number of missing samples;

[0049] Calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain LOF values ​​within a preset range of missing samples;

[0050] Compare the LOF values ​​of the preset range of the missing samples, and feed the comparison result back to the counter;

[0051] The element value in the counter is judged based on the parameter threshold coefficient to obtain the target missing sample detection result;

[0052] Based on the target missing sample detection result, the poisonous sample inserted by the attacker is judged as follows:

[0053] Step 1: The attacker sets the threshold coefficient, K in the KNN filling model

[0054] Step 2: Find the missing samples in the data set and record their numbers in the data set in the missing sample index array missing_sample_index. The sample number is used to identify and locate the data in the data set. The sample number is referred to as the index below. The index can be used to identify a specific sample in the data set. MATLAB users can find missing samples by calling the ismissing() function, R users can call is.na(), and Python users can use pandas.isna().

[0055] Step 3: Obtain the number of missing samples len_ms by counting the length of the missing sample index array missing_sample_index mentioned above.

[0056] Step 4: Calculate the LOF value within the 2*K range of each missing sample

[0057] Step 5: For each sample in the missing sample set, perform the following operations: Take the LOF value of the sample and compare it with the LOF of other missing samples in turn. If its LOF is smaller, add 1 to its corresponding counter.

[0058] Step 6: Sort the elements in the counter. If the element value is greater than the threshold coefficient thresholdcoefficient*the number of missing samples len_ms, it is confirmed to be the target missing sample, and the index of the missing sample is added to the target missing sample set result. The missing samples saved in result are considered to be the target missing samples.

[0059] Step 7: Output the target missing sample set result.

[0060] Step 8: For each target missing sample detected in the result, delete its K neighbors, which are the poisonous samples inserted by the attacker.

[0061] Further optimizing the scheme, the process of calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain the LOF value of the preset range of missing samples includes:

[0062] Obtain the Euclidean distance from the data point p to the data point o in the missing sample;

[0063] Convert the Euclidean distance from the data point p to the data point o into the Kth distance from the data point p to the data point o;

[0064] Acquire a Kth distance neighborhood and a Kth reachable distance based on the Kth distance from the data point p to the data point o;

[0065] Obtaining an improved LRD value based on the Kth distance neighborhood and the Kth reachable distance;

[0066] The improved LRD value and the number of missing samples are calculated based on the improved LOF algorithm to obtain the LOF value of the preset range of missing samples.

[0067] Further optimizing the solution, the expression for obtaining the Kth distance neighborhood is:

[0068] ;

[0069] ;

[0070] in, Defined as all points whose distance from point p is no greater than its Kth distance, is the number of points whose distance from point p is no greater than its Kth distance.

[0071] The expression of the Kth reachable distance is:

[0072] .

[0073] in, is the Kth reachable distance from point p to point o, is the Kth distance of point o, is the distance between point p and point o.

[0074] Further optimizing the solution, the expression for obtaining the improved LRD value based on the Kth distance neighborhood and the Kth reachable distance is:

[0075] ;

[0076] Among them, α is the smoothing coefficient, is the improved local reachability density of point p.

[0077] Further optimizing the scheme, the expression for obtaining the LOF value of the preset range of missing samples is:

[0078] ;

[0079] in, is the local outlier factor of point p.

[0080] A further optimization scheme is to compare the LOF values ​​of the preset range of the missing samples, and the process of feeding back the comparison results to the counter includes: comparing the sample to be compared of the missing sample with other samples, and if the LOF value of the sample to be compared is smaller than the LOF value of the other samples, adding 1 to the counter corresponding to the sample to be compared.

[0081] Further optimizing the scheme, judging the element value in the counter based on the parameter threshold coefficient, and obtaining the target missing sample detection result includes:

[0082] The elements in the counter are sorted to generate element values ​​in the counter. If the element value in the counter is greater than the product of the parameter threshold coefficient and the number of missing samples, the missing sample corresponding to the element value in the counter is determined to be the target missing sample, and the target missing sample detection result is output.

[0083] Further optimizing the solution, the process of judging the poisonous samples inserted by the attacker based on the target missing sample detection result includes:

[0084] Get the K neighbors of each target missing sample in the target missing sample detection result;

[0085] The K neighbors of each target missing sample are judged as poisonous samples inserted by the attacker and deleted.

[0086] Embodiment 2

[0087] This embodiment provides a data poisoning detection method for a KNN missing value filling model, including:

[0088] Targeted means that the attacker only attacks a missing column of a missing sample. Hereinafter, the missing sample will be referred to as the target missing sample, and the missing column will be referred to as the target missing column. Specifically, the attacker's goal is to insert poisonous samples into the K neighbors of the target missing sample. Under the influence of the poisonous samples, the KNN filling model will fill the target missing column of the target missing sample with a value specified by the attacker, which is called the target filling value.

[0089] This detection scheme includes two detection goals. One is to detect poisonous samples inserted by attackers, and the other is to detect missing samples that attackers intend to attack. The purpose of detecting the former is to delete poisonous samples in the training set so that they cannot harm the process of filling missing values, and to trace the detection channels of poisonous samples, so as to prevent data poisoning attacks that may occur in the future from the source. The purpose of detecting the latter is to prevent attackers from continuing to launch attacks in other ways or channels due to the failure of this attack. If the attacker's target missing samples can be identified, the defender can find other missing samples that may be attacked by the attacker based on the characteristics of the sample, and continue to monitor such samples, or improve the defense level or adopt a more robust filling method.

[0090] This embodiment will first find the target missing samples in the data set, and then find the toxic samples. This is because the toxic samples are distributed around the target missing samples. After finding the target missing samples, it is only necessary to delete the K neighbors of the target missing samples to eliminate all toxic samples, so as to get rid of the deviation introduced by the toxic samples to the greatest extent.

[0091] When an attacker poisons data, he must make the poisoned sample a neighbor of the target missing sample. At this time, the size of the feature space formed by the 2K neighbors of the target missing sample does not change, and the number of samples increases. Therefore, the local data density of the target missing sample will increase after the poisoned sample is inserted.

[0092] This embodiment intends to improve the existing Local Outlier Factor LOF (outlier detection algorithm) metric, and then use the improved LOF metric to detect the target missing samples in the data set. If the improved LOF of a missing sample is smaller than the improved LOF of (threshold coefficient * number of missing samples) missing samples, then the sample is the target missing sample, and the calculation process of the improved LOF is as follows:

[0093] S1, the distance from data point p to data point o is expressed as There are many distance measurement methods, and this embodiment uses Euclidean distance.

[0094] S2. Kth distance: The Kth distance of point p is defined as the distance of point o that is Kth closest to p. The expression is as follows:

[0095] ;

[0096] S3, Kth distance neighborhood: For any point p, its Kth distance neighborhood is defined as the set of all points whose distance from p is not greater than its Kth distance, as shown in the following formula:

[0097] ;

[0098] S4, Kth reachable distance: For any two points p and o, the Kth reachable distance from p to o is defined as the maximum value of the Kth distance from o and the distance from p to o, as shown in the following formula:

[0099] ;

[0100] S5. Improved local reachability density LRD: For any point p, its local reachability density is defined as the reciprocal of the sum of the average Kth reachable distance from all points in the Kth distance neighborhood of point p to point p and the average distance from point p to all points in its Kth distance domain. It reflects the density of point p. The higher the density between point p and the surrounding points, the larger the improved LRD value; the lower the density between point p and the surrounding points, the more likely the reachable distance of each point is the actual distance between the two larger points, and the smaller the improved LRD value is. The expression is shown in the following formula:

[0101] ;

[0102] When inserting poisonous samples into the K-th distance neighborhood of the target missing sample, a special strategy that the attacker may use is to insert the poisonous sample at the centroid of the K-th distance field, or more simply, at the center of the tight group formed by the original K neighbors of the target missing sample. In this case, the unmodified local density reachability algorithm may fail to detect such a complex situation. Therefore, by adding , if the value of this item is smaller, it means that the distance between the target missing sample and its K neighbors is smaller, and the attack initiated by the above special strategy may occur at this time. Taking the reciprocal allows the user to amplify the distance relationship between the target missing sample and its K neighbors. The user can adjust the smoothing coefficient α according to their own needs to determine the importance of this item in the local reachable density formula.

[0103] S6. Improved LOF: For any point p, its improved LOF value is the average of the ratios of the improved LRDs of all points in its K-th distance neighborhood to the improved LRD of p. The improved LOF represents the local anomaly factor of the point. The greater this ratio is than 1, the smaller the density of point p is than the density of its surrounding points; the smaller this ratio is than 1, the greater the density of point p is than the density of its surrounding points. The expression is as follows:

[0104] ;

[0105] The following is an implementation of this embodiment:

[0106] The improved LOF of the sample is calculated using the Euclidean distance with K=4 and the threshold coefficient is set to 0.5. =0.3;

[0107] like Figure 2 As shown, samples A and B are missing samples, that is, there are 2 missing samples in the data set, so the threshold = 0.5*2=1;

[0108] The improved LOF of A is 1.52, and the improved LOF of B is 1.75, indicating that the local density of A is higher. At this time, result['A']=1, result['B']=0, so A is the target missing sample in this sample.

[0109] The above are only preferred specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A data poisoning detection method for a KNN missing value filling model, characterized in that: The following steps are involved: Obtain a data set to be tested, and search for missing samples in the data set to be tested; Counting the length of the missing sample index array to obtain the number of missing samples; Calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain LOF values ​​within a preset range of missing samples; Compare the LOF values ​​of the preset range of the missing samples, and feed the comparison result back to the counter; The element value in the counter is judged based on the parameter threshold coefficient to obtain the target missing sample detection result; Determine the poisonous sample inserted by the attacker based on the target missing sample detection result; The process of calculating the missing samples based on the improved LOF algorithm and the number of missing samples to obtain the LOF value of the preset range of missing samples includes: Obtain the Euclidean distance from the data point p to the data point o in the missing sample; Convert the Euclidean distance from the data point p to the data point o into the Kth distance from the data point p to the data point o; Acquire a Kth distance neighborhood and a Kth reachable distance based on the Kth distance from the data point p to the data point o; Obtaining an improved LRD value based on the Kth distance neighborhood and the Kth reachable distance; Calculating the improved LRD value and the number of missing samples based on the improved LOF algorithm to obtain the LOF value of the preset range of missing samples; The expression for obtaining the Kth distance neighborhood is: ; ; in, Defined as all points whose distance from point p is no greater than its Kth distance, is the number of points whose distance from point p is no greater than its Kth distance, is the Kth distance of point p; The expression of the Kth reachable distance is: ; in, is the Kth reachable distance from point p to point o, is the Kth distance of point o, is the distance between point p and point o, For point p and point distance; The expression for obtaining the improved LRD value based on the Kth distance neighborhood and the Kth reachable distance is: ; Among them, α is the smoothing coefficient, is the improved local reachability density of point p; The expression for obtaining the LOF value of the preset range of missing samples is: ; in, is the local anomaly factor of point p; The process of judging the element value in the counter based on the parameter threshold coefficient and obtaining the target missing sample detection result includes: Sort the elements in the counter to generate element values ​​in the counter. If the element value in the counter is greater than the product of the parameter threshold coefficient and the number of missing samples, determine that the missing sample corresponding to the element value in the counter is a target missing sample, and output a target missing sample detection result; The process of determining the poisonous sample inserted by the attacker based on the target missing sample detection result includes: Get the K neighbors of each target missing sample in the target missing sample detection result; The K neighbors of each target missing sample are judged as poisonous samples inserted by the attacker and deleted.

2. The data poisoning detection method for the KNN missing value filling model according to claim 1 is characterized in that: The process of comparing the LOF values ​​of the preset range of the missing samples and feeding back the comparison results to the counter includes: comparing the sample to be compared of the missing sample with other samples, and if the LOF value of the sample to be compared is smaller than the LOF value of the other samples, adding 1 to the counter corresponding to the sample to be compared.

Citation Information

Patent Citations

  • Internet financial application anti-fraud identification method based on LOF algorithm

    CN111833174A

  • member reasoning attack-oriented deep model privacy protection method based on abnormal point detection

    CN113283536A

  • Data abnormal value detection method and storage medium

    CN116150630A

  • Method for detecting stability of movable arm of excavator

    CN117216728A

  • Backdoor attack method and defense method

    CN117473489A