论文信息

Qasim Ali Hashmi / Zain ul Sajjad / Saqib Ali³

Research Square

论文摘要

GreenAI: An Explainable AI and IoT-Enabled Offline Framework for Precision Agriculture。Research Square

全文

Research Square

GreenAI: An Explainable AI and IoT-Enabled Offline
Framework for Precision Agriculture
Qasim Ali Hashmi¹ 
University of Agriculture Faisalabad
Zain ul Sajjad² 
Pir Mehr Ali Shah Arid Agriculture University
Saqib Ali³ 
University of Agriculture Faisalabad
Research Article
Keywords: Precision Agriculture, Crop Recommendation, Plant Disease Detection, Sustainable
Development Goals, SHAP
Posted Date: October 6th, 2026
DOI: https://doi.org/10.21203/rs.3.rs-11233315/v1
License:   This work is licensed under a Creative Commons Attribution 4.0 International License.  
Read Full License
Additional Declarations: No competing interests reported.
Page 1/30

Abstract
Precision agriculture requires intelligent, interpretable and deployment-ready systems capable of
operating under native farming conditions and limited-connectivity environments. This article presents
GreenAI which is an Explainable Artificial Intelligence (XAI) and Internet of Things (IoT)-enabled offline-
first framework for precision agriculture tailored to Pakistan. The proposed framework integrates crop
recommendation, plant disease diagnosis, environmental monitoring and edge-assisted decision
support within a unified multilingual ecosystem. A Punjab-specific crop recommendation dataset
comprising 9,500 balanced samples across 19 major crops was developed and evaluated using multiple
machine learning algorithms. Among these evaluated models XGBoost achieved the best performance
with a test accuracy of 97.40% and a macro F1-score of 0.9741. For plant disease diagnosis an
EfficientNetV2-S model trained on a unified 113-class disease dataset achieved a validation accuracy of
99.03%. To improve transparency and user trust, SHAP-based feature attribution, partial dependence
analysis and Grad-CAM visualizations were incorporated into the decision-making pipeline. The
framework further integrates an ESP32-based IoT sensing platform and lightweight edge inference to
support low-latency operation in resource-constrained environments. Results of this experimental
demonstrate that the effectiveness of the proposed framework in delivering accurate, interpretable and
scalable agricultural decision support. GreenAI provides a practical pathway toward sustainable, data-
driven and farmer-centric precision agriculture.
I. Introduction
Agriculture plays a main role in ensuring food security, economic growth and livelihoods of rural mostly
in developing countries where a significant portion of the population depends on farming. Modern
agriculture faces numerous challenges including climate variability, declining soil fertility, water scarcity,
pest infestations, disease outbreaks and also fluctuating market conditions (Shahi et al., 2025). These
factors make agricultural decision-making increasingly complex and necessitate intelligent solutions
capable of improving productivity while promoting sustainable resource utilization. Recent advances in
Artificial Intelligence (AI), Machine Learning (ML) and Internet of Things (IoT) technologies have created
new opportunities for precision agriculture (Kumar et al., 2026; Emon et al., 2025) like Data-driven crop
recommendation systems can assist farmers in selecting suitable crops based on soil and
environmental conditions, while deep learning techniques enable automated plant disease diagnosis
from leaf images (Pande et al., 2021; Doshi et al., 2018; Kulkarni et al., 2018; Mohanty et al., 2016). IoT-
enabled sensing platforms have facilitated real-time monitoring of agricultural environments providing
valuable information for timely interventions and efficient farm management (Ouammi et al., 2024;
Mohapatra et al., 2023; Lombardo et al., 2021). Explainable Artificial Intelligence (XAI) further enhances
transparency and user trust by providing interpretable insights into model predictions (Arrieta et al.,
2020). Despite these developments most existing studies focus on individual agricultural tasks such as
crop recommendation, disease diagnosis, environmental monitoring or explainability in isolation and
many available solutions depend heavily on cloud-based infrastructures which require continuous
internet connectivity and are developed using generic datasets that may not adequately represent local
Page 2/30

agricultural conditions. These limitations restrict their practical applicability in rural farming
environments, particularly in regions characterized by intermittent connectivity and diverse agro-climatic
conditions.
To address these challenges this paper presents GreenAI, an Explainable AI and IoT-enabled offline-first
precision agriculture framework designed for Pakistan. The proposed framework integrates crop
recommendation, plant disease diagnosis, IoT-based environmental monitoring, explainable decision
support and edge-assisted deployment within a unified ecosystem. A Punjab-specific crop
recommendation dataset comprising 9,500 balanced samples across 19 major crops was developed
and evaluated using multiple machine learning algorithms. An EfficientNetV2-S-based disease diagnosis
module, SHAP and Grad-CAM explainability mechanisms and an ESP32-based IoT sensing platform were
incorporated to improve transparency, accessibility and deployment readiness.
The remainder of this paper is organized as follows. Section II presents the literature survey and
comparative analysis of existing approaches. Section III discusses the identified research gaps, while
Section IV summarizes the major contributions of the proposed work. Section V describes the system
architecture, methodology and implementation details. Experimental results and performance
evaluations are presented in Section VI, and finally Section VII concludes the paper and outlines future
research directions.
II. Literature Survey
Precision agriculture has leveraged machine learning, deep learning, explainable artificial intelligence
(XAI) and Internet of Things (IoT) technologies to improve agricultural decision-making also Machine
learning approaches have been widely adopted for crop recommendation using soil nutrients, rainfall,
humidity, temperature and pH parameters, with ensemble methods such as XGBoost demonstrating
strong predictive performance for structured agricultural datasets (Chen and Guestrin, 2016; Madhuri
and Indiramma, 2021). For plant disease diagnosis, deep learning models have achieved high
classification accuracy using leaf image datasets, particularly with convolutional neural network
architectures and EfficientNet-based models (Tan and Le, 2019; Tan and Le, 2021; Ferentinos, 2018).
To improve transparency and user trust, explainable AI techniques such as SHAP and Grad-CAM have
been incorporated into agricultural systems to provide feature-level and visual explanations of model
predictions (Lundberg and Lee, 2017; Selvaraju et al., 2017). Meanwhile, IoT-based sensing platforms
have enabled real-time environmental monitoring through low-cost sensor networks, supporting
precision farming and smart agricultural management (Islam et al., 2026; Rahman et al., 2025; Ayaz et
al., 2019; Khanna and Kaur, 2019).
These developments are most existing studies focus on individual tasks such as crop recommendation,
disease diagnosis, explainability or environmental monitoring separately. Limited attention has been
given to integrating these components into a unified, deployment-ready framework capable of operating
under low-connectivity rural environments. Furthermore, region-specific agricultural intelligence and
Page 3/30

