Three-color code early warning method for simulating farmland operation prediction based on machine learning
By applying machine learning technology in agriculture, building a agricultural prediction decision tree model, collecting and processing farmland data in real time, and providing three-color code early warning information, it solves the problems of inefficient and incomplete information in traditional agricultural management, and achieves efficient and timely Forecast and management of farmland operations.
Patent Information
- Application Number
- CN202411476430.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2025-02-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional agricultural management relies on manual experience and is inefficient, unable to cover large areas of farmland for 24 hours, incomplete information collection, untimely response, and difficult to ensure the consistency and accuracy of evaluation, and cannot meet the needs of modern agricultural development.
Using a three-color code early warning method based on machine learning, we use the real-time data collection by deploying sensor networks in farmland, cleaning and processing data, and building a agricultural prediction decision tree model to provide real-time three-color code early warning information.
It has achieved highly accurate and timely provision of early warning information, helping farmers respond to potential risks and opportunities in a timely manner, improving the relevance and effectiveness of operations, reducing risks, reducing crop losses, and improving resource utilization efficiency.
Smart Images

Figure CN119476930A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an early warning method for farmland operation prediction, and in particular to a three-color code early warning method based on machine learning simulation of farmland operation prediction, belonging to the technical field of smart agriculture. Background Art
[0002] In traditional agricultural management, the monitoring of agricultural activities and the evaluation of plant growth conditions mainly rely on manual experience, which faces many challenges. First, manual monitoring is inefficient and cannot cover large areas of farmland for 24 hours, resulting in incomplete information collection and untimely response. Second, manual evaluation is easily affected by personal knowledge level, experience differences and subjective judgment, making it difficult to ensure the consistency and accuracy of the evaluation. In addition, with the expansion of agricultural scale, the demand for data processing and analysis is increasing, and traditional methods can no longer meet the needs of modern agricultural development. In order to overcome these limitations, the introduction of intelligent and automated technologies based on machine learning has become the key to improving the efficiency and accuracy of agricultural management. As an important branch of artificial intelligence, machine learning can efficiently process and deeply analyze complex agricultural data by learning patterns and laws from data. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a three-color code early warning method based on machine learning simulation of farmland operation prediction.
[0004] To achieve the above object, the present invention adopts the following technical solution:
[0005] A farmland three-color code early warning method based on machine learning simulation operation prediction includes the following steps:
[0006] Step 1: Data collection: Collect data information from sensors installed on farmland. The data information includes:
[0007] Illumination feature Ill = {ill1, ill2, ill3, ..., ill k}、Air temperature characteristics AirT={at1,at2,at3,…,at k}, soil temperature characteristics SoilT = {st1,st2,st3,…,st k}、Air humidity characteristic AirH={ah1,ah2,ah3,…,ah k}, soil moisture characteristics; SoilH = {sh1, sh2, sh3, …, sh k}; where k represents the number of measurements;
[0008] Step 2: Data cleaning: clean the data information and construct a data set;
[0009] Step 3: Data processing: Handling missing values and outliers in the data set: It consists of the following specific steps:
[0010] Step 3-1: Identify and handle missing values: Check the missing values in the data set, mark the missing values with preset symbols, and delete the rows with missing values if the missing value ratio is less than the preset ratio; if the missing value ratio is greater than the preset ratio, fill the missing values with the mean of the corresponding data in the data set, or fill them with the corresponding value at the previous moment of the missing value;
[0011] Step 3-2: Identify outliers: Identify outliers one by one from the illumination feature, air temperature feature, soil temperature feature, air humidity feature, and soil humidity feature data according to the following method; first, sort from small to large, find the preset first quartile Q1 and the preset second quartile Q2 in the sorted data, determine the lower limit of the outlier as Q1-1.5×(Q2-Q1), and the upper limit as Q3+1.5×(Q2-Q1), and determine whether the current value is less than the lower limit of the outlier or greater than the upper limit of the outlier. If so, mark it as an outlier and go to step 3-3, otherwise go to step 4;
[0012] Step 3-3: Handle outliers: Use normal values before and after to replace outliers;
[0013] Step 4: Data conversion: Use Z-score normalization to normalize the light characteristics, air temperature characteristics, soil temperature characteristics, air humidity characteristics, and soil humidity characteristics data one by one; the calculation method of Z-score y is:
[0014]
[0015] Among them, x is the data value of each eigenvalue; mean and std are the mean and standard deviation of the corresponding eigenvalue respectively;
[0016] Step 5: Filter data: Use mean, median, standard deviation and quartile values, as well as line charts and scatter plots to determine important data A according to preset standards;
[0017] Step 6: Divide the data set: Use the Bootstrap sampling method to divide the important data A into training set and test set;
[0018] The Bootstrap sampling method is to randomly select a sample from the important data A and copy it into the training set A1, repeating the operation until there are m samples in the training set A1, and the samples in the important data A that do not appear in the training set A1 constitute the test set A2; label each sample in the training set A1 with the farming type label;
[0019] Step 7: Construct agricultural prediction decision tree model:
[0020] The illumination feature Ill, air temperature feature AirT, soil temperature feature SoilT, air humidity feature AirH, and soil humidity feature SoilH are divided into two data subsets one by one under each division value; the Gini coefficient of each Gini coefficient subset is calculated respectively, and the calculation method of the Gini coefficient is:
[0021]
[0022] where p i is the proportion of the i-th farming type in the farming type set CropO = {'sowing', 'irrigation', 'turning', 'fertilization'}; n is the number of farming types in the farming type set;
[0023] Select the feature and split point that minimizes the sum of the Gini coefficients of the two Gini coefficient subsets as the optimal feature x of the current layer i ;
[0024] Recursively determine the optimal features of the next layer for the two Gini coefficient subsets after segmentation and construct a decision tree;
[0025] The recursive stopping condition of the decision tree is to stop splitting the data set if one of the following conditions is met:
[0026] (1) The tree depth reaches the specified value;
[0027] (2) The amount of data in the data subset is less than the preset value;
[0028] (3) the farming types of the data subsets are the same;
[0029] (4) Each feature has been judged;
[0030] The farming type of each leaf node is the farming type with the largest number of samples in the corresponding data subset;
[0031] Step 8: Use decision trees to predict farming types: According to the optimal features x of each layer of the decision tree i Divide the data set, and the agricultural activity label corresponding to the leaf node is the predicted agricultural activity type.
[0032] Step 9: Provide three-color code warning information: Provide real-time three-color code warning information based on the prediction results. The three colors in the three-color code represent different warning levels and urgency levels. The first color indicates that the agricultural activity is overdue for more than the preset number of days, the second color indicates that the agricultural activity is overdue for less than the preset number of days, and the third color indicates no warning.
[0033] Furthermore, it also includes a tuning step: marking the agricultural type of the test set, using a decision tree to predict the agricultural type of each sample in the test set; collecting prediction error samples; if the number of prediction error samples is greater than a preset value; using the prediction set to build a decision tree according to the method of step 7.
[0034] The beneficial effects produced by the present invention are:
[0035] 1. By collecting data in real time and applying decision tree algorithms, it can provide highly accurate and timely early warning information to help farmers respond to potential risks and opportunities in a timely manner.
[0036] 2. Personalized recommendations can be provided based on monitoring the specific conditions and historical data of each farmland, rather than general guidance, thereby improving the relevance and effectiveness of operations.
[0037] 3. Through three-color code early warning, farmers can intervene before problems become serious, reduce risks and reduce crop losses; and through precise operation reminders, farmers can allocate resources such as water, fertilizer and labor more efficiently, reduce waste, and improve economic benefits and environmental sustainability. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0039] The following examples serve to illustrate the invention.
[0040] Example 1
[0041] A farmland three-color code early warning method based on machine learning simulation operation prediction includes the following steps:
[0042] Step 1: Data collection: Collect data information from sensors installed on farmland. The data information includes:
[0043] Illumination feature Ill = {ill1, ill2, ill3, ..., ill k}、Air temperature characteristics AirT={at1,at2,at3,…,at k}, soil temperature characteristics SoilT = {st1,st2,st3,…,st k}、Air humidity characteristic AirH={ah1,ah2,ah3,…,ah k}, soil moisture characteristics; SoilH = {sh1, sh2, sh3, …, sh k}; where k represents the number of measurements;
[0044] Step 2: Data cleaning: clean the data information and construct a data set;
[0045] Step 3: Data processing: Handling missing values and outliers in the data set: It consists of the following specific steps:
[0046] Step 3-1: Identify and handle missing values: Check the missing values in the data set, mark the missing values with preset symbols, and delete the rows containing missing values if the missing value ratio is less than the preset ratio; if the missing value ratio is greater than the preset ratio, fill the missing values with the mean of the corresponding data in the data set, or fill them with the corresponding values at the previous moment;
[0047] Step 3-2: Identify outliers: First, sort the illumination characteristics, air temperature characteristics, soil temperature characteristics, air humidity characteristics, and soil humidity characteristics data from small to large, find the 25% position of the sorted data as the first quartile Q1, and the 75% position of the sorted data as the third quartile Q3, calculate the interquartile range IQR = Q3-Q1, determine the lower limit of the outlier as Q1-1.5×IQR, and the upper limit as Q3+1.5×IQR, if the value of the data point is less than the lower limit of the outlier or greater than the upper limit of the outlier, the data point is considered an outlier;
[0048] Step 3-3: Handle outliers: Use normal values before and after to replace outliers;
[0049] Step 4: Data transformation: Normalize the data using Z-score; consists of the following specific steps:
[0050] First, the mean and standard deviation std of each feature are calculated for the illumination feature, air temperature feature, soil temperature feature, air humidity feature, and soil humidity feature data; then, the Z score y of each feature is calculated:
[0051]
[0052] Among them, x is the original data point;
[0053] Then use the Z score y of each feature to normalize the corresponding feature data;
[0054] Step 5: Filter data: Use the mean, median, standard deviation and quartile numbers, as well as line charts and scatter plots to determine important data according to preset standards;
[0055] Step 6: Divide the data set. Use the Bootstrap sampling method to divide the important data into training set and test set; randomly select a sample from the important data A containing m samples and copy it and put it into the training set A1. Repeat the operation m times until there are m samples in A1. In this way, A1 is the training set, and the samples in the important data A that do not appear in the training set A1 constitute the test set A2;
[0056] Step 7: Construct a farming prediction decision tree model to determine the timing of farming type CropO = {'sowing', 'irrigation', 'turning', 'fertilization'}. The core of decision tree training is to recursively divide the data to form a tree structure. Each time the division occurs, the model selects the most appropriate feature, such as light, air temperature, etc., and finds a split point, and divides the data into different subsets based on this feature and split point. The model gradually builds a tree by repeatedly performing this split, and ultimately achieves the purpose of being able to make classifications or predictions. It consists of the following specific steps:
[0057] Step 7-1: define the six features of illumination feature Ill, air temperature feature AirT, soil temperature feature SoilT, air humidity feature AirH, and soil humidity feature SoilH as feature set X, which is a variable used to predict the farming type CropO = {'sowing', 'irrigation', 'turning the soil', 'fertilization'}; the farming type CropO = {'sowing', 'irrigation', 'turning the soil', 'fertilization'} is defined as result set CropO, which is the prediction result of the decision tree;
[0058] Step 7-2: By calculating the Gini coefficient GainIndex of the data set, select the optimal feature x in the feature set X that can distinguish the training set data of the parent node into two purer child nodes. i , a purer child node means that most of the agricultural types of the data in the child node belong to the same category. The closer the Gini coefficient is to 0, the closer the agricultural types of the data in the node are to the same category. The specific steps are as follows:
[0059] Step 7-2-1: Calculate the Gini coefficient of the current node data set, which reflects the purity of the current data set's farming type. The specific calculation formula is as follows:
[0060]
[0061] Where n is the type of farming, that is, n = 4; p i is the proportion of a certain farming type i in the data of the current node, CropO = {'sowing', 'irrigation', 'turning', 'fertilization'}; get the Gini coefficient of the current node data set;
[0062] Step 7-2-2: For these 6 features in feature set X: Lighting feature Ill k 、Air temperature characteristics AirT n , soil temperature characteristics SoilT m 、Air humidity characteristics AirH i , soil moisture characteristics SoilH j, take the middle value of each feature value as the possible split point, (for example: the current illumination value is [10000, 20000, 30000, 40000, 50000], the possible split points are 15000, 25000, 35000, 45000;) take a possible split point of a feature each time, divide the current data set into two subsets, and calculate the Gini coefficient of the two subsets after division.
[0063] Step 7-2-3: Traverse all possible split points of all features, and calculate the Gini coefficient of the two subsets of the data set divided into at different split points of different features. Finally, select the feature with the smallest Gini coefficient and its split point as the optimal feature x i .
[0064] Step 7-3: Recursively construct a decision tree. Use the optimal feature xi and its split point to split the current data set into two subsets, repeat step 7-2, and find the optimal features and split points of the remaining features in each subset.
[0065] Step 7-4: Recursive termination conditions. The recursive construction of the decision tree stops according to the following conditions:
[0066] (1) The tree stops when it reaches the specified maximum depth (max_depth).
[0067] (2) If the amount of data in a node is less than the specified minimum data split (min_samples_split), stop splitting the data set of the node.
[0068] (3) Each leaf node contains at least the minimum number of leaf node data (min_samples_leaf).
[0069] (4) If all the data in the node belong to the same farming type, stop splitting the data set.
[0070] (5) Each feature in the feature set X has been judged.
[0071] When the segmentation of the data set stops, the current node will become the leaf node of the tree, and the agricultural activity type with the most data in the leaf node will be the final prediction result of the decision tree for the agricultural activity type.
[0072] Step 8: Adjust the above parameters of maximum depth (max_depth), minimum data split (min_samples_split), and minimum number of leaf node data (min_samples_leaf) through training set A until the Gini coefficient of each leaf node is the smallest, that is, the data of a certain agricultural type in each leaf node data is the purest.
[0073] Step 9: After training, the decision tree structure has each internal node as a feature, representing the judgment of the feature value of this feature in the data. Each leaf node is the final prediction of the farming type CropO = {'sowing', 'irrigation', 'turning the soil', 'fertilization'}.
[0074] example:
[0075] - Root node: Light > 25,000 lux? Yes: branch right, No: branch left.
[0076] -Left branch node: Air temperature > 20℃? Yes: Water, No: Fertilize.
[0077] -Right branch node: Soil moisture > 30%? Yes: sow seeds, No: till the soil.
[0078] Step 10: Use the test set A2 to evaluate the prediction results of the decision tree model. The specific steps are as follows:
[0079] Step 10-1: Calculate the accuracy of the model (the proportion of correct samples to total samples):
[0080]
[0081] Among them, TP is a true positive example, TN is a true negative example, FP is a false positive example, and FN is a false negative example.
[0082] Step 10-2: Calculate the accuracy of the model (how many of the samples predicted to be positive are actually positive):
[0083]
[0084] Step 10-3: Calculate the recall rate of the model (how many of all true positive samples are correctly predicted as positive by the model):
[0085]
[0086] Step 10-4: Calculate the F1 score of the model (the harmonic mean of precision and recall, used to comprehensively evaluate the performance of the model):
[0087]
[0088] Step 11: Input new data and predict the farming activity type through the decision tree model, where the prediction result is a specific farming activity type, such as sowing, irrigation, tilling, and fertilizing.
[0089] Step 12: Provide three-color code warning information: Provide real-time three-color code warning information based on the prediction results. The three color codes represent different warning levels and urgency levels. The first color indicates that the agricultural activity is overdue for more than a preset number of days, the second color indicates that the agricultural activity is overdue for less than a preset number of days, and the third color indicates no warning.
[0090] Step 13: Apply the model prediction to actual agricultural activities, and provide real-time three-color code warning information to administrators and plot managers based on the prediction results. If the agricultural activity has been submitted within the predicted time of the agricultural activity plan, a "green code" will be given; if the current time exceeds the predicted end time of the agricultural activity plan or is earlier than the start time, and it does not exceed 7 days, a "yellow code" warning will be given; if the current time exceeds the predicted end time of the agricultural activity plan or is earlier than the start time, and it exceeds 7 days, a "red code" warning will be given.
[0091] The present invention uses machine learning to monitor agricultural activities in real time. By deploying a sensor network in farmland to collect data (such as soil moisture, temperature, light intensity, etc.), combined with a machine learning model, the system can automatically monitor the growth environment of crops and predict future trends. For example, time series analysis can be used to predict the impact of weather changes on crop growth and help farmers make adjustments in advance. In addition, machine learning can also assist in the planning of agricultural activities. By analyzing historical data, machine learning models can optimize the timing and methods of agricultural activities such as sowing, irrigation, and fertilization, improve resource utilization efficiency, and reduce waste.
[0092] The introduction of machine learning technology provides new perspectives and tools for modern agricultural management. It can not only improve the efficiency and accuracy of management, but also help farmers better cope with environmental changes and achieve sustainable agricultural development. With the continuous advancement of technology and the reduction of costs, machine learning is expected to play a more important role in the agricultural field in the future.
[0093] At present, the technical solution of the present invention has been piloted, and a user survey has been conducted in a small range. The survey results show that user satisfaction is high, and preparations for the transformation and promotion of the results have begun. At the same time, a survey on intellectual property risk warning has been carried out.
Claims
1. A three-color code early warning method based on machine learning to simulate farmland operation prediction, characterized in that: The following steps are involved: Step 1: Data collection: Collect data information from sensors installed on farmland. The data information includes: Illumination feature Ill = {ill1, ill2, ill3, ..., ill k }、Air temperature characteristics AirT={at1,at2,at3,…,at k }, soil temperature characteristics SoilT = {st1,st2,st3,…,st k }、Air humidity characteristic AirH={ah1,ah2,ah3,…,ah k }, soil moisture characteristics; SoilH = {sh1, sh2, sh3, …, sh k }; where k represents the number of measurements; Step 2: Data cleaning: clean the data information and construct a data set; Step 3: Data processing: Handling missing values and outliers in the data set: It consists of the following specific steps: Step 3-1: Identify and handle missing values: Check the missing values in the data set, mark the missing values with preset symbols, and delete the rows with missing values if the missing value ratio is less than the preset ratio; if the missing value ratio is greater than the preset ratio, fill the missing values with the mean of the corresponding data in the data set, or fill them with the corresponding value at the previous moment of the missing value; Step 3-2: Identify outliers: Identify outliers one by one from the illumination feature, air temperature feature, soil temperature feature, air humidity feature, and soil humidity feature data according to the following method; first, sort from small to large, find the preset first quartile Q1 and the preset second quartile Q2 in the sorted data, determine the lower limit of the outlier as Q1-1.5×(Q2-Q1), and the upper limit as Q3+1.5×(Q2-Q1), and determine whether the current value is less than the lower limit of the outlier or greater than the upper limit of the outlier. If so, mark it as an outlier and go to step 3-3, otherwise go to step 4; Step 3-3: Handle outliers: Use normal values before and after to replace outliers; Step 4: Data conversion: Use Z-score normalization to normalize the light characteristics, air temperature characteristics, soil temperature characteristics, air humidity characteristics, and soil humidity characteristics data one by one; the calculation method of Z-score y is: Among them, x is the data value of each eigenvalue; mean and std are the mean and standard deviation of the corresponding eigenvalue respectively; Step 5: Filter data: Use mean, median, standard deviation and quartile values, as well as line charts and scatter plots to determine important data A according to preset standards; Step 6: Divide the data set: Use the Bootstrap sampling method to divide the important data A into training set and test set; The Bootstrap sampling method is to randomly select a sample from the important data A and copy it into the training set A1, repeating the operation until there are m samples in the training set A1, and the samples in the important data A that do not appear in the training set A1 constitute the test set A2; label each sample in the training set A1 with the farming type label; Step 7: Construct agricultural prediction decision tree model: The illumination feature Ill, air temperature feature AirT, soil temperature feature SoilT, air humidity feature AirH, and soil humidity feature SoilH are divided into two data subsets one by one under each division value; the Gini coefficient of each Gini coefficient subset is calculated respectively, and the calculation method of the Gini coefficient is: where p i is the proportion of the i-th farming type in the farming type set CropO = {'sowing', 'irrigation', 'turning', 'fertilization'}; n is the number of farming types in the farming type set; Select the feature and split point that minimizes the sum of the Gini coefficients of the two Gini coefficient subsets as the optimal feature x of the current layer i ; Recursively determine the optimal features of the next layer for the two Gini coefficient subsets after segmentation and construct a decision tree; The recursive stopping condition of the decision tree is to stop splitting the data set if one of the following conditions is met: (1) The tree depth reaches the specified value; (2) The amount of data in the data subset is less than the preset value; (3) the farming types of the data subsets are the same; (4) Each feature has been judged; The farming type of each leaf node is the farming type with the largest number of samples in the corresponding data subset; Step 8: Use decision trees to predict farming types: According to the optimal features x of each layer of the decision tree i Divide the data set, and the agricultural activity label corresponding to the leaf node is the predicted agricultural activity type. Step 9: Provide three-color code warning information: Provide real-time three-color code warning information based on the prediction results. The three colors in the three-color code represent different warning levels and urgency levels. The first color indicates that the agricultural activity is overdue for more than the preset number of days, the second color indicates that the agricultural activity is overdue for less than the preset number of days, and the third color indicates no warning.
2. The three-color code early warning method based on machine learning simulation farmland operation prediction according to claim 1 is characterized in that: It also includes the tuning steps: labeling the agricultural activity types of the test set, using the decision tree to predict the agricultural activity type of each sample in the test set; collecting prediction error samples; if the number of prediction error samples is greater than the preset value; using the prediction set to build a decision tree according to the method in step 7.