A method and system for classifying liquor spectrum, and a computer system
By selecting suitable characteristic wavelengths and algorithms in the spectral classification of liquor, a classification discriminator is constructed, which solves the problem of inaccurate classification results in the existing technology, and achieves a more accurate and flexible classification of liquor, suitable for different types of liquors.
Patent Information
- Application Number
- CN202411218251.7
- 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
In the existing classification methods of liquor, the same spectral wavelength is used for classification, resulting in inaccurate classification results, and the algorithms and characteristic bands suitable for different types of liquor are different, so the existing methods are not scientific enough.
By selecting different feature wavelengths and classification algorithms on different classification discriminators, a classification discriminator is constructed, and algorithms such as support vector machines, decision trees, linear discriminator analysis is used to combine competitive adaptive reweighting sampling and continuous Projection method, random forest feature importance algorithm, select the most suitable feature wavelength and algorithm, build a prediction model, and determine the best combination through the iterative optimization process.
It improves the accuracy and robustness of liquor classification, ensures the accuracy of classification results, and does not need to reconstruct the entire model when it is necessary to add categories, making it convenient to expand.
Smart Images

Figure CN118734138B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of liquor classification, and in particular relates to a liquor spectrum classification method and system, and a computer system. Background Art
[0002] The difference in the process of different wines will directly affect the quality of the product. In addition, the time cost and material cost vary greatly, which is reflected in the product quality. In order to classify the quality of wine, existing methods such as sensory evaluation require manual labeling of the quality of wine. However, the accuracy of analysis based on human senses is easily affected by subjective factors. In addition, there is also the use of chemometric methods to classify the quality of wine, which is time-consuming and consumes a lot of organic solvents, and is not environmentally friendly. There is also a method of classifying wines through near-infrared spectroscopy technology in the prior art. It can quickly obtain information on these key components without destroying the sample, providing a scientific basis for the quality identification and classification of liquor.
[0003] Existing methods for liquor classification such as SVM and PLS-DA will uniformly use the same spectral wavelength data. Different algorithms are suitable for different types of classification, 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 existing classification methods is obviously not scientific enough, and the classification results are not accurate enough. Summary of the invention
[0004] In view of this, the present invention provides a liquor spectrum classification method and system, and a computer system for selecting different characteristic wavelengths and classification algorithms on different classification discriminators, so as to make the prediction and classification results more accurate.
[0005] In order to solve the above technical problems, the technical solution of the present invention is to adopt a liquor spectrum classification method, comprising:
[0006] Set the liquor classification category;
[0007] A binary classification algorithm is selected between all liquor categories and a characteristic wavelength used for classification is used to construct a classification discriminator; the binary classification algorithm includes a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm;
[0008] Input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results;
[0009] The category with the most repetitions among several classification results is taken as the final category of the liquor to be classified.
[0010] As a further improvement, one or more of a competitive adaptive reweighted sampling algorithm, a continuous projection algorithm, and a random forest feature importance algorithm are used to select characteristic wavelengths for constructing a classification discriminator.
[0011] As another further improvement, one or more of a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm are used to construct a classification discriminator.
[0012] As an improvement, the method of constructing a classification discriminator includes:
[0013] An array creation step is to create m arrays, each array containing n elements; the number of the elements is consistent with the number of characteristic wavelengths of the spectral data, and each element corresponds to a characteristic wavelength;
[0014] 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;
[0015] Random change step, randomly change the values of elements in the array;
[0016] The modeling prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a prediction model, inputs the pre-built validation set into the prediction model, and calculates the prediction accuracy of each prediction model;
[0017] The saving step is to save the array with the highest prediction accuracy of the prediction model established by each algorithm, and replace 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;
[0018] 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.
[0019] As an 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;
[0020] 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;
[0021] The mutation method of elements in an 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.
[0022] As an improvement, the stopping condition is reaching the number of iterations or reaching a preset prediction accuracy.
[0023] As an improvement, the method for setting the mutation probability is to use the formula:
[0024] ;
[0025] 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 N is the number of iterations.
[0026] The present invention also provides a liquor spectrum classification system, comprising:
[0027] Category setting module, used to set the classification category of liquor;
[0028] A classification discriminator building module is used to select a binary classification algorithm between all liquor categories and a characteristic wavelength for classification to build a classification discriminator; the binary classification algorithm includes a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm;
[0029] The classification result acquisition module is used to input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results; and the category with the most repetitions among the several classification results is used as the final category of the liquor to be classified.
[0030] The present invention also provides a computer system, comprising a processor and a memory; a computer program is stored in the memory, and when the computer program is executed by the processor, the above-mentioned liquor spectrum classification method can be implemented.
[0031] The present invention is beneficial in that:
[0032] The present invention establishes classification discriminators between classification categories, inputs spectral data of liquor to be classified into all classification discriminators to obtain several classification results; and takes the category with the most repetitions among the several classification results as the final category of the liquor to be classified.
[0033] 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.
[0034] 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 a binary classification model between the newly added categories and the existing categories, which makes the expansion of the entire model very convenient. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a flow chart of the present invention.
[0036] Figure 2 It is a structural diagram of the present invention. DETAILED DESCRIPTION
[0037] 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.
[0038] Embodiment 1
[0039] Prior art Chinese patent application CN106226263A discloses a method for quickly distinguishing the grade of a strong-flavor liquor base wine based on infrared spectroscopy technology, comprising: professional sensory reviewers conduct sensory review and classification and grading of collected liquor base wine samples; use a gas chromatograph to determine the content of major ester compounds in the liquor base wine samples; use a Fourier transform infrared spectrometer to collect spectra of the liquor base wine samples; establish a qualitative distinction of the base wine grade based on infrared spectroscopy and a quantitative identification model for the major ester compounds in the base wine; collect Fourier transform infrared spectra of the base wine to be graded, and use the established model to quickly distinguish and grade the base wine to be graded.
[0040] In order to construct a model in the above prior art, it is necessary to first perform principal component analysis on the spectral information of the base wine sample to be graded, and then use the established base wine grade qualitative discrimination model to process it to obtain the identification result. However, the above prior art does not provide a method for analyzing the principal components.
[0041] In order to solve the above problems, Figure 1 As shown, the present invention provides a method for classifying liquor spectra, comprising:
[0042] S1 sets the classification category of liquor.
[0043] 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.
[0044] In this embodiment, it is assumed that liquor needs to be classified into n categories, including category 1, category 2, category 3, ... category n. For example, if the quality of liquor is classified, the categories are grade 1, grade 2, grade 3, ... grade n. For example, if the manufacturers of liquor are classified, the categories are manufacturer 1, manufacturer 2, manufacturer 3, ... manufacturer n, and so on.
[0045] 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.
[0046] The spectrum of liquor samples contains multiple characteristic wavelengths. However, when classifying, not all characteristic wavelengths are useful for classification.
[0047] S2 selects a binary classification algorithm between all liquor categories and the characteristic wavelength used for classification to construct a classification discriminator.
[0048] 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 n, and a classification discriminator must be established between level 2 and level 3~level n. Therefore, n levels require n(n-1) / 2 classification discriminators to be established.
[0049] 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.
[0050] 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.
[0051] There are also many algorithms for selecting features, such as competitive adaptive reweighted sampling algorithm, continuous projection algorithm, random forest feature importance algorithm, etc.
[0052] 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 classification algorithm with the highest prediction accuracy and the characteristic wavelength to construct a classification discriminator.
[0053] In addition to the above algorithm, this embodiment also provides a method for constructing a classification discriminator. The specific steps include:
[0054] S21 array creation step, establishing m arrays, each array containing n 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.
[0055] 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:
[0056]
[0057]
[0058]
[0059] .
[0060] The number of elements n 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.
[0061] S22 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.
[0062] 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. n is not selected.
[0063] During initialization, the element values are randomly assigned.
[0064] S23 is a random change step, which randomly changes the values of the elements in the array.
[0065] 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.
[0066] 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.
[0067] 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;
[0068] The method of crossing elements between arrays includes: setting the crossover 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:
[0069]
[0070] .
[0071] The mutation method of elements in an 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 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:
[0072] .
[0073] It is worth noting that as the number of iterations increases, the probability of mutation should decrease. In this embodiment, the formula is used:
[0074] ;
[0075] 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 N 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.
[0076] S24 is a modeling and prediction step, which uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a prediction model, inputs the pre-built validation set into the prediction model, and calculates the prediction accuracy of each prediction model.
[0077] 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.
[0078] 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:
[0079] Table 1 Prediction accuracy list
[0080]
[0081] The table lists the prediction accuracy of each algorithm for each array construction model.
[0082] S25 is a saving step, which saves the array with the highest prediction accuracy of the prediction model established 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.
[0083] 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.
[0084] 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.
[0085] At this point, each algorithm will save an array with the highest prediction accuracy to represent the best characteristic wavelength combination.
[0086] S26 constructs a classification discriminator using the characteristic wavelengths represented by the elements in the array with the highest prediction accuracy and the corresponding algorithm.
[0087] 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.
[0088] The method of constructing classification discriminators between other categories is the same. Through the above method, a total of n(n-1) / 2 classifications between all classification categories are constructed.
[0089] S3 inputs the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results.
[0090] After n(n-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 n(n-1) / 2 classification results.
[0091] S4 takes the category with the most repetitions among several classification results as the final category of the liquor to be classified.
[0092] 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.
[0093] That is to say, only the classification discriminators containing level 1 will output accurate results, that is to say, among the n(n-1) / 2 classification discriminators, ideally n-1 classification discriminators will output results of level 1.
[0094] 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.
[0095] Embodiment 2
[0096] like Figure 2 As shown, the present invention also provides a liquor spectrum classification system, comprising:
[0097] Category setting module, used to set the classification category of liquor;
[0098] A classification discriminator building module is used to select a binary classification algorithm between all liquor categories and a characteristic wavelength for classification to build a classification discriminator; the binary classification algorithm includes a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm;
[0099] The classification result acquisition module is used to input the spectral data of the liquor to be classified into all classification discriminators to obtain several classification results; and the category with the most repetitions among the several classification results is used as the final category of the liquor to be classified.
[0100] Embodiment 3
[0101] The present invention also provides a computer system, comprising a processor and a memory; a computer program is stored in the memory, and when the computer program is executed by the processor, the above-mentioned liquor spectrum classification method can be implemented.
[0102] 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 method for classifying liquor spectra, characterized in that include: Set the liquor classification category; A binary classification algorithm is selected between all liquor categories and a characteristic wavelength used for classification is used to construct a classification discriminator; the binary classification algorithm includes a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm; 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 n elements; the number of the 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 prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a prediction model, inputs the pre-built validation set into the prediction model, and calculates the prediction accuracy of each prediction model; The saving step saves the array with the highest prediction accuracy of the prediction model established 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 stop 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 elements in an 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.
2. A liquor spectral classification method according to claim 1, characterized in that: One or more of a competitive adaptive reweighted sampling algorithm, a continuous projection algorithm, and a random forest feature importance algorithm are used to select a characteristic wavelength for constructing a classification discriminator.
3. A liquor spectral classification method according to claim 1, characterized in that The method to set the mutation probability is to use the formula: ; Set the mutation probability; Among them, v i is the mutation probability of the i-th iteration, v i-1 is the mutation probability of the i-1th iteration, and N is the number of iterations.
4. The method for spectral classification of liquor according to claim 1, characterized in that: The stopping condition is reaching the number of iterations or reaching a preset prediction accuracy.
5. A liquor spectral classification system, characterized in that include: Category setting module, used to set the classification category of liquor; A classification discriminator construction module selects a binary classification algorithm and a characteristic wavelength for classification from among all liquor categories to construct a classification discriminator; the binary classification algorithm includes a support vector machine algorithm, a decision tree algorithm, a linear discriminant analysis algorithm, and a partial least squares discriminant analysis algorithm; A classification result acquisition module is used to input the spectral data of the liquor to be classified into all classification discriminators to obtain a number of 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 n elements; the number of the 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 prediction step uses several binary classification algorithms and the characteristic wavelengths selected in the array to establish a prediction model, inputs the pre-built validation set into the prediction model, and calculates the prediction accuracy of each prediction model; The saving step saves the array with the highest prediction accuracy of the prediction model established 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 stop 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 elements in an 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.
6. A computer system, characterized in that: It comprises a processor and a memory; a computer program is stored in the memory, and when the computer program is executed by the processor, the white wine spectral classification method described in any one of claims 1 to 4 can be implemented.
