Sampling site and sample collection
The fertile soils of Thanjavur, Tiruvarur and Tiruchirappalli districts were considered due to the fact that they have been used for farming practices according to previous studies. The measurements for soil moisture, weather conditions, humidity, temperature and macronutrient nitrogen, phosphorus and potassium (NPK) were performed
via respective sensors. Soils samples have been collected and tested at different levels: 0-15 cm, 15-30 cm and 30-60 cm. The productivity forecasting was performed for 1-15 cm depth level; these forecasting hypotheses concern the enrichment of nutrients in the deeper levels. It is suggested that nitrate nitrogen (NO
3-N) and sulfate sulfur (SO
4-S) can occur in significant amounts in the soils between 15 and 60 cm. Both nitrate and ammonium ions provide nutrition in the form of nitrogen needed for the synthesis of amino acids. Thus, while nitrogen-rich soil can stimulate growth, nitrate can accelerate it even more. Therefore, the parameters of NO
3 and SO
4 need to be assessed for the entire range of depths between 0 and 60 cm as the analysis conducted only on 0-5 cm might misrepresent N and S parameters, especially in case of phosphorus, which is mobile and mostly limited to the ploughing soil of 0-15 cm depth. In turn, majority of phosphorus and potassium occurs in the soils up to 0-1 cm depth. In these soils, data sets include 10 attributes and total 222,853 soil sample records for these parameters. The quantitative and qualitative data collection workflow adopted in this study is illustrated in Fig 2. Real-time IoT-based systems have been shown to enhance soil parameter monitoring for crop prediction
(Pandey et al., 2023). The mathematical symbols and abbreviations used throughout the PSO formulation and regression equations in the following sections are summarized in Table 1.
Advancements in XAI have greatly improved the explainability of ML models employed in vital agricultural applications. Techniques like SHAP and LIME have been combined with ensembles for generating intelligible predictions for soil nutrients assessment and yield prediction
(Sharma et al., 2021). Deep learning architectures integrating CNN-LSTM with attention mechanisms have demonstrated strong performance in crop yield prediction
(Kalmani et al., 2025) and a comprehensive review of ML models for plant disease prediction and detection further underscores the value of robust ensemble approaches in agricultural decision support (
Metagar and Walikar, 2024). RAG systems have proven to be a powerful paradigm in intelligent agricultural analysis by enabling domain-specific decision-making from the outputs of large language models anchored on structured knowledge bases comprising of agronomy principles, soil science publications and local farming data
(Kamilaris et al., 2016). The combination of RAG with a regression pipeline optimized using the PSO algorithm in AgroAdvisor is a novel development in the intersection of intelligent information retrieval and precision agriculture. Prior research has established that the integration of PSO optimization for hyperparameter tuning alongside knowledge-based retrieval results in lower recommendation latency and higher contextual relevance than deep learning algorithms alone
(Stafford et al., 2019).
Particle swarm optimization (PSO) for regression hyperparameter tuning
PSO introduction
Particle swarm optimization (PSO) represents a stochastic population-based optimization technique initially proposed by
Kennedy and Eberhart (1995) in imitation of avian flocking and schooling fish social behavior dynamics. The computationally-efficient optimization tasks, including hyperparameter optimization for machine learning models used in agriculture in Fig 3.
PSO initialization and particle velocity update
Optimization in PSO begins with creating a swarm that consists of N particles that are randomly placed in a D-dimensional search space, where each dimension represents an optimized hyperparameter (L2 regularization, kernel choice, or learning rate,
etc.). In turn, every particle is initialized with some random position and velocity vectors that are then updated in iterations according to the following equations:
velki (t + 1) = Weight [velki (t)] + C1.random () [Parki (t) - Poski (t)] + C2.random () [Parki (t) - Poski (t)] ...(1)
w= The inertial weight.
C1= The cognitive coefficient corresponding to the personal best position of the particle.
C2= The social coefficient corresponding to the global best position of the whole swarm.
r1 and r2= Random numbers in [0,1] range.
pbest (i)= The current personal best position of the ith particle.
gbest= The global best position of the entire swarm.
PSO algorithm-step-by-step
Step 1: Initialization.
Create a starting population of N particles that will be randomly distributed within the D-dimensional search space. Initialize their positions and velocities accordingly.
Step 2: Calculate fitness.
Calculate the fitness function for every particle according to the selected measure. As far as the regression task is concerned, for AgroAdvisor, one can use MAE or R2 scores as a fitness function when the model with particular hyperparameters trained (by setting hyperparameters’ values equal to the coordinates of the particle’s position).
Step 3: Comparing each particle’s fitness with its prior best achieved fitness should be done after each iteration. It is preferable to have the current value equal to the present values than to have the actual position equal to the present position in d-dimensional space and vice versa if the present values are greater.
Step 4: Update position and velocity.
Using the equation above, calculate a new position and velocity for every particle.
Step 5: Termination criteria.
Repeat steps 2-4 until the termination criterion, such as a maximal iteration limit or improvement on gbest below a certain threshold, is met.
AgroAdvisor’s reproducibility was ensured through fixed hyperparameters and validation strategies. The hyperparameters used for PSO include setting N to 30 particles, with 100 iterations as the maximum, an initial value of w at 0.9, a final value of w at 0.4 and c1 and c2 both equal to 2.0. The criteria for convergence entail that the difference in gbest must be less than 1e-6 in the last ten iterations.
Advantages of PSO in AgroAdvisor
- PSO involves fewer parameters compared to genetic algorithm or simulated annealing techniques.
- No gradients required in the optimization process, thus supporting non-differentiable fitness functions.
- Fast convergence on continuous hyperparameter ranges for regression models.
- Multiobjective approach for concurrent hyperparameter optimization in fertility scores and yield prediction.
- Scalability across different data set sizes from small farm data sets to large regional data sets.
Proposed PSO-regression analysis
Feature selection
The combination of several layered generalizations, applied to a PSO algorithm, is shown in Fig 3. PSO Regression is a technique of dividing into the following steps:
Step 1: Create the generalization classifier with many layers of generalizations.
We used the PSO-Regression that discusses in Feature selection. Grid search hyper-parameter tweaking was used to optimize each model in the PSO-Regression system.
Step 2: Determine the location of each position of the particle by PSO.
The feature subset for the particle location was found in this phase when the stacked generalization was produced.
Step 3: The process of verifying the most favorable combinations of swarms and particles.
To validate these two equations are used in these methods:
Cipb ← Ci if f (Ci) > f (Cipb) ...(2)
Cisb ← Ci if f (Ci) > f (Cisb) ...(3)
The variable is first entered into the PSO programmer, which returns a cost score. Then the score is shortened by the weakest score. Input data groups with one parameter into SVR program after being shortened.
The PSO-regression feature selection technique
The suggested approach is designed (Fig 4) to overcome the two issues around identifying the specific benefits of an individual’s actual genome structural features, as well as figuring out a better way to make use of this data without the inherent drawbacks of over-fitting.
PSO-regression pseudocode
1. Input: t1, t2,..., tn are the training sets (folds), whereas v1, v2,..., vn are the validation sets (folds).
2. Output: The outcome of prediction.
3. Initialize: The swarms Xi, the particles positions, the populations posture, the Regression and Kernal parameters are all taken into consideration in this model.
4. Eq(7), determine the parameter fitness (G).
5. Using f (X
i), determine the efficiency of every particle (t).
6. A comparison is made between the efficiency of every individual and their previous best score.
7. if.
8. f [X
i (t)] G < f (p
ibest) then.
9. f [X
i (t)] = f (p
ibest).
10. (p
ibest) = f [X
i (t)].
11. End if.
12. if.
13. f [X
i (t)] G < f (p
Gbest) then.
14. f [X
i (t)] = f (p
Gbest)
15. (p
Gbest) = f [X
i (t)].
16. End if.
17. Calculate the particle and velocity of the data-set.
18. Repeat steps 7 till the implementation is complete.
19. Sorting of fitness is used to classify all of the particles.
PSO-support vector regression (SVR)
The input data must be transformed into the high-dimensional feature set using a nonlinear transformation matrix; this function must be defined beforehand. Once a linear function is defined in the high-dimensional feature space, it is conceptually possible to construct the nonlinear connection between the actual output. It is possible to define a linear model of this kind as follows:
Trained data set (Xi, Oi) ni=1 ...(4)
Where,
Xi ∈ In= Input(I) vector.
Oi= Output value(O).
n= Data set total dimensions.
The goal of modelling is to find a linear regression model.
Y = f(X) ...(5)
That correctly predicts fresh I/O instances. For example, in feature space.
f(Xi) = α∅ (X) + B ...(6)
Where feature space (F)
∅ : In → F, α ε F ...(7)
The following is how the actual evaluation is described: