Minority class sample processing method, apparatus, device, and storage medium
By generating synthetic samples by calculating the distance data between minority class samples and sampling weights, the problems of noise and distribution changes introduced by the SMOTE method are solved, and the balance of sample quantity and quality are achieved, thereby improving the model training effect.
Patent Information
- Application Number
- CN202111273040.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-29
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2041-10-29
AI Technical Summary
When dealing with minority class sample data, the existing technology, SMOTE method, is prone to introducing noisy samples and changing the sample distribution, which affects the model training effect.
By determining the distance data between minority class samples, calculating the sampling weights, and generating synthetic minority class samples based on the weights, the number of samples is increased while keeping the sample distribution unchanged.
It improves the quality and quantity of minority class samples generated, ensures that the sample distribution remains unchanged, and enhances the accuracy and generalization ability of model training.
Smart Images

Figure CN114186605B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a method, apparatus, device and storage medium for processing minority class samples. Background Technology
[0002] With the development of computer and internet technologies, the operating models of basic social industries such as finance and healthcare have been greatly improved. Faced with the processing of massive amounts of data, technological reforms have brought about entirely new processing methods.
[0003] Currently, the processing of minority class sample data mainly utilizes the SMOTE (Synthetic Minority Oversampling Technique) method, which generates minority class sample data through linear interpolation to balance the number of sample data.
[0004] However, this method is prone to producing noisy samples and boundary samples, which alters the distribution of the original sample data, affects the overall authenticity of the samples, and hinders the training of the sample model. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for processing minority class samples, so as to generate synthetic minority class samples based on the distance between samples.
[0006] In a first aspect, embodiments of this application provide a method for processing minority class samples, including:
[0007] Determine the distance data between different original minority class samples in the minority class training sample set;
[0008] Based on the distance data, the sampling weights of each of the original minority class samples are determined respectively;
[0009] Based on the sampling weights described above, synthetic minority class samples are generated using the corresponding original minority class samples as root samples.
[0010] Secondly, embodiments of this application also provide a minority sample processing apparatus, the apparatus comprising:
[0011] The distance determination module is used to determine the distance data between different original minority class samples in the minority class training sample set;
[0012] The weight determination module is used to determine the sampling weight of each of the original minority class samples based on the distance data.
[0013] The sample synthesis module is used to generate synthetic minority class samples based on the sampling weights, using the corresponding original minority class samples as root samples.
[0014] Thirdly, embodiments of this application also provide an electronic device, including:
[0015] One or more processors;
[0016] Memory, used to store one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement a minority sample processing method as described in any embodiment of this application.
[0018] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a minority sample processing method as described in any embodiment of this application.
[0019] The technical solution of this application determines the sampling weight by the distance between the original minority class samples, and generates new synthetic minority class samples according to the sampling weight, thereby increasing the overall number of minority class samples and balancing the relative number of all original sample data. At the same time, the above technical solution uses the sampling weight as a standard to screen the original minority class samples, and synthesizes the minority class samples while ensuring that the sample distribution remains unchanged, thereby improving the quality of minority class sample generation. Attached Figure Description
[0020] Figure 1 This is a flowchart of a minority sample processing method according to Embodiment 1 of this application;
[0021] Figure 2 This is a flowchart of a minority sample processing method according to Embodiment 2 of this application;
[0022] Figure 3 This is a flowchart of a minority sample processing method according to Embodiment 3 of this application;
[0023] Figure 4 This is a flowchart of a minority sample processing method according to Embodiment 4 of this application;
[0024] Figure 5 This is a structural diagram of a minority sample processing device according to Embodiment 5 of this application;
[0025] Figure 6 This is a structural diagram of an electronic device according to Embodiment Six of this application. Detailed Implementation
[0026] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present application, not the entire structure.
[0027] Example 1
[0028] Figure 1 This is a flowchart of a minority class sample processing method provided in Embodiment 1 of this application. This embodiment is applicable to situations balancing sample quantity and sample distribution. The method can be executed by a minority class sample processing device, which can be implemented in software and / or hardware and specifically configured in an electronic device.
[0029] refer to Figure 1 The minority class sample processing method shown includes the following steps:
[0030] S110. Determine the distance data between different original minority class samples in the minority class training sample set.
[0031] In a binary classification model, the minority class can be defined as the smaller class of samples in the sample data. For example, in the financial field, users with no credit risk are classified as positive samples, and users with credit risk are classified as negative samples. Since the number of positive samples is much greater than the number of negative samples, the negative samples can be considered as the minority class.
[0032] The original minority class samples are real, unprocessed minority class samples. The minority class training sample set can be the set of original minority class samples required for training the binary classification model. Different original minority class samples are generally located in different positions within the sample set. The distance between each original minority class sample is calculated. This distance calculation can use Euclidean distance, or it can use Minkowski distance, Manhattan distance, etc. The embodiments of this application do not limit this.
[0033] S120. Based on the distance data, determine the sampling weight of each of the original minority class samples.
[0034] S130. Based on the sampling weights described above, generate synthetic minority class samples using the corresponding original minority class samples as root samples.
[0035] The sampling weight of a given original minority class sample refers to the probability that, when generating new synthetic minority class samples, the number of new samples generated based on that original minority class sample is relative to the predetermined total number of new samples. For example, if the sampling weight of an original minority class sample is determined to be 5% based on its distance from other original minority class samples, and the predetermined number of new samples is 100, then based on that original minority class sample, 5 new synthetic minority class samples should be generated. Synthetic minority class samples are new minority class samples generated based on original minority class samples, which can supplement the number of minority class samples to balance the overall sample data.
[0036] Optionally, the sample center of this batch of minority class data can be determined based on the distance data between all the original minority class samples, and the degree of deviation can be determined based on the distance of different original minority class samples from the sample center. For example, the sampling weight of original minority class samples with a high degree of deviation can be set to be low, and their importance in the selection of original minority class samples can be set to be high; the sampling weight of original minority class samples with a low degree of deviation can be set to be high, and their importance in the selection of original minority class samples can be low.
[0037] Since the synthetic minority class samples are generated from the original minority class samples, the corresponding original minority class samples are the root samples of the synthetic minority class samples. Specifically, all original minority class samples are selected according to their importance, and new synthetic minority class samples are generated based on a portion of these original minority class samples. Original minority class samples with high sampling weights can be selected as the root samples.
[0038] The technical solution of this application determines the sampling weight by the distance between the original minority class samples, and generates new synthetic minority class samples according to the sampling weight, thereby increasing the overall number of minority class samples and balancing the relative number of all original sample data. At the same time, the above technical solution uses the sampling weight as a standard to screen the original minority class samples, and synthesizes the minority class samples while ensuring that the sample distribution remains unchanged, thereby improving the quality of minority class sample generation.
[0039] In one optional implementation, the step of generating synthetic minority class samples based on the corresponding original minority class samples as root samples according to the sampling weights may include: determining the sampling quantity of each original minority class sample according to the preset total number of synthetic samples and the sampling weights; and generating synthetic minority class samples based on the sampling quantities, using the corresponding original minority class samples as root samples.
[0040] The preset total number of synthetic samples refers to the preset number of synthetic minority class samples to be generated. This preset total number can be determined based on the difference between the number of majority class samples and the number of minority class samples in the overall sample size. The sampling quantity refers to the number of synthetic minority class samples generated using a given original minority class sample as the root sample. For example, if the current number of majority class samples is four times the number of minority class samples, and it's necessary to supplement the minority class samples to balance the overall sample size, and there are 150 more majority class samples than minority class samples, then the preset total number of synthetic samples can be set to 150. If the sampling weight of a given original minority class sample is 10%, then using that original minority class sample as the root sample, 15 new synthetic minority class samples will be generated, i.e., the sampling quantity is 15.
[0041] The technical solution of this application determines the sampling weight by the distance between the original minority class samples, and generates new synthetic minority class samples according to the sampling weight, thereby increasing the overall number of minority class samples and balancing the relative number of all original sample data. At the same time, the above technical solution uses the sampling weight as a standard to screen the original minority class samples, and synthesizes the minority class samples while ensuring that the sample distribution remains unchanged, thereby improving the quality of minority class sample generation.
[0042] Example 2
[0043] Figure 2 This is a flowchart illustrating a minority class sample processing method provided in Embodiment 2 of this application. This embodiment optimizes the acquisition operation of the original minority class sample sampling weights based on the technical solutions of the foregoing embodiments, in order to determine the sampling weights according to the degree of deviation.
[0044] refer to Figure 2 The method for handling minority class samples shown includes the following steps:
[0045] S210. Determine the distance data between different original minority class samples in the minority class training sample set.
[0046] S220. Based on the distance data, determine the cumulative distance data of each of the original minority class samples.
[0047] The cumulative distance data is the sum of the distances from a single sample in the minority class to other minority class samples. This sum of distances reflects the distribution of the single sample in the minority class. The larger the sum of distances, the farther the single sample is from the sample center, and vice versa.
[0048] Specifically, after determining the distances between the different original minority class samples, the sum of the distances from each minority class sample to the other minority class samples is calculated sequentially. For example, Euclidean distance can be used to calculate the distances between minority class samples, and the sum of the Euclidean distances D from each minority class sample to the other minority class samples can be calculated. i D of a certain sample i The larger the value of D, the more likely the sample belongs to the marginal or sparse region of the minority class distribution; i The smaller the value, the more likely the sample belongs to the central or concentrated area of the minority class sample distribution.
[0049] Specifically, the cumulative distance data for each original minority class sample is determined using the following formula:
[0050]
[0051] Among them, X i Let X be the i-th original minority class sample. i =(x i1 ,…,x ik ,…,x im ); m is the sample dimension; i = 1, 2, ..., n; n is the original number of minority class samples. D ij (X i ,X j ) represents the original minority class sample X i Compared with the original minority class sample X j Distance data between; D i For the original minority class sample X i The cumulative distance data.
[0052] S230. Based on the cumulative distance data, determine the degree of boundary deviation for each original minority class sample.
[0053] The degree of boundary deviation of the original minority class sample reflects the distance of the original minority class sample from the sample boundary of all original minority class samples. The closer to the sample boundary, that is, the farther away from the sample center, the smaller the degree of boundary deviation. The farther away from the sample boundary, that is, the closer to the sample center, the greater the degree of boundary deviation.
[0054] For example, the degree of boundary deviation of each original minority class sample can be determined based on a preset function and the cumulative distance data. The preset function has the cumulative distance data as the independent variable and the cumulative deviation as the dependent variable. The preset function is a subtractive function of the cumulative distance data.
[0055] Optionally, based on each cumulative distance data, the degree of boundary deviation of each original minority class sample can be determined by: obtaining the maximum value among each cumulative distance data; taking the difference between the maximum value and each cumulative distance data as the boundary distance value; and determining the degree of boundary deviation of the corresponding original minority class sample based on the boundary distance value.
[0056] The boundary distance value is the numerical value representing the distance between the original minority class sample and the boundary of the minority class sample.
[0057] In one specific implementation, the degree of boundary deviation of the corresponding original minority class sample is determined based on the boundary deviation value. This can be achieved by directly using the boundary distance value as the degree of boundary deviation of the corresponding original minority class sample.
[0058] Because the distances from different original minority class samples to the minority class sample boundary vary significantly, directly using the boundary distance value as the boundary deviation degree to determine the sampling weights will result in excessively large differences in sampling weights, leading to an unbalanced distribution of the subsequently generated synthetic minority class samples. To avoid this, another specific implementation determines the boundary deviation degree of the corresponding original minority class sample based on the boundary deviation value. This can be achieved by: determining the maximum distance difference among the cumulative distance data; and determining the boundary deviation degree of the corresponding original minority class sample based on the ratio of the boundary distance value to the maximum distance difference.
[0059] Optionally, the ratio of the boundary distance value to the maximum distance difference can be directly used as the boundary deviation of the corresponding original minority class sample, thereby achieving the purpose of standardizing the cumulative distance data of each original minority class sample, eliminating the situation of unreasonable sampling weight allocation caused by data dispersion, and thus avoiding the situation where the final generated synthetic minority class sample does not match the distribution of the original minority class sample due to unreasonable sampling weight allocation.
[0060] Specifically, the following formula can be used to determine the degree of boundary deviation:
[0061]
[0062] Among them, L i For the original minority class sample X i The degree of boundary deviation, D max D represents the maximum value of the cumulative distance deviation. min This is the minimum value among the cumulative distance deviations.
[0063] S240. Based on the degree of deviation of each boundary, determine the sampling weight of each original minority class sample.
[0064] For example, determining the sampling weight of each original minority class sample based on the degree of deviation from each boundary can be achieved by: determining the deviation level based on the degree of deviation from each boundary; and determining the sampling weight of the original minority class sample based on the deviation level. For instance, boundary deviation intervals can be predetermined, and numerical sampling weights corresponding to different boundary deviation intervals can be set; wherein the sum of the sampling weights corresponding to each boundary deviation interval is 1.
[0065] In one specific implementation, if the number of original minority class samples corresponding to the same boundary deviation interval is at least two, the sampling weights corresponding to the boundary deviation interval can be evenly distributed, and the mean value can be used as the sampling weight of each original minority class sample.
[0066] It should be noted that by pre-setting the correspondence between boundary deviation intervals and sampling weights, the distribution of each original minority class sample can only be represented in a coarse-grained manner. In order to further improve the matching degree between sampling weights and the distribution of original minority class samples, for example, the sampling weight of each original minority class sample can be determined according to the degree of boundary deviation. This can be done by: determining the cumulative boundary deviation degree according to the degree of boundary deviation; and determining the sampling weight of the corresponding original minority class sample according to the ratio of the degree of boundary deviation to the cumulative boundary deviation degree.
[0067] The ratio of the degree of boundary deviation to the cumulative degree of boundary deviation quantifies the relative deviation distance between different original minority class samples and the minority class sample boundary. Using this ratio as the sampling weight for the corresponding original minority class sample improves the matching degree between the sampling weight and the original distribution of the original minority class samples. Specifically, a larger ratio indicates a greater distance from the minority class sample boundary and a smaller distance from the minority class sample center, resulting in a larger sampling weight; conversely, a smaller ratio indicates a smaller distance from the minority class sample boundary and a greater distance from the minority class sample center, resulting in a smaller sampling weight.
[0068] Specifically, the sampling weights can be determined using the following formula:
[0069]
[0070] Among them, W i For the original minority class sample X i The sampling weights.
[0071] S250. Based on the sampling weights described above, generate synthetic minority class samples using the corresponding original minority class samples as root samples.
[0072] For example, the sampling quantity of each original minority class sample can be determined according to the preset total number of synthetic samples and the sampling weights of each sample; and synthetic minority class samples can be generated with the corresponding original minority class sample as the root sample according to the sampling quantity.
[0073] Specifically, the number of samples can be determined using the following formula:
[0074] N i =W i ×N;
[0075] Where, N i For the original minority class sample X i The number of samples; N is the preset total number of synthetic samples.
[0076] The technical solution of this application refines the determination of sampling weights into: determining the cumulative distance data of each original minority class sample based on each distance data; determining the boundary deviation degree of each original minority class sample based on each cumulative distance data; and determining the sampling weight of each original minority class sample based on each boundary deviation degree. This technical solution reduces the computational burden by calculating boundaries. Furthermore, by introducing the boundary deviation degree into the determination of sampling weights, the determined sampling weights effectively reflect the distribution of the original minority class samples, improving the fit between the distribution of the synthesized minority class samples and the original minority class samples, and reducing the influence of the synthesized minority class samples on the distribution of the original minority class samples.
[0077] Example 3
[0078] Figure 3 This is a flowchart illustrating a minority class sample processing method provided in Embodiment 3 of this application. This embodiment supplements the training operations of the classification model based on the foregoing technical solutions, enabling training of the classification model using all generated minority class samples.
[0079] refer to Figure 3 The method for handling minority class samples shown includes the following steps:
[0080] S310. Determine the distance data between different original minority class samples in the minority class training sample set.
[0081] S320. Based on the distance data, determine the sampling weight of each of the original minority class samples.
[0082] S330. Based on the sampling weights described above, generate synthetic minority class samples using the corresponding original minority class samples as root samples.
[0083] S340. Add the at least one synthetic minority class sample to the minority class training sample set to update the minority class training sample set.
[0084] The original minority class training sample set only contains the original minority class samples. Through the operations described in the above embodiments, synthetic minority class samples are generated. The newly generated sample data is then added to the minority class training sample set to increase the number of minority class samples.
[0085] S350. Based on the updated minority class training sample set, train the classification model to be trained to obtain the target classification model.
[0086] The classification model to be trained can be a model used to classify data. The model's classification ability is trained using sample data. The model is trained using a supplemented minority class training sample set, and the resulting model with classification ability is used as the target classification model. The classification model to be trained is typically a binary classification model that performs majority and minority class classification.
[0087] In an optional implementation, the minority class sample processing method may further include: identifying anomalous synthetic samples in each of the synthetic minority class samples; removing the anomalous synthetic samples from the updated minority class training sample set to update the minority class training sample set again; and using the samples in the updated minority class training sample set as the original minority class samples, returning to perform the distance data determination operation until the iteration cutoff condition is met.
[0088] Here, "abnormal synthetic samples" refers to samples in the generated synthetic minority class samples that do not conform to the characteristics of minority class samples, such as marginal samples and noise samples. The iteration cutoff condition refers to the preset condition for stopping the iteration operation. For example, it could be that the number of model iterations has reached a preset value, or it could be based on the effect of model iteration, such as the model's evaluation parameters stabilizing. The model evaluation parameters can include at least one of the following: sensitivity, specificity, precision, and accuracy.
[0089] The above implementation removes abnormal synthetic samples from the minority class training sample set and trains the classification model iteratively, thus solving the negative impact of abnormal samples on the training results during the classification model training process. This helps to improve the training effect of the classification model based on the minority class training sample set after removing abnormal synthetic samples.
[0090] In an optional embodiment, cluster centers can be determined by performing cluster analysis on the minority training set with added synthetic minority samples; synthetic minority samples that are more than a preset distance from the cluster center are identified as abnormal synthetic samples.
[0091] In another optional embodiment, identifying anomalous synthetic samples among the synthetic minority class samples may include: inputting each synthetic minority class sample into the target classification model to obtain the synthetic predicted category of each synthetic minority class sample; and determining anomalous synthetic samples based on the synthetic predicted category and the synthetic true category of the synthetic minority class samples.
[0092] In this context, the synthetic predicted category is the classification prediction of the target classification model for the input minority class sample, and the synthetic true category is the true classification of the synthetic sample itself. In this embodiment, the synthetic true category is the minority class.
[0093] Specifically, for each synthetic minority class sample, the synthetic minority class sample is input into the target classification model, and the model output is used as the synthetic predicted class. If the synthetic predicted class is the minority class, the synthetic minority class sample is determined to be an anomalous sample; if the synthetic predicted class is the majority class, the synthetic minority class sample is determined to be an anomalous synthetic sample.
[0094] The above implementation method identifies abnormal synthetic samples by classifying and predicting the synthetic samples using a classification model. This provides a basis for removing abnormal samples from the minority class training sample set, improves the sample quality in the updated minority class training sample set, and helps to improve the training effect of the classification model based on the minority class training sample set after the abnormal synthetic samples are identified.
[0095] It should be noted that when using a target classification model to remove anomalous synthetic samples, there is a possibility that the poor performance of the target classification model itself may lead to normal synthetic samples being misidentified as anomalous synthetic samples. To avoid this, a model evaluation operation can be added to the target classification model before identifying anomalous synthetic samples, thus ensuring the model performance of the target classification model. In an optional embodiment, before identifying anomalous synthetic samples in each of the synthetic minority class samples, the minority sample processing method may further include: performing a model evaluation on the target classification model. Correspondingly, identifying anomalous synthetic samples in each of the synthetic minority class samples may include: if the model evaluation result meets the optimization iteration conditions, then identifying anomalous synthetic samples in each of the synthetic minority class samples.
[0096] Model evaluation involves assessing the classification model during each iteration to determine if it has achieved the desired classification performance. Evaluation metrics may include, but are not limited to, specificity, sensitivity, precision, and accuracy. Optimization iteration conditions are triggers that occur when the target classification model already performs well, requiring optimization of a minority of samples to further improve its performance. In a specific implementation, optimization iteration conditions may include evaluation metrics exceeding preset thresholds, evaluation metrics stabilizing, or the number of iterations exceeding the first iteration threshold. It's important to note that optimization iteration conditions differ from the aforementioned iteration cutoff conditions. Iteration medium conditions are typically more stringent than optimization iteration conditions. For example, if both optimization iteration conditions and iteration cutoff conditions require accuracy to exceed a corresponding accuracy threshold, then the accuracy threshold for the iteration cutoff condition is higher than the accuracy threshold for the optimization iteration condition.
[0097] Specifically, before identifying anomalous synthetic samples, the target classification model is evaluated. If the optimization iteration conditions are met, anomalous synthetic samples in the minority class training sample set are identified.
[0098] In one optional implementation, the model evaluation of the target classification model may include: inputting test samples into the target classification model to obtain test predicted categories; and evaluating the target classification model based on the test predicted categories and the true test categories of the test samples.
[0099] The test samples are input into the trained target classification model, and the model will output the predicted category. The model is evaluated based on the predicted category and the true category of the sample. For example, the model can be evaluated based on the correctness of its classification judgment.
[0100] In one optional implementation, evaluating the target classification model based on the test predicted category and the test true category of the test sample may include: determining a model evaluation index based on the consistency between the test predicted category and the test true category of the test sample; wherein the model evaluation index includes at least one of specificity, sensitivity, and precision.
[0101] In a binary classification model, the majority class is defined as the positive class, and the minority class as the negative class. Specificity is the proportion of correct predictions for the negative class out of all correct predictions for the negative class, which can be expressed by the formula... The calculation is performed, where TN is the number of actual negative class predicted negative classes, and FP is the number of actual negative class predicted positive classes.
[0102] Sensitivity is the proportion of correct positive class predictions out of all positive class predictions, which can be expressed by the formula... The calculation is performed, where TP is the number of actual positive class predicted positive class, and FN is the number of actual positive class predicted negative class.
[0103] Precision is divided into positive class precision and negative class precision. Positive class precision is the proportion of times the model correctly classifies a class as positive out of all instances of positive class classification. It can be expressed by the formula... The calculation is performed; the negative class precision is the proportion of times the model correctly identifies a class as negative out of all times the model identifies a class as negative. It can be calculated using the formula... Perform the calculation.
[0104] Multiple evaluation refers to using the geometric mean of at least two indicators as the evaluation metric. For example, combining specificity and sensitivity for dual evaluation can be achieved by multiplying the specificity value by the sensitivity value and then taking the square root to obtain the reference value for the dual evaluation.
[0105] The above implementation method refines the model evaluation indicators, setting evaluation indicators such as specificity, sensitivity, precision, and multiple evaluation, which is conducive to evaluating the target classification model from different perspectives and reflecting the classification ability of the target classification model from different angles.
[0106] This application embodiment introduces synthetic minority class samples into the minority class training sample set to train the classification model, thereby increasing the proportion of minority class samples in the model training process. This avoids the occurrence of minority class overfitting in the trained model, which helps to improve the model's generalization ability and thus improves the model performance.
[0107] Example 4
[0108] Figure 4 A flowchart illustrating a minority class sample processing method provided in Embodiment 4 of this application. This embodiment is a preferred embodiment provided based on the foregoing embodiments, see reference. Figure 4 The specific implementation steps are as follows:
[0109] S401. Screen all samples to determine the number of different types of samples.
[0110] S402. Determine whether the ratio of the number of minority class samples to the number of majority class samples is less than a preset threshold. If yes, execute S403A; otherwise, jump to execute S403B.
[0111] S403A Calculate the Euclidean distance from each sample in the minority class sample set to other samples.
[0112] S403B: The preset binary classification model is trained using conventional methods to obtain the target classification model.
[0113] S404. Calculate the sum of Euclidean distances from each sample in the minority class sample set to other samples.
[0114] S405. Determine the maximum and minimum sums among the sums of Euclidean distances.
[0115] S406. The difference between the maximum sum and the sum of the Euclidean distances of all samples in the minority class sample set is taken as the boundary distance value.
[0116] S407. The difference between the maximum sum and the minimum sum is taken as the maximum distance difference.
[0117] S408. The ratio of the boundary distance value to the maximum distance difference of each sample in the minority class sample set shall be used as the sampling weight of the corresponding sample.
[0118] S409. The product of the sampling weight of each sample in the minority class sample set and the preset total number of synthetic samples is used as the sampling quantity of the corresponding sample.
[0119] S410. Using each sample in the minority class sample set as the root sample, generate a synthetic sample of the corresponding sampling number.
[0120] S411. Add the synthesized minority class samples to at least a few class training sample sets to update the minority class training sample set, and sample the updated minority class training samples to train the preset binary classification model to obtain the target classification model.
[0121] S412. Evaluate the target classification model using test samples;
[0122] S413. If the evaluation index is greater than the corresponding first preset threshold, execute S414A; otherwise, execute S414B.
[0123] S414A, Stop training the target classification model.
[0124] S414B: Determine whether the evaluation index is greater than the corresponding second preset threshold; if yes, execute S415; otherwise, return to execute S403.
[0125] Wherein, the second preset threshold is less than the first preset threshold;
[0126] S415. Input the synthetic sample into the target classification model to obtain the synthetic prediction result; continue to execute S416.
[0127] S416. Remove synthetic samples whose synthetic prediction results are in the majority class from the minority class sample set to update the minority class sample set;
[0128] S417. Return to the minority class sample set after elimination and execute S403.
[0129] Example 5
[0130] Figure 5 This is a structural diagram of a minority sample processing device provided in Embodiment 5 of this application. This embodiment is applicable to situations balancing sample quantity and distribution. The device can be implemented in software and / or hardware and can be configured in an electronic device. Figure 5 As shown, the device may include:
[0131] The distance determination module 510 is used to determine the distance data between different original minority class samples in the minority class training sample set;
[0132] The weight determination module 520 is used to determine the sampling weight of each of the original minority class samples based on the distance data.
[0133] The sample synthesis module 530 is used to generate synthesized minority class samples based on the sampling weights, using the corresponding original minority class samples as root samples.
[0134] The technical solution of this application determines the sampling weight by the distance between the original minority class samples, and generates new synthetic minority class samples according to the sampling weight, thereby increasing the overall number of minority class samples and balancing the relative number of all original sample data. At the same time, the above technical solution uses the sampling weight as a standard to screen the original minority class samples, and synthesizes the minority class samples while ensuring that the sample distribution remains unchanged, thereby improving the quality of minority class sample generation.
[0135] In one alternative implementation, the weight determination module 520 may include:
[0136] The cumulative distance determination unit is used to determine the cumulative distance data of each of the original minority class samples based on the distance data.
[0137] The boundary deviation determination unit is used to determine the boundary deviation degree of each original minority class sample based on the cumulative distance data.
[0138] The sampling weight determination unit is used to determine the sampling weight of each of the original minority class samples according to the degree of deviation of each boundary.
[0139] In one optional implementation, the boundary deviation determination unit may include:
[0140] The maximum cumulative distance acquisition subunit is used to acquire the maximum value among the cumulative distance data.
[0141] The boundary distance value determination subunit is used to take the difference between the maximum value and each of the cumulative distance data as the boundary distance value;
[0142] The boundary deviation determination subunit is used to determine the boundary deviation degree of the corresponding original minority class sample based on the boundary distance value.
[0143] In one alternative implementation, the boundary deviation determination subunit may include:
[0144] The maximum distance difference determination unit is used to determine the maximum distance difference among the cumulative distance data.
[0145] The boundary deviation determination unit is used to determine the boundary deviation degree of the corresponding original minority class sample based on the ratio of the boundary distance value to the maximum distance difference value.
[0146] In one optional implementation, the sampling weight determination unit may include:
[0147] The deviation degree accumulation subunit is used to determine the cumulative boundary deviation degree based on the deviation degree of each boundary.
[0148] The sampling weight determination subunit is used to determine the sampling weight of the corresponding original minority class sample based on the ratio of the boundary deviation degree to the cumulative boundary deviation degree.
[0149] In one alternative implementation, the weight determination module 520 may further include:
[0150] The standardization unit is used to standardize the cumulative distance data of each original minority class sample before determining the degree of deviation between each original minority class sample and the center of the minority class sample based on each of the cumulative distance data.
[0151] Accordingly, the deviation determination unit may include:
[0152] The standardized deviation determination sub-unit is used to determine the degree of deviation between each original minority class sample and the center of the minority class sample based on the standardized cumulative distance data.
[0153] In one alternative embodiment, the sample synthesis module 530 may include:
[0154] The sampling quantity determination unit is used to determine the sampling quantity of each original minority class sample according to the preset total amount of synthetic samples and each of the sampling weights;
[0155] The synthesis unit is used to generate synthetic minority class samples based on the respective original minority class samples as root samples, according to the sampling quantity.
[0156] In one optional embodiment, the minority sample processing device may further include:
[0157] A sample update module is used to add the at least one synthetic minority class sample to the minority class training sample set to update the minority class training sample set;
[0158] The classification model acquisition module is used to train the classification model to be trained based on the updated minority class training sample set, so as to obtain the target classification model.
[0159] In one optional embodiment, the minority sample processing device may further include:
[0160] Anomaly detection module, used to identify anomalous synthetic samples among the synthetic minority class samples;
[0161] An anomaly removal module is used to remove the anomalous synthetic samples from the updated minority class training sample set in order to update the minority class training sample set again.
[0162] The iteration condition judgment module is used to take the samples in the updated minority class training sample set as the original minority class samples and return to perform distance data determination operation until the iteration cutoff condition is met.
[0163] In one optional implementation, the anomaly detection module may include:
[0164] A synthetic prediction unit is used to input each of the synthetic minority class samples into the target classification model to obtain the synthetic prediction category of each of the synthetic minority class samples;
[0165] An abnormal synthesis identification unit is used to determine abnormal synthesized samples based on the predicted synthesis category and the true synthesis category of the synthesized minority class samples.
[0166] In one optional implementation, the anomaly detection module may further include:
[0167] A model evaluation unit is used to evaluate the target classification model before identifying anomalous synthetic samples in each of the synthetic minority class samples.
[0168] Accordingly, the anomaly detection module may include:
[0169] An optimization iteration judgment unit is used to identify abnormal synthetic samples among the synthetic minority class samples if the model evaluation result meets the optimization iteration conditions.
[0170] In one alternative implementation, the model evaluation unit may include:
[0171] The prediction category acquisition sub-unit is used to input the test sample into the target classification model to obtain the test prediction category;
[0172] The model evaluation subunit is used to evaluate the target classification model based on the test prediction category and the test true category of the test sample.
[0173] In one optional implementation, the model evaluation subunit is specifically used for:
[0174] The model evaluation index is determined based on the consistency between the predicted test category and the actual test category of the test sample.
[0175] The model evaluation metrics include at least one of specificity, sensitivity, and precision.
[0176] The aforementioned minority sample processing apparatus can execute the minority sample processing method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects for executing each minority sample processing method.
[0177] Example 6
[0178] Figure 6 This is a structural diagram of an electronic device provided in Embodiment Six of this application. Figure 6 A block diagram is shown of an exemplary electronic device 612 suitable for implementing embodiments of this application. Figure 6 The electronic device 612 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0179] like Figure 6 As shown, the electronic device 612 is represented in the form of a general-purpose computing device. The components of the electronic device 612 may include, but are not limited to: one or more processors or processing units 616, system memory 628, and bus 618 connecting different system components (including system memory 628 and processing unit 616).
[0180] Bus 618 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0181] Electronic device 612 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 612, including volatile and non-volatile media, removable and non-removable media.
[0182] System memory 628 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 630 and / or cache memory 632. Electronic device 612 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 634 may be used to read and write non-removable, non-volatile magnetic media (…). Figure 6 Not shown; usually referred to as a "hard drive"). Although Figure 6 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 618 via one or more data media interfaces. Memory 628 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this application.
[0183] A program / utility 640 having a set (at least one) of program modules 642 may be stored, for example, in memory 628. Such program modules 642 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 642 typically perform the functions and / or methods described in the embodiments of this application.
[0184] Electronic device 612 can also communicate with one or more external devices 614 (e.g., keyboard, pointing device, display 624, etc.), and with one or more devices that enable a user to interact with electronic device 612, and / or with any device that enables electronic device 612 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 622. Furthermore, electronic device 612 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 620. As shown, network adapter 620 communicates with other modules of electronic device 612 via bus 618. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 612, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0185] The processing unit 616 executes various functional applications and data processing by running at least one of the other programs among a plurality of programs stored in the system memory 628, such as implementing the minority sample processing method provided in the various embodiments of this application.
[0186] Example 7
[0187] This application also provides a computer-readable storage medium storing a computer program (or computer-executable instructions) thereon. When executed by a processor, the program performs a minority class sample processing method provided in this application: determining distance data between different original minority class samples in a minority class training sample set; determining sampling weights for each original minority class sample based on the distance data; and generating synthetic minority class samples based on the sampling weights, using the corresponding original minority class sample as the root sample.
[0188] The computer storage medium in this application embodiment can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0189] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0190] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0191] Computer program code for performing the operations of the embodiments of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0192] Note that the above are merely preferred embodiments and the technical principles employed in this application. Those skilled in the art will understand that this application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application, the scope of which is determined by the scope of the appended claims.
Claims
1. A minority class sample processing method, characterized by, The method comprises the following steps: determining distance data between different original minority class samples in a minority class training sample set; determining a sampling weight of each original minority class sample according to the distance data; generating a synthetic minority class sample with the corresponding original minority class sample as a root sample according to the sampling weight; The method further comprises the following steps: adding at least one synthetic minority class sample to the minority class training sample set to update the minority class training sample set; training a to-be-trained classification model according to the updated minority class training sample set to obtain a target classification model; The minority class sample is a user with credit risk. The method further comprises the following steps: calculating the distance between each original minority class sample by using the Euclidean distance to determine the distance data between different original minority class samples in the minority class training sample set; The method further comprises the following steps: determining cumulative distance data of each original minority class sample according to the distance data; determining a boundary deviation degree of each original minority class sample according to the cumulative distance data; determining a sampling weight of each original minority class sample according to the boundary deviation degree; The method further comprises the following steps: identifying an abnormal synthetic sample in each synthetic minority class sample; eliminating the abnormal synthetic sample from the updated minority class training sample set to update the minority class training sample set again; taking the sample in the updated minority class training sample set as an original minority class sample to return to the distance data determining operation until an iteration stop condition is met.
2. The method of claim 1, wherein, The method further comprises the following steps: obtaining a maximum value in the cumulative distance data; taking a difference between the maximum value and each cumulative distance data as a boundary distance value; determining the boundary deviation degree of the corresponding original minority class sample according to the boundary distance value.
3. The method of claim 2, wherein, The method further comprises the following steps: determining a maximum distance difference in the cumulative distance data; determining the boundary deviation degree of the corresponding original minority class sample according to a ratio between the boundary distance value and the maximum distance difference.
4. The method of claim 1, wherein, The method further comprises the following steps: determining a cumulative boundary deviation degree according to the boundary deviation degree; determining the sampling weight of the corresponding original minority class sample according to a ratio between the boundary deviation degree and the cumulative boundary deviation degree.
5. The method of claim 1, wherein, The method further comprises the following steps: determining a sampling number of each original minority class sample according to the preset total amount of synthetic samples and the sampling weight; generating a synthetic minority class sample with the corresponding original minority class sample as a root sample according to the sampling number.
6. The method of claim 1, wherein, The identifying of the abnormal synthetic samples in each of the synthetic minority class samples comprises: inputting each of the synthetic minority class samples into the target classification model to obtain a synthetic predicted category of each of the synthetic minority class samples; determining an abnormal synthetic sample according to the synthetic predicted category and a synthetic real category of the synthetic minority class sample.
7. The method of claim 1, wherein, Before the identifying of the abnormal synthetic samples in each of the synthetic minority class samples, the method further comprises: performing model evaluation on the target classification model; correspondingly, the identifying of the abnormal synthetic samples in each of the synthetic minority class samples comprises: if the model evaluation result meets an optimization iteration condition, identifying the abnormal synthetic samples in each of the synthetic minority class samples.
8. The method of claim 7, wherein, The model evaluation on the target classification model comprises: inputting a test sample into the target classification model to obtain a test predicted category; performing model evaluation on the target classification model according to the test predicted category and a test real category of the test sample.
9. The method of claim 8, wherein, The model evaluation on the target classification model according to the test predicted category and the test real category of the test sample comprises: determining a model evaluation index according to consistency of the test predicted category and the test real category of the test sample; wherein the model evaluation index comprises at least one of specificity, sensitivity and precision.
10. A minority class sample processing device, comprising: The method comprises: a distance determining module configured to determine distance data between different original minority class samples in a minority class training sample set; a weight determining module configured to determine a sampling weight of each of the original minority class samples according to each of the distance data; a sample synthesizing module configured to generate a synthetic minority class sample by taking a corresponding original minority class sample as a root sample according to each of the sampling weights. The device further comprises: a sample updating module configured to add at least one synthetic minority class sample to the minority class training sample set to update the minority class training sample set; a classification model obtaining module configured to train a to-be-trained classification model according to the updated minority class training sample set to obtain a target classification model; wherein the minority class sample is a user with credit risk; wherein the distance determining module is further configured to: calculate distances between the original minority class samples by using Euclidean distance to determine the distance data between different original minority class samples in the minority class training sample set; wherein the weight determining module comprises: a cumulative distance determining unit configured to determine cumulative distance data of each of the original minority class samples according to each of the distance data; a boundary deviation degree determining unit configured to determine a boundary deviation degree of each of the original minority class samples according to each of the cumulative distance data; a sampling weight determining unit configured to determine the sampling weight of each of the original minority class samples according to each of the boundary deviation degrees; wherein the minority class sample processing device further comprises: an abnormality identifying module configured to identify abnormal synthetic samples in each of the synthetic minority class samples; an abnormality removing module configured to remove the abnormal synthetic samples from the updated minority class training sample set to update the minority class training sample set again. An iteration condition judging module is configured to take the samples in the re-updated minority class training sample set as original minority class samples, return to perform the distance data determining operation, and continue until an iteration stop condition is met.
11. An electronic device, comprising: The method comprises: one or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement a minority class sample processing method as claimed in any one of claims 1-9.
12. A computer readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement a minority class sample processing method as claimed in any one of claims 1-9.
Citation Information
Patent Citations
Data classification method, device, electronic device and computer readable medium
CN107169518A
Oversampling method and device based on SMOTE algorithm and electronic equipment
CN112036515A