offline operational capabilities remain largely underexplored. These limitations motivate the
development of the proposed GreenAI framework. The comparison of the proposed work with the
existing literature is presented in Table I.
Table I. Comparison of Proposed work with State of the Art.
Page 4/30

Ref Focus Area Methodology Key Contributions Limitations
(Chen and
Guestrin,
2016)
Crop
Recommendation
XGBoost High prediction
accuracy on
structured
agricultural data
No integrated
agricultural
ecosystem
(Mohanty
et al.,
2016)
Disease Detection CNN
(PlantVillage)
Accurate disease
classification
Controlled
laboratory
images
(Tan and
Le, 2021)
Disease Detection EfficientNetV2 Improved accuracy
and computational
efficiency
Limited
integration with
field deployment
(Selvaraju
et al.,
2017)
Explainable AI Grad-CAM Visual explanation of
disease predictions
Focused only on
image
interpretation
(Lundberg
and Lee,
2017)
Explainable AI SHAP Feature-level model
interpretability
Not integrated
with IoT systems
(Shahi et
al., 2025)
Precision
Agriculture
Review
ML-based
Agriculture
Comprehensive
overview of AI in
agriculture
Review only
(Ouammi
et al.,
2024)
IoT Agriculture Smart Sensing
Systems
Real-time agricultural
monitoring
Limited AI
integration
(Lombardo
et al.,
2021)
Smart Farming IoT Architecture Environmental
monitoring and
automation
No explainability
support
(Pande et
al., 2021)
Crop
Recommendation
ML-based
Recommendation
Soil and climate-
based crop
prediction
Standalone
recommendation
system
(Hughes
and
Salathé,
2015)
Disease Detection Dataset Analysis Impact of dataset
diversity on accuracy
No deployment
framework
(Khanna
and Kaur,
2019)
Deep Learning
Agriculture
Review Study DL applications in
agriculture
No practical
implementation
Proposed GreenAI XAI + IoT + Edge
AI
Unified offline-first
framework
integrating
recommendation,
disease detection,
IoT telemetry,
explainability, and
edge deployment
—
Page 5/30

III. Research Gaps
Recent advances in precision agriculture have demonstrated the effectiveness of machine learning, deep
learning, explainable artificial intelligence (XAI), and Internet of Things (IoT) technologies for agricultural
decision support. Existing studies have reported promising results in crop recommendation, plant
disease diagnosis, environmental monitoring, and smart farming automation. However, most of these
solutions focus on individual agricultural tasks and are developed as standalone systems. Consequently,
farmers often need to rely on multiple disconnected platforms for crop selection, disease management,
environmental monitoring, and market-related decision-making.
Furthermore, many reported frameworks are dependent on cloud-based infrastructures and continuous
internet connectivity, limiting their applicability in rural and resource-constrained agricultural
environments. The majority of existing systems also employ generic datasets and they have lack of
region-specific agricultural intelligence which decreasing their adaptability to local climatic conditions,
soil characteristics and crop cultivation practices. Although explainable AI techniques have gained
increasing attention, their integration with practical agricultural decision-support systems remains
limited. Similarly, lightweight edge deployment and offline operation capabilities are rarely considered
despite their importance for real-world implementation.
To clearly identify these limitations Table II summarizes the major gaps observed in the literature and the
corresponding solutions provided by the proposed GreenAI framework.
Table II. Research Gap Analysis and Proposed Solution
Page 6/30

Research Area Existing Approaches Identified Gap Proposed Solution in
GreenAI
Crop
Recommendation
Machine learning-based
recommendation
systems
Standalone
functionality
Integrated within a
unified agricultural
platform
Plant Disease
Detection
CNN and deep learning-
based diagnosis
Limited interaction
with advisory
systems
Unified disease
diagnosis and advisory
support
Explainable AI SHAP or Grad-CAM
applied independently
Limited integration
into practical
farming systems
Integrated SHAP, PDP,
and Grad-CAM
framework
IoT-Based
Agriculture
Real-time environmental
monitoring
Lack of intelligent
decision support
IoT-enabled AI-assisted
recommendations
Smart Farming
Platforms
Cloud-centric
architectures
Dependence on
continuous internet
connectivity
Offline-first architecture
with local caching
Agricultural
Intelligence
Generic agricultural
datasets
Poor regional
adaptability
Punjab-specific
agricultural intelligence
Edge Deployment Computationally
intensive models
Limited deployment
on low-cost
hardware
Lightweight edge-
compatible inference
models
The literature analysis indicates that there is a clear need for an integrated, explainable, region-specific
and deployment-ready ecosystem that can precision agriculture. Motivated by these limitations, this
work proposes GreenAI which is an offline-first framework that combines crop recommendation, plant
disease diagnosis, IoT-based environmental monitoring, explainable AI and also edge intelligence within
a single scalable platform tailored to Punjab’s agricultural ecosystem.
IV. Contributions of the paper
The major contributions of this paper are summarized as follows:
Development of GreenAI, a unified precision agriculture framework that integrates crop
recommendation with plant disease diagnosis, IoT-based environmental monitoring, explainable AI
and market-support services within a single multilingual platform that overcomes the limitations of
standalone agricultural solutions.
Creation of a Punjab-specific agricultural intelligence ecosystem using a balanced set of data
containing 9,500 samples across 19 major crops. The framework enables region-aware crop
recommendations tailored to local soil, climatic and cultivation conditions, improving practical
applicability for farmers in Punjab.
Design and evaluation of an AI-driven crop recommendation module through a comparative
assessment of XGBoost, Random Forest, ExtraTrees, LightGBM and SVM models and the proposed
Page 7/30

