Random forest algorithm-based method for identifying new grains by old grains
By processing grain quality data using the random forest algorithm and combining it with time difference, the inaccuracy of traditional methods for identifying new and old grains is solved. This enables rapid, accurate, and intelligent management of grain classification, improving the safety and efficiency of grain storage.
Patent Information
- Application Number
- CN202510946437.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-09
- Publication Date
- 2025-11-14
AI Technical Summary
Traditional methods for identifying new and old grain rely on human experience and are not very accurate. Existing technologies lack comprehensiveness and systematicity, leading to frequent instances of old grain being passed off as new, which affects the safety and efficiency of grain storage.
The random forest algorithm is used to perform anomaly handling, missing value imputation and normalization on grain quality data. Combined with the difference between grain quality inspection time and harvest time, the random forest model is used to classify and predict new grain and old grain, and an early warning mechanism is used to identify the situation of old grain being replaced by new grain.
It has enabled rapid and accurate classification of old and new grains, reduced manual intervention, improved the safety and efficiency of grain storage, and enhanced the level of intelligent management.
Smart Images

Figure CN120952666A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of grain storage management technology, specifically relating to a method for identifying the new and old grain based on the random forest algorithm. Background Technology
[0002] During grain transportation and storage, the phenomenon of substituting old grain for new grain frequently occurs, meaning that older grain is treated as new grain. This not only poses a threat to grain storage but can also lead to spoilage.
[0003] Traditionally, distinguishing between new and old grains relied primarily on human experience, sensory judgment, and the grain's aroma. This method was time-consuming, labor-intensive, and inaccurate, prone to misjudgment. Currently, although some technologies attempt to use statistical analysis models to assess indicators such as moisture content and impurity content in grains and determine their age, these methods typically select fewer grain quality indicators, lacking comprehensiveness and systematicity. Furthermore, the selection of warning thresholds is highly subjective, resulting in insufficient objectivity and accuracy in the judgments. Summary of the Invention
[0004] To address at least one of the technical problems existing in the background art, this application provides a method for identifying new grain by substituting old grain with new grain based on the random forest algorithm. By using the random forest algorithm to analyze grain quality data, it achieves rapid and accurate classification of new and old grain, effectively avoids the occurrence of substituting old grain with new grain, and improves the safety and efficiency of grain storage.
[0005] The technical solution adopted in this application is as follows:
[0006] The first aspect of this application provides a method for identifying aged grain based on a random forest algorithm, including:
[0007] Acquire grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains, and perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0008] The output category is determined based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0009] Using preprocessed grain quality data as input, a random forest model is used to classify and predict the new grain and the old grain.
[0010] According to the first aspect of this application, the method for identifying new and old grains based on the random forest algorithm first acquires grain quality data, including key indicators such as moldy grains, impurities, bulk density, moisture content, and imperfect grains. This data undergoes anomaly processing, missing value imputation, and data normalization. This preprocessing step not only ensures data quality and consistency but also provides a reliable data foundation for subsequent model training, effectively improving the accuracy and robustness of model predictions. Secondly, the output category is determined based on the difference between the grain inspection time and the harvest time. A difference of 0 between the inspection time and the harvest year is defined as new grain, while the difference is defined as old grain. This method directly uses time difference as the classification basis, is simple and intuitive, and helps to quickly locate the newness or oldness of grain, improving work efficiency. Finally, the preprocessed grain quality data is used as input, and the random forest model is used to classify and predict new and old grains. The random forest model is known for its high accuracy and strong generalization ability, effectively learning the intrinsic relationships between different features, thereby achieving accurate classification of grain attributes. Overall, this method reduces the need for human intervention, lowers the possibility of human error, and significantly improves the safety and efficiency of grain storage.
[0011] According to one embodiment of this application, the acquisition of grain quality data includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. The grain quality data undergoes anomaly processing, missing value imputation, and data normalization, specifically as follows:
[0012] Remove duplicate data and data with numerical errors from the grain quality data, and remove data whose deviation from the index mean exceeds three times the standard deviation;
[0013] For missing values in each grain quality data, the average of the non-null values is used to fill them;
[0014] The minimum-maximum normalization method was used to normalize the filled grain quality data.
[0015] According to one embodiment of this application, the step of using preprocessed grain quality data as input to classify and predict the new grain and the old grain using a random forest model specifically involves:
[0016] The preprocessed grain quality data is divided into a training set and a test set, where the training set is used to build a random forest model and the test set is used to evaluate the model performance.
[0017] The random forest algorithm is used to learn from the training set, multiple decision trees are constructed, and the final classification result is determined by a voting mechanism;
[0018] The quality inspection data of newly stored grain is input into the trained random forest model, which outputs the prediction result of whether the grain is new or old and stores it in the database.
[0019] According to one embodiment of this application, the method further includes:
[0020] After the model prediction is completed, the prediction results are compared with the grain attribute information registered in the warehouse;
[0021] If the prediction result is inconsistent with the registration information, a warning signal for Chen Dingxin will be generated and the warning information will be written into the database.
[0022] According to one embodiment of this application, the early warning information includes grain sample number, grain category registered in the warehouse, grain category predicted by the model, prediction confidence level, anomaly detection time, and corresponding grain quality index data.
[0023] According to one embodiment of this application, the method further includes:
[0024] Before constructing the random forest model, the hyperparameters of the model are tuned using a grid search method. The hyperparameters include the number of decision trees, the maximum depth, the minimum number of samples when splitting nodes, and the maximum number of features. Cross-validation is used to select the appropriate parameter combination to improve classification accuracy.
[0025] According to one embodiment of this application, the method further includes:
[0026] New grain quality data are collected regularly and the training set is updated. The random forest model is periodically retrained using incremental learning to adapt to the changing trends of grain quality indicators over time.
[0027] A second aspect of this application provides a grain identification device based on a random forest algorithm, comprising:
[0028] The data acquisition module is suitable for acquiring grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains, and performs abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0029] The category definition module is suitable for determining the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0030] The prediction module is suitable for using preprocessed grain quality data as input to classify and predict the new grain and the old grain using a random forest model.
[0031] A third aspect of this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the grain identification method based on the random forest algorithm as described in any of the first aspects above.
[0032] This application also provides a non-volatile computer storage medium storing computer-executable instructions thereon, wherein the computer program, when executed by a processor, implements the grain identification method based on the random forest algorithm as described in any embodiment of the first aspect above. Attached Figure Description
[0033] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0034] Figure 1 A flowchart illustrating the grain identification method based on the random forest algorithm provided in this application embodiment;
[0035] Figure 2 A schematic diagram of the structure of the grain identification device based on the random forest algorithm provided in this application embodiment;
[0036] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0037] Figure label:
[0038] 110. Data Acquisition Module; 120. Category Definition Module; 130. Prediction Module;
[0039] 810, Processor; 820, Communication interface; 830, Memory; 840, Communication bus. Detailed Implementation
[0040] To more clearly illustrate the overall concept of this application, a detailed explanation is provided below with reference to the accompanying drawings.
[0041] Many specific details are set forth in the following description to provide a thorough understanding of this application. However, this application may also be implemented in other ways different from those described herein. Therefore, the scope of protection of this application is not limited to the specific embodiments disclosed below. It should be noted that, unless otherwise specified, the embodiments of this application and the features thereof can be combined with each other.
[0042] In this application, unless otherwise expressly specified and limited, the "above" or "below" of the second feature can mean that the first and second features are in direct contact, or that the first and second features are in indirect contact through an intermediate medium. In the description of this specification, references to terms such as "an embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples.
[0043] like Figure 1 As shown, the first aspect of this application provides a method for identifying the newness of grain based on the random forest algorithm, including:
[0044] Step 100: Obtain grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. Perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0045] Step 200: Determine the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0046] Step 300: Using the preprocessed grain quality data as input, classify and predict new and old grains using a random forest model.
[0047] In step 100, the first step is to acquire grain quality data, including information on moldy grains, impurities, bulk density, moisture content, and defective grains. This data forms the basis for assessing grain quality and is crucial for ensuring the accuracy of subsequent modeling. Next, this data undergoes outlier processing, missing value imputation, and data normalization. For example, in the outlier processing stage, duplicate or obviously erroneous data is removed, as well as data whose deviation from the mean of the indicator exceeds three standard deviations. For missing values, the average of non-null values is used for imputation. Finally, the data is normalized using a min-max normalization method. This eliminates the influence of differences in units and value ranges between different features, making the data more standardized. This comprehensive data preprocessing not only improves data quality but also provides more reliable data input for the random forest model, thereby enhancing the accuracy and robustness of the model's predictions.
[0048] In step 200, the newness or oldness of the grain is determined based on the difference between the grain inspection time and the harvest time. Specifically, if the difference between the inspection time and the harvest year is 0, the grain is defined as new grain; otherwise, it is defined as old grain. This method is simple, direct, and easy to operate, while also quickly identifying the newness or oldness of the grain. For example, if a batch of grain was harvested in 2024 and no problems were found in the quality inspection that year, it is classified as new grain; conversely, if the inspection time is 2025, it is automatically classified as old grain. This step effectively avoids errors that may occur with manual judgment, improves work efficiency, and also ensures the consistency and accuracy of grain attribute classification.
[0049] In step 300, preprocessed grain quality data is used as input to classify and predict whether the grain is new or old using a random forest model. The random forest model consists of multiple decision trees, each trained on a subset of samples, and the final classification result is determined through a voting mechanism. For example, in a specific case, after newly received grain undergoes quality inspection, its various quality data (such as moldy grains, impurities, etc.) are input into the trained random forest model. The model can quickly and accurately predict whether this batch of grain is new or old and records the result in the database. Due to its high accuracy, strong generalization ability, and resistance to overfitting, the random forest model is particularly suitable for processing complex grain quality data. It can effectively improve the accuracy of grain attribute classification, reduce the risk of misjudgment caused by human intervention, and further ensure the safety and quality of grain storage.
[0050] According to the first aspect of this application, the method for identifying new and old grains based on the random forest algorithm first acquires grain quality data, including key indicators such as moldy grains, impurities, bulk density, moisture content, and imperfect grains. This data undergoes anomaly processing, missing value imputation, and data normalization. This preprocessing step not only ensures data quality and consistency but also provides a reliable data foundation for subsequent model training, effectively improving the accuracy and robustness of model predictions. Secondly, the output category is determined based on the difference between the grain inspection time and the harvest time. A difference of 0 between the inspection time and the harvest year is defined as new grain, while the difference is defined as old grain. This method directly uses time difference as the classification basis, is simple and intuitive, and helps to quickly locate the newness or oldness of grain, improving work efficiency. Finally, the preprocessed grain quality data is used as input, and the random forest model is used to classify and predict new and old grains. The random forest model is known for its high accuracy and strong generalization ability, effectively learning the intrinsic relationships between different features, thereby achieving accurate classification of grain attributes. Overall, this method reduces the need for human intervention, lowers the possibility of human error, and significantly improves the safety and efficiency of grain storage.
[0051] In some embodiments of this application, grain quality data is obtained, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. The grain quality data is then processed for anomaly handling, missing value imputation, and data normalization. Specifically:
[0052] Remove duplicate and erroneous data from the grain quality data, and remove data whose deviation from the indicator mean exceeds three times the standard deviation.
[0053] For missing values in each grain quality data, the average of the non-null values is used to fill them;
[0054] The minimum-maximum normalization method was used to normalize the filled grain quality data.
[0055] In acquiring grain quality data, the first step is to process outliers. This includes removing duplicate and erroneous data, and further removing data whose values deviate from the mean by more than three standard deviations. For example, when checking the moisture content of a batch of grain, if the moisture content of a sample is significantly higher or lower than the normal range (e.g., exceeding the mean by ±3 standard deviations), it is considered an outlier and removed. This method effectively avoids the negative impact of outliers on model training, ensuring that subsequent analysis is based on accurate and reliable datasets, thereby improving the accuracy and robustness of model predictions.
[0056] For missing values in grain quality data, imputation using the average of non-null values is a common approach. For example, in data on moldy grains, if information on moldy grains is missing for some samples, these missing values can be filled by calculating the average of moldy grains from other samples in the same batch. This not only maintains the integrity of the dataset but also reduces prediction bias caused by incomplete data. This method is simple and easy to implement, particularly suitable for handling missing values in large-scale datasets, and helps improve overall data quality and model performance.
[0057] Finally, the min-max normalization method is used to normalize the filled grain quality data. This means scaling the data of each feature to a specific range (usually [0,1]). For example, the value ranges of bulk density and impurities may vary greatly; normalization can bring them to the same order of magnitude, facilitating learning and prediction by the random forest model. This approach helps eliminate the influence of differences in units and value ranges between different features, making model training more efficient and improving the model's adaptability to new data, ensuring the consistency and accuracy of classification results.
[0058] In some embodiments of this application, preprocessed grain quality data is used as input, and a random forest model is used to classify and predict new and old grains, specifically as follows:
[0059] The preprocessed grain quality data is divided into a training set and a test set, where the training set is used to build a random forest model and the test set is used to evaluate the model performance.
[0060] The random forest algorithm is used to learn from the training set, multiple decision trees are constructed, and the final classification result is determined by a voting mechanism;
[0061] The quality inspection data of newly stored grain is input into the trained random forest model, which outputs the prediction result of whether the grain is new or old and stores it in the database.
[0062] In the process of using preprocessed grain quality data to classify and predict new and old grains, the data first needs to be divided into training and testing sets. For example, an 8:2 ratio can be used, with 80% of the data used to build a random forest model (training set) and the remaining 20% used to evaluate the model's performance (test set). This division method ensures that the model can learn useful patterns from a large amount of data while also validating its generalization ability on independent datasets. This approach not only effectively avoids overfitting but also ensures the reliability of the model in practical applications.
[0063] Next, a random forest algorithm is used to learn from the training set, constructing multiple decision trees, and a voting mechanism is used to determine the final classification result. Each decision tree is trained on a subset of samples, and only a portion of features are considered when splitting nodes. This increases the diversity of the model and improves its robustness and generalization ability. For a concrete example, suppose we have 100 decision trees. When a new set of grain quality data is input, each tree will provide a classification result (new grain or old grain), and the final classification result is determined by majority voting. This method not only improves classification accuracy but also reduces the bias that a single decision tree might introduce.
[0064] Finally, the quality inspection data of newly stored grain is input into a pre-trained random forest model, which outputs a prediction of whether the grain is new or old, and stores this prediction in the database. For example, after a batch of newly stored grain undergoes quality inspection, its quality data, such as moldy grains, impurities, bulk density, moisture content, and defective grains, are input into the model. The model automatically determines whether this batch of grain is new or old and records the result. This step not only simplifies the operation process and reduces the possibility of manual intervention, but also greatly improves work efficiency and accuracy, helping to promptly detect and prevent the substitution of old grain for new grain, thereby ensuring the safety and quality of grain storage.
[0065] In some embodiments of this application, the method further includes:
[0066] After the model prediction is completed, the prediction results are compared with the grain attribute information registered in the warehouse;
[0067] If the prediction result is inconsistent with the registration information, a warning signal for Chen Dingxin will be generated and the warning information will be written into the database.
[0068] This application's method, after completing the prediction using the random forest model, further introduces a mechanism to compare the prediction results with the grain entry registration information. Specifically, after the model outputs the prediction result for new or old grain, the system automatically compares the prediction result with the grain attribute information registered at the time of entry (such as whether it is labeled as new or old grain). For example, if a batch of grain is labeled as "new grain" in the entry registration, but the model predicts it as "old grain," this indicates an inconsistency, which may mean that the batch of grain was substituting old grain for new grain.
[0069] Once a discrepancy is detected between the predicted results and the grain storage registration information, the system will automatically generate a warning signal and write the warning information, including the grain batch, predicted category, actual registered category, and relevant quality inspection data, into the database. This warning mechanism is highly automated and real-time, effectively identifying potential violations or misregistrations, greatly improving the scientific rigor and accuracy of grain storage supervision. Simultaneously, the recording of warning information provides reliable data support for subsequent manual review and audit traceability, enhancing management transparency and accountability.
[0070] This process not only enhances the application value of the model in actual business scenarios, but also builds a closed-loop management system of "automatic identification + intelligent early warning + data traceability", which helps to prevent food quality risks, ensure national food reserve security, and improve the overall intelligence level of food management.
[0071] In some embodiments of this application, the early warning information includes the grain sample number, the grain category registered in the warehouse, the grain category predicted by the model, the prediction confidence level, the anomaly detection time, and the corresponding grain quality index data.
[0072] Grain Sample Number: This is a unique identifier for each batch of grain, facilitating tracking and management. For example, a sample number might be "2025-GR001," which helps managers quickly locate the specific grain batch.
[0073] Grain category registration upon entry into storage: This records the category of grain registered upon entry into storage, i.e., new grain or old grain. This information comes from the initial entry registration record and is crucial for subsequent comparison of predicted results with the actual registration situation.
[0074] The model predicts the grain category: the category (new or old grain) derived from analysis using a random forest model. If the model predicts a batch of grain to be old grain, but it is marked as new grain in the warehousing registration, this may indicate a problem.
[0075] Prediction confidence level: This represents the model's level of confidence in the classification result. For example, if the model predicts a batch of grain to be old grain with a 90% confidence level, this indicates that based on the input data, the model is highly certain that the batch of grain belongs to the old grain category. Confidence level provides additional support for decision-making and helps assess the urgency of the warning.
[0076] Anomaly Detection Time: Records the specific time when the system detected an inconsistency and generated an alert. This is very useful for tracking the occurrence time and response speed of problems, such as "June 30, 2025, 17:47".
[0077] Corresponding grain quality index data: This includes all relevant grain quality data used for model prediction, such as moldy grains, impurities, bulk density, moisture content, and defective grains. This detailed data not only supports the model's prediction process but also provides a basis for subsequent in-depth analysis and validation.
[0078] In some embodiments of this application, the method further includes:
[0079] Before constructing the random forest model, the hyperparameters of the model were tuned using a grid search method. The hyperparameters included the number of decision trees, maximum depth, minimum number of samples when splitting nodes, and maximum number of features. Cross-validation was used to select the appropriate parameter combination to improve classification accuracy.
[0080] Before constructing the random forest model, this method employs a grid search approach to fine-tune the model's hyperparameters to improve classification accuracy. Specifically, this method involves adjusting a series of key hyperparameters, including but not limited to the number of decision trees, the maximum depth of each tree, the minimum number of samples required to split a node, and the maximum number of features used for splitting.
[0081] First, by setting a range of possible values for a hyperparameter, the grid search method systematically traverses all possible combinations of these hyperparameters. For example, the number of decision trees can be set to different values from 10 to 100, the maximum depth can vary from 5 to 20 layers, the minimum number of samples when splitting a node can be any integer between 2 and 10, and the maximum number of features is determined based on the specific circumstances of the actual dataset.
[0082] Next, cross-validation is used to evaluate the performance of each hyperparameter combination. Cross-validation typically employs K-fold cross-validation, which divides the training dataset into K subsets. Each time, one subset is used as the validation set, and the remaining K-1 subsets are combined as the training set. This process is repeated K times, using a different subset as the validation set each time. This ensures that each subset has a chance to be evaluated as a validation set, resulting in more reliable and stable model performance evaluation results.
[0083] Ultimately, the best-performing hyperparameter combination was selected to construct the random forest model. This method effectively improves the model's generalization ability, reduces the risk of overfitting, and maintains high prediction accuracy even when faced with new grain quality data. For example, after grid search and cross-validation, it may be found that the model achieves the highest classification accuracy on the test set when the number of decision trees is 50, the maximum depth is 15 layers, the minimum number of samples for split nodes is 5, and the maximum number of features is 70% of the total number of features. This data-driven approach provides a scientific basis for optimizing the random forest model, further improving the accuracy and reliability of identifying aged grains.
[0084] In some embodiments of this application, the method further includes:
[0085] New grain quality data are collected regularly and the training set is updated. The random forest model is periodically retrained using incremental learning to adapt to the changing trends of grain quality indicators over time.
[0086] In actual grain management, grain quality is affected by various factors such as climate, storage environment, crop variety, and storage policies. Key indicators (such as moisture content, moldy grains, and impurities) may change dynamically over time. Relying solely on an initially constructed static model for classification and prediction may fail to accurately reflect the true attributes of the grain, leading to an increased misjudgment rate. To address this, the system sets a fixed period (such as quarterly or semi-annually) to automatically collect the latest grain quality data from the quality inspection system and add these new samples to the existing training set, forming an expanded training dataset.
[0087] Building upon this, incremental learning is employed to retrain the random forest model. Unlike completely retraining the model, incremental learning retains the original model structure and some learned knowledge, only supplementing the model with new data. This approach reduces computational resource consumption and training time while maintaining model performance. For example, during each update, some decision trees can be fine-tuned based on new data, or a small number of new decision trees can be introduced, allowing the model to gradually adapt to new data distribution trends.
[0088] On the one hand, it ensures that the model can continuously capture the changing patterns of grain quality and maintain a high classification accuracy. On the other hand, through periodic data updates and model optimization, it enhances the system's adaptability and improves the generalization performance of the identification method across different seasons, years, and regions. Furthermore, combined with the aforementioned early warning mechanism, this dynamic update strategy helps to promptly identify potential risks caused by environmental or human factors, providing more intelligent, stable, and sustainable technical support for grain storage supervision.
[0089] like Figure 2 As shown, a second aspect of this application provides a grain aging and aging identification device based on a random forest algorithm, comprising:
[0090] The data acquisition module 110 is suitable for acquiring grain quality data, which includes at least moldy grains, impurities, bulk density, moisture and imperfect grains, and performs abnormal data processing, missing value filling and data normalization on the grain quality data.
[0091] The category definition module 120 is suitable for determining the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as the new grain category; otherwise, it is defined as the old grain category.
[0092] The prediction module 130 is suitable for using preprocessed grain quality data as input to classify and predict new and old grains through a random forest model.
[0093] The grain identification device based on random forest algorithm provided in the second aspect of this application can realize the grain identification method based on random forest algorithm in any of the embodiments of the first aspect above. Therefore, it can achieve any of the technical effects of the above-mentioned grain identification method based on random forest algorithm, which will not be repeated here.
[0094] A third aspect of this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the grain identification method based on the random forest algorithm described in any of the first aspects above.
[0095] Figure 3 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 3As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 can call logical instructions in the memory 830 to execute the grain identification method based on the random forest algorithm in any embodiment of the first aspect described above, the method including:
[0096] Step 100: Obtain grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. Perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0097] Step 200: Determine the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0098] Step 300: Using the preprocessed grain quality data as input, classify and predict new and old grains using a random forest model.
[0099] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0100] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer is able to execute the grain identification method based on the random forest algorithm provided by the above methods, the method comprising:
[0101] Step 100: Obtain grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. Perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0102] Step 200: Determine the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0103] Step 300: Using the preprocessed grain quality data as input, classify and predict new and old grains using a random forest model.
[0104] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the grain identification method based on the random forest algorithm provided by the above methods, the method comprising:
[0105] Step 100: Obtain grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. Perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0106] Step 200: Determine the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0107] Step 300: Using the preprocessed grain quality data as input, classify and predict new and old grains using a random forest model.
[0108] Finally, the present invention also provides a non-volatile computer storage medium storing computer-executable instructions thereon, which, when executed by a processor, implements the above-described grain identification method based on the random forest algorithm, comprising:
[0109] Step 100: Obtain grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains. Perform abnormal data processing, missing value filling, and data normalization on the grain quality data.
[0110] Step 200: Determine the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain.
[0111] Step 300: Using the preprocessed grain quality data as input, classify and predict new and old grains using a random forest model.
[0112] For any parts not mentioned in this application, existing technologies may be used or referenced.
[0113] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
[0114] The above description is merely an embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for identifying the newness of grain based on the random forest algorithm, characterized in that, include: Acquire grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains, and perform abnormal data processing, missing value filling, and data normalization on the grain quality data. The output category is determined based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain. Using preprocessed grain quality data as input, a random forest model is used to classify and predict the new grain and the old grain.
2. The method for identifying the new and old grains based on the random forest algorithm according to claim 1, characterized in that, The acquisition of grain quality data includes at least moldy grains, impurities, bulk density, moisture content, and defective grains. The grain quality data undergoes anomaly processing, missing value imputation, and data normalization, specifically as follows: Remove duplicate data and data with numerical errors from the grain quality data, and remove data whose deviation from the index mean exceeds three times the standard deviation; For missing values in each grain quality data, the average of the non-null values is used to fill them; The minimum-maximum normalization method was used to normalize the filled grain quality data.
3. The method for identifying the new and old grains based on the random forest algorithm according to claim 1, characterized in that, The process of using preprocessed grain quality data as input and classifying and predicting the new and old grains using a random forest model specifically involves: The preprocessed grain quality data is divided into a training set and a test set, where the training set is used to build a random forest model and the test set is used to evaluate the model performance. The random forest algorithm is used to learn from the training set, multiple decision trees are constructed, and the final classification result is determined by a voting mechanism; The quality inspection data of newly stored grain is input into the trained random forest model, which outputs the prediction result of whether the grain is new or old and stores it in the database.
4. The method for identifying aged grain based on random forest algorithm according to any one of claims 1 to 3, characterized in that, The method also includes: After the model prediction is completed, the prediction results are compared with the grain attribute information registered in the warehouse; If the prediction result is inconsistent with the registration information, a warning signal for Chen Dingxin will be generated and the warning information will be written into the database.
5. The method for identifying aged grain based on random forest algorithm according to claim 4, characterized in that, The early warning information includes the grain sample number, the grain category registered upon entry into the warehouse, the grain category predicted by the model, the prediction confidence level, the anomaly detection time, and the corresponding grain quality index data.
6. The method for identifying the new and aged grains based on the random forest algorithm according to claim 1, characterized in that, The method also includes: Before constructing the random forest model, the hyperparameters of the model are tuned using a grid search method. The hyperparameters include the number of decision trees, the maximum depth, the minimum number of samples when splitting nodes, and the maximum number of features. Cross-validation is used to select the appropriate parameter combination to improve classification accuracy.
7. The method for identifying the new and aged grains based on the random forest algorithm according to claim 1, characterized in that, The method also includes: New grain quality data are collected regularly and the training set is updated. The random forest model is periodically retrained using incremental learning to adapt to the changing trends of grain quality indicators over time.
8. A grain identification device based on random forest algorithm, characterized in that, include: The data acquisition module is suitable for acquiring grain quality data, which includes at least moldy grains, impurities, bulk density, moisture content, and imperfect grains, and performs abnormal data processing, missing value filling, and data normalization on the grain quality data. The category definition module is suitable for determining the output category based on the difference between the grain quality inspection time and the harvest time. If the difference between the quality inspection time and the harvest year is 0, it is defined as new grain; otherwise, it is defined as old grain. The prediction module is suitable for using preprocessed grain quality data as input to classify and predict the new grain and the old grain using a random forest model.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the grain identification method based on the random forest algorithm as described in any one of claims 1 to 7.
10. A non-volatile computer storage medium storing computer-executable instructions thereon, characterized in that, When the computer program is executed by the processor, it implements the grain identification method based on the random forest algorithm as described in any one of claims 1 to 7.