Soil nitrogen mineralization rate prediction system based on machine learning
By using the Bonferroni mean fuzzy KNN algorithm and the BER metaheuristic search optimization algorithm in the soil nitrogen mineralization rate prediction system, the problem of the system being sensitive to outliers and fuzziness is solved, the prediction accuracy and optimization efficiency are improved, and the A more robust and efficient prediction of soil nitrogen mineralization rate.
Patent Information
- Application Number
- CN202410418425.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-04-09
AI Technical Summary
Traditional soil nitrogen mineralization rate prediction systems are sensitive to outliers and cannot effectively handle weight differences and ambiguities between soil samples. Moreover, the optimization algorithm has local optimal solution traps, slow convergence speed, search space limitations, and overfitting. risk.
The fuzzy KNN algorithm and BER metaheuristic search optimization algorithm based on Bonferroni mean are used to improve the robustness of the model and optimize the rate prediction model respectively, handle noisy data and anomalies, and conduct global search in the search space.
It improves the robustness and prediction accuracy of the soil nitrogen mineralization rate prediction model, enhances the adaptability and interpretability of the model, achieves rapid convergence and efficient optimization, and improves the performance and efficiency of the model.
Smart Images

Figure CN118070675B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning, and in particular to a soil nitrogen mineralization rate prediction system based on machine learning. Background Art
[0002] Soil nitrogen mineralization rate is one of the important processes in the nitrogen cycle in the soil. Studying the soil nitrogen mineralization rate is crucial to achieving sustainable agricultural production and environmental protection. Machine learning also plays a key role in studying the soil nitrogen mineralization rate. However, in the traditional soil nitrogen mineralization rate prediction system, the KNN algorithm used is sensitive to outliers. If there are outliers in the soil sample, it may have an adverse effect on the prediction results. The traditional KNN algorithm does not take into account the weight differences between different soil samples, and some samples may have a greater impact on the prediction of soil nitrogen mineralization rate. In addition, there are certain Fuzziness. The traditional KNN algorithm cannot handle this ambiguity well. In the general soil nitrogen mineralization rate prediction system, the use of traditional optimization algorithms for the rate prediction model will have problems such as local optimal solution traps, slow convergence, limited search space, overfitting risks and difficulty in tuning. It has a slow convergence speed and requires more iterations to find a solution close to the optimal solution. It is limited by the size and dimension of the search space and cannot effectively explore potential solutions in high-dimensional complex parameter spaces. It may also require manual adjustment of many hyperparameters, such as learning rate, regularization coefficient, etc., to achieve optimal performance, thus affecting the performance and generalization ability of the model. Summary of the invention
[0003] In view of the above situation, the present invention provides a soil nitrogen mineralization rate prediction system based on machine learning. The KNN algorithm is sensitive to outliers, the traditional KNN algorithm does not take into account the weight differences between different soil samples, and cannot handle the ambiguity in the soil nitrogen mineralization rate prediction model well. This solution establishes a rate prediction model by using a fuzzy KNN algorithm based on the Bonferroni mean, and improves the classification accuracy of the model for samples by comprehensively considering the information of multiple nearest neighbor samples. The rate prediction model is more robust by considering the information of multiple nearest neighbor samples, and can handle noisy data and abnormal situations. It does not need to assume the shape of the sample distribution and can adapt well to complex data distribution. Therefore, it improves the prediction accuracy, enhances the robustness of the rate prediction model, adapts to various data types, has good interpretability, and does not require an explicit training process. In the general soil nitrogen mineralization rate prediction system, the rate prediction model uses the traditional Optimization algorithms may have problems such as local optimal solution traps, slow convergence, limited search space, overfitting risks, and difficulty in tuning. This scheme uses the BER meta-heuristic search optimization algorithm to optimize the soil nitrogen mineralization rate prediction model based on machine learning. For rate prediction models, using traditional optimization algorithms will have problems such as local optimal solution traps, slow convergence, limited search space, overfitting risks, and difficulty in tuning. The BER algorithm combines the strategies of exploration and utilization, can perform global search in the search space, and effectively explore potential optimal solutions. It introduces randomness in the search process, which helps to maintain the diversity of solutions during the search process. It also has a faster convergence speed and can find solutions close to the optimal solution in a shorter time. Using the BER meta-heuristic search optimization algorithm to optimize the rate prediction model can bring the benefits of strong global search capabilities, fast convergence speed, diverse solutions, strong adaptability, and easy implementation and tuning, which helps to improve the performance and efficiency of the rate prediction model.
[0004] The soil nitrogen mineralization rate prediction system based on machine learning provided by the present invention includes a data acquisition and preprocessing module, a feature engineering module, a model selection and training module, a model evaluation module, a model deployment and application module, and a model monitoring and maintenance module, which specifically includes the following contents:
[0005] The data acquisition and preprocessing module acquires soil sample data and environmental factor data and performs cleaning, processing and conversion to obtain processed soil sample data and environmental factor data;
[0006] The feature engineering module extracts features related to nitrogen mineralization rate from processed soil sample data and environmental factor data, including soil physical and chemical properties, soil temperature, soil moisture and rainfall;
[0007] The model selection and training module selects a suitable machine learning algorithm, and uses a fuzzy KNN algorithm based on the Bonferroni mean to establish a rate prediction model according to the training data, and uses a BER meta-heuristic search optimization algorithm to optimize the rate prediction model to obtain a trained rate prediction model;
[0008] The model evaluation module uses the test data to evaluate the trained rate prediction model, and evaluates the performance indicators of the rate prediction model, including mean square error, root mean square error and determination coefficient;
[0009] The model deployment and application module deploys the trained rate prediction model into the actual application environment, constructs a prediction system, and allows users to input new soil sample data and environmental factor data to obtain the prediction results of soil nitrogen mineralization rate;
[0010] The model monitoring and maintenance module regularly monitors the performance of the rate prediction model and performs updates and maintenance to ensure the accuracy and reliability of the prediction results.
[0011] Furthermore, in the model selection and training module, the rate prediction model is trained using the Bonferroni mean-based fuzzy KNN algorithm, which specifically includes the following steps:
[0012] Step S1: Data division: put the features related to nitrogen mineralization rate into the data set, divide the data set into a training set and a validation set in a ratio of 7:3, take each feature related to nitrogen mineralization rate as a training sample, set a label for each training sample, and use these labels as the category of the training sample;
[0013] Step S2: Distance calculation: for each training sample, the distance between it and other training samples is calculated using the Euclidean distance.
[0014] Step S3: Find the nearest neighbor. Consider each training sample as a test sample and find the K nearest training samples. These K training samples are called the K nearest neighbors of the test sample.
[0015] Step S4: Calculate the fuzziness. For each category, calculate the fuzziness of the K nearest neighbor samples belonging to the category by distance weighting. The closer the distance, the higher the corresponding fuzziness.
[0016] Step S5: Normalization of fuzziness: normalize the calculated fuzziness and calculate the fuzziness for each category using a distance weighted formula. The formula used is as follows:
[0017] ;
[0018] in, Indicates the fuzziness of the category, is the number of nearest neighbor training samples, Indicates The weights of the nearest neighbor training samples, Indicates The distance from the nearest neighbor training sample to the test sample;
[0019] Step S6: Fuzziness aggregation: use the Bonferroni mean method to aggregate the fuzziness of each category to obtain the confidence of each category. The formula used is as follows:
[0020] ;
[0021] ;
[0022] ;
[0023] in, Indicates category The fuzzy mean of Indicates that the training set belongs to the category The number of training samples, For the belongs to category The fuzziness of the training samples, Indicates category The standard deviation of the fuzziness is Indicates category The confidence level, is a constant with a value of 1;
[0024] Step S7: Establish a model, use the obtained confidence as the category label of the training sample, and build a rate prediction model;
[0025] Step S8: Model verification, using the verification set to verify the rate prediction model and obtain a verification result;
[0026] Step S9: Model tuning: adjusting and optimizing the rate prediction model according to the verification results.
[0027] Furthermore, in the model selection and training module, the rate prediction model is optimized using the BER meta-heuristic search optimization algorithm, which specifically includes the following steps:
[0028] Step M1: Initialize the population, randomly generate a set of initial solutions as the population, set the maximum number of iterations, and the initial solution represents the parameter combination of the rate prediction model;
[0029] Step M2: Evaluate the fitness. For each solution, use the rate prediction model to predict the training set and calculate the error between the predicted result and the true value.
[0030] Step M3: mutation operation, performing mutation operation on each solution in the current population to generate a set of new candidate solutions;
[0031] Step M4: Evaluate the fitness, evaluate each candidate solution and calculate its fitness value;
[0032] Step M5: Replacement operation, select a replacement strategy according to the fitness value, and select a part of the candidate solutions to replace the solutions in the current population;
[0033] Step M6: Termination condition, judging whether the maximum number of iterations has been reached, and terminating the algorithm when the maximum number of iterations has been reached;
[0034] Step M7: output the result, select the solution with the best fitness in the population as the final optimization result, and obtain the optimized rate prediction model parameter combination;
[0035] Furthermore, step M1 specifically includes the following steps:
[0036] Step M11: determining a parameter space, determining a parameter space of a rate prediction model, including all parameters that need to be optimized in the rate prediction model, including a weight, a bias, and a learning rate of the rate prediction model;
[0037] Step M12: Generate an initial solution. For each parameter, randomly generate an initial value according to the value range. All the initial values are combined into an initial solution, which represents a parameter combination of the rate prediction model.
[0038] Step M13: constructing a population, constructing an initial population according to the synthesized initial solution;
[0039] Step M14: repeat steps M12 and M13 to generate multiple initial solutions to construct a population, and repeat steps M12 and M13 until the population size reaches a preset value;
[0040] Step M15: Set the maximum number of iterations, and complete the iteration after setting the maximum number of iterations of the algorithm;
[0041] Further, step M3 specifically includes the following steps:
[0042] Step M31: Select a mutation operator and use Gaussian mutation to adjust the parameters of the rate prediction model;
[0043] Step M32: Determine the mutation probability, determine the probability of the mutation operation, and set the mutation probability to a smaller value, with the range set to [0,1];
[0044] Step M33: mutate each solution, perform traversal operations on each solution in the current population, and decide whether to mutate each solution based on the mutation probability. If the mutation probability is met, the solution is mutated, otherwise, no mutation operation is performed;
[0045] Step M34: Gaussian mutation. For each solution that needs to be mutated, Gaussian mutation is used to adjust the parameters in the solution. Gaussian mutation randomly perturbs each parameter based on the current solution. The formula used is as follows:
[0046] ;
[0047] in, is the parameter value after mutation, For the solution parameters, is the variable step length, which is the parameter that controls the degree of variation. is a standard normally distributed random number with a mean of 0 and a variance of 1;
[0048] Step M35: Repeat the operation. For each solution that needs to be mutated, repeat the Gaussian mutation operation until the mutation operation is completed for all solutions that need to be mutated.
[0049] The beneficial effects achieved by the present invention using the above scheme are as follows:
[0050] (1) The KNN algorithm is sensitive to outliers. The traditional KNN algorithm does not take into account the weight differences between different soil samples and cannot handle the ambiguity in the soil nitrogen mineralization rate prediction model well. This scheme uses the fuzzy KNN algorithm based on the Bonferroni mean to establish a rate prediction model. By comprehensively considering the information of multiple nearest neighbor samples, the model improves the classification accuracy of samples. Considering the information of multiple nearest neighbor samples makes the rate prediction model more robust and able to handle noisy data and abnormal situations. It does not need to assume the shape of the sample distribution and can adapt well to complex data distribution. Therefore, it improves the prediction accuracy, enhances the robustness of the rate prediction model, adapts to various data types, has good interpretability, and does not require an explicit training process.
[0051] (2) In general soil nitrogen mineralization rate prediction systems, the use of traditional optimization algorithms for rate prediction models will result in local optimal solution traps, slow convergence speed, limited search space, overfitting risks, and difficulty in tuning. This scheme uses the BER meta-heuristic search optimization algorithm to optimize the soil nitrogen mineralization rate prediction model based on machine learning. The use of traditional optimization algorithms for rate prediction models will result in local optimal solution traps, slow convergence speed, limited search space, overfitting risks, and difficulty in tuning. The BER algorithm combines the strategies of exploration and utilization, and can conduct a global search in the search space to effectively explore potential optimal solutions. It introduces randomness in the search process, which helps to maintain the diversity of solutions during the search process. It also has a faster convergence speed and can find solutions close to the optimal solution in a shorter time. Using the BER meta-heuristic search optimization algorithm to optimize the rate prediction model can bring the benefits of strong global search capabilities, fast convergence speed, diversity of solutions, strong adaptability, and easy implementation and tuning, which helps to improve the performance and efficiency of the rate prediction model. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 A schematic diagram of a module of a soil nitrogen mineralization rate prediction system based on machine learning provided by the present invention;
[0053] Figure 2 It is a flowchart of the fuzzy KNN algorithm based on Bonferroni mean;
[0054] Figure 3 Flowchart of the BER meta-heuristic search optimization algorithm;
[0055] Figure 4 is a schematic diagram of the process of step M1;
[0056] Figure 5 It is a schematic diagram of the process of step M3.
[0057] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention. DETAILED DESCRIPTION
[0058] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0059] In the description of the present invention, it should be understood that terms such as “upper”, “lower”, “front”, “back”, “left”, “right”, “top”, “bottom”, “inside” and “outside” indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as limiting the present invention.
[0060] Example 1, see Figure 1 The soil nitrogen mineralization rate prediction system based on machine learning provided by the present invention includes a data acquisition and preprocessing module, a feature engineering module, a model selection and training module, a model evaluation module, a model deployment and application module, and a model monitoring and maintenance module, which specifically includes the following contents:
[0061] The data acquisition and preprocessing module acquires soil sample data and environmental factor data and performs cleaning, processing and conversion to obtain processed soil sample data and environmental factor data;
[0062] The feature engineering module extracts features related to nitrogen mineralization rate from processed soil sample data and environmental factor data, including soil physical and chemical properties, soil temperature, soil moisture and rainfall;
[0063] The model selection and training module selects a suitable machine learning algorithm, and uses a fuzzy KNN algorithm based on the Bonferroni mean to establish a rate prediction model according to the training data, and uses a BER meta-heuristic search optimization algorithm to optimize the rate prediction model to obtain a trained rate prediction model;
[0064] The model evaluation module uses the test data to evaluate the trained rate prediction model, and evaluates the performance indicators of the rate prediction model, including mean square error, root mean square error and determination coefficient;
[0065] The model deployment and application module deploys the trained rate prediction model into the actual application environment, constructs a prediction system, and allows users to input new soil sample data and environmental factor data to obtain the prediction results of soil nitrogen mineralization rate;
[0066] The model monitoring and maintenance module regularly monitors the performance of the rate prediction model and performs updates and maintenance to ensure the accuracy and reliability of the prediction results.
[0067] Example 2, see Figure 2 This embodiment is based on the above embodiment. In the model selection and training module, the rate prediction model is trained using the fuzzy KNN algorithm based on the Bonferroni mean, which specifically includes the following steps:
[0068] Step S1: Data division: put the features related to nitrogen mineralization rate into the data set, divide the data set into a training set and a validation set in a ratio of 7:3, take each feature related to nitrogen mineralization rate as a training sample, set a label for each training sample, and use these labels as the category of the training sample;
[0069] Step S2: Distance calculation: for each training sample, the distance between it and other training samples is calculated using the Euclidean distance.
[0070] Step S3: Find the nearest neighbor. Consider each training sample as a test sample and find the K nearest training samples. These K training samples are called the K nearest neighbors of the test sample.
[0071] Step S4: Calculate the fuzziness. For each category, calculate the fuzziness of the K nearest neighbor samples belonging to the category by distance weighting. The closer the distance, the higher the corresponding fuzziness.
[0072] Step S5: Normalization of fuzziness: normalize the calculated fuzziness and calculate the fuzziness for each category using a distance weighted formula. The formula used is as follows:
[0073] ;
[0074] in, Indicates the fuzziness of the category, is the number of nearest neighbor training samples, Indicates The weights of the nearest neighbor training samples, Indicates The distance from the nearest neighbor training sample to the test sample;
[0075] Step S6: Fuzziness aggregation: use the Bonferroni mean method to aggregate the fuzziness of each category to obtain the confidence of each category. The formula used is as follows:
[0076] ;
[0077] ;
[0078] ;
[0079] in, Indicates category The fuzzy mean of Indicates that the training set belongs to the category The number of training samples, For the belongs to category The fuzziness of the training samples, Indicates category The standard deviation of the fuzziness is Indicates category The confidence level, is a constant with a value of 1;
[0080] Step S7: Establish a model, use the obtained confidence as the category label of the training sample, and build a rate prediction model;
[0081] Step S8: Model verification, using the verification set to verify the rate prediction model and obtain a verification result;
[0082] Step S9: Model tuning: adjusting and optimizing the rate prediction model according to the verification results.
[0083] The KNN algorithm is sensitive to outliers. The traditional KNN algorithm does not take into account the weight differences between different soil samples and cannot handle the ambiguity in the soil nitrogen mineralization rate prediction model well. This scheme establishes a rate prediction model by using the fuzzy KNN algorithm based on the Bonferroni mean. By comprehensively considering the information of multiple nearest neighbor samples, the classification accuracy of the model for samples is improved. The information of multiple nearest neighbor samples is considered to make the rate prediction model more robust, able to handle noisy data and abnormal situations, and does not need to assume the shape of the sample distribution. It can also adapt well to complex data distributions. Therefore, the prediction accuracy is improved, the robustness of the rate prediction model is enhanced, it is adaptable to various data types, has good interpretability, and does not require an explicit training process.
[0084] Example 3, see Figure 3 , Figure 4 and Figure 5 This embodiment is based on the above embodiment. In the model selection and training module, the BER meta-heuristic search optimization algorithm is used to optimize the rate prediction model, which specifically includes the following steps:
[0085] Step M1: Initialize the population, randomly generate a set of initial solutions as the population, set the maximum number of iterations, and the initial solution represents the parameter combination of the rate prediction model;
[0086] Step M1 specifically includes the following steps:
[0087] Step M11: determining a parameter space, determining a parameter space of a rate prediction model, including all parameters that need to be optimized in the rate prediction model, including a weight, a bias, and a learning rate of the rate prediction model;
[0088] Step M12: Generate an initial solution. For each parameter, randomly generate an initial value according to the value range. All the initial values are combined into an initial solution, which represents a parameter combination of the rate prediction model.
[0089] Step M13: constructing a population, constructing an initial population according to the synthesized initial solution;
[0090] Step M14: repeat steps M12 and M13 to generate multiple initial solutions to construct a population, and repeat steps M12 and M13 until the population size reaches a preset value;
[0091] Step M15: Set the maximum number of iterations, and complete the iteration after setting the maximum number of iterations of the algorithm;
[0092] Step M2: Evaluate the fitness. For each solution, use the rate prediction model to predict the training set and calculate the error between the predicted result and the true value.
[0093] Step M3: mutation operation, performing mutation operation on each solution in the current population to generate a set of new candidate solutions;
[0094] Step M3 specifically includes the following steps:
[0095] Step M31: Select a mutation operator and use Gaussian mutation to adjust the parameters of the rate prediction model;
[0096] Step M32: determine the mutation probability, determine the probability of the mutation operation, set the mutation probability to a smaller value, and set the range to [0,1];
[0097] Step M33: mutate each solution, perform traversal operations on each solution in the current population, and decide whether to mutate each solution based on the mutation probability. If the mutation probability is met, the solution is mutated, otherwise, no mutation operation is performed;
[0098] Step M34: Gaussian mutation. For each solution that needs to be mutated, Gaussian mutation is used to adjust the parameters in the solution. Gaussian mutation randomly perturbs each parameter based on the current solution. The formula used is as follows:
[0099] ;
[0100] in, is the parameter value after mutation, For the solution parameters, is the variable step length, which is the parameter that controls the degree of variation. is a standard normally distributed random number with a mean of 0 and a variance of 1;
[0101] Step M35: Repeat the operation, for each solution that needs to be mutated, repeat the Gaussian mutation operation until the mutation operation is completed for all solutions that need to be mutated;
[0102] Step M4: Evaluate the fitness, evaluate each candidate solution and calculate its fitness value;
[0103] Step M5: Replacement operation, select a replacement strategy according to the fitness value, and select a part of the candidate solutions to replace the solutions in the current population;
[0104] Step M6: Termination condition, judging whether the maximum number of iterations has been reached, and terminating the algorithm when the maximum number of iterations has been reached;
[0105] Step M7: Output the results, select the solution with the best fitness in the population as the final optimization result, and obtain the optimized rate prediction model parameter combination.
[0106] For general soil nitrogen mineralization rate prediction systems, the use of traditional optimization algorithms for rate prediction models will result in local optimal solution traps, slow convergence, limited search space, overfitting risks, and difficulty in tuning. This solution uses the BER meta-heuristic search optimization algorithm to optimize the soil nitrogen mineralization rate prediction model based on machine learning. The use of traditional optimization algorithms for rate prediction models will result in local optimal solution traps, slow convergence, limited search space, overfitting risks, and difficulty in tuning. The BER algorithm combines exploration and utilization strategies, can perform global search in the search space, and effectively explore potential optimal solutions. It introduces randomness in the search process, which helps maintain the diversity of solutions during the search process, and has a faster convergence speed, and can find solutions close to the optimal solution in a shorter time. Using the BER meta-heuristic search optimization algorithm to optimize the rate prediction model can bring the benefits of strong global search capabilities, fast convergence speed, diversity of solutions, strong adaptability, and easy implementation and tuning, which helps to improve the performance and efficiency of the rate prediction model.
[0107] Example 4: This example is based on the above example and uses the fuzzy KNN algorithm based on the Bonferroni mean to train the rate prediction model. The code used is as follows:
[0108] import numpy as np
[0109] # Assume there is a training data set X_train, a test data set X_test, and a K value
[0110] X_train = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) # Training data set, assuming there are 4 samples, each with 2 features
[0111] X_test = np.array([[0, 1], [9, 10]]) # Test data set, assuming there are 2 samples, each with 2 features
[0112] K = 2 # K value, find the two closest training samples
[0113] # Step S2: Calculate Euclidean distance
[0114] def euclidean_distance(x1, x2):
[0115] return np.sqrt(np.sum((x1 - x2)**2))
[0116] distances = [] # Save the distance between the test sample and all training samples
[0117] for test_sample in X_test:
[0118] test_distances = [] # Save the distance between the test sample and each training sample
[0119] for train_sample in X_train:
[0120] distance = euclidean_distance(test_sample, train_sample)
[0121] test_distances.append(distance)
[0122] distances.append(test_distances)
[0123] # Step S3: Find the nearest neighbor
[0124] nearest_neighbors_indices = np.argsort(distances, axis=1)[:, :K] # Sort the distances and find the indexes of the nearest K training samples for each test sample
[0125] print(nearest_neighbors_indices)
[0126] # Step S4: Calculate blur
[0127] def calculate_fuzziness(distances):
[0128] return 1 / distances # Here we simplify the process and directly use the inverse of the distance as the fuzziness
[0129] fuzziness = np.zeros((len(X_test), len(np.unique(y_train)))) # Store the fuzziness of each test sample for each category
[0130] for i, test_sample in enumerate(X_test):
[0131] for j, class_label in enumerate(np.unique(y_train)):
[0132] class_indices = np.where(y_train == class_label)[0] # Find the index of the training sample belonging to the current category
[0133] nearest_neighbors_distances = np.linalg.norm(X_train[class_indices] - test_sample, axis=1) # Calculate the distance between the test sample and the training sample of the current category
[0134] nearest_neighbors_distances_sorted = np.sort(nearest_neighbors_distances) # Sort the distances
[0135] k_nearest_neighbors_distances = nearest_neighbors_distances_sorted[:K] # Take the distances of the nearest K training samples
[0136] fuzziness[i, j] = np.mean(calculate_fuzziness(k_nearest_neighbors_distances)) # Calculate fuzziness
[0137] # Step S5: Blur Normalization
[0138] normalized_fuzziness = fuzziness / np.sum(fuzziness, axis=1, keepdims=True) # Normalize the fuzziness
[0139] # Step S6: Fuzzy aggregation
[0140] def calculate_confidence(fuzziness):
[0141] mu_c = np.mean(fuzziness) # Calculate the fuzziness mean
[0142] sigma_c = np.std(fuzziness) # Calculate the fuzziness standard deviation
[0143] return mu_c - sigma_c # Calculate confidence
[0144] confidence = calculate_confidence(normalized_fuzziness)
[0145] print(confidence);
[0146] In this embodiment, a simple training data set X_train and the corresponding category label y_train, as well as a test data set X_test are set. First, the distance between each sample in the test data set and the training sample of each category is calculated, and the Euclidean distance is used as the distance metric. For each test sample and each category, the fuzziness of the K nearest neighbor samples is calculated and normalized. According to the formula for fuzzy aggregation, the confidence of each category is calculated.
[0147] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0148] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
[0149] The present invention and its embodiments are described above, and such description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. In short, if ordinary technicians in the field are inspired by it, without departing from the purpose of the invention, they can design a structure and embodiment similar to the technical solution without creativity, which should belong to the protection scope of the present invention.
Claims
1. A soil nitrogen mineralization rate prediction system based on machine learning, characterized in that: It includes data collection and preprocessing module, feature engineering module, model selection and training module, model evaluation module, model deployment and application module and model monitoring and maintenance module, specifically including the following contents: The data acquisition and preprocessing module acquires soil sample data and environmental factor data and performs cleaning, processing and conversion to obtain processed soil sample data and environmental factor data; The feature engineering module extracts features related to nitrogen mineralization rate from processed soil sample data and environmental factor data, including soil physical and chemical properties, soil temperature, soil moisture and rainfall; The model selection and training module selects a suitable machine learning algorithm, and uses a fuzzy KNN algorithm based on the Bonferroni mean to establish a rate prediction model according to the training data, and uses a BER meta-heuristic search optimization algorithm to optimize the rate prediction model to obtain a trained rate prediction model; The model evaluation module uses the test data to evaluate the trained rate prediction model, and evaluates the performance indicators of the rate prediction model, including mean square error, root mean square error and determination coefficient; The model deployment and application module deploys the trained rate prediction model into the actual application environment, constructs a prediction system, and allows users to input new soil sample data and environmental factor data to obtain the prediction results of soil nitrogen mineralization rate; The model monitoring and maintenance module regularly monitors the performance of the rate prediction model and performs updates and maintenance; In the model selection and training module, the rate prediction model is trained using the Bonferroni mean-based fuzzy KNN algorithm, which specifically includes the following steps: Step S1: Data division: put the features related to nitrogen mineralization rate into the data set, divide the data set into a training set and a validation set in a ratio of 7:3, take each feature related to nitrogen mineralization rate as a training sample, set a label for each training sample, and use these labels as the category of the training sample; Step S2: Distance calculation: for each training sample, the distance between it and other training samples is calculated using the Euclidean distance. Step S3: Find the nearest neighbor. Consider each training sample as a test sample and find the K nearest training samples. These K training samples are called the K nearest neighbors of the test sample. Step S4: Calculate the fuzziness. For each category, calculate the fuzziness of the K nearest neighbor samples belonging to the category by distance weighting. The closer the distance, the higher the corresponding fuzziness. Step S5: Normalization of fuzziness: normalize the calculated fuzziness and calculate the fuzziness for each category using a distance weighted formula. The formula used is as follows: ; in, Indicates the fuzziness of the category, is the number of nearest neighbor training samples, Indicates The weights of the nearest neighbor training samples, Indicates The distance from the nearest neighbor training sample to the test sample; Step S6: Fuzziness aggregation: use the Bonferroni mean method to aggregate the fuzziness of each category to obtain the confidence of each category. The formula used is as follows: ; ; ; in, Indicates category The fuzzy mean of Indicates that the training set belongs to the category The number of training samples, For the belongs to category The fuzziness of the training samples, Indicates category The standard deviation of the fuzziness is Indicates category The confidence level, is a constant with a value of 1; Step S7: Establish a model, use the obtained confidence as the category label of the training sample, and build a rate prediction model; Step S8: Model verification, using the verification set to verify the rate prediction model and obtain a verification result; Step S9: Model tuning, adjusting and optimizing the rate prediction model according to the verification results; In the model selection and training module, the rate prediction model is optimized using the BER meta-heuristic search optimization algorithm, which includes the following steps: Step M1: Initialize the population, randomly generate a set of initial solutions as the population, set the maximum number of iterations, and the initial solution represents the parameter combination of the rate prediction model; Step M1 specifically includes the following steps: Step M11: determining a parameter space, determining a parameter space of a rate prediction model, including all parameters that need to be optimized in the rate prediction model, including a weight, a bias, and a learning rate of the rate prediction model; Step M12: Generate an initial solution. For each parameter, randomly generate an initial value according to the value range. All the initial values are combined into an initial solution, which represents a parameter combination of the rate prediction model. Step M13: constructing a population, constructing an initial population according to the synthesized initial solution; Step M14: repeat steps M12 and M13 to generate multiple initial solutions to construct a population, and repeat steps M12 and M13 until the population size reaches a preset value; Step M15: Set the maximum number of iterations, and complete the iteration after setting the maximum number of iterations of the algorithm; Step M2: Evaluate the fitness. For each solution, use the rate prediction model to predict the training set and calculate the error between the predicted result and the true value. Step M3: mutation operation, performing mutation operation on each solution in the current population to generate a set of new candidate solutions; Step M3 specifically includes the following steps: Step M31: Select a mutation operator and use Gaussian mutation to adjust the parameters of the rate prediction model; Step M32: determine the mutation probability, determine the probability of the mutation operation, set the mutation probability to a smaller value, and set the range to [0,1]; Step M33: mutate each solution, perform traversal operations on each solution in the current population, and decide whether to mutate each solution based on the mutation probability. If the mutation probability is met, the solution is mutated, otherwise, no mutation operation is performed; Step M34: Gaussian mutation. For each solution that needs to be mutated, Gaussian mutation is used to adjust the parameters in the solution. Gaussian mutation randomly perturbs each parameter based on the current solution. The formula used is as follows: ; in, is the parameter value after mutation, For the solution parameters, is the variable step length, which is the parameter that controls the degree of variation. is a standard normally distributed random number with a mean of 0 and a variance of 1; Step M35: Repeat the operation, for each solution that needs to be mutated, repeat the Gaussian mutation operation until the mutation operation is completed for all solutions that need to be mutated; Step M4: Evaluate the fitness, evaluate each candidate solution and calculate its fitness value; Step M5: Replacement operation, select a replacement strategy according to the fitness value, and select a part of the candidate solutions to replace the solutions in the current population; Step M6: Termination condition, judging whether the maximum number of iterations has been reached, and terminating the algorithm when the maximum number of iterations has been reached; Step M7: Output the results, select the solution with the best fitness in the population as the final optimization result, and obtain the optimized rate prediction model parameter combination.