XGBoost-based CropAdvisor achieved a test accuracy of 97.40% and a macro F1-score of 0.9741,
demonstrating robust predictive performance.
Development of a high-performance plant disease diagnosis system based on EfficientNetV2-S,
which was trained on a unified 113-class disease dataset and the model achieved a validation
accuracy of 99.03% enabling accurate and scalable disease identification across multiple crop
species.
Integration of Explainable Artificial Intelligence (XAI) through SHAP, Partial Dependence Plots
(PDPs) and Grad-CAM visualizations to increase transparency, interpretability and user trust in both
crop recommendation and disease diagnosis decisions.
Implementation of an offline-first and edge-compatible architecture incorporating ESP32-based IoT
sensing, lightweight edge inference, local data caching and synchronization mechanisms. This
enables reliable operation in low-connectivity rural environments while supporting real-time
agricultural decision-making.
V. Methodology
A. System Architecture Proposed
GreenAI is an offline-first precision agriculture ecosystem with the power of artificial intelligence, IoT
sensing, edge computing and mobile-based advice services to help farmers in Punjab. This design uses
several agricultural intelligence modules into a single platform that may be operated efficiently in rural
and low connection areas. The system is built around five main functions: crop suggestion, fertiliser
advisory, plant disease diagnosis, IoT telemetry monitoring and market-support analytics.
The workflow starts with the collecting of environmental and agricultural characteristics either manually
through the mobile application or automatically through the use of ESP32 based IoT sensor nodes. The
data obtained comprises soil nutrient values (Nitrogen, Phosphorus, Potassium), temperature, humidity,
rainfall, soil moisture and pH levels. These parameters are used to feed into machine learning models to
provide intelligent crop recommendations and fertiliser suggestions. Photos of plant leaves taken using
mobile devices are analysed using deep learning to identify and diagnose diseases at the same time.
This is designed for reliable operation in rural areas where sensor data and prediction outputs are saved
locally in cache and synchronised automatically when internet connectivity is available. This architecture
greatly increases the system reliability in resource-constrained agricultural settings.
The whole workflow and system architecture of the proposed GreenAI framework is shown in Fig. 1. The
architecture has many interlinked steps like data gathering, preprocessing, crop recommendation, illness
detection, explainable AI analysis, edge deployment, backend communication and also have mobile
advice support. It collects environmental data such as soil nutrients, weather conditions and crop related
information using IoT sensors and mobile-based farmer inputs. The collected data is subsequently
Page 8/30

processed by cleaning, normalisation, balancing, and augmentation procedures. The processed data is
then provided to machine learning and deep learning models.
The crop recommendation module generates the suitable crop suggestions based on the soil and
climatic circumstances using different machine learning techniques as XGBoost, SVM, Random Forest,
and LightGBM. Simultaneously, the disease detection module implements the EfficientNetV2-S
convolutional neural network architecture for classifying plant diseases based on leaf pictures. For
explainable AI analysis, the system integrates with SHAP and Grad-CAM for increased transparency and
interpretability.
Moreover, the architecture offers lightweight edge deployment with ESP32 compatible models for real-
time offline inference in low-connectivity rural settings. Backend communication with FastAPI and SQLite
synchronization techniques for quick data interchange and offline telemetry storage. Finally, the
multilingual mobile advisory interface gives prediction findings and agricultural counsel directly to
farmers, thus providing a scalable and deployment ready precision agriculture ecosystem for Punjab’s
farming environment.
B. Data Collection and Pre-processing
The GreenAI decision-support system is built on a heterogeneous corpus spanning tabular agronomic
records, geospatial environmental layers, market intelligence, and crop-disease imagery. The information
for crop suggestion has been produced on the basis of Punjab state specific agriculture conditions. The
dataset includes 19 important crops of Kharif, Rabi and Zaid seasons. The dataset contains over 9500
balanced samples. The features are Nitrogen (N), Phosphorus (P), Potassium (K), temperature, humidity,
rainfall and pH value of soil. To minimise class imbalance and increase model generalisation, we utilised
data balancing and preprocessing procedures. Environmental drivers were assembled from NASA
POWER daily meteorology (MERRA-2/CERES) (NASA, 2024), Pakistan Meteorological Department 0.25°
× 0.25° gridded daily rainfall, and Government of Pakistan district soil-moisture records, market
advisories use AMIS daily price–arrival feeds with price catalogue (FAO, 2024). For disease detection, we
curated a unified 113-class image corpus combining the PlantVillage repository (Hughes and Salathé,
2015) and its augmented Kaggle redistribution (PlantVillage, 2019), with Pakistan and Punjab-relevant
crop-specific datasets covering wheat, rice, cotton, mango, chilli and onion, pomegranate, watermelon,
soybean, lentil, castor, banana, sugarcane, groundnut, and a multi-crop pest–disease collection, among
others. The images were pre-processed by scaling, normalisation, augmentation and noise reduction to
improve the robustness of the classification and reduce the overfitting during the training.
The IoT telemetry subsystem collects environmental data continually with ESP32 microcontrollers
coupled to sensors for soil moisture, temperature and humidity monitoring. Sensor data are saved locally
and sent to the backend using lightweight JSON based communication protocols.
C. Crop Recommendation Module
Page 9/30

