Abstract
The agricultural sector is moving from the Agriculture 4.0 model to the Agriculture 5.0 model because of advances in machine learning (ML), big data, and remote sensing. The purpose of this study is to introduce and validate a novel Attention Temporal Neural Network (ATNN) framework for the high-resolution prediction of soil nutrient concentrations, demonstrating its practical value using a real-world Digital Soil Mapping (DSM) dataset from Bezuidenhout Park, Johannesburg. The ATNN framework explicitly models temporal and contextual dependencies in multisource predictors, which include a Digital Elevation Model (DEM), spectral indices from Landsat and Sentinel-2 imagery, and meteorological covariates. The method involves combining the deep feature extraction capabilities of the ATNN with the strength of gradient-boosting regressors, specifically XGBoost, to leverage both architectures for robust tabular regression. The resulting ATNN–XGBoost hybrid model delivered the best performance in the experiments. It significantly reduced prediction error and improved agreement with laboratory measurements, achieving, for example, an RMSE ≈ 1.98 ppm, MAPE ≈ 2.81%, CCC ≈ of 0.76, and R2 ≈ of 0.69 for aluminium. This approach materially improved nutrient estimation accuracy over baseline models, including Random Forest (RF), Gradient Boosting (GB), and AdaBoost (ADB). The key contributions to this work are threefold: (1) the development of a compact ATNN architecture tailored for soil nutrient time series and spatial covariates; (2) a practical hybridisation strategy that pairs attention-based feature encoding with XGBoost (XGB); and (3) an empirical demonstration of superior performance on a real South African DSM dataset. These advances support more accurate and timely fertiliser management, offering a scalable path towards smarter, more sustainable precision agriculture systems.
Supplementary Information
The online version contains supplementary material available at 10.1038/s41598-026-56150-z.
Keywords: Soil nutrient prediction, Digital soil mapping, ATNN-XGB, Soil nutrient management, Agriculture 5.0, ML
Subject terms: Ecology, Ecology, Environmental sciences, Mathematics and computing
Introduction
Global food security is still at risk. Recent evaluations show that Sustainable Development Goal 2 ending hunger and achieving food security will not be met by 2030. The expected growth in agricultural output is not enough to close the gaps that already exist1,2 Soil degradation and nutrient depletion are central bottlenecks to sustainable production, with the FAO and its allied programs identifying widespread risks to soil health and substantial data gaps that hinder timely intervention and policy formation3. Rapid urbanisation and changing land-use patterns further complicate nutrient management by increasing spatial heterogeneity and introducing novel anthropogenic drivers that are poorly represented in conventional monitoring systems4–6. Hence, accurate prediction of soil nutrient status is challenging because soil properties are controlled by complex, interacting factors (topography, parent material, land management, and microclimate) and because observational data are frequently sparse, noisy, and spatially non-stationary. These issues lead to large local variability and sampling biases that reduce the transferability of empirically fitted models across landscapes and land-use types3,5,6. In urban environments specifically, highly variable microtopography and mixed land uses create conditions that standard regional models do not reliably capture, calling for methods that explicitly account for multi-scale heterogeneity.
ML methods (e.g., SVM, RF, ANN, XGB)7–10 and classical regression approaches (e.g., MLR, PLSR)11,12 have substantially advanced predictive mapping of soil properties by exploiting large multisource datasets and remote sensing proxies12–17. However, reliance on large labelled training sets, sensitivity to feature selection and sampling design, limited interpretability, and variable generalisation to new contexts remain important limitations. Ensemble and stacked approaches have improved accuracy in some studies, yet few investigations have rigorously evaluated such methods within the distinctive conditions of urban green spaces where rapid anthropogenic change and fine-scale variability dominate18–23.
Related work
The study introduces an interpretable deep learning framework for Digital Soil Mapping (DSM) using Explainable AI (XAI)24, addressing the “black box” nature of conventional Convolutional Neural Networks (CNNs) by integrating attention mechanisms, which allow the model to dynamically weigh the importance of different spatial neighbours and environmental covariates. The results demonstrate that the attention-based model maintains high predictive accuracy while significantly improving interpretability. By displaying attention weights, the model reveals which environmental factors and spatial neighbourhoods drive predictions, effectively bridging the gap between advanced machine learning and traditional pedological knowledge. Traditional SOC mapping often relies on single satellite images or static composites (e.g., mean/median), which fail to account for temporal noise like vegetation cover, soil moisture changes, or clouds25 Introduce a temporal attention module (often within LSTM or Transformer networks) to process satellite time-series data. This mechanism dynamically assigns weights to different time steps, allowing the model to automatically “pay attention” to the most relevant dates typically bare soil periods while suppressing irrelevant noisy data (vegetation/clouds). The approach demonstrates that leveraging temporal dependencies significantly improves SOC prediction accuracy compared to static conventional machine learning models26–29 introduce a Spatial Attention Module (SAM) integrated within a CNN to enhance high-resolution soil mapping. This mechanism overcomes the shortcomings of conventional CNNs that treat all pixels uniformly, enabling the model to dynamically concentrate on the most pertinent spatial features (such as specific terrain attributes) while mitigating background noise. The study demonstrates that this attention-driven approach significantly improves prediction accuracy and feature delineation in heterogeneous landscapes compared to traditional interpolation or standard deep learning methods30,31, presents a Transformer-based deep learning framework designed to integrate heterogeneous "multi-modal" soil data sources (e.g., combining proximal Vis–NIR spectroscopy with remote sensing and environmental covariates). The authors use self-attention mechanisms to dynamically weigh the importance of different data modalities, addressing the limitations of traditional fusion methods (like simple concatenations) and standard CNNs. The results demonstrate that the Transformer architecture significantly improves prediction accuracy for soil properties (such as Carbon and texture) by effectively learning complex cross-modal interactions and proving robust even when certain data inputs are noisy or missing. Liu et al. 32, Park et al.33, and Piccini et al.34 provide a critical review of attention mechanisms applied to soil spectroscopy (Vis–NIR/MIR). The paper evaluates how deep learning models, specifically Transformers and Attention-CNNs, are surpassing traditional chemometrics (like PLSR) by dynamically identifying key spectral wavebands. The authors highlight that attention maps offer interpretability, revealing which specific mineralogical features drive predictions (e.g., clay minerals or organic matter absorption features). However, they caution against “blind” applications, pointing out the requirement for rigorous validation of these interpretations against known soil behavior35. Feng et al.36 propose a Hierarchical Attention Network (HAN) to address the multi-scale variability inherent in soil properties. Recognising that soil attributes are driven by local factors (like microtopography) and broad regional trends (like climate), the authors designed a dual-level attention mechanism. One attention layer focuses on extracting fine-scale, high-resolution features, while a second layer aggregates broader, low-resolution contextual information. This hierarchical approach allows the model to simultaneously capture local details and global patterns, significantly outperforming single-scale CNNs in predicting complex soil attributes across large, heterogeneous areas37. Bao et al.38 investigate the interpretability of DL in DSM by treating attention maps as pedagogical explanations. The study assesses whether the spatial features focused on by the model (e.g., topography, vegetation) align with established soil formation theories (SCORPAN). The findings reveal a strong correlation between the model’s “attention” and physical reality, demonstrating that the AI independently discovers valid pedological relationships. This validates the use of attention mechanisms, effectively unlocking the mystery and confirming the physical plausibility of machine-generated soil maps.
This study addresses the gaps (Related Work), the ones in Table 1 (inclusive) by developing and evaluating hybrid ML architectures that pair an ATNN with established learners (RF, ADB, XGB, and GB) to predict soil nutrient content in an urban park (Bezuidenhout Park, Johannesburg). The proposed ATNN model addresses core limitations of data dependency, spatial–temporal generalisability, and model adaptability. It is sensor-agnostic, leveraging various input streams like SAR, optical, and LiDAR based on their contextual relevance, allowing optimal performance despite varying conditions. The ATNN enhances generalisability by learning transferable spatio-temporal patterns from long time series, improving feature detection even in fragmented landscapes. It effectively discriminates spectrally similar crops and minority targets using an attention mechanism focused on critical temporal phases rather than just spectral data. Using high-resolution, multi-source predictors and a comparative evaluation against conventional RF/ADB/XGB/GB baselines, our objectives are to (i) quantify predictive gains from ATNN-based hybrids in an urban context, (ii) assess robustness to local topographic and management-driven heterogeneity, and (iii) examine implications for urban land-use planning and nutrient-smart management. By focusing on urban park soils an under-studied but policy-relevant setting this work aims to extend the applicability of modern ML approaches to contexts characterised by pronounced spatial complexity and sparse observational data. This study makes four concrete contributions that advance the objectives of Agriculture 5.0 by moving soil-nutrient prediction toward more automated, data-driven, and decision-ready systems.
Table 1.
An integrative synthesis of previously established research findings.
| Author | Algorithm employed | Review focus | Limitation |
|---|---|---|---|
| 22 | RF, GBDT, and XGBoost | SOC estimation was carried out using Sentinel-2A and Landsat 8 data and comprises combining climatic variables, topographic factors, index variables, and Sentinel-1A data to create a common variable model for both Sentinel-2A and Landsat 8 data, as well as a full variable model specifically for Sentinel-2A data | The use of a single conventional classifier, the coarse, resampled spatial resolution of its fused data, and its reliance on a decommissioned hyperspectral sensor limit the practical applicability and generalisability of its findings |
| 20 | SVM, RF | Applications of Landsat 8 and Sentinel-2 data offer new insights into land use and land cover through remote sensing analysis | Its exclusive focus on optical data from two specific satellite sensors, thereby neglecting the significant contributions and integration potential of other remote sensing technologies like SAR and LiDAR |
| 19 | SLR, MLR, ANN, XGB and CNN | The accurate classification of urban land cover is significantly enhanced through the use of diverse satellite data, including polarimetric Sentinel-1A and Land Hyperion images | The study’s reliance on a single-year dataset from one urban area limits the ability to validate the proposed fusion model’s generalisability across various temporal conditions, geographic settings, and diverse urban land-use patterns |
| 39 | RF, KNN CART, Naïve Byes and SVM | A dataset comprising 2,150 mango tree samples was gathered from a Punjab, Pakistan, mango farm, utilising Landsat-8 satellite imagery and machine learning techniques for orchard detection, based on seven multispectral bands from the high-resolution imagery | Its reliance on a single Landsat-8 scene and 30-m resolution data constrains the model’s generalisability across different seasons, regions, and mango varieties, as well as its ability to accurately detect smaller or fragmented orchards |
| 40 | RF, GB, SVR, KNN and XGB | The study utilises in-situ soil moisture measurements from time-domain reflectometry (TDR), soil moisture products from SMAP and AMSR2, land surface temperature data, vegetation indices from MODIS, precipitation records, and topography data | The enhanced spatial resolution of the downscaled soil moisture product does not guarantee improved accuracy because it is fundamentally dependent on and constrained by the potential errors and uncertainties that are inherent in the original low-resolution satellite source data |
| 41 | Decision tree classifier (DTC) and RF | The study utilised a methodology to identify cropland and various crop types, including tobacco, wheat, barley, and gram, along with specific cropping patterns prevalent in Gujranwala District, Pakistan. This approach combined optical remote sensing images from Sentinel-2 and Landsat-8 with ML techniques | There is an inherent difficulty in accurately distinguishing between spectrally similar crop types and the model’s reduced performance for minority crop classes, a challenge that persists despite the employed machine learning techniques |
| 42 | RF, (extremely randomized trees) | The research focused on creating a land classification map for combine harvester operations in Kalikoir, Gazipur, Bangladesh, using satellite-derived digital elevation models (DEM) and soil physical property datasets to identify ideal rice fields for efficient harvesting | The system uses static topographic and soil data and does not account for critical dynamic operational constraints such as real-time soil moisture, field geometry, and crop conditions essential for practical, real-world harvester deployment |
| 43 | CART, RF, GBDT, and ERT | The study introduces a stacking integrated learning architecture for SMC retrieval that amalgamates various machine learning models. It highlights 19 factors that affect SMC, including radar backscattering coefficient, vegetation index, and drought index, utilizing data from SENTINEL-1, LANDSAT, and terrain sources | Despite employing advanced ensemble models, the study’s soil moisture retrieval is fundamentally constrained by the representativeness and availability of the sparse in situ data used for training, which may not capture the full spatial heterogeneity and temporal variability of soil moisture across the entire study area |
First, we develop and validate a compact ATNN hybridised with tree-based regressors (ATNN–XGB, ATNN–RF, ATNN–GB, and ATNN–ADB) that materially improve and stretch predictive accuracy and agreement with laboratory assays across twelve macro- and micronutrients in an urban setting, thereby supporting nutrient-smart fertilization and reduced input waste. Second, by integrating high-resolution multi-source predictors (DEM, Landsat/Sentinel-2 indices, and meteorological covariates) with temporal attention encoding, the workflow enables finer spatial and temporal resolution of soil nutrients than standard regional models, directly supporting near-real-time monitoring and targeted interventions in urban and peri-urban agriculture.
Third, the hybrid architecture enhances operational robustness and generalisability across multiple feature dimensions: ATNN provides deep feature extraction and dynamic feature weighting, while the gradient-boosting and ensemble learners supply calibrated tabular regression, uncertainty-robust residual correction, and established interpretability via feature-importance analyses. Finally, the methods and empirical evidence reported here offer a pragmatic route for translating ML advances into Agriculture 5.0 capabilities, namely scalable soil digital twins, adaptive fertiliser recommendations, and decision support for urban land-use planning, thereby bridging algorithmic innovation and actionable agronomic practice.
Materials and methods
Description of the site
Bezuidenhout Park in Johannesburg, South Africa (Longitude 28.09163° or 28° 5′ 30″ east and Latitude −26.18309° or 26° 10′ 59″ south), offers a diverse climate and varying weather conditions, making it an ideal study area for examining soil nutrient dynamics and their environmental influences. The park’s typical temperature fluctuates between 25 and 30 °C during the day, with occasional higher values. Winter is marked by low precipitation and moderate temperatures, with daytime temperatures ranging from 16 to 20 °C and nighttime temperatures dropping to 4 °C. The park receives an average annual rainfall of 713 mm, with the highest amount during summer months, as illustrated in Fig. 1.
Fig. 1.
The study area, Bezuidenhout Park, Johannesburg, Gauteng Province, South Africa.
Sample and data collection
This study used unconventional satellite imagery and APIs to assess soil nutrients and environmental conditions at Bezuidenhout Park, Johannesburg. The study area was delineated using high-resolution satellite imagery and GIS. Initial boundaries and terrain features were assessed via Google Earth Pro, followed by processing in GIS (ArcMap v10.8) for cartographic accuracy and vector boundary generation. Ground-truth field surveys planned for June 2024 aim to validate remote sensing data and address micro-topographical issues related to urban canopy cover, establishing a georeferenced baseline for future spatiotemporal modeling and soil sampling. The Simple Random Sampling (SRS) method was employed to assess soil nutrients, with each member having an equal and independent probability of being chosen for a sample. The methodology involved selecting 15 specific longitudes and latitudes covering the study area. Soil samples was collected, analysed them in a laboratory, and mapped their coordinates using the proposed method. A secondary dataset was compiled using International Soil Data Africa (iSDA) soil’s API for data augmentation and validation, which provided nutrient values in parts per million (ppm), g/kg and Cmol+/kg attached to the coordinates. The iSDA API was used to improve the accuracy of climate conditions44. The Open Weather API was used for months to gather spatial data and environmental information, and data from Earth Explorer and Copernicus was combined to improve the accuracy of climate conditions. A total of 2000 randomly selected samples of surface soil were collected from two depth ranges: 0.00–0.20 m (active layer for major plant soil interactions) and 0.20–0.50 m (active layer for plant growth, nutrient cycling, water dynamics, and long-term health of soil) as illustrated in Fig. 2. Data collection was meticulous, ensuring comprehensive coverage of the study area. The Open Weather API provided detailed climate data for each sampling point, including temperature, humidity, and precipitation, enabling a robust analysis of environmental covariates. Key outcomes include synchronised inputs, reduced mismatches, and improved accuracy, which enhance soil nutrient predictions in dynamic urban environments like Bezuidenhout Park.
Fig. 2.
Flowchart illustrating methodology procedures for the research.
Variables transformation
Changing all the variables to a 10-m raster format helped create a consistent layout and allowed for detailed geospatial analysis, which is important for accurately predicting soil nutrients. We generated the vital factors by converting all the variables to a raster format with a resolution of 10 m. This conversion ensured spatial uniformity and facilitated precise geospatial analysis. The high-resolution raster format was chosen to capture fine-scale variations in environmental covariates, which are crucial for accurate soil nutrient predictions. Each raster data set showed a specific environmental factor, like height from the Digital Elevation Model (DEM), colour bands from Landsat and Sentinel-2, and other calculated measures, like the Normalised Difference Vegetation Index (NDVI) and the Normalised Difference Water Index (NDWI). To integrate these variables with soil sample data, pixel values corresponding to the exact locations of the soil samples were extracted from the raster data sets. This extraction process involved overlaying the soil sample points onto the raster grids and retrieving the pixel values for each variable at these points. By doing so, we ensured that each soil sample was associated with a comprehensive set of environmental covariates, reflecting local conditions accurately. The high-resolution 10-m data allowed micro-environmental variations that might significantly influence soil nutrient dynamics. This granularity is particularly important in heterogeneous landscapes where soil properties can change abruptly over short distances.
Finer resolutions can lead to microtopographic noise and overparameterisation, which causes machine learning models to overfit rather than generalise biogeochemical gradients. The chosen resolution balances the nearest-neighbour distance of field observations with the soil sample size, avoiding representation errors and Modifiable Areal Unit Problem (MAUP) complications. By calibrating the grid to the dataset’s spatial density and nutrient autocorrelation range, the model maximises the signal-to-noise ratio, thereby ensuring reliability by representing the pedological environment and preventing spatial overfitting in the ATNN framework.
Data curation and analysis
Derivation of environmental covariates
The approach to predicting soil nutrients involves meticulous data preparation using features from Digital Elevation Models (DEM), Landsat, and Sentinel-2 images. Preprocessing steps focus on extracting topographic variables, elevation, slope, and aspect that are essential for understanding soil properties. GIS software generates slope and aspect maps, which inform about water flow and solar radiation effects. Landsat images undergo radiometric and atmospheric corrections to calculate spectral indices like NDVI and SAVI, reflecting vegetation health. Sentinel-2 imagery is corrected through Sen2Cor while employing NDVI, Enhanced Vegetation Index (EVI), and Red Edge Position (REP) to evaluate vegetation biomass and chlorophyll. The resulting indices are compiled in a geospatial database, facilitating further analysis through systematic procedures and specialised software, as shown in Fig. 3.
Fig. 3.
Data acquisition.
Programmatically retrieved structure data
This study utilised a REST API to gather soil nutrients from both soil and weather datasets, allowing access to historical and real-time environmental information. This integration of remote sensing with API data improves the precision and comprehensiveness of soil nutrient predictions, thereby facilitating enhanced agricultural and environmental management strategies.
Data characterisation and statistics analysis
The dataset has 2000 observations recorded for the key environmental and spectral variables. Geospatial coordinates are centred at a mean latitude of −26.1826 and a mean longitude of 28.08914, both of which have very narrow distributions around their central values. The target variable represents the soil nutrient values in some units. Nutrient content ranges widely between 0.6 and 402.4 with a mean of 49.32326 units. The spectral bands from the remote sensing data, like the Red Band averaging 6985.436 and the IR1 averaging 11,432.65, have similar standard deviations, which means their values are consistently spread out in the dataset. The atmospheric parameters the water vacuum with a mean of 3474.645 and the temperature with a mean of 280.9287 K show the expected ranges for the area of study. The humidity, at a mean of 65.94821%, and the atmospheric pressure, at a mean of 1024.029 hPa, point to standard climatic conditions. These statistics supply a general overview of central tendencies and variability, which is quite crucial for further modelling and analysis of the dynamics of nutrients in the soil Table 2.
Table 2.
Summary of analytical results.
| Latitude | Longitude | Value | IR1 | NIVR_1 | Water vapor | Temperature | Humidity | Pressure | |
|---|---|---|---|---|---|---|---|---|---|
| Count | 2000.00 | 2000.000 | 2000.000 | 2000.000 | 2000.000 | 2000.000 | 2000.000 | 2000.000 | 2000.000 |
| Mean | − 26.1826 | 28.08914 | 49.32326 | 11,432.65 | 6686.202 | 3474.645 | 280.9287 | 65.94821 | 1024.029 |
| Std | 0.001541 | 0.001177 | 75.81354 | 99.66654 | 30.02113 | 14.88377 | 2.911090 | 8.711961 | 5.681757 |
| Min | − 26.1851 | 28.08720 | 0.600000 | 11,025.15 | 6573.504 | 3412.965 | 269.9781 | 30.34887 | 1001.909 |
| 25% | − 26.1838 | 28.08810 | 5.700000 | 11,365.56 | 6665.820 | 3464.615 | 278.9546 | 60.07026 | 1020.307 |
| 50% | − 26.1826 | 28.08920 | 9.000000 | 11,433.09 | 6686.267 | 3474.691 | 280.9234 | 65.91791 | 1024.088 |
| 75% | − 26.1813 | 28.09020 | 72.70000 | 11,500.47 | 6706.615 | 3484.603 | 282.9343 | 71.84237 | 1027.882 |
| Max | − 26.1799 | 28.09110 | 402.4000 | 11,863.28 | 6795.756 | 3528.377 | 292.1830 | 99.00013 | 1044.757 |
Model construction and analysis
The data modelling phase aims to create robust predictive models by developing algorithms that capture and generalise dataset patterns. Choosing the right ML algorithms is the first step in effective data modelling. For example, ensemble learning methods like RF, GB machines, ADB, and XGB can handle complex and nonlinear relationships between variables and make soil nutrient mapping models more accurate. Table 3, the summary of key characteristics of the different classifier models used in the study.
Table 3.
Summarising the key characteristics of the different classifier models used in the study.
| Model | Algorithm type | Hyperparameters | Strength | Limitation | Computational resources |
|---|---|---|---|---|---|
| XGB | GB | Learning rate: 0.1, max depth: 6, n_estimators: 100 | High accuracy, handles missing data, regularisation | Prone to overfitting, requires careful tuning | High |
| RF | Ensemble, bagging | n_estimators: 100, max depth: 5, Min samples leaf: 5 | Robust to overfitting, handles large datasets well | Computationally intensive, less interpretable | High |
| ADB | Ensemble, boosting | Learning rate: 1.0, n_estimators: 50 | Can improve weak classifiers, relatively simple | Sensitive to noisy data, weaker performance on complex datasets | Low |
| GB | Ensemble boosting | Learning rate: 0.1, max depth: 3, n_estimators: 100 | High predictive power, feature selection | Slower training, risk of overfitting | High |
RF
RF is a robust ensemble ML algorithm that has been widely used in soil nutrient prediction studies. The algorithm integrates multiple decision trees to form a forest, where each tree contributes to the final prediction, thereby yielding an accurate result45. Various environmental and agricultural contexts, including soil nutrient mapping, have applied this methodology. For example45,46, RF has been used to predict soil’s chemical and physical properties at different sizes and show how these models can effectively map soil nutrients. Additionally47, RF is very effective for both sorting data into categories and making numerical predictions, which makes it a good choice for estimating both continuous and categorical variables about soil nutrient levels. Finally48,49, shows that RF is effective at predicting total phosphorus levels in the soil, emphasising its ability to handle large amounts of data and complicated relationships between different soil features. In general, in soil nutrient predictions, RF is compelling due to several reasons: it can model multi-way interactions within its input variables quite well, maintain robustness around outliers, and generate excellent results related to soil nutrients.
ADB
ADB, or adaptive boost, is an ensemble learning technique that leverages the predictions of many weak classifiers to generate a strong classifier, therefore improving accuracy in ML models. It was introduced by50, and its basic idea involves iteratively training weak classifiers, usually decision stumps, in weighted versions of the training dataset. Initially, all instances are given equal weights, but in subsequent iterations, ADB increases the weights of misclassified instances, forcing the next classifier to focus on the hard-to-classify examples. The final model is a weighted sum of these weak classifiers, where each classifier’s contribution is proportional to its accuracy. The result is an adaptive process that works to reduce bias and variance effectively, making ADB compelling for binary classification tasks though it can be extended to multiclass problems. However, ADB has some disadvantages: ADB’s performance can deteriorate due to its sensitivity to noisy data and outliers.
GB
GB is an ML method that optimises soil nutrient prediction by building decision trees to correct residual errors. It models complex relationships between soil properties and nutrient levels, increasing precision. GB’s key mechanisms include loss minimisation, additive training, and hyperparameters. Its advantages include feature importance, robustness, and accuracy. Applications include precise fertilising and sustainable practices51. Challenges include computational intensity and the risk of overfitting with noisy data. Many environmental studies have applied this approach to the complex interactions between soil properties and nutrients. For instance52, showed that arbuscular mycorrhizas play an essential role in minimising aluminium phytotoxicity in acidic soils; therefore, it is necessary to determine the correct soil nutrient predictions. At the same time, adding gradient enhancements to soil nutrition prediction models allows researchers to fully consider how soil properties, like aluminium content and nutrient levels, interact, which improves the accuracy and reliability of soil nutrition predictions.
XGB
XGB refers to the implementation of GB machines, which aim to optimise computational speed and model performance. Originally suggested in53, XGB, it became well-known mainly because it [a] effectively manages sparse data and [b] can handle large data sets while enhancing predictions in different ML tasks. It works by sequentially adding new models, typically decision trees, to correct the errors of the previously made models. The system uses a type of gradient descent algorithm to reduce the loss function. Key features of XGB include regularisation to prevent overfitting, parallel tree construction, and intrinsic capabilities for handling missing data54. So far, XGB has been successful in the implementation of GB in ML for soil nutrient prediction. Most fields, including soil science, have applied it. For instance39, researchers applied Random Forest (RF) and Gradient Boosting (GB) using machine learning methods to predict soil properties. Similarly55, showed XGB’s performance in predicting soil organic matter content, even outperforming other ML methods. Moreover, according to56, the hierarchical ensemble model tree structure, XGB is well-suited for spatial adjustment problems, which are common in soil mapping applications. XGB extends the principles of GB with several improvements in this process enhances efficiency and performance. Look at it from an implementation perspective: the following stages are involved.
Model initialization
The process begins with an initial prediction, which is typically the mean of the target values for regression tasks, specifically the value of a specific soil nutrient.
![]() |
1 |
Gradient and hessian computation:
For each round t, it computes the gradient
and the Hessian
of the loss function concerning the current prediction.
![]() |
2 |
![]() |
3 |
Construction of tree:
Construct a decision tree to fit the gradients
and Hessians
. The objective is to minimise the regularised loss function.
![]() |
4 |
=
is the regularisation term with T being the number of leaves and
the weight of leaf j.
Finding split:
For each possible split, it computes the gain. The gain from splitting a node into left (L) and right (R) is as follows:
![]() |
5 |
Tree pruning:
Prune nodes with negative gain. This step ensures that each split increases the overall gain.
Predictions update:
Update the predictions by adding the output of the newly constructed tree, scaled by learning.
![]() |
6 |
Iterate:
Repeat Eqs. 2 to 6 for a predetermined number of boost rounds or until convergence.
Final model expression:
Hence, the final prediction is the sum of the initial prediction and all the trees’ outputs.
![]() |
7 |
Kriging
Kriging is a Best Linear Unbiased Predictor (BLUP) that estimates soil nutrient values at unsampled locations based on spatial autocorrelation. Among geostatistical methods57, kriging stands out for its ability to provide unbiased predictions with minimal variance, making it ideal for soil nutrient mapping. Soil nutrients, essential for crop productivity, exhibit spatial dependence, which Kriging effectively captures through variogram analysis, a widely used method for estimating soil nutrient values. Variants include Ordinary Kriging (OK), Universal Kriging (UK), Co-Kriging (CK), and Regression Kriging (RK). Ordinary kriging was implemented as shown in Fig. 4. Ordinary kriging, a popular choice for spatial interpolation, balances simplicity and statistical rigour, providing accurate predictions with uncertainty estimates, making it a popular choice in geostatistics. However, challenges like non-stationarity, sparse sampling, and anisotropy lead to unreliable variograms. Recent advancements in kriging include machine learning hybrids. value,
, is equivalent to half the mean squared difference between the values
and 
![]() |
8 |
Fig. 4.
Kriging of different Nutrients values in Bezuidenhout Park.
N represents the quantity of data pairs within a specific class of distances and directions, Z denotes the measured value of soil nutrients, x signifies the location of soil samples, and h indicates the separation distance.
![]() |
9 |
is the prediction value, n is the number of samples, λi is the weight, and x
is the measured value for soil property at the x position. We employed ordinary kriging to predict soil nutrients. In this context,
the predicted value is represented, the number of samples is denoted by n, the weight assigned is indicated by λi, and the measured value for the soil property at position x is corresponded to.
ATNN
The ATNN is an innovative but sophisticated type of neural network that handles data in a sequence by combining attention features, time-based processing, and flexible components. It is suitable for tasks like time-series forecasting, natural language processing (NLP), and speech recognition58. The ATNN has model consists of several components, including an input layer for raw sequential data, an embedding layer, positional encoding, a time processing layer, an attention mechanism, adaptive features, variable parameters, memory improvement techniques, an output layer, and training methods. Fundamental components include multi-head attention, adaptive attention, dynamic parameters, conditional computation, and memory augmentation. The output layer has task-specific heads such as regression, classification, and autoregressive decoding. Training methods include loss functions, optimisation, regularisation, and adaptive training. Applications include time-series forecasting, NLP, speech processing, and healthcare. Advantages of ATNN include context awareness, flexibility, efficiency, scalability, and adaptation. Attention highlights critical sequence segments, handles diverse inputs and tasks, reduces redundancy, and handles long sequences better than pure RNNs59. There are simpler versions called ATNNs that use special kinds of convolutions or sparse attention for devices with less power. Additionally, there are mixed models that combine ATNN with CNNs for various data types, and reinforcement learning is used for making decisions over time. The three main methods for training a hybrid ATNN are ADB, XGB/GB, and RF. ADB involves iteratively training ATNNs, reweighting misclassified samples, and combining weighted predictions. XGB corrects residuals with additive ATNNs, allowing for time-series regression and forecasting. RF combines ATNNs with static features, allowing for average predictions in noisy sequential data. Data preparation involves aligning sequential and static features, and the model design includes an ATNN core, a temporal layer, and attention. Boosting involves weighted/residual-driven training, while bagging involves bootstrap sampling. The process of inference involves analysing ensemble outputs by weighing or averaging them. The best ensemble method depends on the data type, such as rare events in sequences, regression with complex residuals, or robustness in noisy/multimodal data. This research work addresses all the stated shortcomings.
The existing temporal attention models, such as Transformers, Temporal Convolutional Networks, and LSTM+Attention, are limited in environmental and nutrient prediction tasks due to their data-hungry nature and susceptibility to overfitting, particularly with moderately sized tabular datasets. These models struggle with the heterogeneity of tabular data and are unable to establish effective decision boundaries within features like chemical concentrations and temperature. Furthermore, deep neural networks generally face the “black box” dilemma, lacking the interpretability necessary to understand variable contributions in environmental science. The new ATNN framework addresses these shortcomings by conceptualising temporal modelling and prediction as interconnected processes instead of merely employing end-to-end learning. Key innovations of the ATNN framework include targeted temporal feature extraction that assigns dynamic weights to historical data, enhancing prediction accuracy; algorithmic symbiosis for better context awareness, where temporally weighted features are handled by tree-based ensemble learners; and dynamic noise reduction techniques to eliminate irrelevant historical data, which improves metrics like Mean Absolute Error (MAE) and Root Mean Square Error (RMSE). Positioning the ATNN framework in relation to existing literature reveals it as a merging of Sequence Representation Learning with Advanced Ensemble Modeling. This approach surpasses traditional machine learning by utilising crucial temporal memory and weighting, allowing for improved time-series data processing without the computational burdens and overfitting risks associated with deep learning. Moreover, it presents a more efficient, localised predictive solution that can effectively manage complex, non-linear, multidimensional datasets, such as those involved in soil nutrient forecasting, by introducing a hybrid feature-fusion mechanism that differentiates between temporal feature extraction and predictive mapping, setting it apart from standard temporal attention methods.
Methodological novelty and positioning of the ATNN framework
The proposed ATNN framework offers a methodological innovation in analysing static, tabular pedological datasets. Unlike traditional attention methods focused on sequential data, the ATNN emphasises feature-wise attention, assessing relationships among soil parameters like pH and moisture. It incorporates a localised self-attention module to dynamically evaluate feature interactions, allowing adaptive feature weighting that minimises the influence of redundant data. This framework addresses gaps in existing ensemble models, which rely on global feature evaluations and often struggle with heterogeneous soil survey data. By integrating strengths from temporal attention and ensemble methods, ATNN preprocesses inputs to create context-aware feature representations for baseline ensemble trees, merging the adaptive learning of deep networks with the robustness of established techniques. Ultimately, it recontextualises the attention mechanisms for complex biogeochemical data, optimising the model architecture for high-dimensional soil chemistry.
Furthermore, the proposed ATNN introduces a hybrid feature-fusion mechanism that separates temporal feature extraction from predictive mapping, which diverges from standard temporal attention methods. The ATNN architecture comprises two main innovations:
The ATNN is a dynamic feature generator that improves gradient boosting and bagging models. Instead of producing a direct prediction, it outputs attention-weighted contextual vectors that are combined with the original feature set and used by foundational learners, like Random Forests (RF), AdaBoost (ADB), Gradient Boosting (GB), and XGBoost (XGB). This hybrid approach leverages the strengths of neural attention for temporal sequencing along with the nonlinear mapping capabilities of tree-based methods.
An ablation study empirically validates the necessity of the ATNN framework, demonstrating its superiority over conventional ensemble models (RF, ADB, GB, XGB) that inadequately address nutrient temporal dynamics, as indicated by low baseline R2 scores. The ATNN-XGB architecture significantly improves predictive capability. The study isolates the ATNN module, demonstrating that dynamic temporal weighting reduces Mean Absolute Percentage Error (MAPE) by up to 26% and enhances model correlation, confirming the framework’s methodological advantage.
To capture the cumulative environmental influence on nutrient dynamics, temporal sequences were constructed using a sliding-window approach anchored to the physical soil sampling date
for each sampling location, meteorological variables (Precipitation, Temperature) and satellite-derived indices (NDVI, LST) were extracted for the T months preceding the sample collection. This results in a dynamic feature matrix
where T (representing a full annual cycle) and
is the number of dynamic covariates. These sequences allow the ATNN to learn the ‘lagged’ biogeochemical response of nutrients to seasonal climatic forcing, which a static model would ignore.
The ATNN architecture is designed to handle heterogeneous inputs: a dynamic tensor and a static vector. The input X consists of:
Dynamic Tensor:
(Batch size, Time steps, Dynamic features).
Static Vector:
(Batch size, Static soil/topographic features).
The temporal encoder utilises a multi-head self-attention mechanism where the Queries (Q), Keys (K), and Values (V) are derived from the dynamic tensor. The attention weights are calculated as:
![]() |
10 |
This allows the model to assign weights to specific months (e.g., peak growing season) that are most predictive of the target nutrient. Unique to this study, the static vector
is used to initialize the hidden state or gate the attention weights, ensuring the temporal analysis is contextualized by the local geology.
The ATNN functions as a deep feature extractor. Once the attention layers have processed the temporal sequences, a Global Average Pooling layer collapses the time dimension
, resulting in a fixed-length latent representation vector
, D is the embedding dimension. This latent vector z is then concatenated with the original static features
to form a comprehensive ‘environmental fingerprint’ for each sample. This unified feature set is passed into the downstream regressor (e.g., XGBoost or RF), which serves as the final prediction head. This hybrid approach allows the ATNN to handle the complex temporal feature engineering, while the tree-based regressors handle the non-linear decision boundaries for nutrient quantification.
Targeted Temporal Weighting: This mechanism employs a localised, multi-headed attention layer that differentiates itself from typical global attention by assessing alignment scores at specific temporal lags relevant to certain nutrients.
represent the input feature vector at time t. The ATNN computes the attention weights α αt using a specialised scoring function tailored for environmental covariates:
![]() |
11 |
Algorithmic synergy (neural-to-tree fusion)
The ATNN is a dynamic feature generator that improves gradient boosting and bagging models. Instead of producing a direct prediction, it outputs attention-weighted contextual vectors that are combined with the original feature set and used by foundational learners, like Random Forests (RF), AdaBoost (ADB), Gradient Boosting (GB), and XGBoost (XGB). This hybrid approach leverages the strengths of neural attention for temporal sequencing along with the nonlinear mapping capabilities of tree-based methods.
An ablation study empirically validates the necessity of the ATNN framework, demonstrating its superiority over conventional ensemble models (RF, ADB, GB, XGB) that inadequately address nutrient temporal dynamics, as indicated by low baseline R2 scores. The ATNN-XGB architecture significantly improves predictive capability. The study isolates the ATNN module, demonstrating that dynamic temporal weighting reduces Mean Absolute Percentage Error (MAPE) by up to 26% and enhances model correlation, confirming the framework’s methodological advantage.
For a given time step tt, the attention mechanism computes a relevance score
for each feature j as follows:
-
Feature score calculation
Here,
represents the encoded feature vector for feature j at time t,
and
are learnable parameters, and
is a weight vector. The function tanh introduces non-linearity to model complex interactions. -
Attention weights:
The relevance scores
are normalised across all features using a softmax function:
13
The attention weigh t
quantifies the importance of feature j at time t.
Weighted feature representation:
The attention weights are used to compute a weighted feature representation for each time step:
![]() |
14 |
The vector
represents a refined feature set, where irrelevant or less significant features are down weighted and critical features are emphasised. With this incorporation of a feature-level attention mechanism, the ATNN adapts to varying temporal patterns and feature relevance, making it highly effective for datasets where the importance of features changes over time. This dynamic weighting ensures that the most informative features drive the prediction process, while less relevant features have minimal impact. The ATNN’s output, which is a series of weighted feature representations, is then combined into a context vector that gives a summary of the information at both the feature and time levels. This context vector is subsequently passed to the Random Forest component, which leverages its ensemble learning capabilities to generate robust predictions.
Cross-validation and hyperparameter tuning
To ensure robust evaluation while accounting for spatial autocorrelation typical of soil datasets, samples were partitioned using a spatially stratified scheme. The fully labelled dataset was split into training (70%), validation (15%), and independent test (15%) sets using spatial block sampling such that nearby samples were placed in the same fold whenever possible to avoid information leakage. For hyperparameter selection and model development, we adopted a fivefold spatial cross-validation on the training set (i.e., the 70% subset was further divided into five spatial folds). This spatial CV preserves local structure and provides conservative estimates of out-of-sample performance compared with random folds. The validation set was used to stop the process early and choose the best model, while the held-out test set was used to report the final performance. All splits used a fixed random seed (seed = 42) to ensure reproducibility, and continuous predictors were standardised (zero mean, unit variance) using parameters estimated only from the training set. Geospatial data management requires distinct geographic blocks for training and testing to avoid memorising location-specific traits. In time-series forecasting, it is essential to train solely on historical data to avoid look-ahead bias. Additionally, maintaining similar statistical distributions across data splits is essential for handling skewed datasets, thereby preventing bias from unrepresentative samples.
Model training and evaluation
The procedure of model selection and validation had been designed in such a way that it yielded the optimum generalisable models to predict soil nutrient levels. To begin with, the dataset had been split into 12 nutrient-specific data sets, each bearing a different type of nutrient, such as aluminium, calcium, carbon, iron, nitrogen, pH, phosphorus, sulphur, zinc, potassium, magnesium, and cation exchange capacity; hence, it needed specialised model training. The goal was to enhance predictive accuracy and generalisability across diverse environmental contexts. This process looked at how different environmental factors interact, making sure the models could adjust to various soil nutrient changes caused by things like land shape, plant growth, and weather conditions. The metrics used for the evaluation included the RMSE, R2, MAE, MAPE, and CCC60. Each metric provides a unique perspective on the model’s performance, capturing different aspects of prediction accuracy and reliability61. The equations for each metric are detailed below.
Nutrient-specific optimisation and biogeochemical feature relevance
While the computational workflow for the twelve nutrition targets was standardised for comparative validity, the models’ internal mechanics were tailored to reflect specific biogeochemical processes throughout the soil nutrients. A uniform parameterisation would neglect the distinct pedological dynamics of each target; thus, the methodology employed meticulous nutrient-specific model tuning and localised feature relevance analysis. Hyperparameter optimisation for algorithms like RF, XGB, and ATNN-enhanced architectures was conducted through Bayesian optimisation for the twelve nutrients. Key parameters, including network depth, learning rates, tree estimators, and attention weights, were refined to minimise the target-specific RMSE. This approach allowed the models to accommodate the specific variance and noise related to each nutrient’s distribution, acknowledging the differences between macronutrients, such as Nitrogen, and trace elements. By combining nutrient-specific hyperparameter optimisation with personalised feature relevance analysis, the methodology firmly anchors computational models in soil science. The variations in variable importance across the twelve targets demonstrate that the ATNN-enhanced architectures effectively identify and leverage the unique biogeochemical pathways for each nutrient rather than rely on generalised proxy variables.
Root mean squared error (RMSE)
![]() |
15 |
R-squared (R2)
![]() |
16 |
![]() |
17 |
Mean absolute percentage error (MAPE)
![]() |
18 |
Concordance correlation coefficient (CCC)
![]() |
19 |
Rsults
This section of scientific reports presents, evaluates, and interprets the results of the experiments. This section combines data presentation, analysis, comparison with previous work, and implications of the findings.
Benchmarking of machine learning (ML) models
Result for aluminium (ppm) level prediction
In Table 4, the ATNN-XGB model achieves the lowest RMSE of 1.9832 ppm, outperforming the standard XGB (2.1855 ppm) by about 9.25%, indicating significant potential for cost savings or safety improvements in developed forecasting. Its MAPE of ~ 2.81% reflects that predictions are within 3% of actual aluminium levels, outperforming XGB’s 3.3544 ppm by over 16%. An MAE of 1.2312 ppm shows a 28.4% improvement over XGB’s 1.7182 ppm, affirming the model’s consistent precision. A CCC of 0.7634 indicates strong agreement between predictions and actual observations, ensuring high accuracy and reliability for deployment. The model explains 68.32% of variance with an R2 of 0.6832, a notable improvement over XGB’s 61.32%, suggesting the ATNN component effectively captures complex, non-linear relationships that tree-based models may overlook Fig. 5.
Table 4.
Models comparative plot analysis on aluminum (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 2.1976 | 2.4887 | 2.3593 | 2.1855 | 2.0045 | 2.1003 | 2.0123 | 1.9832 |
| MAPE | 3.4607 | 4.5112 | 3.8108 | 3.3544 | 2.7463 | 4.0022 | 3.2122 | 2.8131 |
| MAE | 1.7698 | 2.3149 | 1.9542 | 1.7182 | 1.2342 | 1.8311 | 1.3212 | 1.2312 |
| CCC | 0.7437 | 0.6378 | 0.7000 | 0.7647 | 0.8432 | 0.8210 | 0.7732 | 0.7634 |
| R2 | 0.6093 | 0.5002 | 0.5498 | 0.6132 | 0.7004 | 0.6990 | 0.6876 | 0.6832 |
Fig. 5.
Performance metrics for predicting aluminium (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for carbon (g/kg) level prediction
The analysis of models for predicting carbon levels, as summarised in Table 5, An RMSE of 0.5032 g/kg and an MAE of 0.3821 g/kg indicate a significant improvement in predictive accuracy, with a minimal difference suggesting a well-behaved error distribution free from large outliers. The MAPE of 4.1242% translates this accuracy into practical terms, indicating effective model performance for real-world applications. A CCC value of 0.9831 demonstrates near-perfect agreement between predicted and observed values, showcasing both high precision and accuracy. The R2 value of 0.9577 illustrates that the ATNN-XGB model explains approximately 95.77% of the variance in the target variable, confirming its effectiveness as an explanatory tool. Overall, the ATNN-XGB architecture stands out as highly reliable and ready for deployment in critical forecast scenarios, enabling optimised processes and informed decision-making as shown in Fig. 6.
Table 5.
Models comparative plot analysis on carbon (g/kg) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.5794 | 0.6690 | 0.5964 | 0.5857 | 0.5032 | 0.6232 | 0.5321 | 0.5120 |
| MAPE | 4.5584 | 5.2056 | 4.7233 | 4.7890 | 4.1242 | 5.0043 | 4.1202 | 4.3211 |
| MAE | 0.4137 | 0.4747 | 0.4311 | 0.4323 | 0.3821 | 0.3912 | 0.4021 | 0.4021 |
| CCC | 0.9607 | 0.9471 | 0.9579 | 0.9597 | 0.9831 | 0.9576 | 0.9621 | 0.9698 |
| R2 | 0.9247 | 0.8997 | 0.9203 | 0.9231 | 0.9577 | 0.9322 | 0.9324 | 0.9532 |
Fig. 6.
Performance metrics for predicting carbon (g/kg) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for calcium (ppm) level prediction
Table 6, shows the ATNN-RF model achieves the lowest RMSE of 14.3211 ppm, indicating strong predictive accuracy and robustness against outliers, which is vital in contexts where large errors can have significant implications. Additionally, it has a MAPE of 4.2312%, signifying that its predictions are reliably within a 4% error margin of actual calcium values, enhancing its utility in decision-support systems. The model’s R2 value of 0.8457 shows it explains approximately 84.57% of variance in calcium levels, effectively capturing the underlying data-generating processes. In comparison, ATNN-XGB, with an RMSE of 15.9325 ppm and R2 of 0.7832, also presents strong performance, outperforming the standard XGB model and validating the ATNN hybrid approach’s effectiveness. The performance differentiation between ATNN-RF and ATNN-XGB can be linked to the dataset characteristics, suggesting that RF bagging method is more advantageous than XGB’s boosting in this specific scenario when merged with ATNN’s feature abstraction., as shown in Fig. 7.
Table 6.
Models comparative plot analysis on calcium (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 18.4419 | 20.5698 | 18.1080 | 18.9525 | 14.3211 | 15.6957 | 14.4380 | 15.9325 |
| MAPE | 4.9704 | 5.7842 | 4.9791 | 5.2324 | 4.2312 | 5.4329 | 4.3212 | 4.3214 |
| MAE | 13.6006 | 15.6263 | 13.6329 | 14.3094 | 11.4312 | 11.363 | 11.6332 | 11.6432 |
| CCC | 0.8544 | 0.8100 | 0.8571 | 0.8485 | 0.9001 | 0.8423 | 0.8732 | 0.8921 |
| R2 | 0.7457 | 0.6852 | 0.7552 | 0.7319 | 0.8457 | 0.7018 | 0.7921 | 0.7832 |
Fig. 7.
Performance metrics for predicting calcium (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for iron (ppm) level prediction
The results for iron level prediction, as outlined in Table 7, An RMSE of 2.6346 ppm and an MAE of 2.0211 ppm indicate significant reductions in overall error magnitude, suggesting a well-behaved error distribution with minimal large outliers. This consistency is vital for real-world applications, where reliability complements average accuracy. The MAPE of 4.0001% shows that the model’s predictions are, on average, within 4% of true observed values, transforming it into a reliable tool for critical decision-making, where slight improvements in prediction accuracy can lead to substantial advantages. A CCC of 0.9944, nearly at the theoretical maximum of 1.0, signifies excellent alignment between predicted and observed values, showcasing both high precision and accuracy, confirming the ATNN-RF model’s capability to predict trends accurately and calibrate to the actual data scale. An R2 value of 0.9893 indicates that the model accounts for approximately 98.93% of the total variance in the target variable, leaving only 1.07% unexplained. This high R2 indicates that ATNN-RF effectively captures the underlying data-generating process, establishing a new benchmark for predictive efficacy, with its minimal error and superior performance marking a significant advance in predictive systems methodology, as shown in Fig. 8, proving that the attention mechanism at the feature level improves prediction accuracy for iron levels.
Table 7.
Models comparative plot analysis on iron (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 3.0666 | 3.5828 | 3.2519 | 3.2877 | 2.6346 | 3.4328 | 3.0519 | 3.2832 |
| MAPE | 4.4736 | 5.4345 | 4.9833 | 5.0259 | 4.0001 | 5.0215 | 4.3233 | 5.0229 |
| MAE | 2.2936 | 2.7698 | 2.5069 | 2.4653 | 2.0211 | 2.4212 | 2.5236 | 2.4253 |
| CCC | 0.9927 | 0.9901 | 0.9918 | 0.9916 | 0.9944 | 0.9921 | 0.9912 | 0.9216 |
| R2 | 0.9856 | 0.9803 | 0.9838 | 0.9834 | 0.9893 | 0.9840 | 0.9839 | 0.9972 |
Fig. 8.
Performance metrics for predicting iron (ppm) levels using RF, ADB, GD, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for nitrogen (g/kg) level prediction
The result in Table 8 show that the model demonstrates exceptional precision in its error metrics, with a RMSE of 0.0482 g/kg and a MAE of 0.0335 g/kg, indicating only slight deviations from actual nitrogen values. The closeness of these values suggests a robust model with a narrow error distribution and minimal outliers, vital for applications in precision agriculture and water quality monitoring. Additionally, the MAPE of 4.1054% indicates that model predictions are approximately 4.1% from true values, reinforcing its reliability for decision-support systems where percentage error is crucial. The model’s robustness is further evidenced by a CCC of 0.9773, signifying near-perfect agreement and excellent calibration alongside an R2 value of 0.9521, which reveals over 95% variance explanation in nitrogen levels. This demonstrates that the model not only predicts well but captures the fundamental mechanisms influencing nitrogen variations. The alternate model, ATNN-RF, also shows commendable performance (RMSE: 0.0432 g/kg, R2: 0.9356 g/kg), illustrating the hybrid ATNN framework’s effectiveness. The strong results in both ATNN-XGB and ATNN-RF suggest a broader architectural advantage, with the boosting mechanism of XGB potentially more adept at enhancing features for this specific predictive task compared to RF’s bagging approach. As shown in Fig. 9.
Table 8.
Models comparative plot analysis on nitrogen (g/kg) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.0559 | 0.0595 | 0.0557 | 0.0543 | 0.0432 | 0.0442 | 0.0557 | 0.0482 |
| MAPE | 4.7519 | 5.0006 | 4.8746 | 4.9055 | 4.3200 | 4.5426 | 4.8746 | 4.1054 |
| MAE | 0.0416 | 0.0444 | 0.0428 | 0.0425 | 0.0309 | 0.0381 | 0.0428 | 0.0335 |
| CCC | 0.9583 | 0.9525 | 0.9583 | 0.9583 | 0.9599 | 0.9652 | 0.9583 | 0.9773 |
| R2 | 0.9200 | 0.9091 | 0.9207 | 0.9197 | 0.9356 | 0.9101 | 0.9321 | 0.9521 |
Fig. 9.
Performance metrics for predicting nitrogen (g/kg) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for pH level prediction
The pH level prediction results in Table 9 model’s predictions of pH values, with errors consistently below 0.7%. This precision is vital for sectors requiring exact pH measurements, such as pharmaceuticals, chemical synthesis, and aquatic monitoring. The model’s CCC of 0.7701 and R2 of 0.5932, both the highest among competitors, showcase its strong predictive capability and substantial variance explanation in pH levels. ATNN-RF excels at accuracy and low error rates, while ATNN-XGB provides robust explanatory power and generalisation potential. This indicates a multifaceted model performance complemented by the effective integration of attention mechanisms with ensemble methods, making it well-suited for the complex and non-linear nature of pH prediction challenges, as shown in Fig. 10.
Table 9.
Models comparative plot analysis on pH level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.0652 | 0.0715 | 0.0640 | 0.0608 | 0.0192 | 0.0666 | 0.0432 | 0.0554 |
| MAPE | 0.8553 | 0.9821 | 0.8463 | 0.7987 | 0.6932 | 0.8954 | 0.7621 | 0.6732 |
| MAE | 0.0505 | 0.0579 | 0.0500 | 0.0472 | 0.0452 | 0.0421 | 0.0439 | 0.0399 |
| CCC | 0.6805 | 0.6128 | 0.6884 | 0.7415 | 0.7701 | 0.7312 | 0.7218 | 0.8321 |
| R2 | 0.5207 | 0.4224 | 0.5387 | 0.5793 | 0.5932 | 0.6431 | 0.6592 | 0.7542 |
Fig. 10.
Performance metrics for predicting pH levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for phosphorus (ppm) level prediction
The results in Table 10 show that The ATNN-XGB model has a high predictive power, with an R2 value of 0.7902. This means that it explains about 79.02% of the differences in phosphorus levels in the dataset. This achievement reflects the model’s ability to capture the intricate factors influencing phosphorus concentration, marking it as the most effective model available. The model also has a MAPE of 6.3211%, which means that its predictions are, on average, within 6.32% of the actual phosphorus values. This is important for environmental monitoring, agricultural management, and wastewater treatment, where accuracy is very important. The performance benchmarks of the ATNN-ADB and ATNN-GB models (R2 values of 0.7320 and 0.7327, respectively) affirm the effectiveness of the ATNN hybrid framework, establishing it as a state-of-the-art solution for phosphorus level prediction. The synergy of attention mechanisms with advanced ensemble methods in these models promotes enhanced predictive performance and reliability, demonstrating their application in managing complex environmental systems, as seen in Fig. 11.
Table 10.
Models comparative plot analysis on phosphorus (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.6786 | 0.7113 | 0.6723 | 0.6376 | 0.6630 | 0.6003 | 0.6001 | 0.6432 |
| MAPE | 7.8415 | 8.5848 | 7.9661 | 7.4647 | 7.5472 | 7.0231 | 7.1212 | 6.3211 |
| MAE | 0.5311 | 0.5758 | 0.5364 | 0.5049 | 0.4102 | 0.4921 | 0.3211 | 0.4812 |
| CCC | 0.4628 | 0.4131 | 0.4737 | 0.5806 | 0.5566 | 0.5932 | 0.5891 | 0.6721 |
| R2 | 0.3255 | 0.2606 | 0.3386 | 0.4057 | 0.6021 | 0.7320 | 0.7327 | 0.7902 |
Fig. 11.
Performance metrics for predicting phosphorus (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for Sulphur (ppm) level prediction
The results for predicting sulphur, presented in Table 11, The ATNN-XGB model has achieved a remarkable R2 value of 0.9632, indicating it explains about 96.32% of the variance in sulphur levels, with only 3.68% remaining unexplained. This high R2 signifies the model’s capacity not just to predict but to capture the underlying data-generating process effectively, marking it as a premier tool for forecasting and gaining scientific insights. The mention of "superior predictive accuracy" is reinforced by the low error metrics, implied by the high R2, demonstrating that predictions closely cluster around true values. The model also showcases an RMSE of 0.1440 ppm, indicating minimal deviation from actual sulphur values, which is crucial in real-world applications where large prediction errors can have severe operational or safety repercussions. Moreover, the CCC of 0.9702 reflects a near-perfect agreement between predicted and observed values, emphasising both the precision and accuracy of ATNN-RF and ATNN-XGB. Collectively, these models exemplify a superior hybrid framework in machine learning for predicting sulphur levels, combining an attention mechanism’s dynamic feature-weighting with the robust performance of ensemble methods, thus presenting a significant advancement over traditional models. As shown in Fig. 12
Table 11.
Models comparative plot analysis on Sulphur (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.1940 | 0.2110 | 0.1915 | 0.1928 | 0.1440 | 0.2110 | 0.1212 | 0.1731 |
| MAPE | 5.3475 | 5.6907 | 5.3038 | 5.3588 | 5.6471 | 5.6211 | 5.2334 | 5.3521 |
| MAE | 0.1479 | 0.1573 | 0.1456 | 0.1476 | 0.0979 | 0.0992 | 0.1456 | 0.1476 |
| CCC | 0.9639 | 0.9573 | 0.9644 | 0.9642 | 0.9702 | 0.9652 | 0.9691 | 0.9122 |
| R2 | 0.9302 | 0.9177 | 0.9321 | 0.9311 | 0.9398 | 0.9632 | 0.9321 | 0.9321 |
Fig. 12.
Performance metrics for predicting Sulphur (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for zinc (ppm) level prediction
The results for predicting zinc levels presented in Table 12, highlight that The ATNN-XGB model demonstrates exceptional predictive capabilities with an R2 value of 0.7932, indicating it accounts for approximately 79.32% of the variance in zinc levels in the dataset. This high explanatory power suggests it effectively captures complex factors influencing zinc concentration, establishing it as an advanced tool for understanding zinc dynamics. The model’s error metrics are robust, featuring an RMSE of 0.1223 ppm and an MAE of 0.0961 ppm, indicating strong predictive accuracy with minimal errors. The close proximity of the MAE to the RMSE implies high precision, enhancing reliability for sectors like mining, water quality management, and agriculture. Additionally, a CCC of 0.8721 indicates solid agreement between predicted and observed values, affirming the model’s accuracy and calibration across zinc levels. Overall, the ATNN-XGB model not only excels in performance metrics but also sets a new standard for zinc level prediction, illustrating the advantages of combining an attention mechanism with advanced boosting algorithms for effective predictive analysis, as shown in Fig. 13.
Table 12.
Models comparative plot analysis on zinc (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.1187 | 0.1371 | 0.1244 | 0.1223 | 0.1321 | 0.1371 | 0.1244 | 0.1223 |
| MAPE | 8.1712 | 10.0010 | 8.8824 | 8.0383 | 8.0123 | 10.0010 | 8.8210 | 8.0300 |
| MAE | 0.0977 | 0.1202 | 0.1056 | 0.0961 | 0.0821 | 0.1202 | 0.10321 | 0.0961 |
| CCC | 0.8108 | 0.7422 | 0.7842 | 0.8022 | 0.8867 | 0.7212 | 0.7912 | 0.8721 |
| R2 | 0.6861 | 0.5813 | 0.6553 | 0.6661 | 0.7021 | 0.7013 | 0.7821 | 0.7932 |
Fig. 13.
Performance metrics for predicting Zinc (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for potassium (ppm) level prediction
The results for predicting potassium levels, presented in Table 13, show that The ATNN-XGB model achieves a remarkable precision, evidenced by its lowest RMSE of 5.0211 ppm and MAE of 4.0921 ppm. The RMSE highlights its robustness against significant outliers, while the low MAE indicates a consistent error distribution critical attributes for real-world applications where error costs must be minimised. The model demonstrates a strong R2 value of 0.7880, suggesting that it explains approximately 78.8% of the variance in the target variable, elevating it beyond mere forecasting to a comprehensive representation of the underlying data dynamics. The MAPE of 5.6121% translates this accuracy into operational relevance, showing predictions within 5.6% of actual values vital for decision-making. Furthermore, the model’s CCC of 0.7673 affirms a strong alignment between predicted and observed values, indicating well-calibrated performance. The ATNN-XGB model outperforms the standard XGB model, showcasing the added value of the ATNN framework, which integrates an attention mechanism with gradient boosting for enhanced predictive capability and insights compared to traditional approaches as shown in Fig. 14
Table 13.
Models comparative plot analysis on potassium (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 6.1862 | 6.9290 | 6.1871 | 5.8126 | 5.3162 | 6.9290 | 6.2171 | 5.0211 |
| MAPE | 5.9749 | 6.9523 | 6.0716 | 5.6115 | 4.4749 | 6.9523 | 5.6716 | 5.6121 |
| MAE | 4.8209 | 5.5099 | 4.9018 | 4.5193 | 4.0409 | 5.5099 | 4.9018 | 4.0921 |
| CCC | 0.7505 | 0.6832 | 0.7469 | 0.7916 | 0.7932 | 0.7320 | 0.7732 | 0.7673 |
| R2 | 0.6062 | 0.5070 | 0.6057 | 0.6480 | 0.7213 | 0.6979 | 0.7257 | 0.7880 |
Fig. 14.
Performance metrics for predicting potassium (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for magnesium (ppm) level prediction
The results in Table 14 indicate that the ATNN-XGB model achieves a remarkable precision, evidenced by its lowest RMSE of 5.0211 ppm and MAE of 4.0921 ppm. The RMSE highlights its robustness against significant outliers, while the low MAE indicates a consistent error distribution critical attributes for real-world applications where error costs must be minimised. The model demonstrates a strong R2 value of 0.7880, suggesting that it explains approximately 78.8% of the variance in the target variable, elevating it beyond mere forecasting to a comprehensive representation of the underlying data dynamics. The MAPE of 5.6121% translates this accuracy into operational relevance, showing predictions within 5.6% of actual values vital for decision-making. Furthermore, the model’s CCC of 0.7673 affirms a strong alignment between predicted and observed values, indicating well-calibrated performance. The ATNN-XGB model outperforms the standard XGB model, showcasing the added value of the ATNN framework, which integrates an attention mechanism with gradient boosting for enhanced predictive capability and insights compared to traditional approaches, as illustrated in Fig. 15.
Table 14.
Models comparative plot analysis on magnesium (ppm) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 7.6971 | 9.6564 | 8.7437 | 7.7605 | 6.6321 | 9.6564 | 8.7437 | 7.7605 |
| MAPE | 4.6804 | 6.0390 | 5.4146 | 4.7275 | 4.0214 | 6.0390 | 5.4116 | 4.7175 |
| MAE | 6.1355 | 7.8441 | 7.0789 | 6.1876 | 5.1235 | 7.8441 | 7.0729 | 6.0176 |
| CCC | 0.7057 | 0.4534 | 0.5922 | 0.7098 | 0.7537 | 0.7012 | 0.7002 | 0.7213 |
| R2 | 0.5730 | 0.3264 | 0.4491 | 0.5646 | 0.6730 | 0.7110 | 0.7302 | 0.7631 |
Fig. 15.
Performance metrics for predicting magnesium (ppm) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
Result for effective cation exchange capacity (Cmol+/kg) level prediction
Table 15 presents the comparative analysis of models used to predict exchange capacity levels. The model achieved impressive metrics, recording the lowest RMSE of 0.4016 ppm and MAE of 0.2991 ppm, highlighting its high precision. The low RMSE suggests resilience against significant outliers, while the lower MAE indicates a consistent error distribution. This accuracy is crucial for ECEC, which plays a vital role in soil fertility and nutrient management. The model’s CCC of 0.8012 reflects a strong alignment between predicted and observed values, asserting the ATNN-RF’s excellence in both precision and accuracy. Additionally, an R2 value of 0.7322 shows that approximately 73.22% of the total variance in ECEC is explained by the model, elevating it from merely a forecasting tool to a reliable representation of soil processes in ion exchange. The analysis confirms the superior performance of hybrid ATNN models for predicting ECEC, with ATNN-RF establishing a benchmark for accuracy and reliability. Furthermore, the ATNN-XGB model’s high explanatory power further emphasises the general applicability of the ATNN framework for enhanced predictive performance. The results demonstrate that both hybrid models outperform the traditional XGB model, underscoring the advantages of integrating an attention mechanism into machine learning architectures. This synergy between dynamic processing and ensemble methods offers a more effective tool for managing and understanding soil systems, which is well beyond traditional machine learning capabilities, as shown in Fig. 16.
Table 15.
Models comparative plot analysis effective cation exchange capacity (Cmol+/kg) level prediction.
| RF | ADB | GB | XGB | ATNN-RF | ATNN-ADB | ATNN-GB | ATNN-XGB | |
|---|---|---|---|---|---|---|---|---|
| RMSE | 0.4306 | 0.5205 | 0.4804 | 0.4318 | 0.4016 | 0.5205 | 0.4804 | 0.4138 |
| MAPE | 5.6189 | 6.6607 | 6.3026 | 5.4848 | 5.0119 | 6.6607 | 6.3026 | 5.1238 |
| MAE | 0.3587 | 0.4218 | 0.4029 | 0.3497 | 0.2991 | 0.4218 | 0.4029 | 0.3197 |
| CCC | 0.7026 | 0.5017 | 0.6047 | 0.7119 | 0.8012 | 0.8110 | 0.8047 | 0.8119 |
| R2 | 0.5534 | 0.3474 | 0.4423 | 0.5488 | 0.7322 | 0.7412 | 0.7223 | 0.7489 |
Fig. 16.
Performance metrics for predicting Effective Cation Exchange Capacity (Cmol+/kg) levels using RF, ADB, GB, and XGB models, with evaluation over RMSE, MAPE, MAE, and CCC.
The model achieved impressive metrics, recording the RMSE of 0.4016 ppm and MAE of 0.2991 ppm, highlighting its high precision. The low RMSE suggests resilience against significant outliers, while the lower MAE indicates a consistent error distribution. This accuracy is crucial for ECEC, which plays a vital role in soil fertility and nutrient management. The model’s CCC of 0.8012 reflects a strong alignment between predicted and observed values, asserting the ATNN-RF’s excellence in both precision and accuracy. Additionally, an R2 value of 0.7322 shows that approximately 73.22% of the total variance in ECEC is explained by the model, elevating it from merely a forecasting tool to a reliable representation of soil processes in ion exchange. The analysis confirms the superior performance of hybrid ATNN models for predicting ECEC, with ATNN-RF establishing a benchmark for accuracy and reliability. Furthermore, the ATNN-XGB model’s high explanatory power further accentuates the general applicability of the ATNN framework for enhanced predictive performance. The results demonstrate that both hybrid models outperform the traditional XGB model, underscoring the advantages of integrating an attention mechanism into machine learning architectures. This synergy between dynamic processing and ensemble methods offers a more effective tool for managing and understanding soil systems, which is well beyond traditional machine learning capabilities, as shown in Fig. 17. These findings underscore the importance of selecting the appropriate models for specific nutrients, as performance varies significantly depending on the soil property predicted.
Fig.17.
Performance metrics for predicting all soil nutrient levels using RF, ADB, GB, XGB and the novel ATNN variant models, with evaluation over RMSE, R2, MAPE, MAE, and CCC.
Discussion
This study establishes that an integrated approach, fusing multi-source geospatial data with advanced ML, significantly enhances the prediction of soil nutrient levels. The core of our methodological success lies in the ATNN, whose consistent variance outperformed other classifiers, indicating its superior ability to model the complex, non-linear relationships within the data. Our findings robustly align with the broader scientific consensus on the power of remote sensing and ML. However, this study moves beyond confirmation by implementing a more comprehensive data fusion strategy. By synergistically combining DEM, Landsat, and Sentinel-2 imagery, we have captured a wider spectrum of topographic and spectral features, thereby achieving a tangible increase in prediction accuracy. A critical finding is the exceptional performance of the XGB algorithm. As quantified by a suite of robust metrics including RMSE, MAE, and MAPE, alongside higher CCC and R2 scores XGB demonstrated remarkable stability and predictive power across all tested nutrients. This positions it as a premier, reliable tool for digital soil mapping. The most significant advancement of this work is its scope. While previous studies have often been restricted to Soil Organic Carbon (SOC) and basic texture fractions, our analysis provides a comprehensive profile of 12 macro- and micronutrients. This comprehensive evaluation provides an integrated perspective on soil health, representing a significant advancement over the disjointed nutrient analyses prevalent in current literature. Finally, the empirical success of ensemble learning methods, specifically RF and GB, confirms their theoretical advantages. Their strong performance validates that these ensemble techniques are exceptionally well-suited for modelling the high-dimensional, noisy data characteristic of geospatial and environmental science, effectively reducing variance and bias and yielding more generalisable models. This study has several limitations, despite its promising results. Reliance on satellite-based remote sensing data may be subject to various biases because of atmospheric interference, sensor noise, and issues of temporal resolution. The performance might also be site-specific since the model performance will depend considerably upon the quality and resolution of input data. Even though our models used many different environmental factors, the complicated ways they interact and change over time might not be completely reflected, which could affect how well the results apply in other situations. To mitigate data leakage and target redundancy in ATNN-enhanced models, stringent protocols were enacted due to their high predictive performance (often R2 > 0.95). A pre-modelling collinearity audit was performed, removing input covariates with high correlation (r > 0.85) to prevent trivial proxies. Additionally, data splitting was conducted using a specified method, ensuring that testing data remained independent from the training set in both feature space and geographic proximity. All normalisation and hyperparameter tuning were confined to the training folds to maintain the integrity of the blind test set.
Future studies should investigate the use of hyperspectral imagery and on-site soil measurements as supplementary data sources to improve nutrient predictions. Combining deep learning methods with traditional ML algorithms in hybrid models could make them even more accurate and reliable. Further, it would be worth extending the study to different geographical regions with varying climatic and soil conditions so that enough insight may be garnered for the adaptability and scalability of proposed methods. Looking at how soil nutrients change over time, considering seasonal shifts and how land is used, could provide more profound insights and enhance our ability to make predictions. Three synergistic factors account for the superior performance of the ATNN–XGB hybrid in most of these nutrient predictions.
The ATNN model provides richer, temporally aware representation learning by utilising multiple source predictors.
The sample-efficient, regularised tabular regression and residual correction capability of XGB.
The particular structure and information content of the predictors used in this study.
ATNN’s feature-level temporal attention learns to weight spectral indices, topographic derivatives, and meteorological covariates differently across time steps so that the most informative feature-time combinations are in the learning encoding. ATNN is able to fuse these time-varying and time-invariant signals into compact, discriminative representations. By producing low-dimensional encodings that capture both long-range temporal dependencies and cross-feature interactions, ATNN reduces noise and redundancy in the input space while amplifying the predictive signal available to the downstream regressor.
Recommendations
This work is expected to serve as a key foundation for precision agriculture practices and sustainable land management in the near future. Future studies could refine models for other variables, enabling more spatially disaggregated predictions for localised applications. This research highlights that, by using remote sensing technologies, combining environmental data, and applying ML algorithms, we could significantly improve how we understand localised soil nutrient changes. Furthermore, we should explore advanced optimisation techniques, real-time data integration, and simple models to enhance predictions across various fields. Our findings have established a foundation for informed decision-making in agriculture, conservation, and environmental policy, promoting resilience and sustainability not only within our case study area, Bezuidenhout Park in South Africa, but also across wider ecosystems and agricultural landscapes. The implications of this research will deeply influence soil management practices and agronomic strategies. High accuracy in nutrient predictions can lead to more strategic and resource-efficient fertiliser practices, which result in better crop production and lower environmental risks. Our findings pave the way for precision farming, which optimises resource usage for sustainability by combining ML-based models with comprehensive remote sensing data. Future efforts should focus on further refining predictive models by incorporating additional variables, such as soil microbial activity and climate change projections, and enhancing the resolution for local applications. Extending our scope to other regions with diverse environmental conditions will help validate and generalise our findings. This study thus provides a foundation for informed decision-making in agriculture, conservation, and policy-making, contributing to the resilience and sustainability of both urban and rural ecosystems.
Conclusion
The results of this study show that ML methods can effectively analyse different types of environmental data and accurately predict soil nutrient levels as long as the data is thoroughly prepared and the model is carefully checked. In this paper, we looked at how well ML algorithms can predict soil nutrient levels by using a detailed dataset that includes environmental information from DEM, Landsat, and Sentinel-2 images, as well as real-time environmental data from APIs. The integration of these diverse data sources has allowed us to capture nuanced spatial and temporal variations in soil properties, which are critical for effective agricultural management and environmental sustainability. Our approach involved comprehensive data preprocessing, including feature extraction from raster images and API data integration, followed by rigorous analysis and modelling. Choosing and refining the right features was crucial for making our models work better, allowing them to effectively use the complex environmental data. Techniques such as PCA and feature importance analysis guided the selection and optimisation of ML models by offering more profound insights into the key drivers of soil nutrient variability. In our analysis, ATNN-XGB emerged as the top-performing model, consistently delivering superior predictive accuracy across various soil nutrients. Its ability to handle complex interactions among predictors and adapt to nonlinear relationships was crucial for minimising prediction errors and maximising model interpretability. The comparison with RF, ADB, and GB showed that it was very effective at identifying important patterns in soil nutrient changes. Additionally, this study stressed the need to evaluate our model’s accuracy using strong measures like RMSE, MAE, CCC, MAPE, and R2, which helped confirm that our predictions were reliable and could be applied in different situations. By systematically assessing model performance across multiple metrics and nutrient types, we emphasised the versatility and applicability of our methodology in a wide range of agricultural and environmental contexts.
Electronic supplementary material
Below is the link to the electronic supplementary material.
Abbreviations
- AI
Artificial intelligence
- ACO
Ant colony optimisation
- AdaBoost or ADB
Adaptive boosting
- ATNN
Attention temporal neural network
- API
Application programming interface
- CCC
Concordance correlation coefficient
- CP
Correlation plot
- DEM
Digital elevation model
- DT
Decision tree
- DP
Deep learning
- EDA
Exploratory data analysis
- EA
Evolutionary algorithm
- GB
Gradient boost
- GIS
Geographic information system
- IR
Infrared ray
- LR
Linear regression
- LST
Land surface temperature
- MAE
Mean absolute error
- MAPE
Mean percentage error
- MIRAS
Microwave imaging radiometer using aperture synthesis
- MSE
Mean square error
- ML
Machine learning
- NDVI
Normalised difference vegetation index
- OLI
Operational land imager
- OLS
Ordinary least squares
- PCA
Principal component analysis
- RF
Random forest
- RGB
Red–green–blue
- RMSE
Root mean square error
- R2
R-squared (coefficient of determination)
- SMOS
Soil moisture and ocean salinity
- SOC
Soil organic carbon
- SRTM
Shuttle radar topography mission
- SWI
Short-wave infrared
- TIRS
Thermal infrared sensor
- UTC
Coordinated universal time
- UV
Ultraviolet
- XGB
Extreme gradient boosting
Appendix I: ATNN architecture and training specifications
| Parameter | Value | Notes |
|---|---|---|
| Model variant | Attention temporal neural network (ATNN) | Temporal encoder with attention mechanism |
| Number of encoder layers | 4 | Stacked attention-based encoder blocks |
| Hidden dimension (d_model) | 128 | Embedding and attention projection size |
| Feed-forward dimension (d_ff) | 512 | Inner FFN layer size |
| Number of attention heads | 4 | Multi-head self-attention |
| Sequence length | 12 | Temporal timesteps per input sequence |
| Dropout rate | 0.20 | Applied in attention and FFN layers |
| Activation function | GELU | Non-linear activation in FFN |
| Batch size | 64 | Mini-batch size |
| Training epochs | 150 | With early stopping |
| Optimiser | AdamW | Adaptive optimiser with weight decay |
| Learning rate | 1e-4 | Initial learning rate |
| Weight decay | 1e-5 | Regularisation parameter |
| Learning rate scheduler | ReduceLROnPlateau | Factor = 0.5, patience = 5 |
| Loss function | Mean squared error (MSE) | Regression loss |
| Early stopping | Yes (patience = 15) | Validation-based stopping |
| Gradient clipping | 1.0 | L2 norm clipping |
| Random seed | 42 | Ensures reproducibility |
| Data normalisation | StandardScaler | Fitted on training data only |
| Train/validation/test split | 70% / 15% / 15% | Spatial block sampling |
| Framework | PyTorch | Version ≥ 1.10 |
| Hardware | Single GPU (≥ 16 GB VRAM) | CPU supported but slower |
Author contributions
**Bamidele A. Dada:** Conceptualisation, writing—review & editing, Writing—original draft, Visualisation, Validation, Software, Methodology, Investigation, Formal analysis, Data curation. **Nnamdi I. Nwulu:** Writing—review & editing, Visualisation, Supervision, Formal analysis, **Seun O. Olukanmi:** Supervision, Investigation, Data curation.
Funding
This research did not receive funding.
Data availability
I have research data to declare URL: https://kaggle.com/datasets/5b1561933a372a6541338f90cca3e0b9ef0c5acb049ca68aafdd73ac9d5d0cc2
Declarations
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Contributor Information
Bamidele A. Dada, Email: dada.abayomi@futminna.edu.ng
Nnamdi I. Nwulu, Email: nwulu@uj.ac.za
References
- 1.Lee, B. X. et al. Transforming our world: Implementing the 2030 Agenda through sustainable development goal indicators. J. Public Health Policy37, 13–31 (2016). [DOI] [PubMed] [Google Scholar]
- 2.Steenkamp, J., Cilliers, E. J., Cilliers, S. S. & Lategan, L. Food for thought: Addressing urban food security risks through urban agriculture. Sustainability13(3), 1267 (2021). [Google Scholar]
- 3.Lugato, E., Lavallee, J. M., Haddix, M. L., Panagos, P. & Cotrufo, M. F. Different climate sensitivity of particulate and mineral-associated soil organic matter. Nat. Geosci.14(5), 295–300 (2021). [Google Scholar]
- 4.Akbari, M. et al. The evolution of food security: Where are we now, and where should we go next?. Sustainability14(6), 3634 (2022). [Google Scholar]
- 5.Gerke, J. The central role of soil organic matter in soil fertility and carbon storage. Soil Syst.6(2), 33 (2022). [Google Scholar]
- 6.Song, Y. Q. et al. Predicting spatial variations in soil nutrients with hyperspectral remote sensing at a regional scale. Sensors18(9), 3086 (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 7.Huang, D. et al. Land use/Land cover remote sensing classification in complex subtropical Karst environments: Challenges, methodological review, and research frontiers. Appl. Sci.15(17), 9641. 10.3390/app15179641 (2024). [Google Scholar]
- 8.Malakouti, S. M. Heart disease classification based on ECG using machine learning models. Biomed. Signal Process. Control84(2023), 104796 (2023). [Google Scholar]
- 9.Shen, L. et al. A methodological study on improving the accuracy of soil organic matter mapping in mountainous areas based on Geo-Positional Transformers CNN: A case study of Longshan County, Hunan Province, China. Appl. Sci.15(14), 8060. 10.3390/app15148060 (2024). [Google Scholar]
- 10.Sousa, D. & Small, C. Joint characterisation of Sentinel-2 reflectance: Insights from manifold learning. Remote Sens.14(22), 5688. 10.3390/rs14225688 (2021). [Google Scholar]
- 11.Abate, N. et al. Approach for processing high-resolution UAS LiDAR data in archaeological contexts: A case study from Epirus, Greece. J. Archaeol. Method Theory32, 38. 10.1007/s10816-025-09706-8 (2025). [Google Scholar]
- 12.Ghavami, M. S. et al. Optimal mapping of soil erodibility factor (K) using machine learning models in a semi-arid watershed. Earth Syst. Environ.10.1007/s41748-024-00553-3 (2025). [Google Scholar]
- 13.Dada, B. A., Nwulu, N., & Olukanmi, S. O. A soil nutrient prediction model for bezuidenhout park, Johannesburg, Gauteng Province, South Africa. In Johannesburg, Gauteng Province, South Africa (2024). [DOI] [PMC free article] [PubMed]
- 14.Ghavami, M. S. et al. Digital mapping of soil physical and mechanical properties using machine learning at the watershed scale. J. Mt. Sci.20(10), 2975–2992 (2023). [Google Scholar]
- 15.Baghche-Maryam, M. Z. et al. Covariate selection approaches in spatial prediction of soil quality indices using machine learning models at the watershed scale, west of Iran. Soil Tillage Res.252, 106571. 10.1016/j.still.2025.106571 (2025). [Google Scholar]
- 16.Nazeri, P. S. et al. Machine learning-based soil aggregation assessment under four scenarios in northwestern Iran. Int. Agrophys.38, 293–310. 10.31545/intagr/188506 (2024). [Google Scholar]
- 17.Saidi, S. S. et al. Digital mapping of soil phosphorous sorption parameters (PSPs) using environmental variables and machine learning algorithms. Int. J. Digit. Earth.16, 1752–1769 (2023). [Google Scholar]
- 18.Behrouz, M. S., Yazdi, M. N. & Sample, D. J. Using random forest, a machine learning approach to predict nitrogen, phosphorus, and sediment event mean concentrations in urban runoff. J. Environ. Manag.317, 115412 (2022). [DOI] [PubMed] [Google Scholar]
- 19.Dagne, S. S. et al. Fusion of Sentinel-1 SAR and Sentinel-2 MSI data for accurate urban land use-land cover classification in Gondar City, Ethiopia. Environ. Syst. Res.12, 40. 10.1186/s40068-023-00324-5 (2023). [Google Scholar]
- 20.Chaves, M. E. D., Picoli, M. C. A. & Sanches, I. D. Recent applications of Landsat 8/OLI and Sentinel-2/MSI for land use and land cover mapping: A systematic review. Remote Sens.12(18), 3062 (2020). [Google Scholar]
- 21.Gurubaran K. Machine learning approach for soil nutrient prediction. In 2023 IEEE Silchar Subsection Conference (SILCON) 1–6 (2023).
- 22.Zhou, T., Li, Z. & Pan, J. Multi-feature classification of multi-sensor satellite imagery based on dual-polarimetric Sentinel-1A, Landsat-8 OLI, and Hyperion images for urban land-cover classification. Sensors18(2), 373 (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 23.Kok, Z. H., Shariff, A. R. M., Alfatni, M. S. M. & Khairunniza-Bejo, S. Support vector machine in precision agriculture: A review. Comput. Electron. Agric.191, 106546 (2021). [Google Scholar]
- 24.Padarian, J., Stockmann, U., Minasny, B. & McBratney, A. Monitoring changes in global soil organic carbon stocks from space. Remote Sens. Environ.281, 113260. 10.1016/j.rse.2022.113260 (2022). [Google Scholar]
- 25.Cui, Z. et al. A novel framework for improving soil organic carbon mapping accuracy by mining temporal features of time-series Sentinel-1 data. Land14(4), 677. 10.3390/land14040677 (2025). [Google Scholar]
- 26.Katrompas, A. & Metsis, V. Temporal attention signatures for interpretable time-series prediction. In Artificial Neural Networks and Machine Learning—ICANN 2023. ICANN 2023. Lecture Notes in Computer Science Vol. 14259 (eds Iliadis, L. et al.) (Springer, 2023). 10.1007/978-3-031-44223-0_22. [Google Scholar]
- 27.Lu, Y., Li, H., Zhang, C. & Zhang, S. Object-based semi-supervised spatial attention residual UNet for urban high-resolution remote sensing image classification. Remote Sens.16(8), 1444. 10.3390/rs16081444 (2023). [Google Scholar]
- 28.Zhang, L. et al. A CNN-LSTM model for soil organic carbon content prediction with long time series of MODIS-based phenological variables. Remote Sens.14(18), 4441. 10.3390/rs14184441 (2021). [Google Scholar]
- 29.Zhu, Y., Qi, L., Wu, Z. & Shi, P. Spectra-based predictive mapping of soil organic carbon in croplands: Single-date versus multitemporal bare soil compositing approaches. Geoderma449, 116987. 10.1016/j.geoderma.2024.116987 (2024). [Google Scholar]
- 30.Guo, Q. et al. Multi-modal fusion deep learning model for excavated soil heterogeneous data with efficient classification. Comput. Geotech.175, 106697. 10.1016/j.compgeo.2024.106697 (2024). [Google Scholar]
- 31.Wittstruck, L., Waske, B. & Jarmer, T. Multi-modal vision transformer for high-resolution soil texture prediction of German agricultural soils using remote sensing imagery. Remote Sens. Environ.331, 114985. 10.1016/j.rse.2025.114985 (2025). [Google Scholar]
- 32.Liu, Y., Shen, L., Zhu, X., Xie, Y. & He, S. Spectral data-driven prediction of soil properties using LSTM-CNN-attention model. Appl. Sci.14(24), 11687. 10.3390/app142411687 (2023). [Google Scholar]
- 33.Park, S. et al. Application of near-infrared spectroscopy to predict chemical properties in clay rich soil: A review. Eur. J. Agron.159, 127228. 10.1016/j.eja.2024.12722 (2024). [Google Scholar]
- 34.Piccini, C. et al. In-field soil spectroscopy in Vis–NIR range for fast and reliable soil analysis: A review. Eur. J. Soil Sci.75(2), e13481. 10.1111/ejss.13481 (2024). [Google Scholar]
- 35.Tang, K. et al. Using convolutional neural network combined with multi-scale channel attention module to predict soil properties from visible and near-infrared spectral data. Microchem. J.207, 111815. 10.1016/j.microc.2024.111815 (2024). [Google Scholar]
- 36.Feng, G., Li, Z., Zhang, J. & Wang, M. Multi-scale spatial attention-based multi-channel 2D convolutional network for soil property prediction. Sensors24(14), 4728. 10.3390/s24144728 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 37.Adeniyi, O. D., Bature, H. & Mearker, M. A systematic review on digital soil mapping approaches in lowland areas. Land13(3), 379. 10.3390/land13030379 (2024). [Google Scholar]
- 38.Bao, Y. et al. A fine digital soil mapping by integrating remote sensing-based process model and deep learning method in Northeast China. Soil Tillage Res.238, 106010. 10.1016/j.still.2024.106010 (2024). [Google Scholar]
- 39.Tanveer, M. U., Munir, K., Raza, A. & Almutairi, M. S. Novel artificial intelligence assisted Landsat-8 imagery analysis for mango orchard detection and area mapping. PLoS ONE19(6), e0304450. 10.1371/journal.pone.0304450 (2024). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 40.Tahmouresi, M. S., Niksokhan, M. H. & Ehsani, A. H. Enhancing spatial resolution of satellite soil moisture data through stacking ensemble learning techniques. Sci. Rep.14(1), 25454. 10.1038/s41598-024-77050-0 (2024). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 41.Tariq, A., Yan, J., Gagnon, A. S., Riaz Khan, M. & Mumtaz, F. Mapping of cropland, cropping patterns and crop types by combining optical remote sensing images with decision tree classifier and random forest. Geo. Spat. Inf. Sci.26(3), 302–320. 10.1080/10095020.2022.2100287 (2022). [Google Scholar]
- 42.Rahman, M. M. et al. A GIS framework to demarcate suitable lands for combine harvesters using satellite DEM and physical properties of soil. J. Geovis. Spat. Anal.7, 27. 10.1007/s41651-023-00156-y (2023). [Google Scholar]
- 43.Wang, S., Wu, Y., Li, R. & Wang, X. Remote sensing-based retrieval of soil moisture content using stacking ensemble learning models. Land Degrad. Dev.34(3), 911–925. 10.1002/ldr.4505 (2023). [Google Scholar]
- 44.Folorunso, O. et al. GeaGrow: A mobile tool for soil nutrient prediction and fertiliser optimisation using artificial neural networks. Front. Sustain. Food Syst.9, 1533423 (2025). [Google Scholar]
- 45.Moradpour, S., Entezari, M., Ayoubi, S., Karimi, A. & Naimi, S. Digital exploration of selected heavy metals using random forest and a set of environmental covariates at the watershed scale. J. Hazard. Mater.455, 131609. 10.1016/j.jhazmat.2023.131609 (2023). [DOI] [PubMed] [Google Scholar]
- 46.Zhang, W., Zhu, L., Zhuang, Q., Chen, D. & Sun, T. Mapping cropland soil nutrients contents based on multi-spectral remote sensing and machine learning. Agriculture13(8), 1592. 10.3390/agriculture13081592 (2023). [Google Scholar]
- 47.Folorunso, O. et al. Exploring machine learning models for soil nutrient properties prediction: A systematic review. Big Data Cogn. Comput.7(2), 113 (2023). [Google Scholar]
- 48.Xu, S., Zhao, Y. & Wang, Y. Optimizing machine learning models for predicting soil pH and total P in intact soil profiles with visible and near-infrared reflectance (VNIR) spectroscopy. Comput. Electron. Agric.218, 108643 (2024). [Google Scholar]
- 49.Xu, X. et al. Machine learning algorithms realized soil stoichiometry prediction and its driver identification in intensive agroecosystems across a north-south transect of Eastern China. Sci. Total Environ.906, 167488 (2024). [DOI] [PubMed] [Google Scholar]
- 50.Ramakrishna, M. T., Venkatesan, V. K., Izonin, I., Havryliuk, M. & Bhat, C. R. Homogeneous adaboost ensemble machine learning algorithms with reduced entropy on balanced data. Entropy25(2), 245 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 51.Malakouti, S. M., Menhaj, M. B. & Suratgar, A. A. Machine learning and transfer learning techniques for accurate brain tumor classification. Clin. eHealth7(2024), 106–119 (2024). [Google Scholar]
- 52.Munyaneza, V. et al. Strategies for alleviating aluminum toxicity in soils and plants. Plant Soil504(1), 167–190 (2024). [Google Scholar]
- 53.Asselman, A., Khaldi, M. & Aammou, S. Enhancing the prediction of student performance based on the machine learning XGBoost algorithm. Interact. Learn. Environ.31(6), 3360–3379 (2023). [Google Scholar]
- 54.Malakouti, S. M. Refining cancer prediction with deoxyribonucleic acid sequencing and combined machine learning approaches, PREPRINT (Version 1). Available at Research Square 10.21203/rs.3.rs-6247134/v1 (2025). [DOI] [PMC free article] [PubMed]
- 55.Sun, J. et al. Prediction of TOC content in organic-rich shale using machine learning algorithms: Comparative study of random forest, support vector machine, and XGBoost. Energies16(10), 4159 (2023). [Google Scholar]
- 56.Wu, X. et al. Machine learning ensemble technique for exploring soil type evolution. Sci. Rep.15(1), 24332 (2025). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 57.Zolfaghari, Z., Ayoubi, S. & Mosaddeghi, M. R. Spatial variability of some soil shrinkage indices in hilly calcareous region of Western Iran. Soil Tillage Res.150, 180–191. 10.1016/j.still.2015.01.016 (2015). [Google Scholar]
- 58.Oikonomou, D., Leontaris, L., Dimitriou, N. & Tzovaras, D. Time-series forecasting in industrial environments: A performance study and a novel late fusion framework. IEEE Sens. J.10.1109/jsen.2025.3526362 (2025). [Google Scholar]
- 59.De Santana Correia, A. & Colombini, E. L. Attention, please! A survey of neural attention models in deep learning. Artif. Intell. Rev.55(8), 6037–6124 (2022). [Google Scholar]
- 60.Carvalho, D. V., Pereira, E. M. & Cardoso, J. S. Machine learning interpretability: A survey on methods and metrics. Electronics8(8), 832 (2019). [Google Scholar]
- 61.Zhou, J., Gandomi, A. H., Chen, F. & Holzinger, A. Evaluating the quality of machine learning explanations: A survey on methods and metrics. Electronics10(5), 593 (2021). [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Supplementary Materials
Data Availability Statement
I have research data to declare URL: https://kaggle.com/datasets/5b1561933a372a6541338f90cca3e0b9ef0c5acb049ca68aafdd73ac9d5d0cc2


































