Imbalanced data classification method and system based on SMOTE and dynamic threshold optimization
By balancing the class distribution in the training set using the SMOTE technique and adjusting the boundary of the classification model using a dynamic threshold algorithm, the decision bias problem in imbalanced datasets is solved, improving the recognition rate of minority class samples and the adaptability of the model.
Patent Information
- Application Number
- CN202511369686.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2025-12-19
AI Technical Summary
When dealing with imbalanced data, traditional machine learning algorithms tend to shift the decision boundary towards the majority class, which has a larger sample size, leading to a decrease in the recognition rate of minority class samples. Furthermore, existing methods use synthetic samples in the validation and test sets, resulting in distorted model performance evaluation results.
The SMOTE technique is used to balance the class distribution of the training set, and the boundary of the classification model is adjusted by a dynamic threshold algorithm to optimize the decision threshold of the classification model, thereby improving the recognition rate of minority class samples.
It significantly improves the recognition accuracy of minority class samples, enhances the model's adaptability to class distribution, overcomes the bias problem of traditional classifiers towards majority class samples, and improves the model's generalization and practical value.
Smart Images

Figure CN121167446A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine learning data processing technology, and more specifically, to an imbalanced data classification method and system based on SMOTE and dynamic threshold optimization. Background Technology
[0002] In tasks involving identifying crop production areas such as tobacco and agricultural products, yields vary across regions due to natural factors like climate, soil, and topography, resulting in an imbalance in the class distribution of collected samples. Traditional machine learning algorithms, aiming to maximize global classification accuracy, tend to have their decision boundaries shift towards the majority class, which has a larger sample size, leading to a significant decrease in the recognition rate (recall) of minority class samples. Directly using such imbalanced data to build models weakens the model's ability to identify areas with lower crop yields (minority classes), severely limiting the model's generalization and practical value.
[0003] Existing technologies primarily balance data distribution through sampling methods (such as SMOTE and its improved algorithms). For example, existing technology CN201610114730.3 proposes to focus on boundary samples and outliers in SMOTE to improve the representativeness of generated samples; patent CN201510953660.6 proposes to combine SMOTE and Boosting, adjusting the weight of synthetic samples in the loss function through a penalty factor, guiding the classifier to focus on samples with high credibility and reasonable distribution, thereby improving the accuracy of the minority class. However, existing methods have key limitations: First, most studies uniformly apply sampling techniques to the global dataset (including training, validation, and test sets), resulting in synthetic samples being mixed into the validation and test sets. The model performance evaluation results are distorted due to data contamination and cannot reflect the model's classification ability on real, unprocessed data. Second, traditional classification models generally use a fixed probability threshold to determine the class of a sample. When the probability value output by the model is greater than or equal to the threshold, the sample is classified into that class; when it is lower than the threshold, it is classified into another class. This leads to the influence of the difference in sample size between classes on the decision boundary, causing minority class samples to be incorrectly rejected due to low classification confidence.
[0004] Currently, the market urgently needs technical solutions that can effectively address the problem of uneven distribution of samples among different classes and improve the model's learning ability for minority class samples. Summary of the Invention To address the problems existing in the prior art, this invention proposes an imbalanced data classification method and system based on SMOTE and dynamic threshold optimization. This aims to overcome the bias of traditional classifiers towards the majority class and significantly improve the recognition accuracy of the minority class. The technical solution adopted in this invention is as follows: In a first aspect, the present invention provides an imbalanced data classification method based on SMOTE and dynamic threshold optimization, the method comprising: Obtain the dataset, in which the data consists of samples, and all samples belong to several categories; The dataset, after data preprocessing, is divided into training set, validation set, and test set according to a certain ratio; After balancing the number of samples in each class in the training set using the SMOTE (synthetic minority oversampling technique), a pre-built classification model is trained based on the training set. Based on the validation set, a dynamic thresholding algorithm is used to adjust the boundary of the classification model to obtain the optimal threshold for all categories. The classification model is optimized by using the optimal thresholds for all categories as the classification boundaries of the classification model. The classification performance of the optimized classification model is evaluated based on the test set.
[0005] Preferably, dividing the preprocessed dataset into training, validation, and test sets proportionally includes: Perform data preprocessing on the data in the dataset; The dataset is divided into training, validation, and test sets proportionally using the hold-out method and stratified sampling.
[0006] Preferably, the data preprocessing includes Min-Max normalization calculations to eliminate the influence of the dimensions of chemical components.
[0007] Preferably, the step of using SMOTE (synthetic minority oversampling technique) to balance the number of samples in each class in the training set, and then constructing a classification model using the training set, includes the following sub-steps: The category with the most samples in the training set is designated as the "majority category," and the remaining categories are designated as the "minority category." The SMOTE technique is used to expand the number of samples in each minority category to match the number of samples in the majority category, so that the number of samples in the majority category and the number of samples in each minority category are balanced. After balancing the number of samples in the majority class with the number of samples in each minority class, a pre-built classification model is trained based on the training set.
[0008] It is understandable that the goal is to balance the number of samples in the majority class with the number of samples in each minority class—that is, to expand the number of samples in each minority class to match the number of samples in the majority class. This balances the training set, and training the classification model with the balanced training set can resolve decision bias caused by class imbalance. It is important to note that only the training set uses the SMOTE technique for sample augmentation; the validation and test sets maintain their original distribution after data preprocessing, preserving the authenticity of the validation and test sets.
[0009] Preferably, the classification model is constructed using any one of the following models: Support Vector Machine (SVM), Random Forest (RF), Convolutional Neural Network (CNN).
[0010] Preferably, the step of adjusting the boundary of the classification model using a dynamic threshold algorithm based on the validation set to obtain the optimal threshold for all categories includes the following sub-steps: The classification model is used to obtain the probability value of each sample in the validation set being classified into each category. Generate several different candidate thresholds with values ranging from 0 to 1; The classification model uses all candidate thresholds as decision thresholds, and performs classification prediction based on the probability values of each sample in the validation set belonging to each category, generating prediction results corresponding to all candidate thresholds. The prediction results for each candidate threshold include: true positive samples, false positive samples, and false negative samples. The prediction results corresponding to all candidate thresholds are compared with the known categories of each sample in the validation set, and the F1-Score of each candidate threshold under each category is calculated. The candidate threshold with the highest F1-Score for each category is taken as the optimal threshold for that category. Summarize the optimal thresholds for each category.
[0011] Preferably, the generation of several different candidate thresholds with values ranging from 0 to 1 includes: The range of values is set to [0.1, 0.9]; Within the range of values, 50 equally spaced candidate thresholds are generated, with a step size of 0.016 between any two adjacent candidate thresholds.
[0012] Preferably, after optimizing the classification model by using the optimal thresholds of all categories as the classification boundaries of the classification model, the method further includes setting decision logic for the classification model.
[0013] Preferably, the determination logic includes: The sample is classified using the discriminant model to obtain the probability value of the sample belonging to each category. The decision probability value and the optimal threshold corresponding to each category are compared respectively, and the category whose decision probability value is greater than the optimal threshold is taken as the category of the sample. If multiple categories have a probability value greater than the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample. If the probability values for all categories are less than or equal to the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample.
[0014] Preferably, the method further includes: using the optimized classification model for classification prediction of the data to be predicted.
[0015] In a second aspect, the present invention provides an imbalanced data classification system based on SMOTE and dynamic threshold optimization, characterized in that the system comprises: A data acquisition unit is used to acquire a dataset, wherein the data in the dataset are samples, and it is known that all samples belong to several categories; A data partitioning unit is used to divide the preprocessed dataset into a training set, a validation set, and a test set according to a certain ratio. The model building unit is used to train a pre-built classification model based on the training set after the number of samples of each class in the training set is balanced by using the SMOTE (synthetic minority oversampling technique). The model adjustment unit is used to adjust the boundary of the classification model based on the validation set using a dynamic threshold algorithm to obtain the optimal threshold for all categories. The model optimization unit is used to optimize the classification model by using the optimal thresholds of all categories as the classification boundaries of the classification model.
[0016] Preferably, the system further includes a model evaluation unit for evaluating the classification performance of the optimized classification model based on a test set.
[0017] Preferably, the system further includes a prediction application module, used to apply the optimized classification model to the classification prediction of the data to be predicted.
[0018] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the aforementioned imbalanced data classification method based on SMOTE and dynamic threshold optimization.
[0019] In a fourth aspect, the present invention provides an electronic device including a bus, a transceiver, a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the transceiver, the memory, and the processor are connected via the bus, characterized in that the computer program, when executed by the processor, implements the aforementioned imbalanced data classification method based on SMOTE and dynamic threshold optimization.
[0020] This invention offers several advantages: it provides a method and system for processing imbalanced datasets by integrating SMOTE and dynamic threshold optimization. SMOTE technology is used to synthesize and amplify minority class samples, balancing the class distribution in the training set. Simultaneously, by dynamically adjusting the classification boundaries to better suit the characteristics of each class's data distribution, the recognition rate for minority classes is improved. The combined use of SMOTE and threshold optimization effectively addresses the problem of imbalanced sample distribution between classes, improving the performance of production area discrimination models.
[0021] Compared with existing technologies, the imbalanced dataset data processing method that integrates SMOTE and dynamic threshold optimization provided by this invention can more effectively solve the problem of imbalanced sample distribution between categories, improve the model's learning ability for minority class samples, and enhance the model's adaptability to differences in category distribution. This significantly improves the recognition recall rate of key minority classes and the overall reliability of classification decisions, overcomes the bias problem of traditional classifiers towards majority class samples, and significantly improves the recognition accuracy of minority class samples. Attached Figure Description
[0022] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating the imbalanced data classification method based on SMOTE and dynamic threshold optimization in Embodiment 1 of the present invention.
[0024] Figure 2 This is the architecture of the classification model described in Embodiment 1 of the present invention.
[0025] Figure 3 This is a schematic diagram illustrating how the dynamic threshold algorithm is used in Embodiment 1 of the present invention to adjust the boundary of the classification model and obtain the optimal threshold for all categories.
[0026] Figure 4This is a quantitative illustration of the classification effect of the imbalanced data classification method based on SMOTE and dynamic threshold optimization in Embodiment 1 of the present invention.
[0027] Figure 5 The model evaluation unit is an optional logical block diagram of the imbalanced data classification system based on SMOTE and dynamic threshold optimization in Embodiment 2 of the present invention. Detailed Implementation
[0028] The present invention will now be described in detail with reference to the accompanying drawings and embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other.
[0029] The following detailed description is exemplary and intended to provide further detailed explanation of the invention. Unless otherwise specified, all technical terms used in this invention have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. The terminology used in this invention is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention.
[0030] Example 1: like Figure 1 As shown, an imbalanced data classification method based on SMOTE and dynamic threshold optimization is proposed, the method comprising: S100. Obtain the dataset, wherein the data in the dataset are samples, and all samples belong to several categories.
[0031] In this embodiment, a dataset was constructed using several tobacco leaves from eight major ecological tobacco-growing regions in China. These ecological regions are referred to simply as "production areas." Categories were created for each production area, and samples were constructed for each tobacco leaf. In the dataset, each category corresponds to one production area, and each sample corresponds to one tobacco leaf. All samples belong to several categories, indicating that each sample corresponds to a known category, i.e., the actual category to which the sample belongs.
[0032] This embodiment aims to address the problem of low recognition rates for a few categories of samples in existing classification models due to the uneven distribution of tobacco leaf quantity in different ecological regions. In implementation, representative chemical components can be selected from tobacco leaves to construct sample features, thereby achieving high-quality classification in each production area based on the chemical components in tobacco leaves. Although this embodiment lists eight major production areas as examples, it does not mean that the invention can only classify these eight areas. The specific number of production areas (categories) and samples can be determined according to needs. This embodiment uses multiple chemical components in tobacco leaves as sample features to construct a production area classification (judgment) model. Since the construction of sample features is existing technology, and the selection of specific sample features does not affect the implementation of this invention, it will not be elaborated upon here.
[0033] S200. The dataset after data preprocessing is divided into training set, validation set and test set according to the proportion.
[0034] Specifically, dividing the preprocessed dataset into a training set, a validation set, and a test set proportionally may include steps S210 and S220.
[0035] S210. Perform data preprocessing on the data in the dataset.
[0036] The data preprocessing may include Min-Max normalization calculations to eliminate the influence of the dimensions of chemical components.
[0037] S220. The dataset is divided into training, validation, and test sets proportionally using the hold-out method and stratified sampling. The training set is used for subsequent classification model training, the validation set is used to adjust the boundaries of the classification model, and the test set is used to evaluate the performance of the classification model.
[0038] Furthermore, the ratio of the training set, validation set, and test set can be determined according to actual needs, and can be 6:2:2.
[0039] S300. After using SMOTE (synthetic minority oversampling technique) to balance the number of samples in each class in the training set, a pre-built classification model is trained based on the training set.
[0040] The SMOTE technique was used to augment the training set, rebalancing the imbalanced data. The number of samples in the training set before and after SMOTE balancing is shown in Table 1. The validation and test sets retained their original data distribution.
[0041] Table 1 Comparison of training set samples before and after equalization
[0042] Specifically, step S300 involves using SMOTE technology to balance the number of samples in each category in the training set, and then constructing a classification model using the training set, including steps S310 to S330.
[0043] S310. The category with the most samples in the training set is designated as the "majority category", and the remaining categories are designated as the "minority category".
[0044] Table 1 shows that category VII is the "majority category," while the other categories are considered "minority categories." From the sample sizes before category balance, it's clear that the minority categories are significantly imbalanced. Balance means that the sample size of the minority category is equal to the sample size of the majority category.
[0045] S320. Using SMOTE technology, the number of samples in each minority category is expanded to match the number of samples in the majority category, so that the number of samples in the majority category and the number of samples in each minority category are balanced.
[0046] It is understandable that the goal is to balance the number of samples in the majority class with the number of samples in each minority class—that is, to expand the number of samples in each minority class to match the number of samples in the majority class. This balances the training set, and training the classification model with the balanced training set can resolve decision bias caused by class imbalance. It is important to note that only the training set uses the SMOTE technique for sample augmentation; the validation and test sets maintain their original distribution after data preprocessing, preserving the authenticity of the validation and test sets.
[0047] The SMOTE technology used in step S320 may include the following steps (1) to (5).
[0048] Step (1): Select minority category i from all minority categories in sequence. In this embodiment, i ∈ (Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ, Ⅵ, Ⅷ).
[0049] Step (2): Randomly select one sample from all samples of the minority class i as the original sample. x o .
[0050] Step (3): Determine the original sample x o Given K nearest neighbor samples (K is usually an odd number, such as 3, 5, 7, etc.), respectively, compare the K nearest neighbor samples with the corresponding original samples. x o A new synthetic sample is generated by linear interpolation. x new As shown below: x new =x o+ λ(x k -x o ) ; In the formula, x new Represents a synthetic sample. λA random number between 0 and 1 x k yes x o The k-th nearest neighbor sample, 1<=k<=K.
[0051] Step (4): Calculate the upsampling factor corresponding to the minority category i. m i ,like m i If the value is 1, proceed to step (5); otherwise, return to step (2). This is achieved by adjusting the upsampling ratio. m i It can be determined whether the minority category i has reached a balanced state, thereby expanding the sample size of the minority category i to be consistent with the sample size of the majority category, so as to achieve a balance between the sample size of the majority category and the sample size of the minority category i.
[0052] The upsampling factor represents the degree of imbalance in the minority class i, as shown below:
[0053] In the formula, n 1 represents the number of samples in the majority category; n i Represents the number of samples in the minority category i; i is the number of a minority category, i∈(Ⅰ、Ⅱ、Ⅲ、Ⅳ、Ⅴ、Ⅵ、Ⅷ); m i This represents the upsampling factor for the minority category i.
[0054] Step (5): If the minority category i is the last minority category—that is, the sample size of all minority categories has reached a balance with the sample size of the majority category—then terminate; otherwise, it means that there are other minority categories that need to expand their sample size, and return to step (1).
[0055] S330. After balancing the number of samples in the majority class with the number of samples in each minority class, train the pre-built classification model based on the training set.
[0056] Preferably, the classification model can be constructed using any of the following models: Support Vector Machine (SVM), Random Forest (RF), Convolutional Neural Network (CNN).
[0057] This embodiment takes the construction of the classification model using a convolutional neural network (CNN) as an example. For instance, the feature vectors of the 70 chemical components mentioned above are reconstructed into a 9×8 matrix, and double-layer outer padding (padding=2) is applied to generate a 13×14 extended matrix, preserving edge feature responses to avoid loss of edge information during the convolution process.
[0058] like Figure 2 As shown, the classification model can adopt a five-stage convolutional architecture.
[0059] Phase 1: Two convolutional layers (3×3 kernel size, 32 channels), batch normalization layer, max pooling layer, and Dropout layer (30% dropout rate).
[0060] The second stage consists of two convolutional layers (64 channels) and a Dropout layer (40% dropout rate).
[0061] The third stage consists of two convolutional layers (128 channels) and a Dropout layer (50% dropout rate).
[0062] Phase 4: Replace fully connected layers with global average pooling.
[0063] Phase 5: Softmax Classifier. The network design incorporates L2 weight regularization (λ=1e-4) and the AdamW optimizer (lr=1e-4, wd=1e-4), with Xavier initialization ensuring weight reproducibility. The classification model training process introduces an early stopping mechanism (early stopping patience value=15) and dynamic learning rate decay (decay factor=0.5), using a batch size of 128 for 100 training rounds.
[0064] S400. Based on the validation set, a dynamic threshold algorithm is used to adjust the boundary of the classification model to obtain the optimal threshold for all categories.
[0065] Specifically, step S400 involves adjusting the boundary of the classification model based on the validation set using a dynamic threshold algorithm to obtain the optimal threshold for all categories, including steps S410 to S460.
[0066] S410. Using the classification model, obtain the probability value of each sample in the validation set being determined to belong to each category.
[0067] In S410, for each sample, we need to obtain the probability values of belonging to production areas I, II, III, IV, V, VI, VII, and VIII, respectively. For example, for sample 1, we obtain the probability values of sample 1 belonging to production areas I, II, III, IV, V, VI, VII, and VIII, respectively.
[0068] S420. Generate several different candidate thresholds with values ranging from 0 to 1.
[0069] The generation of several different candidate thresholds with values ranging from 0 to 1 includes steps S421 and S422.
[0070] S421. Set the value range to [0.1, 0.9].
[0071] S422. Within the range of values, generate 50 equally spaced candidate thresholds, with a step size of 0.016 between two adjacent candidate thresholds.
[0072] S430. The classification model uses all candidate thresholds as decision thresholds, and performs classification prediction based on the probability values of each sample in the validation set belonging to each category, generating prediction results corresponding to all candidate thresholds.
[0073] The prediction results corresponding to each candidate threshold include: true positive samples (samples correctly predicted as the corresponding category), false positive samples (the number of samples incorrectly predicted as the corresponding category), and false negative samples (the number of samples of the corresponding category that are predicted as other categories).
[0074] It is worth noting that each candidate threshold should be used independently as a decision threshold and participate in the prediction of all samples in the validation set. Taking sample 1 as an example, assume that the probability values of sample 1 belonging to each category [Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ, Ⅵ, Ⅶ, Ⅷ] are [0.10, 0.25, 0.30, 0.05, 0.15, 0.02, 0.08, 0.05]. Assuming the first candidate threshold is 0.10, the third candidate threshold is calculated to be 0.132. Taking the third candidate threshold as an example: the classification model uses the third candidate threshold as the decision threshold, and uses the probability values [0.10, 0.25, 0.30, 0.05, 0.15, 0.02, 0.08, 0.05] of sample 1 belonging to each category as the basis for judgment to predict which category sample 1 belongs to. The prediction result for sample 1 under the third candidate threshold is: sample 1 is judged to belong to category [II, III, V] and not to category [I, III, VI, VII, VIII]. This process is repeated to obtain the prediction results of the classification model for all samples under the third candidate threshold as the decision threshold. The prediction process for other samples is similar to the above process. After obtaining all prediction results, the model is finally divided into units based on the candidate threshold, and the prediction results corresponding to the classification prediction of all samples under each candidate threshold as the decision threshold can be aggregated.
[0075] In the prediction results corresponding to each candidate threshold, by comparing the prediction results of each sample with the known category corresponding to that sample, it is easy to distinguish the true positive samples (samples correctly predicted as the corresponding category), false positive samples (samples incorrectly predicted as the corresponding category), and false negative samples (samples of the corresponding category that are predicted as other categories) corresponding to that candidate threshold.
[0076] S440. Compare the prediction results corresponding to all candidate thresholds with the known categories of each sample in the validation set, and calculate the F1-Score of each candidate threshold under each category.
[0077] The F1-Score for each candidate threshold in category i can be calculated using the following formula:
[0078] In the formula, i represents the category number, i∈(Ⅰ、Ⅱ、Ⅲ、Ⅳ、Ⅴ、Ⅵ、Ⅶ、Ⅷ); F1-Score i This is the F1-Score value corresponding to the candidate threshold in category i.
[0079] TP i This represents the number of true positive samples in category i, i.e., the number of samples correctly predicted to belong to category i. FP i is the number of false positive samples of category i, that is, the number of samples that are incorrectly predicted to belong to category i; FN i is the number of false negative samples of category i, that is, the number of samples of category i that are predicted to belong to other categories.
[0080] S450. Take the candidate threshold with the largest F1-Score for each category as the optimal threshold for that category. .
[0081] Understandably, by comparing the prediction results corresponding to all candidate thresholds with the known categories of each sample in the validation set, we can obtain the true positive samples corresponding to each candidate threshold in category i. TP i False positive samples FP i and false negative samples FN iBy statistical analysis, the number of true positive samples, false positive samples, and false negative samples corresponding to each candidate threshold under category i can be obtained, and the F1-Score corresponding to each candidate threshold under category i can be calculated.
[0082] For each category, the F1-Score value of each candidate threshold in that category is calculated. That is, each category corresponds to multiple candidate thresholds and F1-Score combinations. The candidate threshold with the largest F1-Score value is obviously the best decision threshold for the classification model to determine whether a sample belongs to that category, and thus serves as the classification boundary of the classification model.
[0083] In this embodiment, the optimal threshold for each category can be selected using the following formula: ; In the formula, represents the optimal threshold corresponding to category i, where i∈(Ⅰ、Ⅱ、Ⅲ、Ⅳ、Ⅴ、Ⅵ、Ⅶ、Ⅷ).
[0084] S460. Summarize the optimal thresholds for all categories: .
[0085] The optimal thresholds for the eight categories were ultimately generated by S400. See Table 2 below and Figure 3 .
[0086] Table 2 Optimal Thresholds for Each Category (Production Area)
[0087] The core idea of S400 is to adjust or modify the decision threshold for the classification model to make the final category prediction based on the importance or misclassification cost of each category; that is, the optimal threshold for each category. The optimal threshold for each category is used as the decision threshold for the classification model to determine whether a sample belongs to that category, thereby realizing the extension of the dynamic threshold algorithm to the classification problem of multi-regional production areas.
[0088] S500. The classification model is optimized by using the optimal thresholds of all categories as the classification boundaries of the classification model.
[0089] Preferably, after optimizing the classification model by using the optimal thresholds of all categories as the classification boundary of the classification model in S500, the method further includes setting decision logic for the classification model.
[0090] Preferably, the determination logic includes: The sample is classified using the discriminant model to obtain the probability value of the sample belonging to each category. The decision probability value and the optimal threshold corresponding to each category are compared respectively, and the category whose decision probability value is greater than the optimal threshold is taken as the category of the sample. If multiple categories have a probability value greater than the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample. If the probability values for all categories are less than or equal to the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample.
[0091] The above-mentioned judgment logic can make the classification model more reasonable in prediction and judgment, avoid judgment errors caused by special cases such as multiple categories having a judgment probability value greater than their corresponding optimal threshold, or all categories having a judgment prediction value less than their corresponding optimal threshold, and further improve the accuracy of classification.
[0092] To make it easier to understand, let's take Sample 1 as an example. We still assume that the probability values of Sample 1 corresponding to the eight categories are [0.10, 0.25, 0.30, 0.05, 0.15, 0.02, 0.08, 0.05], and the optimal thresholds for the eight categories are [0.15, 0.20, 0.25, 0.10, 0.10, 0.05, 0.05, 0.05]. Then, the probability values of Sample 1 in categories II, III, V, VII, and VIII all exceed the optimal thresholds for the corresponding categories. Therefore, we select category III, which corresponds to the highest probability value of 0.3, as the predicted category (production area) of Sample 1. Taking sample 2 as an example, assuming that the probability values of sample 2 in the eight categories are [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.3], and the optimal thresholds for the eight categories are [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], then category VIII, which corresponds to the highest discrimination probability of 0.3, is selected as the predicted category (production area) of sample 2.
[0093] S600. Based on the test set, evaluate the classification performance of the optimized classification model.
[0094] After determining the optimal thresholds for all categories, the classification model is evaluated based on the test set at the optimal thresholds. The classification performance is shown in Table 3 below, and the classification result parameters are as follows.
[0095] Table 3 Classification results parameters of the classification model on the test set.
[0096] To verify the effectiveness of the imbalanced data classification method proposed in this embodiment in solving the problem of uneven sample distribution among production area categories, the test set can be used as the original data to compare the differences in classification performance of the following four methods: original data, original data combined with dynamic threshold optimization, original data combined with SMOTE technology, and original data combined with the imbalanced data classification method provided in this embodiment. Then, the classification effect of each method is quantified and displayed using the F1-Score for each category. See [link / reference]. Figure 4 The results show that combining the original data with the imbalanced data classification method provided in this embodiment significantly improves the problem of imbalanced distribution of the original data and effectively enhances the classification performance of the classification model.
[0097] Furthermore, the method also includes: S700, using the optimized classification model for classification prediction of the data to be predicted.
[0098] Example 2: like Figure 5 As shown, an imbalanced data classification system based on SMOTE and dynamic threshold optimization is disclosed. The system includes: The data acquisition unit 100 is used for S100 to acquire a dataset, wherein the data in the dataset are samples, and it is known that all samples belong to several categories; The data partitioning unit 200 is used in S200 to divide the dataset after data preprocessing into a training set, a validation set, and a test set according to a certain ratio. The model building unit 300 is used in S300 to train a pre-built classification model based on the training set after the number of samples of each class in the training set is balanced by using SMOTE (synthetic minority oversampling technique). The model adjustment unit 400 is used by S400 to adjust the boundary of the classification model based on the validation set using a dynamic threshold algorithm to obtain the optimal threshold for all categories. The model optimization unit 500 is used in S500 to optimize the classification model by using the optimal threshold of all categories as the classification boundary of the classification model.
[0099] Furthermore, the system also includes a model evaluation unit 600, which is used to evaluate the classification performance of the optimized classification model based on a test set.
[0100] Furthermore, the system also includes: The prediction application module 700 is used by S700 to apply the optimized classification model to the classification prediction of the data to be predicted.
[0101] Example 3: A computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it implements the imbalanced data classification method based on SMOTE and dynamic threshold optimization provided in Embodiment 1.
[0102] Example 4: An electronic device includes a bus, a transceiver, a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the transceiver, the memory, and the processor are connected via the bus, characterized in that the computer program, when executed by the processor, implements the imbalanced data classification method based on SMOTE and dynamic threshold optimization provided in Embodiment 1.
[0103] In summary, the imbalanced data classification method and system based on SMOTE and dynamic threshold optimization provided by this invention uses SMOTE technology to synthesize and amplify minority class samples, balancing the class distribution of the training set. Simultaneously, by dynamically adjusting the classification boundary to better suit the characteristics of each class's data distribution, it improves the recognition rate of the minority class. The synergistic use of SMOTE technology and threshold optimization effectively addresses the problem of imbalanced sample distribution between classes, improving the model's performance in determining production areas. Compared to existing technologies, this invention more effectively solves the problem of imbalanced sample distribution between classes, enhances the model's learning ability for minority class samples, and strengthens the model's adaptability to differences in class distribution. This significantly improves the recognition recall rate of key minority classes and the overall reliability of classification decisions, overcoming the bias problem of traditional classifiers towards majority class samples and significantly improving the recognition accuracy of minority class samples.
[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. An imbalanced data classification method based on SMOTE and dynamic threshold optimization, characterized in that, The method includes: Obtain the dataset, in which the data consists of samples, and all samples belong to several categories; The dataset, after data preprocessing, is divided into training set, validation set, and test set according to a certain ratio; After balancing the number of samples in each category in the training set using the SMOTE technique, a pre-built classification model is trained based on the training set. Based on the validation set, a dynamic thresholding algorithm is used to adjust the boundary of the classification model to obtain the optimal threshold for all categories. The classification model is optimized by using the optimal thresholds for all categories as the classification boundaries of the classification model. The classification performance of the optimized classification model is evaluated based on the test set.
2. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 1, characterized in that, The step of dividing the preprocessed dataset into training, validation, and test sets proportionally includes: Perform data preprocessing on the data in the dataset; The dataset was divided into training, validation and test sets proportionally using hold-out and stratified sampling.
3. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 2, characterized in that, The data preprocessing includes Min-Max normalization calculation.
4. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 1, characterized in that, After using the SMOTE technique to balance the number of samples in each category in the training set, a classification model is constructed using the training set, including the following sub-steps: The category with the most samples in the training set is designated as the "majority category," and the remaining categories are designated as the "minority category." The SMOTE technique is used to expand the number of samples in each minority category to match the number of samples in the majority category, so that the number of samples in the majority category and the number of samples in each minority category are balanced. After balancing the number of samples in the majority class with the number of samples in each minority class, a pre-built classification model is trained based on the training set.
5. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 1, characterized in that, The classification model is constructed using any one of support vector machines, random forests, or convolutional neural networks.
6. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 1, characterized in that, The step of adjusting the boundary of the classification model based on the validation set using a dynamic threshold algorithm to obtain the optimal threshold for all categories includes the following sub-steps: The classification model is used to obtain the probability value of each sample in the validation set being classified into each category. Generate several different candidate thresholds with values ranging from 0 to 1; The classification model uses all candidate thresholds as decision thresholds, and performs classification prediction based on the probability values of each sample in the validation set belonging to each category, generating prediction results corresponding to all candidate thresholds. The prediction results for each candidate threshold include: true positive samples, false positive samples, and false negative samples. The prediction results corresponding to all candidate thresholds are compared with the known categories of each sample in the validation set, and the F1-Score of each candidate threshold under each category is calculated. The candidate threshold with the highest F1-Score for each category is taken as the optimal threshold for that category. Summarize the optimal thresholds for each category.
7. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 6, characterized in that, The generation of several different candidate thresholds with values ranging from 0 to 1 includes: The range of values is set to [0.1, 0.9]; Within the range of values, 50 equally spaced candidate thresholds are generated, with a step size of 0.016 between any two adjacent candidate thresholds.
8. The imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in claim 1, characterized in that, After optimizing the classification model by using the optimal thresholds of all categories as the classification boundaries of the classification model, the method further includes: setting decision logic for the classification model; The determination logic includes: The sample is classified using the discriminant model to obtain the probability value of the sample belonging to each category. The decision probability value and the optimal threshold corresponding to each category are compared respectively, and the category whose decision probability value is greater than the optimal threshold is taken as the category of the sample. If multiple categories have a probability value greater than the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample. If the probability values for all categories are less than or equal to the corresponding optimal threshold, then the category with the highest probability value is taken as the category of the sample.
9. An imbalanced data classification system based on SMOTE and dynamic threshold optimization, characterized in that, The system includes: A data acquisition unit is used to acquire a dataset, wherein the data in the dataset are samples, and it is known that all samples belong to several categories; A data partitioning unit is used to divide the preprocessed dataset into a training set, a validation set, and a test set according to a certain ratio. The model building unit is used to train a pre-built classification model based on the training set after the number of samples of each category in the training set is balanced using the SMOTE technique. The model adjustment unit is used to adjust the boundary of the classification model based on the validation set using a dynamic threshold algorithm to obtain the optimal threshold for all categories. The model optimization unit is used to optimize the classification model by using the optimal threshold of all categories as the classification boundary of the classification model. The model evaluation unit is used to evaluate the classification performance of the optimized classification model based on the test set.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the imbalanced data classification method based on SMOTE and dynamic threshold optimization as described in any one of claims 1 to 8.
Citation Information
Patent Citations
A Software Defect Tendency Prediction Method Based on SMOTE+Boosting Algorithm
CN105589806B
Efficient imbalanced data set classification method
CN105760889A