The crop recommendation system was built using supervised machine learning techniques. We trained
and assessed several classification models including XGBoost, Random Forest, ExtraTrees, LightGBM,
and Support Vector Machine (SVM) (Chen and Guestrin, 2016; Madhuri and Indiramma, 2021) with the
same stratified train-validation-test divides. We evaluated them on the accuracy of prediction, macro F1-
score, inference latency and memory footprint. XGBoost presented the best trade-off between
classification performance and feasibility of deployment among all studied models. The trained model is
used to predict the most suited crop based on real-time environmental and soil variables. In order to
increase the interpretability, we used SHAP (SHapley Additive exPlanations) analysis into the
recommendation pipeline to assess the contribution of each agricultural feature to the prediction results.
D. Explainable AI Framework
To increase the interpretability of crop recommendation decisions, SHAP (SHapley Additive
exPlanations) was integrated into the proposed XGBoost based CropAdvisor model and SHAP is a
game-theoretic explainability technique that quantifies the contribution of each input feature toward the
final prediction, conventional feature such as importance measures, SHAP provides both global and
local explanations also enabling a comprehensive understanding of model behaviour.
For each prediction SHAP values were computed for all agricultural input variables, including nitrogen
(N), phosphorus (P), potassium (K), temperature, humidity, rainfall and soil pH. The generated
explanations were utilized to identify influential environmental factors affecting crop recommendation
outcomes and to improve transparency in AI-assisted agricultural decision-making. Global feature is
importance rankings and SHAP summary visualizations were subsequently arrange to the overall
analyze but it different in agronomic parameters on model predictions. SHAP-based feature attribution,
Partial Dependence Plot (PDP) analysis was employed to investigate the marginal effect of individual
agricultural variables on crop recommendation predictions. PDPs estimate the average influence of a
selected feature while averaging out the effects of all remaining features in the dataset. This approach
provides an intuitive understanding of how changes in environmental and soil parameters affect model
outputs. The PDP analysis was performed for the most influential variables identified through SHAP
analysis, namely rainfall, nitrogen, humidity, and soil pH. The generated plots facilitate interpretation of
nonlinear relationships learned by the XGBoost model and provide additional evidence regarding the
agronomic validity of the recommendation framework.
E. Disease Detection Subsystem
The disease identification module was constructed using transfer learning based on the convolutional
neural network architecture EfficientNetV2-S. The model was trained on the combined 113 class plant
disease dataset with GPU acceleration with CosineAnnealingLR scheduling for stable optimisation and
better convergence. Plant leaf photos are captured, pre-processed and scaled for classification. The
model is trained to predict illness categories and provide confidence levels for diagnosis. We also apply
Grad-CAM visualization to highlight the disease afflicted regions in the leaf pictures to improve
transparency and to assist users grasp model predictions more effectively.
Page 10/30

F. Deploying Edge and IoT
The IoT subsystem uses ESP32-based sensor nodes for the real-time monitoring of agricultural. These
devices are continuously measuring environmental factors and interacting with the backend through
lightweight APIs also to enable deployment under constrained hardware resources a lightweight SVM
model was optimised for edge inference with ultra-low memory consumption and minimum latency, this
edge-oriented implementation allows for fast crop prediction on embedded devices without the need of
constant cloud connectivity. Edge intelligence integration which improves response speed, decreases
dependence on internet access and also improves implementation feasibility in rural farming.
The hardware architecture of the developed IoT sensor node is illustrated in Fig. 2. The sensing unit is
built around an ESP32-WROOM-32 microcontroller that provides integrated Wi-Fi and Bluetooth
connectivity for wireless communication with multiple sensors including soil moisture, temperature–
humidity (DHT22), pH, light intensity (BH1750) and GPS modules are interfaced with the ESP32 to collect
field-level environmental information. A MicroSD card module is incorporated for local data logging and
offline storage it enabling continuous operation under intermittent network conditions this collected
measurements are processed locally and transmitted to the backend server through Wi-Fi connectivity
and the modular design allows easy integration of additional sensors and supports low-power
deployment in resource-constrained agricultural environments.
G. Mobile Application and Backend Integration
To facilitate practical deployment and user accessibility the GreenAI framework includes a mobile
application and backend communication architecture designed to combine AI-driven decision support
with IoT-enabled agricultural monitoring and the proposed backend architecture is based on FastAPI,
enabling efficient communication among machine learning models, IoT sensor nodes and end-user
applications. The architecture also incorporates SQLite-based local caching and synchronization
mechanisms to support offline operation and delayed data synchronization in low-connectivity rural
environments at the current stage of this research the core AI models, explainability modules and IoT
telemetry framework have been successfully developed and experimentally validated also in parallel the
development of a multilingual mobile application and a fully integrated backend infrastructure is actively
underway. The planned application will provide farmers with crop recommendations, fertilizer advisory
services, plant disease diagnosis, environmental monitoring information and also market-related
insights through a unified user interface. The mobile platform is being designed with an offline-first
philosophy that allowing prediction results and sensor data to be stored locally and synchronized
automatically when network connectivity becomes available this approach is expected to improve
system reliability and accessibility in resource-constrained agricultural environments, the complete
integration of the mobile application, backend services and IoT infrastructure will enable the realization
of a fully deployable farmer-centric precision agriculture ecosystem capable of supporting real-time
decision-making with continuous monitoring and sustainable farming practices across diverse
agricultural regions.
Page 11/30

