A sampling method for imbalanced data sets based on density and complexity

By calculating the sample density and complexity, clustering and sampling ratio in the imbalanced data set, and selecting benchmark and auxiliary samples, the problem of misclassification of minority class samples in the imbalanced data set classification algorithm is solved, and the balance and sampling of the data set are achieved. Classifier performance improvement.

CN114936589BActive Publication Date: 2024-09-24KUNMING UNIV OF SCI & TECH
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202210413977.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-17
Publication Date
2024-09-24
Estimated Expiration
2042-04-17

AI Technical Summary

Technical Problem

When existing classification algorithms deal with imbalanced data sets, it is easy to cause minority class samples to be misclassified, and existing sampling methods fail to effectively solve the problem of data set balance.

Method used

By calculating the density and complexity of samples, cluster minority class samples, determine the sampling rate, select benchmark samples and auxiliary samples with sample complexity as the probability, and randomly insert new samples to achieve the balance of the data set.

Benefits of technology

It effectively improves the balancing effect of imbalanced data sets and the consolidation of minority class decision boundaries, and improves the utilization of new samples and the performance of classifiers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114936589B
    Figure CN114936589B
Patent Text Reader

Abstract

The present invention relates to a method for sampling an imbalanced data set based on density and complexity, and belongs to the technical field of data classification. The present invention first quantifies the distribution of minority class samples and defines it as the complexity of the samples. The minority class samples are clustered by a density peak clustering algorithm, the sampling rate of each subcluster is determined according to the density and distribution of each subcluster, and the baseline sample and auxiliary sample are selected based on the complexity of the samples in the cluster, and finally new samples are randomly inserted between the baseline sample and the auxiliary sample. The present invention quantifies the distribution of samples, considers the number and complexity of samples at the same time in the sampling rate determination stage, and generates new samples based on complexity in the sample generation stage, thereby effectively improving the utilization rate of new samples.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a density- and complexity-based unbalanced data set sampling method, belonging to the technical field of data classification in data mining. Background Art

[0002] In recent years, the rapid development of technologies such as the Internet, big data, and cloud computing has generated massive data resources, providing conditions for the rapid development of artificial intelligence technology. Artificial intelligence consists of many basic fields, such as machine learning, natural language processing, and data mining, and data classification is one of the important means to provide information for research in these fields. Its essence is to use algorithms to fully and effectively learn the characteristics of data, obtain a classifier model, and use this classifier model to classify unknown data. After a long period of exploration and research, many classification algorithms have been proposed, such as Support Vector Machine (SVM), k-nearest neighbor (k-NN), decision tree (Decision Tree) and random forest (RF) classification algorithms. After learning some common data sets, they can obtain classifier models with good performance. When using unbalanced data sets to train classification models in traditional classification algorithms, the model will try to predict unknown samples as the majority class because of the principle of minimizing the loss function, which also leads to an increase in the probability of minority class samples being misclassified. However, the data sets collected in actual production life are usually unbalanced. The number of samples of each category in these data sets cannot be basically consistent, which brings challenges to some existing classification algorithms. Specifically, suppose there are 100 banknotes in an opaque bag, 99 of which are real and 1 is a counterfeit. Each time a banknote is put back, a banknote is randomly grabbed from the pocket and its authenticity is predicted. When we predict that the grabbed banknote is a real banknote every time, our prediction accuracy will reach 99%, but the probability of correctly predicting the grabbed banknote as a counterfeit is 0. Obviously, this result is not what we need. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a density and complexity-based unbalanced data set sampling method to solve the above-mentioned problem.

[0004] The technical solution of the present invention is: a density- and complexity-based unbalanced data set sampling method, which first quantifies the distribution of samples and defines it as the complexity of samples, then clusters the minority class samples in the data set, and then determines the sampling ratio of the minority class samples in the corresponding subcluster based on the number of samples and the sample distribution in each minority class subcluster after clustering, and selects samples with corresponding sampling ratios as benchmark samples in each subcluster with the probability of the complexity ratio of the samples, and finally performs k-nearest neighbor queries on these benchmark samples, and then selects auxiliary samples with the probability of the complexity ratio of the samples, and randomly inserts a new sample between the benchmark sample and the auxiliary sample.

[0005] The specific steps are:

[0006] Step 1: Calculate the density and complexity of minority class samples.

[0007] Step 2: Cluster the minority class samples.

[0008] Step 3: For each sub-cluster after clustering, calculate the cluster density and cluster complexity respectively, and use this to calculate the cluster density weight and cluster complexity weight.

[0009] Step 4: Calculate the sampling weight and sampling ratio of each sub-cluster.

[0010] Step 5: In each sub-cluster, select benchmark samples and auxiliary samples according to the sampling ratio of the sub-cluster and the sample complexity as a guide, and randomly insert new samples between the selected benchmark samples and auxiliary samples.

[0011] The Step 1 is specifically as follows:

[0012] Step 1.1: Use the Gaussian kernel function to estimate the density of each minority class sample.

[0013] Step 1.2: Set the nearest neighbor parameter k.

[0014] Step 1.3: Perform k-nearest neighbor query on each minority class sample.

[0015] Step 1.4: Calculate the number of samples that are not minority class samples among the k nearest neighbors, and use this number as the complexity of the corresponding minority class samples.

[0016] The Step 3 is specifically as follows:

[0017] Step 3.1: Take the sum of the sample densities within the cluster as the cluster density.

[0018] Step 3.2: Take the sum of the complexity of samples within the cluster as the cluster complexity.

[0019] Step 3.3: Calculate the density weight of the cluster.

[0020] Step 3.4: Calculate the complexity weight of the cluster.

[0021] Step 3.5: Repeat the above steps until the density weights and complexity weights of all clusters are calculated.

[0022] The Step 4 is specifically as follows:

[0023] Step 4.1: The sub-cluster uses the linear combination of its own density weight and complexity weight as the sampling weight for the cluster.

[0024] Step 4.2: Calculate the sampling ratio of the sub-cluster based on the sampling weight.

[0025] Step 4.3: Repeat the above steps until the sampling weights of all clusters are calculated.

[0026] The Step 5 is specifically as follows:

[0027] Step 5.1: Take the ratio of the complexity of the minority class sample to the complexity of the cluster it belongs to as the selection probability, and select the benchmark sample according to the probability.

[0028] Step 5.2: Query the k nearest neighbors of the selected benchmark sample.

[0029] Step 5.3: Take the ratio of the complexity of the sample among the k nearest neighbors to the sum of the complexities of all the k nearest neighbor samples as the selection probability, and select auxiliary samples according to the probability.

[0030] Step 5.4: Randomly insert new samples between the baseline samples and the auxiliary samples.

[0031] Step 5.5: Repeat the above steps until all clusters generate new samples equal to the number of sampling multiples.

[0032] The beneficial effects of the present invention are:

[0033] 1. In the sampling ratio determination stage, the present invention takes into account the number and distribution of samples at the same time, effectively improving the balancing effect of new samples on unbalanced data between classes and within classes.

[0034] 2. The present invention is guided by sample complexity and selects reference samples and auxiliary samples in a probabilistic extraction manner, which effectively improves the utilization rate of new samples and improves the consolidation effect of the decision boundary of the minority class. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 is a flow chart of the steps of the present invention;

[0036] Figure 2 It is a sample distribution complexity diagram of the abalone data set in an embodiment of the present invention. DETAILED DESCRIPTION

[0037] The present invention will be further described below in conjunction with the accompanying drawings and specific implementation methods.

[0038] Example 1: Figure 1 As shown in Figure 1, a density and complexity-based unbalanced data set sampling method is described. The specific steps are as follows:

[0039] Step 1: Use the Gaussian kernel function according to the formula Estimate the density of each minority class sample, where d ij represents the distance between sample i and sample j, d c is the cutoff distance, usually d c Set to 7% of the maximum distance between samples.

[0040] The complexity of the minority class samples is calculated according to the distribution of the minority class samples, the k nearest neighbors of the minority class samples are queried, the number of samples that do not belong to the minority class samples among the k nearest neighbors is counted, and the number of samples counted is recorded as the complexity of the minority class samples.

[0041] According to the formula Calculate the complexity of each minority class sample, where NN i represents the k nearest neighbor set of sample i, j represents NN i A sample of C j represents the type of sample j, when C j When the type is max (majority class), the value of I is 1.

[0042] Step 2: Cluster the minority samples using the density peak clustering algorithm combined with the minority sample density calculated in step 1, and divide the minority samples into multiple sub-clusters.

[0043] Step 3: Based on the density and complexity of the minority class samples obtained in Step 1, calculate the density and complexity of each sub-cluster obtained after clustering in Step 2.

[0044] The density of the sub-cluster is calculated according to the formula Calculated, where j represents the minority cluster c i The samples in ,ρ j represents the density of minority class sample j.

[0045] The complexity of the subcluster is calculated according to the formula Calculated, where j represents the minority cluster c i Samples in cpl j represents the complexity of the minority class sample j.

