1. Introduction
Agriculture forms an important part of the Pakistani economy, employing a significant segment of the population and securing food security in the country. The primary staple crop is wheat, the output of which is about 24–25 million tons per year, and the estimated turnover is over Rs. 6078 billion [
1,
2]. Regardless of its significance, the cultivation of wheat in Pakistan is associated with significant risks, such as unpredictable weather conditions, poor application of irrigation methods, and the lack of access to more practical, data-driven information to manage the crop [
3,
4]. Traditional farming techniques, which are often intuitive or traditional, often do not maximize the utilization of resources.
Recent developments in artificial intelligence (AI), especially machine learning, have exhibited high capabilities of enhancing agricultural productivity as they can precisely predict yield depending on different environmental factors [
5,
6,
7]. Regarding this possibility, this research paper suggests an AI-based, web-based decision support system, which runs on a Long Short-Term Memory (LSTM) deep learning framework. The system leverages 23 years of past weather and soil history of Meteoblue and yield data provided by the Pakistan Bureau of Statistics to produce precise forecasts on the yield of wheat and aid in informed decision-making at the farm level.
The research targets large agricultural districts in the province of Punjab due to the economic significance of wheat and the fact that Punjab accounts for almost 70 percent of the total national production of wheat [
8,
9]. The proposed system will provide a bilingual user interface to enhance accuracy in yield prediction, manage resources optimally, and assist in sustainable wheat production in Pakistan by integrating predictive modeling, irrigation scheduling, and agronomic guidance.
2. Materials and Methods
2.1. Overview of System Implementation
The project was created in the form of a full-stack, bilingual, responsive web-based application to assist wheat farmers in the major districts of Punjab, Pakistan. The system incorporates real-time weather analytics, historical weather–soil data, rule-based irrigation logic, and a wheat yield prediction model based on deep learning.
2.2. Technology Stack
React.js was used to build the frontend and React-Bootstrap was used to ensure modularity and responsiveness. Bilingual (English and Urdu) functionality was provided by the i18next library. FastAPI (Python, v0.104.1) was used to create the backend as it is a highly performing, asynchronous machine learning system. Lightweight data storage was enabled through SQLite. The application was implemented on Microsoft Azure (as a backend) and Vercel (as a frontend) with Progressive Web App functionality to enable access when offline.
2.3. Data Sources
The 23-year (2000–2023) meteorological (Meteoblue) data obtained consisted of evapotranspiration, soil moisture, soil temperature, relative humidity, sea-level pressure, and minimum temperature. To obtain a reliable ground truth, annual district-level statistics of wheat yields were acquired through the Pakistan Bureau of Statistics. Other agronomic and advisory data, such as the fertilizer principles, pest management, and phenology, were obtained from national agricultural extension sources.
2.4. Data Preprocessing and Feature Engineering
Min–Max scaling was used to normalize all the numerical input variables to improve the stability of training and convergence of the learning models. To avoid the occurrence of any data leakage, the scaling parameters were fit to the training data only and then applied to the test data to ensure that no information about future observations affected the learning process.
A one-year look-back window was applied to the time-series data in order to maintain temporal dependence; it was then converted into supervised learning sequences. Linear interpolation was applied to the minor missing meteorological values, whereas records that had significant discontinuities were omitted.
The eight features included in the final model input were six main variables of agro-meteorology parameters (minimum temperature, relative humidity, soil moisture, soil temperature, evapotranspiration, and rainfall) and two derived features of time used to represent seasonal and lagged climatic effects. The target variable was the annual district-level wheat yield.
2.5. Development of Machine Learning Model
Several machine learning and deep learning models were compared, including Random Forest, Artificial Neural Networks (ANNs), XGBoost, Gated Recurrent Units (GRUs), and Long Short-Term Memory (LSTM).
In order to give uniformity to the various experiments, the baseline machine learning models were trained with standard hyperparameters that are usually used in other related agricultural forecasting research. The comparative analysis aimed to evaluate how the sequential and non-sequential modeling methods compare with agro-climatic time-series data as opposed to hyperparameter optimization, which is exhaustive.
The LSTM architecture chosen was a stacked pair of 30 hidden units and finally a dense output unit. The model was trained with the Adam optimizer, and early stopping after 100 epochs was applied to reduce overfitting.
Since the data is time-based, an 80:20 chronological train–test split was used, with the older data being used as the training data and the more recent data being used as the test data. The evaluation of the model performance was based on MAE, MSE, RMSE, and R2.
2.6. Rule-Based Irrigation System
An irrigation advisory module was included in the form of a rule-based system to aid decision-making at the farm level. This system uses deterministic thresholds, which are calculated using rainfall, evapotranspiration, and maximum temperature, based on nationally accepted agronomic guidelines and irrigation scheduling requirements of wheat production in semi-arid areas, as expressed by the FAO.
This module is designed to offer actionable and decipherable irrigation guidance instead of dynamic optimization to assist farmers in defining irrigation timing and estimated water needs depending on the current weather and crop development phase.
2.7. Application Workflow
User registers/logs in;
User enters district, land area, and sowing date;
The system checks sowing timing;
Real-time weather is displayed;
Recommendations on irrigation are produced;
Fertilizer planner offers stage directions;
Prediction is obtained based on user requests;
LSTM-based prediction is sent to the backend;
The dashboard is updated dynamically.
2.8. Functional Requirements
Table 1 shows the key characteristics of the suggested smart agriculture system and the description of its functions with references to weather analysis, crop management, and decision support tools.
2.9. Non-Functional Requirements
The summary of the most important system quality attributes and technical features are presented in
Table 2, with a focus on performance, security, scalability, reliability and usability in order to guarantee strong and accessible functioning to the end users.
3. Results
The experimental analysis aimed to establish the predictability of various machine learning and deep learning models when used on 23 years of historical meteorological and soil data. To ensure a strict and unbiased comparison, the methodology used the same preprocessing pipelines and normalization procedures, feature inputs, and data partitions in all models. This part introduces the quantitative performance of the LSTM model, which is the main focus of the study, and the comparative results of other models, which are backed up by statistical and visual analysis.
3.1. Performance of the LSTM Model
To assess the performance of the LSTM model, 23 years (2000–2023) of past agro-meteorological and soil data in the form of a univariate annual time series, with multivariate inputs, were used. The model was trained to obtain cumulative climatic effects on wheat yield in consecutive growing seasons using a one-year look-back window.
Table 3 highlights the quantitative measures of performance calculated on the test data provided. The LSTM provided the coefficient of determination (R
2) of 0.979, which implies that there is a good relationship between the values of predicted and observed yields. The small values of the error measures of MAE, MSE, and RMSE are also indicative that the model was able to fit the overall yield-driving patterns that were prevalent in the historical data.
The training and validation loss curves as a function of epoch are shown in
Figure 1. The monotonic convergence of the two curves and the smooth convergence demonstrated in the two curves represent the stability of learning behavior and show that the model has been successful in minimizing prediction error, and there is no sign of divergent behavior or oscillatory over-fitting. The high correspondence between training and validation loss also implies that the model was generalized to the unseen data despite the small sample size.
Figure 2 shows a correlation between the predicted and actual yield of wheat. The fact that the data points are very close to the 45-degree reference line proves that the model is capable of monitoring the changes in interannual yields in varying climatic conditions. The purpose of this visualization is not to be a quantitative measure of performance per se, but to offer qualitative affirmation of alignment as a trend.
When combined, the quantitative evaluations and visual inspection show that the LSTM model has successfully learned long-term temporal interdependences hidden in the agro-climatic data. Since long-term yield observations are necessarily scarce, such results must be viewed as signs of great model viability and intertemporal stability as opposed to predictive certitude.
In order to check the predictive veracity of this trained model,
Figure 2 plots the actual and predicted values from the LSTM model, which confirms that almost all the data points are very close to the ideal line, which signifies a nearly perfect correspondence between the predicted values and the actual values. This particular behavior of the model signifies that the model is not only precise but also consistent with respect to all values, including the most extreme data.
Taken cumulatively, the numeric and graphical results indicate that the LSTM neural network had a highly impressive degree of overall generalization performance, as it remained consistent throughout the entire process of training as well as the testing phases. This is especially useful for applications within agricultural systems that make decisions.
3.2. Comparison with Other Models
The performance of the LSTM model was contrasted with that of other baseline machine learning and deep learning methods, such as Random Forest, Artificial Neural Networks (ANNs), XGBoost, and Gated Recurrent Units (GRUs), in order to place the LSTM model into perspective. These models have been chosen to illustrate non-sequential and sequential learning models, which are widely applied in the agricultural yield prediction research.
Table 4 presents the results of using non-sequential models, including the Random Forest, ANN, and XGBoost, with the annual time-series data, the predictive performance of which was relatively low. This may be because they lack the capability to model long-term time dependencies and cumulative climatic impacts, which are essential in the formation of crop yields. Although such models prove to be useful when modeling static nonlinear relationships, they do not provide any explicit memory mechanisms needed to learn interannual dependencies.
Sequential deep learning architectures, on the other hand, were superior. The improvement of the GRU model compared to non-sequential baselines indicated the advantages of the gated recurrent structures in learning the order. Nonetheless, the LSTM was always more successful than the GRU and produced smaller error values and explanatory power. This performance capability is also in line with the fact that LSTM has better gating mechanisms that enable it to retain and update long-term information more effectively.
It should be mentioned that the difference between the absolute magnitude of error between models depends on dissimilarities in sensitivity to feature scaling and temporal representation. In this regard, comparative analysis focuses on relative modeling competency and temporal learning performance and not absolute metric hegemony. The findings are all indicative of the appropriateness of LSTM-based architectures to the modeling of climate-influenced agricultural systems with limited yet time-structured datasets.
3.3. Interpretation of Model Behavior in the Context of Predictive Agriculture
The findings are highly correlated with the agronomic facts of wheat production. The accumulated environmental stresses and resource availability during long periods of growth affect wheat yields. Thus, long-range nonlinear temporal dependencies refer to the ability of LSTM networks to learn and forecast such biological processes in a closer manner than models based on instantaneous or independent observations.
Moreover, the error rates obtained by the LSTM model were likely exceptionally low, which indicates that the input variables used in this study, namely, evapotranspiration, relative humidity, soil moisture, soil temperature, minimum temperature, mean sea level pressure, and rainfall, were right and sufficient to represent the main climatic determinants of the wheat yield in the target area.
The results of the LSTM model also prove the preprocessing policy, normalization strategy, and look-back structure adopted in this method. The similarity of the predicted values among the ordinary as well as abnormal climatic years also indicates the possibility that the model was not built on central tendencies but trained to deviate and detect exceptions in the past data.
The overall findings suggest that the LSTM model is an effective and predictive model with high accuracy and stable results when it comes to predicting wheat yield. Its high performance compared to any other model, such as advanced tree models and GRU architectures, reveals how effective recurrent deep learning methods are compared to various agricultural applications, particularly in areas that are defined by high climatic variability.
The results not only confirm the technical approach but also show the reason why the LSTM model should be implemented as a part of the decision support system developed. The system can improve the planning process, the allocation of resources, and strategic decision-making required by the wheat farmers in Punjab through the provision of accurate yield forecasts.
4. Discussion
The results of this work can be used to confirm the high effectiveness of deep learning-based methods, especially LSTM, in wheat yield forecasting under the conditions of complex and dynamic agro-climate in Pakistan, which is consistent with recent wheat-focused machine learning studies conducted under climate change scenarios [
10]. The high performance of the LSTM model can be compared to the literature, which outlines the benefits of deep recurrent models in agricultural forecasting [
5,
6]. A high coefficient of determination (R
2 = 0.979) and low prediction errors indicate the capability of this model to simultaneously describe the cumulative and lagged impact of climatic variables as the most essential factors influencing the variability of wheat yield in Pakistan [
3,
4].
It was observed that classical machine learning models had a poor generalization ability for time-series agricultural data; the GRU model was worse than the traditional methods, but still worse than the LSTM because it has low long-term memory capacity [
11,
12]. The high correlation between the anticipated and measured yields supports the applicability of important climatic inputs, such as evapotranspiration, temperature, humidity, and soil moisture [
1,
13,
14,
15]. The findings reveal the applicability of sequential deep learning structures in the forecasting of cumulative agro-climatic effects on wheat yield. Instead of being concerned with only the accuracy of the absolute prediction, the results highlight the fact that the LSTM model is better at learning time-dependent information than its non-sequential counterparts.
Since there are few long-term past yield observations, the findings are to be taken as indicators of model feasibility and consistency of trends over time. However, deep learning-based forecasting combined with decision-support systems has a viable potential in climate-resilient agricultural planning in data-scarce areas.