VI. Results and Discussion
A. Experimental Setup
All model training and evaluation was performed on a Windows workstation with an NVIDIA CUDA-
capable GPU. The crop recommendation models were trained in Python 3.13 using scikit-learn 1.x and
XGBoost 2.x (Chen and Guestrin, 2016) within a virtual environment. The disease detection model was
trained using PyTorch 2.10 and torchvision 0.25 on CUDA. Evaluation uses macro-averaged precision,
recall, and F1 score across all classes; accuracy is reported on the held-out test split (1,425 samples for
crop recommendation; validation set for disease detection). Model sizes are measured as serialised file
sizes on disk. Inference latency is reported as the mean wall-clock time per single sample on the
respective hardware.
B. Crop Recommendation Multi-Model Comparison
Five machine learning classifiers were trained and tested on the Punjab-19 dataset using the same
70/15/15 data split to ensure fair comparison. Table III presents the performance of all five models in
terms of test accuracy, macro F1-score, model size and average inference time for a single prediction.
Table III. Multi-model comparison on Punjab-19 dataset (test set, n = 1,425)
Model Test Accuracy (%) Macro F1 Size (MB) Inf. Latency (ms)
XGBoost (production) 97.40 0.9741 5.919 2.386
ExtraTrees 97.33 0.9734 98.297 32.174
Random Forest 97.19 0.9719 36.975 41.485
LightGBM 96.84 0.9684 5.616 1.673
SVM Edge 96.84 0.9684 0.432 0.179
The comparative analysis shows that XGBoost provides balanced performance among all evaluated
models for Punjab-specific crop recommendation. While ExtraTrees and Random Forest achieved
accuracy values close to XGBoost, their large model sizes (98.297 MB and 36.975 MB) make them less
suitable for deployment on mobile or embedded agricultural devices where memory and storage are
limited and the XGBoost model achieved the highest macro F1-score of 0.9741 while maintaining
relatively lower storage requirements and fast inference speed, making it practical for real-time
agricultural advisory applications. The lightweight SVM model produced slightly lower prediction
accuracy than XGBoost but its also have extremely low latency of 0.179 ms and its compact model size
of 0.432 MB make it highly suitable for ESP32-based edge deployment and these observations indicate
that this framework effectively balances prediction performance with hardware efficiency which is a
requirement for real-world precision agriculture systems operating in rural environments.
C. Crop Recommendation Per-Crop Analysis
Page 12/30

Table IV reports the XGBoost per-crop precision, recall and F1 score on the 1,425-sample test set (75
samples per crop). Ten crops achieve perfect classification (F1 = 1.000): banana, cotton, gram,
groundnut, moth, mung, rice, sesame, sugarcane, tur and udad.
Table IV. Per-crop classification report XGBoost (test set, 75 samples/crop)
Crop Precision Recall F1-Score Support
bajra 0.9437 0.8933 0.9178 75
banana 1.0000 1.0000 1.0000 75
castor 0.9342 0.9467 0.9404 75
cotton 1.0000 1.0000 1.0000 75
cumin 0.8765 0.9467 0.9103 75
fennel 0.9420 0.8667 0.9028 75
gram 1.0000 1.0000 1.0000 75
groundnut 1.0000 1.0000 1.0000 75
jowar 0.8590 0.8933 0.8758 75
maize 0.9867 0.9867 0.9867 75
moth 1.0000 1.0000 1.0000 75
mung 1.0000 1.0000 1.0000 75
mustard 0.9865 0.9733 0.9799 75
rice 1.0000 1.0000 1.0000 75
sesame 1.0000 1.0000 1.0000 75
sugarcane 1.0000 1.0000 1.0000 75
tur 1.0000 1.0000 1.0000 75
udad 1.0000 1.0000 1.0000 75
wheat 0.9868 1.0000 0.9934 75
Overall (macro avg) 0.9745 0.9740 0.9741 1425
The per-crop study demonstrates that the proposed model operates well on multiple crop categories, as
many Punjab crops have comparable soil nutrients and meteorological conditions. Crops including
cotton, rice, sugarcane, peanuts and sesame have near perfect classification scores which indicates that
their agricultural traits are more distinctly recognizable in the dataset. The comparatively lower F1-
scores for jowar, bajra, cumin and fennel are representative of true agronomic overlap rather than
instability of the model. Jowar and bajra are grown under similar semi-arid climatic circumstances with
Page 13/30

similar nitrogen, phosphorus, potassium and rainfall characteristics. As a result, the decision boundaries
within the feature space are close to each other. Cumin and fennel are also grown under similar
environmental circumstances of Rabi season in North Punjab districts which explains the slight
uncertainty in classification of these spice crops. These observations imply that the proposed model
represents realistic agricultural variability, rather than overfitting to artificially constructed patterns.
D. Disease Detection Training History
The EfficientNetV2-S model was trained for 15 epochs using CosineAnnealingLR that scheduling for
stable learning and Table V presents the training progress across all epochs this model achieved 96.41%
validation accuracy in the first epoch itself and gradually improved to 99.03% by the final epoch. The
training performance remained stable throughout the process that indicating smooth convergence with
minimal signs that despite the large 113-class disease set of data.
Table V. EfficientNetV2-S training history (15 epochs, Cuda)
Epoch Train Loss Train Acc (%) Val Acc (%) LR
1 1.2070 87.53 96.41 2.967e-4
2 0.9994 93.55 96.66 2.871e-4
3 0.9613 94.66 97.08 2.715e-4
4 0.9372 95.41 97.61 2.505e-4
5 0.9196 95.96 97.92 2.253e-4
6 0.9054 96.40 97.97 1.967e-4
7 0.8897 96.90 98.26 1.661e-4
8 0.8782 97.22 98.41 1.349e-4
9 0.8664 97.62 98.54 1.043e-4
10 0.8575 97.89 98.60 7.575e-5
11 0.8505 98.10 98.85 5.046e-5
12 0.8441 98.31 98.90 2.955e-5
13 0.8386 98.51 98.92 1.392e-5
14 0.8350 98.59 98.99 4.270e-6
15 0.8338 98.64 99.03 1.000e-6
The training and validation accuracy curves of the EfficientNetV2-S model across 15 epochs have stable
and consistent learning behavior. Initial training stages the model converged quickly and achieved
validation accuracy above 96%. The performance improved gradually and stabilized over subsequent
Page 14/30