[0046] The density weight and complexity weight of each subcluster are calculated based on the density and complexity of each subcluster. Since the denser the subcluster, the larger the number of samples in the cluster, the smaller the sampling rate should be, and the density weight of the subcluster should be inversely proportional to the density of the subcluster. Therefore, the density weight of the sub-cluster is calculated according to the formula Calculated, where represents the density of cluster i, and C represents all minority clusters.

[0047] The complexity weight of the sub-cluster is calculated according to the formula It is calculated that, where C represents all minority class clusters, and the numerator and denominator are added by 1 to avoid the situation where the complexity of all minority classes is 0.

[0048] Repeat this step until the density weights and complexity weights of all subclusters are calculated.

[0049] Step 4: Calculate the sampling weight of each sub-cluster, taking into account the number and distribution of samples in the sub-cluster. The larger the number of samples, the smaller the sampling ratio; the more complex the distribution of samples, the larger the sampling ratio. Therefore, according to the formula Calculate the sampling weight of each subcluster, where represents the complexity weight of cluster i, represents the density weight of cluster i, and α is a random number between 0 and 1.

[0050] The final sampling ratio is calculated based on the sampling weight of each sub-cluster. Assuming the total sampling amount is m, according to the formula Here, j represents a minority cluster. Repeat this step until the sampling ratios of all subclusters are calculated.

[0051] Step 5: The specific method of selecting the benchmark sample is to use the complexity of the sample divided by the sum of the complexity of all samples in the cluster as the probability of the sample being extracted. According to the extraction probability, a sample is selected from the current cluster as the benchmark sample, according to the formula Calculate the extraction probability of the benchmark sample, where c is the cluster where the minority class sample i is located, j is the sample in cluster c, and N is the number of minority class samples in cluster c.

[0052] Assuming that a sample has been extracted from a minority class subcluster as a benchmark sample, the next step is to query the k nearest neighbor samples of the benchmark sample in the current subcluster, and then select another sample from the queried k nearest neighbors as an auxiliary sample.

[0053] The selection of auxiliary samples is based on the ratio of the complexity of the sample in the nearest neighbor to the sum of the complexity of all the nearest neighbor samples as the extraction probability to select auxiliary samples. According to the formula Calculate the extraction probability of auxiliary samples, where NN represents the current neighbor space of sample i, j represents the sample in the current neighbor space, and N represents the number of samples in the current neighbor space.

[0054] A new sample is randomly inserted between the selected baseline sample and the auxiliary sample. This step is repeated until all clusters generate new samples equal to the sampling multiplier.

[0055] Example 2: Taking the Abalone dataset as an example, the method proposed in the present invention is used to sample the dataset to achieve dataset balance and improve the classification performance of the classifier for minority class samples.

[0056] Since the original data of Abalone is multi-category, we first take out samples of category 16 and category 6 from the dataset and construct a new dataset Abalone. The dataset description is shown in Table 1. The ratio of the number of samples of category 16 and category 6 in the dataset is 1 to 3.9.

[0057]

[0058] Table 1: Abalone dataset

[0059] The method proposed in the present invention is implemented on the Abalone dataset after category merging. The specific steps are as follows:

[0060] Step 1: According to the formula and formula The sample density and complexity of all 16 categories in the Abalone dataset are calculated respectively.

[0061] Step 2: Take all samples of category 16 from the data set and cluster them according to the density peak clustering algorithm. After clustering, three sub-clusters are obtained. For the convenience of description, the three sub-clusters are named using the sample numbers of the three minority class samples selected as cluster centers during the clustering process: cluster 11, cluster 50, and cluster 168.

[0062] Step 3: According to the formula and formula The cluster density and cluster complexity of cluster 11, cluster 50 and cluster 168 in step 2 are calculated respectively.

[0063] Step 4: According to the formula The sampling weights of clusters 11, 50, and 168 are calculated respectively, where α is 0.2; according to the description in Table 1, the difference in the number of samples of category 16 and category 6 is 192, which will be used as the total number of samples generated in the end. According to the formula The sampling ratios of the three sub-clusters are calculated respectively, as shown in Table 2.

[0064]

[0065] Table 2: Sampling ratios of the three subclusters of the Abalone dataset

[0066] Step 5: Generate new minority samples according to the sampling ratios assigned to the three subclusters in Step 4. Taking cluster 11 as an example, calculate the ratio of the complexity of each minority sample in the cluster to the sum of the complexity of all minority samples in the cluster, and use this ratio as the probability of the corresponding minority sample being extracted as the benchmark sample.

