A method and system for liquor spectrum classification and regression prediction
By constructing a classification model group and expanding the training set using Bayesian optimization algorithm, the problem of insufficient universality and mobility of the liquor spectral prediction model is solved, and accurate classification and prediction of different liquor categories is achieved, and sample collection costs are reduced.
Patent Information
- Application Number
- CN202411218265.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-02
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2044-09-02
AI Technical Summary
The existing liquor spectral prediction model lacks universality and mobility, making it difficult to accurately predict products from different liquor manufacturers and brewing methods. The existing classification methods use a unified spectral wavelength, resulting in the classification results that are not scientific and accurate enough, and cannot effectively adapt to different types of Characteristic band.
By building a classification model group, selecting suitable binary classification algorithms and feature wavelengths to build a classification discriminator, using Bayesian optimization algorithm to calculate the number of replicated training samples, expand the training set and train the regression prediction model, and realize the accurate classification of the samples to be tested and prediction.
It improves the mobility and prediction accuracy of the model, reduces sample collection costs, and realizes accurate classification and prediction of different liquor categories, enhancing the robustness of the system and the scalability of the model.
Smart Images

Figure CN118734139B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of liquor classification and prediction, and in particular relates to a liquor spectrum classification and regression prediction method and system. Background Art
[0002] In order to improve detection efficiency, liquor manufacturers usually build models to predict certain aspects of liquor, such as predicting quality grades through spectra.
[0003] Since each manufacturer produces liquor with its own flavor, their production indicators and methods are different, which makes the model lack universality when predicting through spectral features. In other words, the model trained by a manufacturer through samples of its own products only has a good prediction accuracy for its own products, and often fails to achieve the ideal effect when predicting the products of other wineries. Similarly, even if the same manufacturer predicts the same indicator of liquor of different types (different brewing methods, raw materials, etc.), its effect is not satisfactory. The bottom line is that the model is not portable enough and cannot achieve a universal effect.
[0004] In order to adapt the model to other types of predictions, the general approach is to re-collect appropriate samples to train the model. However, the training model requires a large number of samples, and relying on re-collection will lead to a sharp increase in costs.
[0005] Another problem that may arise during actual use is that it is impossible to know the type of liquor, so it is necessary to first classify the liquor and then train the corresponding prediction model. Of course, there are also methods for classifying liquor by liquor spectra, such as the existing SVM method, PLS-DA method, etc., but these multi-classification methods will uniformly use the wavelength data of the spectrum. But in fact, for different types of classification, different algorithms are suitable, and the characteristic bands of different types are not necessarily the same. The method of using a unified spectral wavelength for classification in the above-mentioned existing classification methods is obviously not scientific enough, and the classification results are not accurate enough. Summary of the invention
[0006] In view of this, the present invention provides a liquor spectrum classification and regression prediction method and system, which can improve the transferability of the model and retrain the model by collecting a small amount of samples.
[0007] In order to solve the above technical problems, the technical solution of the present invention is to adopt a liquor spectrum classification and regression prediction method, comprising:
[0008] Classify the samples to be tested;
[0009] According to the category of the sample to be tested, the number of training samples of the same category that need to be copied is calculated, and the number of training samples copied corresponding to the category is used to expand the training set;
[0010] Use the expanded training set to train the pre-built regression prediction model;
[0011] The sample to be tested is input into the trained regression prediction model to predict the sample to be tested.
[0012] As an improvement, a classification model group is constructed to classify the samples to be tested, including:
[0013] Set the liquor classification category;
[0014] Select binary classification algorithms between all liquor categories and construct classification discriminators using characteristic wavelengths for classification;
[0015] Input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results;
[0016] The category with the most repetitions among several classification results is taken as the final category of the liquor to be classified.
[0017] As a further improvement, in the array creation step, m arrays are established, each array contains j elements; the number of elements is consistent with the number of characteristic wavelengths of the spectral data, and each element corresponds to a characteristic wavelength;
[0018] The assignment step randomly assigns values to each element in the array, including A value and B value; wherein the A value represents the selection of the corresponding characteristic wavelength, and the B value represents the non-selection of the corresponding characteristic wavelength;
[0019] Random change step, randomly change the values of elements in the array;
[0020] The modeling and prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a classification prediction model, inputs the pre-built validation set into the classification prediction model, and calculates the prediction accuracy of each classification prediction model;
[0021] The saving step saves the array with the highest prediction accuracy of the classification prediction model constructed by each algorithm, and replaces the array with the lowest prediction accuracy with the array with the highest prediction accuracy; the random change step, the modeling prediction step and the saving step are repeated until the stopping condition is reached;
[0022] The classification discriminator is constructed using the characteristic wavelength represented by the elements in the array with the highest prediction accuracy and the corresponding algorithm.
[0023] As another further improvement, the method of randomly changing the values of elements in an array includes crossing elements between arrays and / or mutation of elements in an array;
[0024] The method for crossing elements between arrays includes: setting a crossing probability, randomly selecting two arrays when crossing, and randomly selecting a number of corresponding elements from the two arrays to exchange element values;
[0025] The mutation method of the elements in the array includes: setting the mutation probability, randomly selecting an array when performing mutation, and randomly selecting several elements from the array, and replacing the element values of the selected elements, specifically replacing the A value with the B value, and replacing the B value with the A value.
[0026] As an improvement, the method for calculating the number of training samples that need to be replicated includes:
[0027] Calculate the distance between the sample to be tested and each training sample in the training set of the same category;
[0028] The weight of each training sample is calculated based on the distance between the sample to be tested and each sample in the training set of the same category;
[0029] The weight of each training sample is used to obtain the number of copies required for each training sample.
[0030] As an improvement, the method for calculating the weight of the training sample includes using the formula:
[0031] ;
[0032] Calculate the weights of the training samples; where, is the weight of the nth training sample, d n is the distance between the nth training sample and the sample to be tested, is the standard deviation, k is the weight hyperparameter, and exp() is the exponential function. As an improvement, the method of obtaining the number of training samples that need to be replicated includes using the formula:
[0033] ;
[0034] Calculate the number of training samples that need to be replicated; where l n is the number of copies required for the nth training sample, is the weight of the nth training sample, is the weight of the training sample farthest from the sample to be tested, and α is the quantity hyperparameter.
[0035] As an improvement, the Bayesian optimization algorithm is used to search for the best combination of weight hyperparameter k and quantity hyperparameter α.
[0036] As an improvement, when the mean root mean square error of the regression prediction model is When it is minimum, the corresponding weight hyperparameter k and quantity hyperparameter α are selected as the weight hyperparameter k and quantity hyperparameter α used to obtain the number of training samples to be replicated;
[0037] The mean RMS error The methods for obtaining include:
[0038] Assign values to the weight hyperparameter k and quantity hyperparameter α;
[0039] In the expansion step, one of the N training samples of the same category as the sample to be tested in the training set is used as the test sample; the remaining N-1 training samples of the same category are used to calculate the number of copies required for expanding the training set using the assigned weight hyperparameter k and quantity hyperparameter α;
[0040] The training step uses the expanded training set to train the pre-built regression prediction model;
[0041] Prediction step: input the test sample into the trained regression prediction model to predict the test sample;
[0042] Calculation steps: Calculate the root mean square error using the predicted value and true value of the test sample Repeat the expansion step, training step, prediction step, and calculation step until all training samples of the same category are used as test samples to obtain N root mean square errors. ;
[0043] Calculate N root mean square errors The average .
[0044] The present invention also provides a liquor spectrum classification and regression prediction system, comprising:
[0045] Classification module, used to classify the samples to be tested;
[0046] The training set expansion module is used to calculate the number of training samples of the same category as the sample to be tested that need to be copied according to the category of the sample to be tested, and use the corresponding number of training sample copies to expand the training set;
[0047] A model training module is used to train a pre-built regression prediction model using the expanded training set;
[0048] The prediction module is used to input the sample to be tested into the trained regression prediction model to predict the sample to be tested.
[0049] The present invention is beneficial in that:
[0050] The present invention first classifies the samples to be tested by a classification model group. Classification discriminators are established between classification categories, and the spectral data of the liquor to be classified are input into all classification discriminators to obtain several classification results; the category with the most repetitions among the several classification results is taken as the final category of the liquor to be classified.
[0051] When constructing the classification discriminator, we select the corresponding algorithm and the combination of characteristic wavelengths for the characteristics of the two classification categories, so that the classification discriminator is more targeted, and the final classification result is more accurate. Finally, the classification result that appears most frequently in several prediction results is taken as the final category through data statistics, which ensures the robustness of the system.
[0052] In addition, when it is necessary to add categories, there is no need to tear down and rebuild the entire model. It is only necessary to establish classification discriminators between the newly added categories and the existing categories, which makes the expansion of the entire model very convenient.
[0053] After obtaining the category of the sample to be tested, the regression prediction model is trained after expanding the training samples of the same category as the sample to be tested, so that the regression prediction model is more targeted and the prediction result is more accurate.
[0054] At the same time, the regression prediction model in the present invention has very good transferability. When it is necessary to predict different categories of test samples, only a small amount of training samples is needed to expand a training set sufficient to train the model without the need to re-collect samples. Compared with the existing method of re-collecting samples to train the model, it can save a lot of manpower and material resources used for collecting samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 It is a flow chart of the present invention.
[0056] Figure 2 It is a structural diagram of the present invention. DETAILED DESCRIPTION
[0057] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods.
[0058] Embodiment 1
[0059] The prior art Chinese patent CN202211379961.9 discloses a method for evaluating the degree of association of liquor aging based on mid-infrared spectroscopy detection technology, and realizes rapid detection of the degree of association of liquor, which belongs to the field of detection of the degree of association of liquor storage. The method includes: configuring samples with different storage times and different temperature treatments; acquiring sample spectral data through a Fourier infrared spectroscopy system; selecting the hydroxyl band (4000cm-1~2600cm-1); normalization processing to eliminate the differences caused by different sampling amounts; processing samples with different storage times through multi-peak fitting to classify the degree of association; defining labels for all spectral data according to the classification and making a data set; preprocessing the spectral data in different ways; training and predicting through different models, comparing the effects of different combinations, and providing a reference for realizing rapid detection of the degree of association of liquor.
[0060] In the above-mentioned prior art, in order to make predictions more accurate, it is necessary to first classify the degree of association, and make data sets according to the classification, so as to train different models for prediction. The above-mentioned prior art has the following problems: First, for samples with unknown levels, it is impossible to make data sets according to their levels to train the model, which makes the model less targeted and the prediction results inaccurate. Secondly, even if the level of the sample is known, a large number of samples need to be collected to train the model. For example, 500 samples are needed to train a model, and for ten levels, 5,000 samples are needed, which is a huge workload.
[0061] In order to solve the two problems in the above-mentioned prior art, Figure 1 As shown, the present invention provides a liquor spectrum classification and regression prediction method, and its specific steps include:
[0062] S1 classifies the samples to be tested.
[0063] In this step, the samples to be tested can be classified by the existing classification model. However, since different types of classifications are suitable for different algorithms, the characteristic bands of different types are not necessarily the same. Therefore, a fixed classification model may lead to inaccurate classification results. In order to make the classification results more accurate, the classification model group is constructed for classification in this embodiment, which specifically includes:
[0064] S11 sets the classification category of liquor.
[0065] The classification of liquor in the present invention is not limited to quality grade, and can also be based on year, manufacturer or any attribute that can be classified.
[0066] In this embodiment, it is assumed that liquor needs to be classified into D categories, including category 1, category 2, category 3, ... category D. For example, if the quality of liquor is classified, the categories are grade 1, grade 2, grade 3, ... grade D. For example, if the manufacturers of liquor are classified, the categories are manufacturer 1, manufacturer 2, manufacturer 3, ... manufacturer D, and so on.
[0067] After setting the classification categories, it is necessary to collect multiple liquor samples of each category and perform spectral analysis to obtain the spectrum of each liquor sample. Similarly, for quality grade classification, it is necessary to collect several liquor samples of each quality grade to construct a data set.
[0068] The spectrum of liquor samples contains multiple characteristic wavelengths. However, when classifying, not all characteristic wavelengths are useful for classification.
[0069] S12 selects a binary classification algorithm between all liquor categories and constructs a classification discriminator using the characteristic wavelength used for classification.
[0070] In this embodiment, it is first necessary to establish a classification discriminator for each of the classification categories, that is, a classification discriminator must be established between level 1 and level 2~level D, and a classification discriminator must also be established between level 2 and level 3~level D. D levels require D(D-1) / 2 classification discriminators to be established.
[0071] Since the differences between categories are not the same, in order to improve the accuracy of the classification discriminator, each classification discriminator must select the most suitable algorithm and the most suitable characteristic wavelength to construct.
[0072] There are many existing algorithms for binary classification, such as the holding vector machine algorithm, decision tree algorithm, linear discriminant analysis algorithm, partial least squares discriminant analysis algorithm, etc.
[0073] There are also many algorithms for selecting features, such as competitive adaptive reweighted sampling algorithm, continuous projection algorithm, random forest feature importance algorithm, etc.
[0074] Those skilled in the art can select the most suitable algorithm and characteristic wavelength according to the specific situation. Of course, the rule for selecting the algorithm and characteristic wavelength in the present invention is to select the binary classification algorithm with the highest prediction accuracy and the characteristic wavelength to construct a classification discriminator.
[0075] In addition to the above algorithm, this embodiment also provides a method for constructing a classification discriminator. The specific steps include:
[0076] S121 array creation step, establishing m arrays, each array containing j elements; the number of elements is consistent with the number of characteristic wavelengths of the spectral data, and each element corresponds to a characteristic wavelength.
[0077] The number of arrays m is random. It is understandable that the larger m is, the more accurate the final result will be, but the computing power consumption and time will also be greater. The array is specifically:
[0078]
[0079]
[0080]
[0081] .
[0082] The number of elements j is consistent with the number of characteristic waveforms in the spectrum of the liquor sample, and the two correspond one to one. That is, if the spectrum contains 100 characteristic wavelengths, then there should be 100 elements in each array.
[0083] S122 is a value assignment step, in which a value is randomly assigned to each element in the array, including an A value and a B value; wherein the A value represents the selection of the corresponding characteristic wavelength, and the B value represents the non-selection of the corresponding characteristic wavelength.
[0084] In this embodiment, the elements in the array are binary, that is, non-0 is 1, and 1 is used to express the selection of the corresponding characteristic wavelength, and 0 is used to express that the characteristic wavelength is not selected. , characteristic wavelength No. 1 is not selected, characteristic wavelength No. 2 is selected, characteristic wavelength No. 3 is not selected...characteristic wavelength No. j is not selected.
[0085] During initialization, the element values are randomly assigned.
[0086] S123 is a random change step, in which the values of the elements in the array are randomly changed.
[0087] For classification problems, in fact, not every characteristic wavelength among the 100 characteristic wavelengths will affect the final classification result. On the contrary, many characteristic wavelengths will cause interference. Therefore, it is also necessary to select characteristic wavelengths that are valuable for classification.
[0088] In this step, more arrays are created by random changes, and the most valuable combination of characteristic wavelengths is found in a similar exhaustive manner.
[0089] In this embodiment, the method for randomly changing the values of elements in an array includes crossing elements between arrays and / or mutation of elements in an array;
[0090] The method for crossing elements between arrays includes: setting a crossing probability, randomly selecting two arrays when crossing, and randomly selecting a number of corresponding elements from the two arrays to exchange element values. For example, arrays A1 and A2 are randomly selected for crossing, and the elements for crossing are the first element and the second element:
[0091]
[0092] .
[0093] The mutation method of the elements in the array includes: setting the mutation probability, randomly selecting an array when performing the mutation, and randomly selecting a number of elements from the array, and replacing the element values of the selected elements, specifically replacing the value A with the value B, and replacing the value B with the value A. For example, array A1 is randomly selected for mutation, and the elements to be mutated are the first element and the second element:
[0094] .
[0095] It is worth noting that as the number of iterations increases, the probability of mutation should decrease. In this embodiment, the formula is used:
[0096] ;
[0097] Set the mutation probability; where v i is the mutation probability of the i-th iteration, v i-1 is the mutation probability of the i-1th iteration, and L is the number of iterations. The number of iterations here refers to the number of times the method is cyclically run to find the best algorithm and the best characteristic wavelength combination when constructing the same classification discriminator. This number can be set manually.
[0098] S124 is a modeling and prediction step, which uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a classification prediction model, inputs a pre-built validation set into the classification prediction model, and calculates the prediction accuracy of each classification prediction model.
[0099] As mentioned in the above steps, the binary classification algorithms include vector machine algorithm, decision tree algorithm, linear discriminant analysis algorithm, partial least squares discriminant analysis algorithm, etc. In fact, when constructing a classification discrimination model, it is impossible to know which algorithm and which characteristic wavelength combination is the best.
[0100] Therefore, in this step, the classification model is constructed based on the existing binary classification algorithm and the characteristic wavelength combination represented by the randomly changed array. After the model is constructed, a part of the data set constructed in step S1 is used as a training set for model training, and a part of the data set is used as a verification set to verify the accuracy of the model to obtain the prediction accuracy of the model. The results are shown in Table 1:
[0101] Table 1 Prediction accuracy list
[0102]
[0103] The table lists the prediction accuracy of each algorithm for each array construction model.
[0104] S125 is a saving step, which saves the array with the highest prediction accuracy of the classification prediction model constructed by each algorithm respectively, and replaces the array with the lowest prediction accuracy with the array with the highest prediction accuracy; the random change step, the modeling prediction step and the saving step are repeated until the stopping condition is reached.
[0105] In each iteration, one array with the highest prediction accuracy and one array with the lowest prediction accuracy will be generated from the m arrays. In this step, the array with the highest prediction accuracy of each algorithm in the previous step is saved (the premise of saving is that it is higher than the highest prediction accuracy in the previous iteration), and the array with the highest prediction accuracy replaces the array with the lowest prediction accuracy, thereby eliminating the array with low prediction accuracy, so that after iterations, the prediction accuracy will become higher and higher.
[0106] And steps S23 to S25 are repeatedly executed until the stopping condition is reached, that is, the number of iterations is reached or the preset prediction accuracy is reached.
[0107] At this point, each algorithm will save an array with the highest prediction accuracy to represent the best characteristic wavelength combination.
[0108] S126 constructs a classification discriminator using the characteristic wavelengths represented by the elements in the array with the highest prediction accuracy and the corresponding algorithm.
[0109] The highest prediction accuracy of several algorithms is compared, and the algorithm with the highest prediction accuracy and the model constructed by the array are selected as the classification discriminator of the two categories.
[0110] The method of constructing classification discriminators between other categories is the same. Through the above method, a total of D(D-1) / 2 classifications between all classification categories are constructed.
[0111] S13 inputs the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results.
[0112] After D(D-1) / 2 classification discriminators between n classification categories are constructed, the spectral data of the liquor to be classified are input into all the classification discriminators respectively to obtain D(D-1) / 2 classification results.
[0113] S14 takes the category with the most repetitions among several classification results as the final category of the liquor to be classified.
[0114] It is foreseeable that if the spectrum data of liquor at level 1 is input into the classification discriminator between level 1 and level 2, the output result will be level 1. Similarly, if it is input into the classification discriminator between level 1 and level 3, the output result will still be level 1. If the spectrum data of liquor at level 1 is input into the classification discriminator between level 2 and level 3, the result may be level 2 or level 3. However, no matter which level is output, it is wrong.
[0115] That is to say, only the classification discriminators containing level 1 will output accurate results, that is to say, among the D(D-1) / 2 classification discriminators, ideally D-1 classification discriminators will output results of level 1.
[0116] Therefore, in the present invention, the category with the largest number of outputs is taken as the final category of the liquor to be classified, and the final result is judged by the principle of statistics.
[0117] S2 calculates the number of training samples that need to be copied according to the category of the sample to be tested, and uses the corresponding number of training sample copies to expand the training set.
[0118] After obtaining the model of the sample to be tested by using the classification model group in step S1, it is also necessary to expand the training samples of the same category according to the category of the sample to be tested. For example, this embodiment includes 10 categories in total. According to the traditional model training method, 500 samples need to be prepared for each category. In the present invention, only 50 samples need to be prepared for each category, and then they can be expanded when the model needs to be trained. Specifically, the method for calculating the number of training samples that need to be copied includes:
[0119] S21 calculates the distance between the sample to be tested and each training sample in the training set of the same category.
[0120] Continuing with the previous example, there are 500 training samples in the training set, of which 50 training samples are of the same category as the sample to be tested. In this step, the distance between the sample to be tested and the 50 samples of the same category needs to be calculated. Specifically, the formula is used:
[0121] ;
[0122] Calculate the distance between samples; where d nis the distance between the sample to be tested and the nth training sample of the same category, x n is the nth training sample of the same category, x q is the sample to be tested, and T is the transposed symbol.
[0123] Of course, other types of distances may also be used, and the present invention does not limit this.
[0124] S22 calculates the weight of each training sample according to the distance between the sample to be tested and each sample in the training set of the same category; specifically, using the formula:
[0125] ;
[0126] Calculate the weights of the training samples; where, is the weight of the nth training sample, d n is the distance between the nth training sample and the sample to be tested, is the standard deviation, k is the weight hyperparameter, and exp() is the exponential function.
[0127] In addition, the standard deviation uses the formula:
[0128] ;
[0129] Calculate; where is the standard deviation, d1~d N is a distance from 1 to N, is the average value of the distance, and N is the number of samples of the same category in the training set.
[0130] S23 uses the weight of each training sample to obtain the number of copies of each training sample. Specifically, the formula is used:
[0131] ;
[0132] Calculate the number of training samples that need to be replicated; where l n is the number of copies required for the nth training sample, is the weight of the nth training sample, is the weight of the training sample farthest from the sample to be tested, and α is the quantity hyperparameter.
[0133] From step S22 and the formula in this step, we can find that if we want to calculate the number of copies that need to be made, the weight hyperparameter k and the quantity hyperparameter a are key parameters. However, the weight hyperparameter k and the quantity hyperparameter a are uncertain values, and we need to find an optimal combination of the two. And each category has its own unique optimal combination of weight hyperparameter k and quantity hyperparameter a. Therefore, when training the model for each category separately, we need to calculate the specific values of weight hyperparameter k and quantity hyperparameter a.
[0134] In this embodiment, the Bayesian optimization algorithm is used to search for the best combination of weight hyperparameter k and quantity hyperparameter α. Bayesian optimization is a global optimization method based on Bayesian statistics, which is mainly used to optimize expensive functions, especially when the accurate analytical form of the objective function cannot be directly obtained. The Bayesian optimization algorithm is an existing algorithm in the field for finding the best hyperparameters, and its specific steps are not repeated in this invention.
[0135] It is worth noting that in the present invention, when the Bayesian optimization algorithm is used to search for the best combination of weight hyperparameter k and quantity hyperparameter α, the index is the mean value of the root mean square error of the pre-built regression prediction model. When the value is the smallest, the corresponding weight hyperparameter k and quantity hyperparameter α are the best combination of the two. RMSECV (Root Mean Square error of Cross-Validation) is an indicator used to evaluate the prediction performance of the model during the cross-validation process. It reflects the error of the model on unseen data. In this embodiment, the regression prediction model can use an existing regression model, such as partial least squares algorithm, support vector regression algorithm, neural network algorithm, etc.
[0136] The mean root mean square error of the regression prediction model The methods for obtaining include:
[0137] S231 assigns values to the weight hyperparameter k and the quantity hyperparameter α;
[0138] S232 expansion step, taking one of the N training samples of the same category as the sample to be tested in the training set as the test sample; using the remaining N-1 training samples of the same category, using the assigned weight hyperparameter k and quantity hyperparameter α to calculate the number of copies required to expand the training set;
[0139] S233 training step, using the expanded training set to train the pre-built regression prediction model;
[0140] S234 prediction step, inputting the test sample into the trained regression prediction model to predict the test sample;
[0141] S235 calculation step, using the predicted value and true value of the test sample to calculate the root mean square error Repeat the expansion step, training step, prediction step, and calculation step until all training samples of the same category are used as test samples to obtain N root mean square errors. ;
[0142] S236 Calculate N root mean square errors The average .
[0143] The Bayesian optimization algorithm is used to find the optimal combination of weight hyperparameter k and quantity hyperparameter α. The two are then put into the above formula to calculate the number of copies of each sample that need to be made.
[0144] S3 uses the expanded training set to train the pre-built regression prediction model.
[0145] It is worth noting that in addition to the training samples of the same category as the samples to be tested, the training samples of other categories will also be input into the regression prediction model for training.
[0146] S4 inputs the sample to be tested into the trained regression prediction model to predict the sample to be tested.
[0147] After the model for the sample to be tested is trained, the sample to be tested is input into the regression prediction model to predict the sample to be tested. After targeted modeling and training, the accuracy of the regression prediction model will be greatly improved.
[0148] Embodiment 2
[0149] like Figure 2 As shown, the present invention also provides a liquor spectrum classification and regression prediction system, comprising:
[0150] The classification module is used to build a classification model group to classify the samples to be tested;
[0151] The training set expansion module is used to calculate the number of training samples of the same category as the sample to be tested that need to be copied according to the category of the sample to be tested, and use the corresponding number of training sample copies to expand the training set;
[0152] A model training module is used to train a pre-built regression prediction model using the expanded training set;
[0153] The prediction module is used to input the sample to be tested into the trained regression prediction model to predict the sample to be tested.
[0154] The above are only preferred embodiments of the present invention. It should be noted that the above preferred embodiments should not be regarded as limiting the present invention, and the protection scope of the present invention should be based on the scope defined by the claims. For ordinary technicians in this technical field, several improvements and modifications can be made without departing from the spirit and scope of the present invention, and these improvements and modifications should also be regarded as the protection scope of the present invention.
Claims
1. A liquor spectrum classification and regression prediction method, characterized in that: include: Classify the samples to be tested; According to the category of the sample to be tested, the number of training samples of the same category that need to be copied is calculated, and the number of training samples copied corresponding to the category is used to expand the training set; Use the expanded training set to train the pre-built regression prediction model; Input the sample to be tested into the trained regression prediction model to predict the sample to be tested; Construct a classification model group to classify the samples to be tested, including: Set the liquor classification category; Select binary classification algorithms between all liquor categories and construct classification discriminators using characteristic wavelengths for classification; Input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results; The category with the most repetitions among several classification results is taken as the final category of the liquor to be classified. Methods for building a classification discriminator include: An array creation step is to create m arrays, each array containing j elements; the number of elements is consistent with the number of characteristic wavelengths of the spectral data, and each element corresponds to a characteristic wavelength; The assignment step randomly assigns values to each element in the array, including A value and B value; wherein the A value represents the selection of the corresponding characteristic wavelength, and the B value represents the non-selection of the corresponding characteristic wavelength; Random change step, randomly change the values of elements in the array; The modeling and prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a classification prediction model, inputs the pre-built validation set into the classification prediction model, and calculates the prediction accuracy of each classification prediction model; The saving step saves the array with the highest prediction accuracy of the classification prediction model constructed by each algorithm, and replaces the array with the lowest prediction accuracy with the array with the highest prediction accuracy; the random change step, the modeling prediction step and the saving step are repeated until the stopping condition is reached; The classification discriminator is constructed using the characteristic wavelength represented by the element in the array with the highest prediction accuracy and the corresponding algorithm; Methods for randomly changing the values of elements in an array include crossing elements between arrays and / or mutation of elements within an array; The method for crossing elements between arrays includes: setting a crossing probability, randomly selecting two arrays when crossing, and randomly selecting a number of corresponding elements from the two arrays to exchange element values; The mutation method of the elements in the array includes: setting the mutation probability, randomly selecting the array when the mutation is performed, and randomly selecting a number of elements from the array, and replacing the element values of the selected elements, specifically replacing the A value with the B value, and replacing the B value with the A value; Methods for calculating the number of training samples that need to be replicated include: Calculate the distance between the sample to be tested and each training sample in the training set of the same category; Calculate the weight of each training sample based on the distance between the sample to be tested and each sample in the training set of the same category; The weight of each training sample is used to obtain the number of copies required for each training sample.
2. A liquor spectrum classification and regression prediction method according to claim 1, characterized in that: The method of calculating the weight of the training samples includes using the formula: ; Calculate the weights of the training samples; where, is the weight of the nth training sample, d n is the distance between the nth training sample and the sample to be tested, is the standard deviation, k is the weight hyperparameter, and exp() is the exponential function.
3. A liquor spectrum classification and regression prediction method according to claim 2, characterized in that: Methods for obtaining the number of copies required for a training sample include using the formula: ; Calculate the number of training samples that need to be replicated; where l n is the number of copies required for the nth training sample, is the weight of the nth training sample, is the weight of the training sample farthest from the sample to be tested, and α is the quantity hyperparameter.
4. A liquor spectrum classification and regression prediction method according to claim 3, characterized in that: The Bayesian optimization algorithm is used to search for the best combination of weight hyperparameter k and quantity hyperparameter α.
5. A liquor spectrum classification and regression prediction method according to claim 4, characterized in that: When the mean root mean square error of the regression prediction model When it is minimum, the corresponding weight hyperparameter k and quantity hyperparameter α are selected as the weight hyperparameter k and quantity hyperparameter α used to obtain the number of training samples to be replicated; The mean RMS error The methods for obtaining include: Assign values to the weight hyperparameter k and quantity hyperparameter α; In the expansion step, one of the N training samples of the same category as the sample to be tested in the training set is used as the test sample; the remaining N-1 training samples of the same category are used to calculate the number of copies required for expanding the training set using the assigned weight hyperparameter k and quantity hyperparameter α; The training step uses the expanded training set to train the pre-built regression prediction model; Prediction step: input the test sample into the trained regression prediction model to predict the test sample; Calculation steps: Calculate the root mean square error using the predicted value and true value of the test sample Repeat the expansion step, training step, prediction step, and calculation step until all training samples of the same category are used as test samples to obtain N root mean square errors. ; Calculate N root mean square errors The average .
6. A liquor spectrum classification and regression prediction system, characterized in that: include: Classification module, used to classify the samples to be tested; The training set expansion module is used to calculate the number of training samples of the same category as the sample to be tested that need to be copied according to the category of the sample to be tested, and use the corresponding number of training sample copies to expand the training set; A model training module is used to train a pre-built regression prediction model using the expanded training set; The prediction module is used to input the sample to be tested into the trained regression prediction model to predict the sample to be tested; Construct a classification model group to classify the samples to be tested, including: Set the liquor classification category; Select binary classification algorithms between all liquor categories and construct classification discriminators using characteristic wavelengths for classification; Input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results; The category with the most repetitions among several classification results is taken as the final category of the liquor to be classified. Methods for building a classification discriminator include: An array creation step is to create m arrays, each array containing j elements; the number of elements is consistent with the number of characteristic wavelengths of the spectral data, and each element corresponds to a characteristic wavelength; The assignment step randomly assigns values to each element in the array, including A value and B value; wherein the A value represents the selection of the corresponding characteristic wavelength, and the B value represents the non-selection of the corresponding characteristic wavelength; Random change step, randomly change the values of elements in the array; The modeling and prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a classification prediction model, inputs the pre-built validation set into the classification prediction model, and calculates the prediction accuracy of each classification prediction model; The saving step saves the array with the highest prediction accuracy of the classification prediction model constructed by each algorithm, and replaces the array with the lowest prediction accuracy with the array with the highest prediction accuracy; the random change step, the modeling prediction step and the saving step are repeated until the stopping condition is reached; The classification discriminator is constructed using the characteristic wavelength represented by the element in the array with the highest prediction accuracy and the corresponding algorithm; Methods for randomly changing the values of elements in an array include crossing elements between arrays and / or mutation of elements within an array; The method for crossing elements between arrays includes: setting a crossing probability, randomly selecting two arrays when crossing, and randomly selecting a number of corresponding elements from the two arrays to exchange element values; The mutation method of the elements in the array includes: setting the mutation probability, randomly selecting the array when the mutation is performed, and randomly selecting a number of elements from the array, and replacing the element values of the selected elements, specifically replacing the A value with the B value, and replacing the B value with the A value; Methods for calculating the number of training samples that need to be replicated include: Calculate the distance between the sample to be tested and each training sample in the training set of the same category; Calculate the weight of each training sample based on the distance between the sample to be tested and each sample in the training set of the same category; The weight of each training sample is used to obtain the number of copies required for each training sample.