epochs. Both the training and validation accuracy curves followed a similar trend without major
fluctuations, suggesting that the model learned effectively with very limited overfitting decrease the
complexity of the 113-class disease classification problem. The accuracy of 99.03% reflects the good
feature learning and generalization ability of the model to multiple plant disease categories and Fig. 4
shows the training and validation loss curves during the optimization. The loss values have a steady
decrease during the training, which indicates the smooth convergence of the model under the
CosineAnnealingLR scheduling strategy. Furthermore, there is no significant spikes or unstable jitters in
the validation loss curve, which proves the stable gradient updates with the efficient optimization
behavior. The loss curve starts to flatten gradually after the epoch 10 which implies the model is
reaching the optimal convergence while maintaining good generalization performance without
significant overfitting.
Figure 3 and 4 show the training behaviour of the EfficientNetV2-S disease detection model throughout
15 training epochs. Figure 3 shows the growth of training and validation accuracy. Both curves show a
steady improvement with very little divergence suggesting stable learning and effective model with
generalization despite the complexity of the 113-class disease classification job. The model trained on
the data resulted in a validation accuracy of more than 96% in the first epoch and eventually converged
to 99.03% in the last epoch. The corresponding training and validation loss curves obtained throughout
the optimization are shown in Fig. 4. The decrease of loss values during training validates smooth
convergence and steady optimization under the chosen learning approach.
Figure 5 shows the classification performance of the EfficientNetV2-S disease detection model. This
model achieved high values for accuracy, precision, recall and F1-score with suggesting balanced and
performance across various disease categories. In these evaluation metrics indicates that the classifier
correctly identifies disease classes with a low rate of false predictions the proposed model can offer
dependable plant disease diagnosis for practical agricultural applications.
The Bottom-20 class performance analysis for the disease detection model are in Fig. 6, and these
classes achieve comparatively lower scores than dominant disease categories, the overall classification
performance remains robust. Most low-performing classes correspond to visually similar diseases or
classes with limited inter-class variability that increases feature-level prediction and this model
maintains stable recognition capability across difficult categories, demonstrating a strong generalization
even under fine-grained disease classification conditions.
E. Explainable AI Analysis
To investigate the decision-making behaviour of the proposed XGBoost CropAdvisor model, SHAP-based
explainability analysis was performed. Figure 7 presents the SHAP summary plot, while Fig. 8 shown
that the global feature importance ranking derived from the trained model. Figure 7 shows that the
rainfall is the most influential parameter affecting crop recommendation decisions, High rainfall values
generally contribute positively toward crops requiring greater water availability and lower rainfall
conditions favour drought-tolerant crops commonly cultivated in semi-arid regions of Punjab. The
Page 15/30

dominance of rainfall in the SHAP analysis highlights the main role of climatic conditions in determining
crop suitability the analysis reveals that the nitrogen is most important soil nutrient influencing crop
recommendations also nitrogen directly affects plant growth, chlorophyll formation and yield potential
also its strong contribution which is consistent with established agronomic principles in this phosphorus
and potassium also predict outcomes like confirming the importance of balanced soil fertility in crop
selection decisions.
Influential environmental variables such as humidity and soil pH are identified like humidity affects crop
adaptability and disease susceptibility under different climatic conditions such as soil pH influences
nutrient availability and root development and temperature contributes to model predictions as well as
its overall impact is comparatively lower than rainfall and nutrient-related parameters. The SHAP
analysis demonstrates that the proposed model captures meaningful agricultural relationships rather
than depending on arbitrary correlations and the consistency between results and established
agronomic knowledge further it validates the reliability and practical applicability of the proposed crop
recommendation framework.
To investigate the behaviour of this crop recommendation model is partial dependence analysis it was
conducted for the most influential variables identified through SHAP analysis. Figure 9 presents the
partial dependence plots corresponding to rainfall, nitrogen, humidity and soil pH. The rainfall PDP
demonstrates that there is a positive relationship between rainfall availability and crop recommendation
confidence. Prediction scores increase steadily with increasing in rainfall before reaching a saturation
region it indicating that additional rainfall is beyond a certain threshold that contributes marginally to
crop suitability decisions the nitrogen PDP reveals a strong positive influence of soil nitrogen
concentration on recommendation outcomes the model increased confidence with increasing nitrogen
levels and reflecting the main role of nitrogen in plant growth, chlorophyll synthesis and also in crop
productivity. Humidity exhibits a nonlinear relationship with crop recommendations and it generally
improves prediction whereas extremely low or excessively high humidity values contribute less
significantly by this observation aligns with practical agricultural conditions where optimal humidity
ranges that support healthy crop development. The soil pH PDP indicates that the model have favors
near-neutral soil conditions. Prediction confidence reaches its maximum within the pH range of
approximately 6.5–7.5 and gradually decreases outside interval this behavior established agronomic
knowledge as nutrient availability and it’s root development are optimized under slightly acidic to neutral
soil conditions this PDP results complement the SHAP analysis and further demonstrate that the
proposed XGBoost model captures meaningful agricultural relationships than it’s arbitrary statistical
patterns.
F. System Latency and API Performance
Table VI reports end-to-end response latencies measured from a local network test with the FastAPI
backend running on a standard laptop (AMD Ryzen/Intel Core, no GPU required for inference after
Page 16/30

training). Crop recommendation inference is CPU-bound at 2.386 ms; disease detection at 224×224 on
CPU takes approximately 150–300 ms per image depending on the host hardware.
Table VI. API Endpoint Latency Measurements
Endpoint / Operation Mean Latency Notes
POST /predict/crop (XGBoost, server) 2.386 ms
(mean)
7-dim feature vector, CPU
POST /predict/crop (SVM, edge/ESP32) 0.179 ms
(mean)
On-device, no network hop
POST /predict/disease (EfficientNetV2-
S)
~ 200 ms (est.) 224×224 image, CPU; <50 ms on
GPU
GET /market/prices < 5 ms SQLite CSV cache
POST /sensor/log (write) < 3 ms SQLite INSERT
ESP32 → API (offline buffer flush) < 1 s per record JSON over WiFi, retry on fail
The results show that the GreenAI framework effectively combines machine learning, edge computing
and also offline-first deployment into a single agricultural intelligence system. Unlike many existing
precision agriculture solutions that mainly focus on individual tasks, crop recommendation, disease
detection, fertilizer advisory and IoT-based environmental monitoring within one unified platform
designed specifically for Punjab’s agricultural conditions. The inclusion of explainable AI techniques, low-
latency prediction and ESP32-compatible edge deployment further improves the practical usability of the
system in rural farming areas where internet connectivity and computational resources are often limited.
These results indicate that this method is suitable for real-world agricultural deployment in low-resource
environments.
G. Real-Time IoT Prototype Validation
To verify the practical feasibility of the proposed IoT subsystem, an ESP32-based prototype was
developed and experimentally evaluated under real-time operating conditions. The fabricated sensing
node integrated soil moisture, temperature–humidity, and pH sensing modules and was deployed in a
plant monitoring environment. As shown in Fig. 10 (a)–(b), the sensors were connected to the ESP32
controller and inserted into the soil for continuous environmental monitoring. The acquired
measurements were validated through the serial monitoring interface, as illustrated in Fig. 10(c), where
real-time sensor readings including soil moisture, temperature, humidity, pH, and light intensity were
continuously recorded. The collected data are subsequently transmitted wirelessly to the backend server
which is shown in Fig. 10 (d) it visualized through a web-based dashboard also shown in Fig. 10(e). The
complete experimental setup presented in Fig. 10(f) that demonstrates successful end-to-end operation
of the proposed IoT monitoring framework. These results confirm the capability of the system to
perform reliable real-time environmental sensing, wireless communication, and remote monitoring for
precision agriculture applications.
Page 17/30