[0067] Assume that a minority class sample has been extracted as a benchmark sample according to probability. Next, query the k nearest neighbors of the sample. Here, the k value is set to 5, that is, query the 5 nearest neighbors of the sample. In order to select another one from these 5 nearest neighbors as an auxiliary sample, calculate the ratio of the complexity of the 5 nearest neighbor samples to the sum of the complexity of these 5 nearest neighbor samples, and use this as the extraction probability. Repeatedly extract the benchmark sample and its corresponding auxiliary sample in cluster 11, and insert new samples between them until the number of inserted new samples reaches the sampling multiple assigned by cluster 11. The other two clusters complete the generation of samples in the same way.

[0068] After the above five steps, the present invention has completed the sampling of the imbalanced data set, and then the sampled data set can be applied to the existing classification algorithm. For the completeness of the embodiment, the sampled data set is classified and tested using the decision tree classification algorithm. Table 3 shows the accuracy of the data set in the decision tree after being sampled by the sampling method proposed by the present invention and three other commonly used sampling methods.

[0069]

[0070] Table 3: Precision in decision trees

[0071] It can be seen from the above table that the method proposed by the present invention is effective. Figure 2 The overall complexity of samples in the Abalone dataset after being sampled by several different sampling methods is shown in FIG. 1 . It can be seen that after being sampled by the sampling method of the present invention, the complexity of the samples in the dataset is lower, which further illustrates the effectiveness of the present invention.

[0072] The specific implementation modes of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above implementation modes, and various changes can be made within the knowledge scope of ordinary technicians in this field without departing from the purpose of the present invention.

Claims

1. A density and complexity based sampling method for imbalanced datasets. Features: The data set is the Abalone data set; Step 1: Calculate the density and complexity of minority class samples; Step 2: Cluster the minority class samples; Step 3: For each sub-cluster after clustering, calculate the cluster density and cluster complexity respectively, and use this to calculate the cluster density weight and cluster complexity weight; Step 4: Calculate the sampling weight and sampling ratio of each sub-cluster; Step 5: Select benchmark samples and auxiliary samples in each sub-cluster according to the sampling ratio of the sub-cluster and the sample complexity, and randomly insert new samples between the selected benchmark samples and auxiliary samples; The Step 5 is specifically as follows: Step 5.1: Take the ratio of the complexity of the minority class sample to the complexity of the cluster to which it belongs as the selection probability, and select the benchmark sample according to the probability; Step 5.2: Query the k nearest neighbors of the selected benchmark sample; Step 5.3: Take the ratio of the complexity of the sample in the k nearest neighbors to the sum of the complexity of all k nearest neighbors as the selection probability, and select auxiliary samples according to the probability; Step 5.4: Randomly insert new samples between the benchmark samples and the auxiliary samples; Step 5.5: Repeat the above steps until all clusters generate new samples equal to the number of sampling multiples.

2. The method for sampling an imbalanced data set based on density and complexity according to claim 1, It is characterized in that The Step 1 is specifically as follows: Step 1.1: Use the Gaussian kernel function to estimate the density of each minority class sample; Step 1.2: Set the nearest neighbor parameter k; Step 1.3: Perform k-nearest neighbor query on each minority class sample; Step 1.4: Calculate the number of samples that are not minority class samples among the k nearest neighbors, and use this number as the complexity of the corresponding minority class samples.

3. The method for sampling an imbalanced data set based on density and complexity according to claim 1, It is characterized in that The Step 3 is specifically as follows: Step 3.1: The sum of the sample densities within the cluster is taken as the cluster density; Step 3.2: The sum of the complexity of the samples within the cluster is taken as the cluster complexity; Step 3.3: Calculate the density weight of the cluster; Step 3.4: Calculate the complexity weight of the cluster; Step 3.5: Repeat the above steps until the density weights and complexity weights of all clusters are calculated.

4. The method for sampling an imbalanced data set based on density and complexity according to claim 1, It is characterized in that The Step 4 is specifically as follows: Step 4.1: The sub-cluster uses its own linear combination of density weight and complexity weight as the sampling weight for the cluster; Step 4.2: Calculate the sampling ratio of the sub-cluster according to the sampling weight; Step 4.3: Repeat the above steps until the sampling weights of all clusters are calculated.

Citation Information

Patent Citations

  • Weight clustering and under-sampling-based unbalanced data classification method

    CN106778853A

  • Unbalanced data classification method based on clustering downsampling

    CN107688831A

  • A K-nearest neighbor and multi-class merge based density peak clustering method and image segmentation system

    CN109409400A

  • A density peak value clustering method based on KNN

    CN109697471A

  • Unbalanced data processing method based on clustering and boundary points

    CN112633337A