VII. Conclusion
This paper presented GreenAI, an Explainable Artificial Intelligence (XAI) and Internet of Things (IoT)-
enabled offline-first precision agriculture framework designed to support data-driven agricultural
decision-making in resource-constrained environments. The proposed system integrates crop
recommendation, plant disease diagnosis, explainable AI, IoT-based environmental monitoring, and
edge-compatible deployment within a unified agricultural intelligence ecosystem tailored to Punjab's
farming conditions. For crop recommendation, a Punjab-specific dataset comprising 9,500 balanced
samples across 19 major crops was developed and evaluated using multiple machine learning
algorithms. Among the evaluated models, XGBoost achieved the best performance with a test accuracy
of 97.40% and a macro F1-score of 0.9741. For plant disease diagnosis, the EfficientNetV2-S model
achieved a validation accuracy of 99.03% on a unified 113-class disease dataset. To improve
transparency and user trust, SHAP-based feature attribution, partial dependence analysis and Grad-CAM
visualizations were incorporated into the decision-support pipeline. An ESP32-based IoT sensing
platform was experimentally validated, demonstrating the feasibility of real-time environmental
monitoring and edge-assisted agricultural intelligence. The obtained results demonstrate that GreenAI
provides an accurate, interpretable and scalable solution for precision agriculture while supporting
operation in low-connectivity rural environments. Future work will also focus on completing the
multilingual mobile application, large-scale field deployment, cloud-edge synchronization, integration of
additional agricultural sensors and validation across multiple agro-climatic regions to further increase
the practical applicability of the proposed framework.
Declarations
Competing interests.
The authors declare that they have no competing financial or non-financial interests that are directly or
indirectly related to the work submitted for publication.
Ethics approval.
This study did not involve human participants or animals. The study used publicly available crop and
plant-disease datasets together with environmental and market data; no field experiments requiring
ethical approval were conducted.
Consent to participate.
Not applicable.
Consent for publication.
Not applicable.
Page 18/30

Funding.
The authors did not receive support from any organization for the submitted work.
Author Contribution
Qasim Ali Hashmi: Conceptualization, Methodology, Software, Validation, Formal analysis, Investigation,
Data curation, Writing – original draft. Zain ul Sajjad: Writing – review & editing. Saqib Ali: Supervision,
Writing – review & editing. All authors read and approved the final manuscript.
Data Availability
The datasets analysed during the current study are derived from publicly available sources cited in the
text (PlantVillage, NASA POWER, and FAO AMIS). The Punjab-specific crop-recommendation dataset and
source code are available online
References

  1. Arrieta, A. B., et al. (2020). Explainable Artificial Intelligence (XAI): Concepts, taxonomies,
    opportunities and challenges toward responsible AI. Information Fusion, 58, 82–115.
    https://doi.org/10.1016/j.inffus.2019.12.012

  2. Ayaz, M., Ammad-Uddin, M., Sharif, Z., Mansour, A., & Aggoune, E. H. M. (2019). Internet-of-Things
    (IoT)-based smart agriculture: Toward making the fields talk. Ieee Access : Practical Innovations,
    Open Solutions, 7, 129551–129583. https://doi.org/10.1109/ACCESS.2019.2932609

  3. Chen, T., & Guestrin, C. (2016). XGBoost: A scalable tree boosting system. In Proceedings of the
    22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (pp. 785–
    794). https://doi.org/10.1145/2939672.2939785

  4. Doshi, Z., Nadkarni, S., Agrawal, R., & Shah, N. (2018). AgroConsultant: Intelligent crop
    recommendation system using machine learning algorithms. In Proceedings of the 4th International
    Conference on Computing Communication Control and Automation (ICCUBEA) (pp. 1–6). IEEE.

  5. Emon, M. H., et al. (2025). Integration of IoT, machine learning, and sensors for intelligent
    environmental monitoring and agricultural development. Journal of Computer Networks and
    Communications. https://doi.org/10.1155/jcnc/6611890

  6. FAO (2024). AMIS: Agricultural Market Information System — daily price and arrival feeds.
    https://www.amis-outlook.org

  7. Ferentinos, K. P. (2018). Deep learning models for plant disease detection and diagnosis. Computers
    and Electronics in Agriculture, 145, 311–318. https://doi.org/10.1016/j.compag.2018.01.009
    Page 19/30

  8. Hughes, D. P., & Salathé, M. (2015). An open access repository of images on plant health to enable
    the development of mobile disease diagnostics. arXiv. https://arxiv.org/abs/1511.08060

  9. Islam, M. R. (2026). An IoT-based smart plant monitoring and irrigation system with real-time
    environmental sensing, automated alerts, and cloud analytics. arXiv.
    https://arxiv.org/abs/2601.15830

  10. Khanna, A., & Kaur, S. (2019). Evolution of Internet of Things (IoT) and its significant impact in the
    field of precision agriculture. Computers and Electronics in Agriculture, 157, 218–231.
    https://doi.org/10.1016/j.compag.2018.12.039

  11. Kulkarni, N. H., Srinivasan, G. N., Sagar, B. M., & Cauvery, N. K. (2018). Improving crop productivity
    through a crop recommendation system using ensembling technique. In Proceedings of the 3rd
    International Conference on Computational Systems and Information Technology for Sustainable
    Solutions (CSITSS) (pp. 114–119). IEEE.

  12. Kumar, S., et al. (2026). An IoT-driven machine learning system for real-time smart crop
    recommendation and optimization in precision agriculture. Discover Artificial Intelligence.
    https://doi.org/10.1007/s44163-026-00896-y

  13. Lombardo, A., et al. (2021). Monitoring soil and ambient parameters in the IoT precision agriculture
    scenario: An original modeling approach dedicated to low-cost soil water content sensors. Sensors
    (Basel, Switzerland), 21(15), 5110. https://doi.org/10.3390/s21155110

  14. Lundberg, S. M., & Lee, S. I. (2017). A unified approach to interpreting model predictions. In
    Advances in Neural Information Processing Systems (Vol. 30, pp. 4765–4774).

  15. Madhuri, J., & Indiramma, M. (2021). Artificial neural networks-based integrated crop
    recommendation system using soil and climatic parameters. Indian Journal of Science and
    Technology, 14(19), 1587–1597.

  16. Mohanty, S. P., Hughes, D. P., & Salathé, M. (2016). Using deep learning for image-based plant
    disease detection. Frontiers in Plant Science, 7, 1419. https://doi.org/10.3389/fpls.2016.01419

  17. Mohapatra, S., et al. (2023). An IoT-based soil moisture management system for precision agriculture.
    Real-time monitoring and automated irrigation control.

  18. NASA (2024). POWER: Prediction of Worldwide Energy Resources — daily meteorology (MERRA-
    2/CERES). NASA Langley Research Center. https://power.larc.nasa.gov

  19. Ouammi, A. (2024). Low-cost IoT-based monitoring system for precision agriculture. E3S Web of
    Conferences, 492, 01003. https://doi.org/10.1051/e3sconf/202449201003

  20. Pande, S. M. (2021). Crop recommendation system using machine learning approach. In
    Proceedings of the 5th International Conference on Computing Methodologies and Communication
    (ICCMC). IEEE.

  21. PlantVillage (2019). PlantVillage dataset (augmented) [Data set]. Kaggle.
    https://www.kaggle.com/datasets/abdallahalidev/plantvillage-dataset

  22. Rahman, S., et al. (2025). The potential of low-cost IoT-enabled agrometeorological stations: A
    systematic review. Sensors (Basel, Switzerland), 25(19), 6020.
    Page 20/30

  23. Selvaraju, R. R., Cogswell, M., Das, A., Vedantam, R., Parikh, D., & Batra, D. (2017). Grad-CAM: Visual
    explanations from deep networks via gradient-based localization. In Proceedings of the IEEE
    International Conference on Computer Vision (ICCV) (pp. 618–626).
    https://doi.org/10.1109/ICCV.2017.74

  24. Shahi, T. B., et al. (2025). Smart farming for a sustainable future: Implementing IoT-based systems in
    precision agriculture. Bulletin of the National Research Centre. https://doi.org/10.1186/s42269-025-
    01366-8

  25. Tan, M., & Le, Q. V. (2019). EfficientNet: Rethinking model scaling for convolutional neural networks.
    In Proceedings of the 36th International Conference on Machine Learning (ICML) (pp. 6105–6114).

  26. Tan, M., & Le, Q. V. (2021). EfficientNetV2: Smaller models and faster training. In Proceedings of the
    38th International Conference on Machine Learning (ICML) (pp. 10096–10106).
    Figures
    Figure 1
    Overall Architecture and Workflow of Proposed GreenAI Framework.
    Page 21/30

Figure 2
Architecture of the ESP32-based IoT sensor node used for real-time environmental monitoring and
agricultural data acquisition.
Page 22/30

Figure 3
EfficientNetV2-S training curves Train Accuracy and Validation Accuracy vs. Epoch (1–15).
Page 23/30

Figure 4
EfficientNetV2-S training and Validation loss vs. Epoch (1–15).
Page 24/30

Figure 5
EfficientNetV2-S overall classification metrics outcomes.
Page 25/30

Figure 6
EfficientNetV2-S Bottom 20 classes result analysis.
Page 26/30

Figure 7
SHAP summary plot showing the contribution of environmental and soil parameters to crop
recommendation predictions.
Page 27/30

Figure 8
Global feature importance ranking derived from SHAP value analysis of the XGBoost CropAdvisor model.
Page 28/30

Figure 9
Partial dependence plots showing how (a) rainfall, (b) nitrogen, (c) humidity, and (d) soil pH influence
crop recommendation predictions.
Page 29/30

Figure 10
Real-time experimental validation of the proposed IoT-enabled precision agriculture monitoring system:
(a) ESP32 sensing node, (b) sensor deployment in soil, (c) live sensor acquisition through serial
monitoring, (d) wireless data transmission, (e) backend dashboard visualization, and (f) complete
experimental setup.
Page 30/30

论文原文与出版信息

Research Square
查看论文原文

继续探索