Next Article in Journal
Effect of Organic Fertilizer and Water-Retaining Agent Application on Soil Structure and Water Availability in Different Soil Layers of a Semi-Arid Region
Previous Article in Journal
Regulatory Effects of Nitrogen Fertilization on Soil Extracellular Enzyme Activity and Greenhouse Gas Emissions in Paddy Fields with Straw Return
Previous Article in Special Issue
How Optical Sensors and Deep Learning Enhance the Production Management in Smart Agriculture
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Enhancing Near-Infrared Estimation of Total Nitrogen in Manure Slurry by Integrating Contextual Farm Information with MultiScaleSE-GatedCNN

1
College of Mathematics and Computer Science, Zhejiang A&F University, Hangzhou 311300, China
2
Wenzhou Key Laboratory of AI Agents for Agriculture, Wenzhou Academy of Agricultural Sciences, Wenzhou 325006, China
*
Authors to whom correspondence should be addressed.
These authors contributed equally to this work.
Agriculture 2026, 16(9), 965; https://doi.org/10.3390/agriculture16090965
Submission received: 27 March 2026 / Revised: 14 April 2026 / Accepted: 24 April 2026 / Published: 28 April 2026

Abstract

Near-infrared spectroscopy (NIRS) offers significant advantages for the rapid and non-destructive detection of nutrients in livestock manure slurry. However, conventional models based only on spectral features often show limited robustness under cross-seasonal and multi-farm conditions due to differences in farm source, treatment stage, and complex spatiotemporal background. To improve the accuracy and applicability of total nitrogen (TN) prediction in dairy farm manure slurry, this study used 747 samples collected from 36 large-scale dairy farms in Tianjin, China, covering 24 treatment stages and four seasons, together with sample-contextual information such as farm name, longitude, latitude, and season. Competitive adaptive reweighted sampling (CARS) was applied to select key wavelengths from near-infrared spectra. On this basis, a multi-branch gated fusion deep learning model, MultiScaleSE-GatedCNN, was developed to integrate spectral and sample-contextual information. The model combines multi-scale one-dimensional convolution for spectral feature extraction, separate encoding branches for numerical and categorical inputs, and a gated fusion unit for adaptive weighting of different information sources. Results showed that partial least squares regression remained a strong baseline under single-source spectral conditions, but the proposed deep learning fusion model achieved superior predictive performance after introducing sample-contextual information. Ablation experiments demonstrated that different combinations of sample-contextual information contributed differently to model performance, and the combination of spectra, farm name, longitude, and season yielded the best results. Under this optimal input combination, MultiScaleSE-GatedCNN achieved a test-set R2 of 0.905, an RMSEP of 367.389, and an RPD of 3.242. These results demonstrate that integrating NIRS with sample-contextual information can effectively improve the accuracy and robustness of TN prediction in dairy farm manure slurry.

1. Introduction

With the rapid development of large-scale dairy farming, the amount of manure generated by dairy farms has continued to increase, and manure slurry produced by dairy farms has become an important potential source of agricultural non-point-source pollution [1]. Manure slurry is rich in nutrient resources such as nitrogen and phosphorus. If rapid detection and accurate evaluation can be achieved, this would not only help improve the efficiency of manure resource utilization, but also provide an important basis for farmland nutrient management, fertilization decision-making, and non-point-source pollution control [2,3,4]. Among these nutrients, total nitrogen (TN), as one of the key indicators reflecting the fertilizer value and environmental risk of manure slurry, is of great significance for manure slurry resource utilization and agricultural ecological environment protection [5]. Traditional methods for nutrient determination in manure slurry mainly rely on chemical analysis. Although these methods generally provide high analytical accuracy, they usually involve cumbersome sample pretreatment, long detection cycles, high reagent consumption, and difficulty in meeting the demand for rapid on-site detection [6]. Near-infrared spectroscopy (NIRS), with the advantages of rapidity, non-destructiveness, and environmental friendliness, has been widely applied in recent years in agricultural product quality evaluation, feed composition analysis, and nutrient detection of livestock manure [7,8,9,10]. For dairy farm manure slurry, which has complex composition and highly variable physical states, NIRS provides a promising technical basis for rapid nutrient detection. However, manure slurry systems exhibit pronounced heterogeneity and dynamic fluctuations. Their spectral responses are influenced not only by the concentrations of target nutrients, but also by multiple factors such as particle distribution, moisture status, organic matter composition, and differences in sample origin [11,12,13]. In particular, under cross-farm, cross-season, and different treatment-stage conditions, the physicochemical properties and background composition of manure slurry may change substantially, resulting in distribution shifts in the mapping relationship between spectral features and target constituents, thereby affecting the generalization ability and robustness of predictive models. Therefore, identifying suitable models for near-infrared spectral analysis is of great importance.
In quantitative near-infrared analysis, partial least squares regression (PLSR) has long been one of the most widely used classical modeling methods because it can effectively handle high-dimensional and highly collinear spectral data [14]. For spectral modeling tasks under small- and medium-sample conditions, PLSR often exhibits strong stability and competitiveness [15]. Meanwhile, machine learning and deep learning methods such as support vector machines, random forests, multilayer perceptrons, and convolutional neural networks have gradually been applied in spectral analysis and have demonstrated good nonlinear modeling capabilities under certain conditions [16,17]. In addition, deep learning methods have attracted increasing attention in the field of near-infrared spectral analysis in recent years [18,19,20]. Compared with traditional machine learning methods, deep learning models can automatically extract hierarchical features from spectra through multilayer nonlinear transformations, showing certain advantages in handling complex sample systems and potential nonlinear relationships [21]. In particular, architectures such as one-dimensional convolutional neural networks can mine combined response features among adjacent wavelengths while preserving the local correlations of spectral sequences, thereby providing new modeling strategies for quantitative near-infrared analysis [22,23].
In addition to the spectra themselves, dairy farm manure slurry samples are usually accompanied by certain sample-contextual information, such as farm source, geographical location, sampling season, and treatment stage. To some extent, this information can reflect the sample formation environment, differences in feeding and management practices, spatial distribution characteristics, and seasonal variation patterns, and therefore has potential value for explaining fluctuations in manure slurry composition and corresponding spectral differences [24,25,26]. Compared with pure spectral modeling, introducing sample-contextual information as auxiliary inputs may help compensate for the limited representational capacity of spectra alone and enhance the adaptability and predictive robustness of models for heterogeneous samples [27,28]. In a recent study, Li et al. systematically investigated the influence of seasonal fluctuations on NIRS modeling of dairy farm manure slurry and preliminarily confirmed the feasibility of constructing a global prediction model to cope with cross-season monitoring [29]. However, that study also revealed a deeper scientific challenge: within a purely spectral feature space, it is difficult for the model to completely disentangle the non-characteristic baseline drift caused by complex spatiotemporal backgrounds. For heterogeneous data collected under large-scale and multi-farm conditions, spectral features alone are often insufficient to independently support a highly robust prediction framework, resulting in phenomena such as “similar background but different spectra” or “different background but similar spectra”. This means that if the model relies solely on spectral physical signals while ignoring the contextual information associated with sample generation, its prediction accuracy will inevitably suffer severe deviations when facing samples from unseen farms or under extreme climatic conditions. Moreover, the introduction of contextual information does not necessarily lead to optimal performance simply through direct addition, because different features may provide complementary information, but may also introduce redundancy or even interference. Therefore, systematic investigation is needed at both the feature-combination level and the fusion-mechanism level [30,31,32].
To address the above issues, this study focused on manure slurry samples collected from dairy farms in Tianjin, China, with the specific objective of total nitrogen (TN) prediction, and constructed a multi-branch gated deep learning model integrating near-infrared spectra and multi-source sample-contextual features. First, CARS-selected characteristic near-infrared wavelengths were used as the primary input to establish baseline models under pure spectral conditions, and classical machine learning methods were compared with deep learning methods to clarify the baseline role of PLSR in the current task. Subsequently, sample-contextual information including farm name, longitude, latitude, and season was introduced as auxiliary features, and separate numerical-feature and categorical-feature branches were constructed. On this basis, a joint framework integrating multi-scale convolution, squeeze-and-excitation (SE) attention, and gated fusion, namely MultiScaleSE-GatedCNN, was proposed to achieve collaborative modeling of spectral and sample-contextual information. Finally, through multi-model comparison and feature-combination ablation experiments, the effects of multi-source sample-contextual features on TN prediction performance were systematically analyzed, and the optimal feature combination and the relative contributions of different information sources were identified. Compared with the study of Li et al. [29], the present work differs in both research objective and modeling strategy. That study mainly focused on the influence of seasonal variation on NIRS-based prediction of TN and TP in dairy farm manure slurry, and established single-season models as well as a global model of four seasons (GMFS) using PLS regression. Their results demonstrated the importance of season in slurry NIRS modeling, but the modeling framework remained essentially based on spectral information and season-oriented scenario analysis. In contrast, the present study extends the problem from seasonal-effect analysis to multi-source contextual fusion under cross-farm heterogeneous conditions. In addition to near-infrared spectra, contextual variables such as farm name, longitude, latitude, and season were incorporated as auxiliary inputs, and a MultiScaleSE-GatedCNN framework was developed to achieve branch-specific representation learning and adaptive fusion of heterogeneous information sources. Therefore, the improvement explored in this study is not limited to an architectural replacement, but lies in a broader modeling framework that explicitly integrates spectral and sample-contextual information to enhance TN prediction robustness under complex backgrounds.

2. Materials and Methods

2.1. Study Area and Sample Collection

The samples used in this study were collected from 36 representative large-scale dairy farms in Tianjin, China, as shown in Figure 1. Tianjin is located in the North China Plain and is a densely concentrated area of intensive livestock farming. Its manure slurry management patterns and nutrient distribution characteristics are highly representative at the regional scale. To ensure that the developed model could adequately cover the nutrient complexity and spatiotemporal variability encountered in real production scenarios, sampling was conducted across multiple years (2018, 2019, and 2022) and strictly covered all four seasons: spring, summer, autumn, and winter.
A total of 768 manure slurry samples were initially collected. After the two-stage outlier detection and removal procedure described in Section 2.4, 747 samples were retained for subsequent modeling analysis. These samples were collected from frontline production sites and covered 24 typical manure slurry treatment stages, including oxidation ponds, sewage collection pools, secondary sedimentation tanks, epidemic prevention ditches, and biogas slurry tanks. To enable deep integration of multi-source information, each sample was synchronously associated with detailed sample-contextual features during spectral acquisition and physicochemical measurement, including the geographical coordinates of the sampling point, farm name, treatment stage, and sampling season. This multidimensional data structure not only recorded the chemical composition of manure slurry nutrients, but also characterized the specific spatiotemporal context in which each sample was generated, thereby laying the foundation for subsequent investigation of the role of sample-contextual features in prediction modeling.

2.2. Spectral Acquisition

To obtain near-infrared spectral information from manure slurry samples, a Fourier-transform near-infrared spectrometer (PerkinElmer, Shelton, CT, USA) equipped with an indium gallium arsenide (InGaAs) detector and an integrating sphere accessory was used for spectral acquisition. Scanning was performed at room temperature over the spectral range of 4000–12,000 cm−1, with a resolution of 8 cm−1 and a scanning interval of 2 cm−1. To improve spectral stability and signal-to-noise ratio, each sample was scanned 64 times, and the average spectrum was used as the final spectral data for that sample. The parameters and accessory configuration are consistent with your related slurry NIRS studies.
For sample preparation, slurry samples were collected and mixed according to our previous sampling protocol. Briefly, subsamples were collected below the liquid surface, thoroughly mixed, transferred into sampling bottles, and transported to the laboratory in an insulated container. Before spectral acquisition, each sample bottle was thoroughly shaken to reduce particle sedimentation and local non-uniformity. The homogenized slurry was then transferred into a sample cup to approximately two-thirds of its volume, placed on the rotating platform of the integrating sphere, and scanned using the built-in reference background. Spectral acquisition was initiated immediately after sample loading. All samples were scanned under identical testing conditions to ensure comparability of spectral data among samples.

2.3. Physicochemical Determination

To establish a quantitative near-infrared prediction model for total nitrogen (TN), reference TN values were measured for all manure slurry samples. Immediately after collection, the samples were stored in a portable incubator at 4 °C and transported back to the laboratory to minimize changes in sample properties during transportation and short-term storage. The TN content was determined according to the relevant standard methods and analyzed using an automatic Kjeldahl analyzer (Kjeltec 8400, FOSS, Hillerød, Denmark). Parallel samples were included during the experiment to ensure the accuracy and repeatability of the measurements. The obtained physicochemical TN values were used as the reference values for near-infrared spectral modeling, model training, and performance evaluation. In addition, to ensure a one-to-one correspondence between spectral data and physicochemical data, each sample was matched with its measured TN value after spectral acquisition and further linked with sample-contextual information such as farm source, geographical location, and season, ultimately forming a complete dataset for subsequent modeling analysis.

2.4. Outlier Detection and Removal

Before model construction, a two-stage outlier removal strategy was applied to improve the reliability of the dataset. In the first stage, samples with obviously abnormal spectral morphology and baseline patterns were identified through visual inspection and removed. These spectra showed clear deviations from the overall spectral trend and were considered unsuitable for subsequent modeling. In total, 11 samples were excluded at this stage.
In the second stage, a residual-based screening procedure was performed using the deep learning framework developed in this study. Specifically, a five-fold out-of-fold (OOF) prediction strategy was adopted for the remaining samples. In each fold, the model was trained on four subsets and used to predict the held-out subset, so that OOF predictions were obtained for the entire dataset. The absolute residuals between the predicted and reference TN values were then calculated, and the 10 samples with the largest absolute residuals were identified as residual outliers. These samples were synchronously removed from both the spectral file and the auxiliary-feature file. After the above two-stage procedure, 747 samples were retained for subsequent modeling and analysis.

2.5. Spectral Preprocessing and Feature Variable Selection

During spectral acquisition, a large amount of noise may be introduced from the environment, stray light, and the internal components of the instrument. Large quantities of irrelevant and redundant information, as well as noisy and unreliable data, make knowledge discovery during the training stage more difficult. Therefore, data preprocessing is a crucial step in machine learning. This step plays a key role in addressing problems such as noise, redundancy, and missing data values [33]. The specific preprocessing strategies included the use of multiplicative scatter correction (MSC) to eliminate optical path differences and scattering interference caused by uneven particle distribution in samples [34]; application of first derivative (FD) processing to remove slowly varying baseline background and highlight overlapping characteristic peaks [35]; and use of the Savitzky–Golay (SG) smoothing algorithm to suppress high-frequency random noise while preserving spectral characteristics without distortion [36]. In this study, the above three preprocessing methods, as well as the combination of SG and FD (SG_1st), were used as candidate preprocessing schemes. SG_1st denotes first-derivative preprocessing implemented using a Savitzky–Golay filter. The polynomial order was set to 2, and the window length was adaptively selected as the largest valid odd number from 15, 11, 9, 7, and 5 that was smaller than the number of retained spectral variables. By comparing the statistical performance of the calibration set and the test set under different preprocessing strategies, the preprocessing result with the highest prediction accuracy was finally selected for the subsequent feature selection step. By comparing the statistical performance of the calibration set and the test set under different preprocessing strategies, the preprocessing result with the highest prediction accuracy was finally selected for the subsequent feature selection step.
For spectral feature variable selection, considering the high dimensionality, strong collinearity, and dispersed effective information of the near-infrared spectra of manure slurry, this study employed the competitive adaptive reweighted sampling (CARS) algorithm. This algorithm first simulates the “survival of the fittest” mechanism in biological evolution and uses Monte Carlo sampling together with an exponentially decreasing function to forcibly remove wavelengths with relatively small absolute regression coefficients, thereby achieving an initial coarse screening of spectral dimensions [37].

2.6. Sample-Contextual Information Processing and Quantification Strategy

Many machine learning algorithms require numerical input data; therefore, categorical features must be converted into numerical representations before being introduced into the algorithm [38]. For the non-spectral features introduced in this study, a refined quantification strategy was adopted, as illustrated in Figure 2. Farm name, treatment stage, and sampling season were treated as discrete categorical variables and converted into numerical features using label encoding. This processing strategy was intended to characterize the evolutionary background of the physicochemical properties of manure slurry under different management modes, biochemical transformation stages, and temperature fluctuations. For longitude and latitude coordinates, normalization was applied to ensure that spatial features and spectral features were kept on a comparable numerical scale in subsequent calculations. Through this explicit representation of multi-source information, the model was able to obtain support from sample-contextual information in addition to the “physical spectral signal”.

2.7. Model Construction

To systematically evaluate the effects of near-infrared spectra and multi-source sample-contextual features on total nitrogen (TN) prediction in dairy farm manure slurry, this study constructed traditional machine learning models and a deep learning model under a unified data partition scheme. All models were trained and evaluated using the same split to ensure a fair comparison among different modeling strategies. Specifically, the dataset retained after outlier removal was randomly divided into a training set and a test set at a ratio of 8:2 using a fixed random seed, and a validation set was further split from the training set for model selection and training monitoring. It should be noted that the purpose of this study was to develop a robust prediction framework for complex heterogeneous samples collected across multiple farms, seasons, and treatment stages, rather than to establish a strict leave-one-farm-out extrapolation model for completely unseen farms. Therefore, the present split setting is intended to evaluate model robustness under heterogeneous sample conditions within the studied population. At the same time, because “farm name” was introduced as a contextual feature, this setting does not constitute a rigorous farm-wise generalization assessment, and this issue is further discussed as a limitation of the present study.

2.7.1. Machine Learning Model Construction

For the traditional machine learning models, partial least squares regression (PLSR), support vector regression (SVR) [39], random forest (RF) [40], k-nearest neighbors regression (KNN) [41], and multilayer perceptron (MLP) [42] were selected as comparative models. Among them, PLSR, as a classical method in quantitative near-infrared analysis, was used to construct a strong baseline under pure spectral conditions, whereas the remaining models were used to compare the predictive ability of different nonlinear modeling methods under both pure spectral and multi-source feature conditions. To improve the rationality of comparison, moderate hyperparameter search was performed for each machine learning model, and relatively optimal parameter combinations were determined based on the validation results on the training set. Specifically, the number of latent variables was mainly optimized for PLSR; the penalty parameter C, kernel parameter gamma, and error tolerance parameter epsilon were mainly optimized for SVR; the number of trees, tree depth, minimum number of samples in leaf nodes, and maximum number of features were mainly optimized for RF; the number of neighbors and weighting scheme were mainly optimized for KNN; and the hidden-layer structure, regularization coefficient alpha, and learning rate were mainly optimized for MLP. Ultimately, all traditional machine learning models participated in the subsequent result comparison using their respective optimal parameter settings.

2.7.2. MultiScaleSE-GatedCNN Model Construction

For the deep learning model, a MultiScaleSE-GatedCNN model was proposed for TN prediction, and its structural configuration and architecture are shown in Table 1 and Figure 3, respectively. This model takes spectral variables as the primary input and performs collaborative modeling together with numerical sample-contextual features and categorical sample-contextual features. The model consists of a spectral branch, a numerical feature branch, a categorical feature branch, a gated fusion unit, and a regression head. The spectral branch uses multi-scale one-dimensional convolutions to extract local spectral-shape features under different receptive fields and combines them with an SE module to enhance important channel responses. The numerical branch extracts latent representations of continuous variables through a multilayer perceptron. The categorical branch learns compact representations of discrete variables through an embedding layer and a fully connected network. The gated fusion unit dynamically allocates the contribution weights of different information sources through an adaptive weighting mechanism, and the final TN prediction is produced through the regression head. Such as Table 2, for model training, the AdamW optimizer was used together with a cosine annealing learning-rate scheduler. The maximum number of epochs was set to 160, the batch size was 16, the initial learning rate was 0.0008, the weight decay coefficient was 0.0005, and the dropout ratio was 0.18. To improve robustness to outliers, the Huber loss was adopted with δ = 1.0. In addition, gradient clipping with a threshold of 1.0 was applied to suppress unstable gradient fluctuations during training. Model performance on the validation set was evaluated every 5 epochs, and early stopping was triggered when no improvement was observed for 15 consecutive evaluation rounds. The optimal parameter setting determined on the training–validation split was then fixed for final model training and test-set evaluation. To improve the interpretability of the proposed model, the outputs of the gated fusion unit after the Softmax operation were further analyzed during inference.

2.7.3. SimpleConcatMLP Baseline Construction

To evaluate whether the gated fusion mechanism provides practical benefits beyond a straightforward fusion strategy, an additional deep learning baseline, denoted as SimpleConcatMLP, was introduced. In this baseline, the CARS-selected spectral variables and the encoded sample-contextual features were directly concatenated into a single input vector and then fed into a standard multilayer perceptron for regression. Unlike MultiScaleSE-GatedCNN, this model did not include branch-specific feature extraction or gated weighting, and therefore represented a direct-concatenation fusion strategy.
For fair comparison, the same training, validation, and test split as described in Section 2.7 was used. The same spectral preprocessing procedure, contextual feature encoding strategy, and evaluation metrics were also retained. Under the optimal feature combination of spectra + farm name + longitude + season, the final hyperparameters of SimpleConcatMLP were set as follows: epochs = 160, batch size = 16, learning rate = 0.0008, weight decay = 0.0005, and dropout = 0.18.

2.8. Model Evaluation

To objectively evaluate the predictive performance of different models for total nitrogen (TN) in dairy farm manure slurry, the coefficient of determination (R2), root mean square error (RMSE), and residual prediction deviation (RPD) were adopted as the main evaluation indicators. These metrics were used to comprehensively assess the models in terms of goodness of fit, prediction error, and practical applicability.
The coefficient of determination (R2) reflects the proportion of variance in the reference values that can be explained by the model, and a larger value indicates better predictive ability [43]. The root mean square error (RMSE) represents the average deviation between the predicted values and the reference values, and a smaller value indicates higher prediction accuracy [44]. The residual prediction deviation (RPD) is defined as the ratio of the standard deviation of the reference values to the prediction error and is commonly used to evaluate the practical usefulness of a model. In general, an RPD value greater than 2.0 indicates that the model has good predictive ability, while an RPD value greater than 3.0 suggests excellent predictive performance and practical application potential. To further distinguish model performance during calibration and external prediction, Rc2 and RMSEC were used to evaluate the fitting performance of the calibration set, whereas Rp2, RMSEP, and RPD were used to evaluate the predictive performance of the test set. Among them, Rc2 and Rp2 represent the coefficients of determination for the calibration set and test set, respectively; RMSEC and RMSEP represent the root mean square errors of calibration and prediction, respectively. In this study, model performance was comprehensively compared based on these indicators to identify the optimal modeling method and feature combination for TN prediction in dairy farm manure slurry.
The corresponding calculation formulas are shown as follows:
R 2 = 1 i = 1 n ( y i y ^ i ) 2 i = 1 n ( y i y ¯ ) 2
RMSE = 1 n i = 1 n ( y i y ^ i ) 2
RPD = SD RMSE
SD = 1 n 1 i = 1 n ( y i y ¯ ) 2
where y i is the reference value of sample i , y ^ i is the predicted value of sample i , y ¯ is the mean of all reference values, n is the number of samples, and SD is the standard deviation of the reference values in the prediction set. Data processing and model development were conducted in Python (v3.10.18). Deep learning was implemented using PyTorch (v2.5.1) and torchaudio (v2.5.1), machine learning analysis was performed using scikit-learn (v1.7.2), and figures were prepared using Origin 2021.

3. Results

3.1. Statistical Analysis of the Physicochemical Characteristics of Manure Slurry

To clarify the overall distribution characteristics of total nitrogen (TN) in the studied samples and to provide a data basis for subsequent modeling analysis, the physicochemical determination results of TN in manure slurry samples were statistically analyzed, and the results are shown in Table 3 and Figure 4. As shown in Table 3, the TN content of the samples in this study varied over a wide range, indicating obvious nutrient differences among samples. The broad value range and the high coefficient of variation suggest strong dispersion and heterogeneity of the samples, which are closely related to farm source, spatial location, seasonal variation, and the complex composition of manure slurry. Overall, the TN content exhibited substantial variation, providing a rich data basis for the subsequent development of a robust quantitative prediction model.
Figure 4 further shows that the frequency distribution of TN did not fully follow a symmetric distribution, but instead exhibited a certain right-skewed characteristic. Most samples were concentrated in the relatively low-to-medium concentration range, whereas the number of high-concentration samples was relatively small, resulting in a long-tail distribution in the high-value region. This indicates that a few manure slurry samples with relatively high TN contents were present in the dataset, causing the overall distribution to extend toward higher values. The fact that the mean was higher than the median also further suggests that the TN data as a whole followed a positively skewed distribution pattern. This distribution characteristic indicates obvious non-uniformity and complexity in the nutrient composition of manure slurry samples. On the one hand, the broad value range is beneficial for improving the model’s learning ability across different concentration intervals; on the other hand, the skewed distribution and the long tail of high-value samples also increase the difficulty of model fitting, especially for the prediction of high-concentration samples.
In summary, the TN content of the studied samples exhibited a large variation range and obvious non-uniform distribution characteristics, indicating that the dataset constructed in this study can effectively reflect the complexity of manure slurry samples under actual farm production conditions and provide a basis for comparing the effectiveness of different models and multi-source feature-fusion strategies.

3.2. Analysis of Raw Spectral Curves

As shown in Figure 5, the raw absorbance spectra of manure slurry samples over the range of 4000–12,000 cm−1 exhibited obvious molecular vibration characteristics. The spectrum showed the strongest absorption peak near 5150 cm−1, which is highly consistent with the combination vibration of the O–H bond in the high-moisture matrix of manure slurry [45]. The absorption peak in the range of 6400–7000 cm−1 was mainly caused by the first overtone stretching vibration of water-related O–H groups around 1440 nm (6944 cm−1) [46]. In addition, relatively consistent peaks were also observed near 8400 cm−1 and 10,400 cm−1. Among them, the peak near 8400 cm−1 was associated with the second overtone vibration of the C–H bond [47], whereas the absorption peak near 10,400 cm−1 resulted from the combination absorption of the symmetric and asymmetric stretching vibrations of O–H bonds [48]. After feature selection, 258 spectral variables were retained and used as the spectral input of subsequent models. The full list of retained variables is provided in Table S1.

3.3. Comparison of Traditional Machine Learning Models Under Single-Source Spectral Conditions

To compare the predictive ability of different modeling methods for total nitrogen (TN) in dairy farm manure slurry under single-source spectral conditions, PLSR, RF, SVR, KNN, and MLP models were constructed based on CARS-selected characteristic wavelengths and compared under the same data partition. The results are shown in Table 4. It should be noted that, to ensure fair comparison among models, the spectral preprocessing method used in single-source spectral modeling was selected based on the performance of the training and validation sets, and feature wavelength selection was uniformly performed using the CARS method.
As shown in Table 4, under single-source spectral conditions, PLSR achieved the best overall performance on the test set, with an R2 of 0.850, an RMSEP of 526.323 mg/L, and an RPD of 2.584, indicating that PLSR had strong predictive ability on the current CARS-selected spectral data. By contrast, RF ranked second overall, with a training-set R2 of 0.968 and an RMSEC of 216.710 mg/L, while its test-set R2 was 0.817, its RMSEP was 533.551 mg/L, and its RPD was 2.337.
KNN achieved an almost perfect fit on the training set (R2 = 0.999, RMSEC = 38.549 mg/L), but its test-set R2 was only 0.782, with an RMSEP of 582.387 mg/L. SVR and MLP performed relatively weakly overall. Specifically, the test-set R2 of SVR was 0.656, with an RMSEP of 731.166 mg/L and an RPD of 1.706, whereas the test-set R2 of MLP was 0.615, with an RMSEP of 774.053 mg/L and an RPD of 1.611, both lower than those of PLSR and RF. Overall, under single-source spectral input conditions, the predictive performance of different traditional machine learning models varied considerably, with PLSR showing the best performance and RF ranking second.

3.4. Comparative Analysis of Traditional Machine Learning Models Under Different Sample-Contextual Feature Combinations

Based on the model comparison under single-source spectral conditions, contextual features were further introduced on top of spectral input, and the multi-source modeling results of different traditional machine learning models were compared. The results are shown in Table 5. Overall, after incorporating their respective optimal contextual feature combinations, all traditional machine learning models showed varying degrees of improvement compared with the single-source spectral condition.
For PLSR, the optimal contextual feature combination was “spectra + farm name + season”, with a test-set R2 of 0.851, an RMSEP of 526.229 mg/L, and an RPD of 2.585. Compared with the single-source spectral condition, the predictive performance of PLSR improved only slightly. RF performed best under the multi-source condition, and its optimal contextual feature combination was “spectra + longitude + season”, with the test-set R2 reaching 0.854, the RMSEP decreasing to 475.851 mg/L, and the RPD increasing to 2.621. The optimal contextual feature combination for KNN was “spectra + latitude + season”, with a test-set R2 of 0.825, an RMSEP of 522.389 mg/L, and an RPD of 2.387, which also represented an improvement over the single-source spectral condition.
SVR and MLP also showed some degree of improvement after the incorporation of contextual features, but their overall performance remained relatively weak. Among them, the optimal contextual feature combination for SVR was “spectra + season”, with the test-set R2 improving to 0.682, the RMSEP decreasing to 703.520 mg/L, and the RPD reaching 1.773. For MLP, the optimal contextual feature combination was “spectra + farm name + season”, with a test-set R2 of 0.790, an RMSEP of 571.234 mg/L, and an RPD of 2.183. Overall, the comparative results of traditional machine learning models under multi-source feature conditions indicate that auxiliary contextual information can improve TN prediction performance as a whole, although the optimal contextual feature combination differed across models.

3.5. Ablation Analysis of Feature Combinations for MultiScaleSE-GatedCNN

To further clarify the influence of different contextual feature combinations on the predictive performance and information utilization of the proposed MultiScaleSE-GatedCNN model, ablation experiments were conducted under different contextual feature combinations on top of near-infrared spectral input. The results are shown in Table 6. In addition to the predictive metrics, Table 6 also reports the normalized gate weights of the active branches, including the spectral branch, numerical branch, and categorical branch, so as to provide further insight into how the gated fusion unit allocated attention to different information sources under each input configuration.
As shown in Table 6, among all candidate contextual feature combinations, the model corresponding to “spectra + farm name + longitude + season” achieved the best overall performance, with an Rc2 of 0.904, an RMSEC of 381.722 mg/L, an Rp2 of 0.905, an RMSEP of 367.389 mg/L, and an RPD of 3.242, representing the best comprehensive performance among all combinations. A closely comparable combination was “spectra + farm name + latitude + season”, with an Rp2 of 0.901, an RMSEP of 374.007 mg/L, and an RPD of 3.185. By contrast, the combination with more contextual features, namely “spectra + farm name + longitude + latitude + season”, yielded an Rp2 of 0.875, an RMSEP of 421.576 mg/L, and an RPD of 2.825, failing to further improve model performance. For the combinations with fewer variables, the results of “spectra + longitude + season” and “spectra + latitude + season” were relatively close, with Rp2 values of 0.806 and 0.805, respectively. When only “spectra + season” was used, the Rp2 dropped to 0.798, the RMSEP increased to 535.986 mg/L, and the RPD decreased to 2.222.
The normalized gate weights further reveal how the model utilized different information sources. For the optimal combination of “spectra + farm name + longitude + season”, the spectral branch retained the largest gate weight, indicating that near-infrared spectra remained the primary source of TN-related information. Meanwhile, the numerical and categorical branches also received non-negligible weights, suggesting that longitude and categorical contextual information provided complementary cues beyond the spectral signal alone. Across different feature combinations, the gate-weight distribution changed accordingly, demonstrating that the gated fusion unit did not assign fixed importance to each branch, but adaptively adjusted branch contributions according to the available contextual inputs.
It is also noteworthy that adding latitude did not further improve the model performance. A plausible explanation is that all samples in this study were collected from farms within Tianjin, where the north–south spatial span represented by latitude was relatively limited compared with the heterogeneity introduced by farm identity, management conditions, and seasonal variation. Under this dataset structure, latitude provided less additional discriminative information and was partly redundant with farm name and season. Therefore, after longitude, farm name, and season had already been incorporated, adding latitude increased input complexity but contributed limited new information, which likely weakened the generalization benefit of the model.
In addition, to further validate the predictive performance of the model under the optimal feature combination, the prediction scatter plots for the training and test sets (Figure 6) and the training-loss curves (Figure 7) were plotted. As shown in Figure 6, the sample points of both the training and test sets were generally distributed around the line y = x, indicating good agreement between predicted and measured values. Figure 7 shows that both the training loss and validation loss decreased rapidly during the early stage of training and then gradually stabilized, with the best epoch appearing around epoch 130, indicating that the training process of the model was generally stable. Overall, “spectra + farm name + longitude + season” was identified as the optimal input combination for MultiScaleSE-GatedCNN.

3.6. Comparison with the SimpleConcatMLP Baseline

To further verify whether the proposed gated fusion mechanism provides advantages beyond simple feature fusion, an additional baseline experiment based on direct feature concatenation was conducted. Specifically, a SimpleConcatMLP model was established by directly concatenating the spectral variables and encoded sample-contextual features, followed by regression using a standard multilayer perceptron. The comparison was carried out under the same optimal feature combination, namely spectra + farm name + longitude + season, so as to isolate the effect of the fusion mechanism itself.
The results showed that SimpleConcatMLP already achieved competitive predictive performance, with a training-set R2 of 0.956, a training RMSEP of 258.453 mg/L, a training RPD of 4.763, a test-set R2 of 0.893, a test RMSEP of 389.404 mg/L, and a test RPD of 3.059. This indicates that direct concatenation of spectral and contextual information can effectively improve TN prediction performance.
However, under the same feature combination, the proposed MultiScaleSE-GatedCNN still achieved better overall prediction performance, with a test-set R2 of 0.905, an RMSEP of 367.389 mg/L, and an RPD of 3.242. Compared with SimpleConcatMLP, the proposed model improved the test-set R2 by 0.012, reduced the RMSEP by 22.015 mg/L, and increased the RPD by 0.183. These results indicate that the performance gain in this study does not come only from introducing contextual information itself, but also from the more effective organization and utilization of heterogeneous inputs through branch-specific encoding and gated fusion.

3.7. Comprehensive Comparison of Different Modeling Strategies

To further provide an intuitive comparison of the comprehensive performance of single-source models, multi-source fusion models, and the proposed MultiScaleSE-GatedCNN model in TN prediction, a radar chart of different modeling strategies was plotted, as shown in Figure 8. The results show that multi-source fusion models as a whole outperformed single-source models, while MultiScaleSE-GatedCNN achieved the best performance in terms of Rp2, RMSEP, and RPD.
Overall, from single-source spectral models to traditional multi-source fusion models and then to MultiScaleSE-GatedCNN, different modeling strategies showed a progressive improvement trend in TN prediction performance. Among them, MultiScaleSE-GatedCNN achieved the highest comprehensive predictive performance under the optimal feature combination.

4. Discussion

4.1. Sample Heterogeneity and the Limitations of Single-Source Spectral Modeling

In this study, the TN content of manure slurry samples showed a wide fluctuation range and an obvious right-skewed distribution, indicating strong heterogeneity among samples. Meanwhile, although the raw spectral curves had similar overall contours, obvious parallel shifts and baseline drift were still observed. This suggests that the spectral responses of dairy farm manure slurry samples were influenced not only by the concentration of the target nutrient, but also by particle distribution, moisture status, suspended solids concentration, and differences in sample source.
From the perspective of physical optical characteristics, the absorbance over the full spectral range exhibited obvious parallel shifts and baseline drift, reflecting enhanced scattering effects caused by differences in particle size, suspended solids concentration, and viscosity of manure slurry across different treatment stages. Such signal shifts caused by physical properties often lead to nonlinear bias of the chemical nutrient signals along the spectral axis. Because the signals of chemical composition and physical background noise are highly coupled, the fluctuations in spectral features are not completely dominated by nitrogen contents, but are jointly driven by spatiotemporal background and treatment-stage variation [49].
Under such conditions, single-source spectral models were still able to achieve a certain level of predictive ability. In particular, PLSR showed strong comprehensive performance under single-source spectral conditions, indicating that near-infrared spectra still retained effective information related to TN variation. For high-dimensional and highly collinear spectral data, PLSR is able to extract latent variables closely related to the target variable, which explains why it maintained a strong baseline position in the current task.
It should be emphasized that the predictive usefulness of spectral information in this study does not rely only on direct N–H absorption. Manure slurry is a high-moisture, organic-rich heterogeneous matrix, and variations in TN are closely associated with changes in moisture status, organic matter composition, ammonium-related forms, and other physicochemical properties of the matrix. Therefore, even though the dominant absorption regions identified in the raw spectra were mainly associated with O–H and C–H vibrations, these bands still carried TN-related indirect information through covariance with the overall sample composition. This helps explain why the pure spectral model already provided reasonable performance, while the addition of contextual information further improved robustness under heterogeneous conditions.
However, the overall results indicate that relying single-source spectral information alone was insufficient to fully characterize the complex differences among samples collected under cross-farm, cross-season, and different treatment-background conditions. Especially when sample background differences are large, the mapping relationship between spectral features and target components is easily disturbed by physical background and spatiotemporal variation, thereby limiting the generalization ability and robustness of the model. Therefore, although single-source spectral modeling can serve as an important foundation for TN prediction, its adaptability under complex real-world scenarios remains limited.

4.2. Auxiliary Role of Contextual Information in TN Prediction

The overall performance of traditional machine learning models improved to varying degrees after the introduction of contextual features, indicating that auxiliary contextual information has practical value for TN prediction. Although variables such as farm name, longitude, latitude, and season do not directly reflect nutrient content itself, they can characterize the background environment in which the samples were formed from different perspectives. Farm name reflects differences in management practices, feed composition, and manure source across farms; longitude and latitude represent spatial differences; and season corresponds to stage-specific variation in environmental temperature, feeding conditions, and the physicochemical state of manure slurry.
From the results, season was retained in the optimal combinations of PLSR, RF, SVR, KNN, and MLP, indicating that it plays a relatively stable auxiliary role in TN prediction. This suggests that seasonal variation affects not only the compositional fluctuation of manure slurry itself, but also its spectral response characteristics. By contrast, the retention of farm name, longitude, and latitude was not consistent across models, reflecting that different models differ in their ability to utilize categorical contextual information and spatial contextual information.
Therefore, the introduction of contextual information is not a simple addition to spectral information, but rather compensates, to a certain extent, for the insufficient representational ability of single-source spectral modeling, enabling the model to achieve more robust prediction results under more complex heterogeneous sample conditions [29,33,50]. This also indicates that, in systems such as dairy farm manure slurry that are strongly affected by spatiotemporal background, multi-source information fusion has clear practical significance.

4.3. Advantages of MultiScaleSE-GatedCNN in Multi-Source Fusion

Compared with traditional machine learning models, MultiScaleSE-GatedCNN achieved the best comprehensive results under the optimal feature combination, indicating that simply introducing contextual features is not sufficient and that effective fusion of different information sources is equally critical. Structurally, the model simultaneously considers spectral features, numerical contextual features, and categorical contextual features, learns representations of different types of information through a multi-branch architecture, and then realizes collaborative utilization of different information sources through a gated fusion unit.
Among them, the multi-scale one-dimensional convolution is capable of extracting local spectral-shape features under different receptive fields, while the SE module helps enhance the responses of important channels [51]. The numerical branch and the categorical branch respectively encode continuous variables and discrete variables in a targeted manner. This structural design enables the model to retain local response patterns in near-infrared spectra relatively well while simultaneously absorbing auxiliary information related to sample source, spatial position, and seasonal variation from the contextual variables.
More importantly, the gated fusion unit does not simply concatenate multi-source features directly, but dynamically adjusts the contribution of different information sources through an adaptive weight allocation mechanism. This fusion strategy enables the model to utilize information from different sources more flexibly when dealing with complex heterogeneous samples, thereby improving prediction accuracy and generalization ability [52]. From the final results, MultiScaleSE-GatedCNN outperformed both traditional single-source models and traditional multi-source models under the optimal feature combination, further indicating that a reasonable fusion mechanism is the key to improving TN prediction performance under complex scenarios.
The comparison with the SimpleConcatMLP baseline further supports this interpretation. Although direct concatenation of spectral and contextual features already yielded competitive predictive performance, the proposed MultiScaleSE-GatedCNN still achieved better results under the same optimal feature combination. This suggests that the benefit of the proposed method lies not merely in adding more inputs, but in organizing heterogeneous information in a more structured manner. By separating spectral, numerical, and categorical information into dedicated branches and then adaptively weighting them through the gated fusion unit, the proposed model can make more effective use of complementary information and achieve improved prediction accuracy.
The present study can also be compared with the work of Li et al. [29], who investigated the effect of seasonal variation on NIRS modeling of dairy farm manure slurry. Their study demonstrated that season was an important source of variation and showed that the GMFS could improve applicability across seasons, although at the expense of some prediction precision. In the present work, season was likewise retained as an important contextual factor, but it was not treated as the only auxiliary clue. Instead, it was jointly modeled with farm identity and spatial information within a multi-branch gated fusion framework. In this sense, the advancement of the present study is not merely that a deep learning architecture was used instead of PLS, but that the modeling unit was extended from spectral data alone to a coordinated representation of spectral and sample-contextual information. Under the optimal feature combination of spectra + farm name + longitude + season, the proposed MultiScaleSE-GatedCNN achieved a test-set Rp2 of 0.905, an RMSEP of 367.389 mg/L, and an RPD of 3.242, whereas the previous study [29] reported Rp2 = 0.85, RMSEP = 443.39 mg/L, and RPD = 2.38 for the TN global model of four seasons. Although these results are not from a strictly identical experimental setting, they suggest that integrating multi-source contextual information together with adaptive fusion can provide a more robust solution for TN prediction under heterogeneous farm conditions.

4.4. Differences in Feature Combinations, Practical Significance, and Research Limitations

The ablation results of MultiScaleSE-GatedCNN indicate that multi-source feature fusion does not follow the simple rule of “the more features, the better.” Although adding contextual variables can expand the input information range, it does not necessarily lead to better prediction performance. On the contrary, if newly added variables are redundant with existing information or contain insufficient effective information, they may interfere with model training and thereby weaken generalization ability [53].
The gate-weight analysis further supports the above observation. The spectral branch consistently retained a substantial proportion of the normalized gate weight across different feature combinations, indicating that spectral information remained the dominant basis for TN prediction. At the same time, the numerical and categorical branches contributed complementary information with magnitudes that varied across input combinations, confirming that the gated fusion unit adaptively balanced the reliance on spectral and contextual information rather than applying a fixed fusion pattern.
It should also be noted that the proposed model did not indiscriminately rely on the full raw spectrum. Instead, CARS was first applied to retain 258 informative spectral variables, meaning that the spectral input was already reduced to characteristic wavelengths associated with chemically meaningful absorption regions. In this sense, the present framework can be regarded as a feature-screened spectral modeling strategy rather than a direct full-spectrum input strategy. Combined with the raw spectral analysis in Section 3.2, these retained variables were mainly associated with the major absorption regions of manure slurry spectra, including bands near 5150 cm−1, 6400–7000 cm−1, 8400 cm−1, and 10,400 cm−1, which are related to O–H- and C–H-associated absorptions in the high-moisture and organic-rich manure slurry matrix. This indicates that the model relied on chemically meaningful spectral regions after variable screening rather than using the entire raw spectrum indiscriminately. A more fine-grained post hoc wavelength attribution analysis, such as SHAP-based interpretation, will be further explored in future work. And the combination of selected raw spectral variables with engineered spectral descriptors, such as the intensities of characteristic bands and integrated spectral regions, will be further investigated to determine whether these hybrid representations can provide additional predictive benefits. Moreover, easily obtainable physicochemical parameters such as pH may serve as useful auxiliary inputs for the MultiScaleSE-GatedCNN model and deserve further evaluation.
In this study, “spectra + farm name + longitude + season” achieved the best overall performance, whereas adding latitude did not further improve model performance. This indicates that the key to multi-source feature fusion lies in selecting variables that can form effective complementarity with spectral information rather than simply increasing input dimensionality. In addition, although treatment-stage features were included among the initial contextual variables, they showed relatively weak performance in preliminary experiments and were not included in the final key combinations. In addition, treatment-stage features were evaluated in preliminary screening experiments, but they did not provide stable performance gains. As shown in Supplementary Table S2, when treatment-stage information was added to three representative feature combinations, the predictive performance consistently deteriorated. Specifically, for the combination of spectra + farm name + longitude + latitude + season, the test-set Rp2 decreased from 0.875 to 0.872, while the RMSEP increased from 421.576 to 426.690 mg/L. For spectra + farm name + longitude + season, the test-set Rp2 decreased from 0.902 to 0.892, and the RMSEP increased from 373.148 to 391.733 mg/L. For spectra + farm name + latitude + season, the test-set Rp2 decreased from 0.901 to 0.885, and the RMSEP increased from 374.007 to 403.794 mg/L. Meanwhile, the corresponding RPD values also decreased in all three cases. These results indicate that treatment-stage information provided limited or unstable contribution under the current dataset and model setting, and therefore it was not retained in the final key feature combinations reported in this study.
From an application perspective, the modeling strategy integrating near-infrared spectra with contextual information can effectively improve the accuracy and robustness of TN prediction in dairy farm manure slurry and has certain application potential for rapid nutrient detection, resource utilization, and precision management of manure. To provide a practical reference for on-site deployment, the inference efficiency of the optimal MultiScaleSE-GatedCNN model was additionally evaluated under the feature combination of spectra + farm name + longitude + season. The average single-sample inference time was approximately 0.847 ms/sample on a 12th Gen Intel(R) Core(TM) i5-12400F CPU and 1.189 ms/sample on an NVIDIA GeForce RTX 4060 GPU. When processed in batches, the average inference time was further reduced to 0.122 ms/sample on CPU and 0.028 ms/sample on GPU. These values refer only to model inference after the spectral and contextual inputs were prepared, and do not include spectral acquisition time. Although the end-to-end latency in practical deployment will also depend on spectral acquisition and preprocessing, these results suggest that the proposed model is computationally feasible for near-real-time prediction tasks. However, this study still has several limitations. For example, the research samples were mainly collected from farms in Tianjin, the types of contextual variables were still relatively limited, and the cross-regional applicability of the model as well as its online application capability under more complex field conditions remain to be further verified. Future studies may evaluate the generalization ability and practical applicability of the model under larger sample sizes, broader regional coverage, and richer contextual variables.
In addition, it should be noted that farm name was incorporated as a contextual feature to characterize sample-background heterogeneity. Under this setting, the present study primarily evaluates model robustness within a regional multi-farm population represented by the Tianjin dataset, rather than universal extrapolation to entirely unseen farms. Because the data were split using a fixed random train–test strategy rather than a farm-wise split, samples from the same farm may contribute contextual patterns to both model development and evaluation. Therefore, the current results should be interpreted as evidence that integrating spectra with sample-contextual information can improve prediction robustness under complex heterogeneous conditions within the studied regional population, but not as proof of unrestricted cross-farm or cross-regional generalization. For practical use, the proposed framework is expected to be more suitable for regional deployment in populations with similar farm backgrounds, management conditions, and environmental contexts. Future work should further assess this framework using farm-wise validation, leave-one-farm-out strategies, and external datasets from other regions to more rigorously verify its extrapolation ability. Another limitation should also be noted for practical deployment. In this study, the samples were stored at low temperature and analyzed within a relatively short period after collection, so the constructed model mainly reflects the spectral–composition relationship under short-term storage conditions. However, in real farm scenarios, manure slurry may undergo compositional and spectral changes during prolonged storage, standing, or repeated handling, which may affect the long-term stability of the model. Therefore, whether the proposed model can maintain its predictive accuracy over time under extended storage conditions was not explicitly evaluated in the present study. This issue should be further investigated in future work by combining time-dependent storage experiments with model updating or recalibration strategies.
To further position the present work relative to previous studies, a concise comparison of representative NIRS-based studies related to TN prediction is provided in Table 7. The present study differs from previous work not only in predictive performance, but also in explicitly integrating sample-contextual information into TN modeling under cross-farm heterogeneous conditions.

5. Conclusions

In this study, a multi-branch gated fusion deep learning model, MultiScaleSE-GatedCNN, was constructed for total nitrogen (TN) prediction in dairy farm manure slurry by integrating near-infrared spectra and sample-contextual information. Using 747 manure slurry samples collected from 36 large-scale dairy farms in Tianjin, China, this study systematically evaluated the predictive performance of traditional machine learning models and deep learning models under single-source spectral conditions and multi-source feature fusion conditions, and further analyzed the effects of different sample-contextual feature combinations on model performance through ablation experiments. The results showed that under single-source spectral input conditions, PLSR still exhibited strong predictive ability and served as an important baseline model for the current task. After the introduction of sample-contextual information, the predictive performance of traditional machine learning models generally improved to different extents, indicating that sample-contextual information can provide useful supplementary information for TN prediction in manure slurry. Among these traditional machine learning models, RF achieved the best overall performance under the multi-source condition. For the proposed MultiScaleSE-GatedCNN model, the ablation results showed that different sample-contextual feature combinations had markedly different effects on prediction performance. The combination of “spectra + farm name + longitude + season” was identified as the optimal input combination. Based on this combination, MultiScaleSE-GatedCNN achieved the best prediction performance, with a test-set Rp2 of 0.905, an RMSEP of 367.389 mg/L, and an RPD of 3.242, outperforming both the traditional machine learning models under single-source conditions and those under multi-source conditions. These results indicate that the proposed model can more effectively exploit the complementary relationship between near-infrared spectra and sample-contextual information, thereby improving the prediction accuracy and robustness of TN in manure slurry under complex scenarios.
Overall, this study demonstrates that integrating near-infrared spectra with sample-contextual information is an effective strategy for improving TN prediction in dairy farm manure slurry. The proposed MultiScaleSE-GatedCNN model provides a new methodological framework for rapid nutrient detection in heterogeneous manure slurry systems and offers technical support for nutrient assessment, precision fertilization, and intelligent management of livestock manure.

Supplementary Materials

The following supporting information can be downloaded at: https://www.mdpi.com/article/10.3390/agriculture16090965/s1. Table S1. Selected wavenumber variables retained after CARS and their corresponding wavelengths. Table S2. Preliminary comparison of treatment-stage-inclusive feature combinations under MultiScaleSE-GatedCNN.

Author Contributions

Conceptualization, H.L. and J.L.; methodology, J.L., H.L. and X.L.; software, J.L.; validation, J.L., H.L. and Q.Z.; formal analysis, H.L., J.L. and Z.L.; investigation, H.L., Z.L. and B.H.; resources, H.L., Q.Z., N.W. and Y.L.; data curation, J.L.; writing—original draft preparation, J.L. and H.L.; writing—review and editing, H.L., J.L., X.L., N.W. and Y.L.; visualization, J.L. and H.L.; supervision, N.W. and Y.L.; project administration, H.L. and N.W.; funding acquisition, N.W. and Y.L. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by: Natural Science Foundation of Zhejiang Province, grant number LQN25C160004; Postdoctoral Research Program of Zhejiang Province, grant number ZJ2024132; Yongjia Advanced Agricultural and Industry Institute, grant number 2023YJ010; and Scientific Research Foundation of Zhejiang A&F University, grant number 2022LFR107.

Data Availability Statement

The raw data supporting the conclusions of this article will be made available by the authors on request.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Luo, M.; Liu, X.; Legesse, N.; Liu, Y.; Wu, S.; Han, F.X.; Ma, Y. Evaluation of agricultural non-point source pollution: A review. Water. Air. Soil Pollut. 2023, 234, 657. [Google Scholar] [CrossRef]
  2. Murphy, D.; Dillon, P.; Donovan, M.O.; Shalloo, L.; Ruelle, E. Nitrate leaching on Irish grassland dairy farms: A review. Eur. J. Agron. 2024, 153, 127042. [Google Scholar] [CrossRef]
  3. van Doorn, M.; van Rotterdam, D.; Ros, G.; Koopmans, G.F.; Smolders, E.; de Vries, W. The phosphorus saturation degree as a universal agronomic and environmental soil P test. Crit. Rev. Environ. Sci. Technol. 2024, 54, 385–404. [Google Scholar] [CrossRef]
  4. Zhang, X.; Davidson, E.A.; Zou, T.; Lassaletta, L.; Quan, Z.; Li, T.; Zhang, W. Quantifying nutrient budgets for sustainable nutrient management. Glob. Biogeochem. Cycles 2020, 34, e2018GB006060. [Google Scholar] [CrossRef]
  5. Ren, T.; Wang, J.; Chen, Q.; Zhang, F.; Lu, S. The effects of manure and nitrogen fertilizer applications on soil organic carbon and nitrogen in a high-input cropping system. PLoS ONE 2014, 9, e97732. [Google Scholar] [CrossRef]
  6. Rodrigues, M.; Argenta, J.C.; Cezar, E.; dos Santos, G.L.A.A.; Özal, Ö.; Reis, A.S.; Nanni, M.R. The use of Vis-NIR-SWIR spectroscopy in the prediction of soil available ions after application of rock powder. Inf. Process. Agric. 2024, 11, 26–44. [Google Scholar] [CrossRef]
  7. Chen, L.; Xing, L.; Han, L. Review of the Application of Near-Infrared Spectroscopy Technology to Determine the Chemical Composition of Animal Manure. J. Environ. Qual. 2013, 42, 1015–1028. [Google Scholar] [CrossRef]
  8. Chen, L.; Xing, L.; Han, L. Quantitative determination of nutrient content in poultry manure by near infrared spectroscopy based on artificial neural networks. Poult. Sci. 2009, 88, 2496–2503. [Google Scholar] [CrossRef]
  9. Feng, X.; Larson, R.A.; Digman, M.F. Digman, Evaluation of Near-Infrared Reflectance and Transflectance Sensing System for Predicting Manure Nutrients. Remote Sens. 2022, 14, 963. [Google Scholar] [CrossRef]
  10. Junior, S.B.; Mastelini, S.M.; Barbon, A.P.A.; Barbin, D.F.; Calvini, R.; Lopes, J.F.; Ulrici, A. Multi-target prediction of wheat flour quality parameters with near infrared spectroscopy. Inf. Process. Agric. 2020, 7, 342–354. [Google Scholar] [CrossRef]
  11. Aguirre-Villegas, H.A.; Sharara, M.A.; Larson, R.A. Nutrient variability following dairy manure storage agitation. Appl. Eng. Agric. 2018, 34, 908–917. [Google Scholar] [CrossRef]
  12. Al Riza, D.F.; Widodo, S.; Yamamoto, K.; Ninomiya, K.; Suzuki, T.; Ogawa, Y.; Kondo, N. External defects and severity level evaluation of potato using single and multispectral imaging in near infrared region. Inf. Process. Agric. 2024, 11, 80–90. [Google Scholar] [CrossRef]
  13. Piepel, M.-F.; Olfs, H.-W. Development of a physicochemical test kit for on-farm measurement of nutrients in liquid organic manures. Agriculture 2023, 13, 477. [Google Scholar] [CrossRef]
  14. Wold, S.; Sjöström, M.; Eriksson, L. PLS-regression: A basic tool of chemometrics. Chemom. Intell. Lab. Syst. 2001, 58, 109–130. [Google Scholar] [CrossRef]
  15. Cheng, J.-H.; Sun, D.-W. Partial least squares regression (PLSR) applied to NIR and HSI spectral data modeling to predict chemical properties of fish muscle. Food Eng. Rev. 2017, 9, 36–49. [Google Scholar] [CrossRef]
  16. de Santana, F.B.; de Souza, A.M.; Poppi, R.J. Visible and near infrared spectroscopy coupled to random forest to quantify some soil quality parameters. Spectrochim. Acta. A Mol. Biomol. Spectrosc. 2018, 191, 454–462. [Google Scholar] [CrossRef]
  17. Ni, L.-J.; Zhang, L.-G.; Xie, J.; Luo, J.-Q. Pattern recognition of Chinese flue-cured tobaccos by an improved and simplified K-nearest neighbors classification algorithm on near infrared spectra. Anal. Chim. Acta 2009, 633, 43–50. [Google Scholar] [CrossRef]
  18. Cao, L.; Sun, M.; Yang, Z.; Jiang, D.; Yin, D.; Duan, Y. A novel transformer-CNN approach for predicting soil properties from LUCAS Vis-NIR spectral data. Agronomy 2024, 14, 1998. [Google Scholar] [CrossRef]
  19. Chakravartula, S.S.N.; Moscetti, R.; Bedini, G.; Nardella, M.; Massantini, R. Use of convolutional neural network (CNN) combined with FT-NIR spectroscopy to predict food adulteration: A case study on coffee. Food Control 2022, 135, 108816. [Google Scholar] [CrossRef]
  20. Novianty, I.; Baskoro, R.G.; Nurulhaq, M.I.; Nanda, M.A. Empirical mode decomposition of near-infrared spectroscopy signals for predicting oil content in palm fruits. Inf. Process. Agric. 2023, 10, 289–300. [Google Scholar] [CrossRef]
  21. Bu, Y.; Luo, J.; Tian, Q.; Li, J.; Cao, M.; Yang, S.; Guo, W. Nondestructive detection of internal quality in multiple peach varieties by Vis/NIR spectroscopy with multi-task CNN method. Postharvest Biol. Technol. 2025, 227, 113579. [Google Scholar] [CrossRef]
  22. Sadeghi, A.; Khani, S.; Sabourian, R.; Hajimahmoodi, M.; Ghasemi, J.B. Integrating CNNs and chemometrics for analyzing NIR spectra and RGB images in turmeric adulterant detection. J. Food Compos. Anal. 2025, 141, 107324. [Google Scholar] [CrossRef]
  23. Xia, H.; Zhu, R.; Yuan, H.; Song, C. Rapid quantitative analysis of cotton-polyester blended fabrics using near-infrared spectroscopy combined with CNN-LSTM. Microchem. J. 2024, 200, 110391. [Google Scholar] [CrossRef]
  24. Ding, F.; Li, C.; Zhai, W.; Fei, S.; Cheng, Q.; Chen, Z. Estimation of nitrogen content in winter wheat based on multi-source data fusion and machine learning. Agriculture 2022, 12, 1752. [Google Scholar] [CrossRef]
  25. Li, Y.; Chang, C.; Wang, Z.; Li, T.; Li, J.; Zhao, G. Identification of cultivated land quality grade using fused multi-source data and multi-temporal crop remote sensing information. Remote Sens. 2022, 14, 2109. [Google Scholar] [CrossRef]
  26. Zhao, J.; Pan, F.; Xiao, X.; Hu, L.; Wang, X.; Yan, Y.; Zhang, S.; Tian, B.; Yu, H.; Lan, Y. Summer maize growth estimation based on near-surface multi-source data. Agronomy 2023, 13, 532. [Google Scholar] [CrossRef]
  27. Lu, J.; Dai, E.; Miao, Y.; Kusnierek, K. Improving active canopy sensor-based in-season rice nitrogen status diagnosis and recommendation using multi-source data fusion with machine learning. J. Clean. Prod. 2022, 380, 134926. [Google Scholar] [CrossRef]
  28. Wang, Y.; Zhang, Z.; Feng, L.; Du, Q.; Runge, T. Combining multi-source data and machine learning approaches to predict winter wheat yield in the conterminous United States. Remote Sens. 2020, 12, 1232. [Google Scholar] [CrossRef]
  29. Li, M.; Sun, D.; Liu, S.; Zhao, R.; Zhang, K. Construction of rapid prediction models for TN and TP in dairy farms slurry under different seasons by near infrared spectroscopy. Spectrochim. Acta. A Mol. Biomol. Spectrosc. 2024, 305, 123517. [Google Scholar] [CrossRef]
  30. Htun, H.H.; Biehl, M.; Petkov, N. Survey of feature selection and extraction techniques for stock market prediction. Financ. Innov. 2023, 9, 26. [Google Scholar] [CrossRef] [PubMed]
  31. Theng, D.; Bhoyar, K.K. Feature selection techniques for machine learning: A survey of more than two decades of research. Knowl. Inf. Syst. 2024, 66, 1575–1637. [Google Scholar] [CrossRef]
  32. Wang, H.; Liang, Q.; Hancock, J.T.; Khoshgoftaar, T.M. Feature selection strategies: A comparative analysis of SHAP-value and importance-based methods. J. Big Data 2024, 11, 44. [Google Scholar] [CrossRef]
  33. Kotsiantis, S.B.; Kanellopoulos, D.; Pintelas, P.E. Data preprocessing for supervised leaning. Int. J. Comput. Sci. 2006, 1, 111–117. [Google Scholar]
  34. Mou, Y.; You, X.; Xu, D.; Zhou, L.; Zeng, W.; Yu, S. Regularized multivariate scatter correction. Chemom. Intell. Lab. Syst. 2014, 132, 168–174. [Google Scholar] [CrossRef]
  35. Rinnan, Å. Pre-processing in vibrational spectroscopy–when, why and how. Anal. Methods 2014, 6, 7124–7129. [Google Scholar] [CrossRef] [PubMed]
  36. Bromba, M.U.; Ziegler, H. Application hints for Savitzky-Golay digital smoothing filters. Anal. Chem. 1981, 53, 1583–1586. [Google Scholar] [CrossRef]
  37. Yang, Y.; Jin, Y.; Wu, Y.; Chen, Y. Application of near infrared spectroscopy combined with competitive adaptive reweighted sampling partial least squares for on-line monitoring of the concentration process of Wangbi tablets. J. Infrared Spectrosc. 2016, 24, 171–178. [Google Scholar] [CrossRef]
  38. Dahouda, M.K.; Joe, I. A deep-learned embedding technique for categorical features encoding. IEEE Access 2021, 9, 114381–114391. [Google Scholar] [CrossRef]
  39. Awad, M.; Khanna, R. Support vector regression. In Efficient Learning Machines: Theories, Concepts, and Applications for Engineers and System Designers; Springer: Berlin/Heidelberg, Germany, 2015; pp. 67–80. [Google Scholar]
  40. Rigatti, S.J. Random forest. J. Insur. Med. 2017, 47, 31–39. [Google Scholar] [CrossRef]
  41. Halder, R.K.; Uddin, M.N.; Uddin, M.A.; Aryal, S.; Khraisat, A. Enhancing K-nearest neighbor algorithm: A comprehensive review and performance analysis of modifications. J. Big Data 2024, 11, 113. [Google Scholar] [CrossRef]
  42. Kruse, R.; Mostaghim, S.; Borgelt, C.; Braune, C.; Steinbrecher, M. Multi-layer perceptrons. In Computational Intelligence: A Methodological Introduction; Springer: Berlin/Heidelberg, Germany, 2022; pp. 53–124. [Google Scholar]
  43. Zhao, S.; Zhang, Y.; Qiu, Z.; He, Y.; Zhang, Y. Towards a fast and generalized microplastic quantification method in soil using terahertz spectroscopy. Sci. Total Environ. 2022, 841, 156624. [Google Scholar] [CrossRef]
  44. Paltseva, A.A.; Deeb, M.; Di Iorio, E.; Circelli, L.; Cheng, Z.; Colombo, C. Prediction of bioaccessible lead in urban and suburban soils with Vis-NIR diffuse reflectance spectroscopy. Sci. Total Environ. 2022, 809, 151107. [Google Scholar] [CrossRef]
  45. Christy, A.A. Chemistry of desiccant properties of carbohydrate polymers as studied by near-infrared spectroscopy. Ind. Eng. Chem. Res. 2013, 52, 4510–4516. [Google Scholar] [CrossRef]
  46. Liu, Z.; Zhang, R.; Yang, C.; Hu, B.; Luo, X.; Li, Y.; Dong, C. Research on moisture content detection method during green tea processing based on machine vision and near-infrared spectroscopy technology. Spectrochim. Acta A Mol. Biomol. Spectrosc. 2022, 271, 120921. [Google Scholar] [CrossRef] [PubMed]
  47. Liu, J.; Chu, X.; Wang, Z.; Xu, Y.; Li, W.; Sun, Y. Optimization of characteristic wavelength variables of near infrared spectroscopy for detecting contents of cellulose and hemicellulose in corn stover. Spectrosc. Spectr. Anal. 2019, 39, 743–750. [Google Scholar]
  48. Buijs, K.; Choppin, G. Near-infrared studies of the structure of water. I. Pure Water. J. Chem. Phys. 1963, 39, 2035–2041. [Google Scholar] [CrossRef]
  49. Evangelista, C.; Basiricò, L.; Bernabucci, U. An overview on the use of near infrared spectroscopy (NIRS) on farms for the management of dairy cows. Agriculture 2021, 11, 296. [Google Scholar] [CrossRef]
  50. Zhang, Z.-T.; Li, Y.; Bai, L.; Chen, P.; Jiang, Y.; Qi, Y.; Guan, H.; Liang, Y.; Yuan, D.; Lu, T.; et al. Machine learning combined with multi-source data fusion for rapid quality assessment of yellow rice wine with different aging years. Microchem. J. 2024, 199, 110126. [Google Scholar] [CrossRef]
  51. Ma, W.; Liu, X.; Yue, C.; Wang, L.; Liang, S.Y. Multi-scale one-dimensional convolution tool wear monitoring based on multi-model fusion learning skills. J. Manuf. Syst. 2023, 70, 69–98. [Google Scholar] [CrossRef]
  52. Du, Y.; Liu, Y.; Peng, Z.; Jin, X. Gated attention fusion network for multimodal sentiment classification. Knowl.-Based Syst. 2022, 240, 108107. [Google Scholar] [CrossRef]
  53. Li, X.; Dunkin, F.; Dezert, J. Multi-source information fusion: Progress and future. Chin. J. Aeronaut. 2024, 37, 24–58. [Google Scholar] [CrossRef]
  54. Eslamifar, M.; Tavakoli, H.; Thiessen, E.; Kock, R.; Lausen, P.; Hartung, E. Low-Cost NIR Spectroscopy Versus NMR Spectroscopy for Liquid Manure Characterization. Sensors 2025, 25, 6745. [Google Scholar] [CrossRef]
  55. Tang, R.; Jiang, K.; Li, C.; Li, X.; Wu, J. Modeling to Correct the Effect of Soil Moisture for Predicting Soil Total Nitrogen by Near-Infrared Spectroscopy. Electronics 2023, 12, 1271. [Google Scholar] [CrossRef]
  56. Devianti, S.; Bulan, R.; Sitorus, A. Vis-NIR Spectra Combined with Machine Learning for Predicting Soil Nutrients in Cropland from Aceh Province, Indonesia. Case Stud. Chem. Environ. Eng. 2022, 6, 100268. [Google Scholar] [CrossRef]
Figure 1. Geographical distribution of manure slurry sampling sites in large-scale dairy farms in Tianjin, China (Different colors in the map are used for visual distinction among administrative districts in Tianjin and have no quantitative meaning).
Figure 1. Geographical distribution of manure slurry sampling sites in large-scale dairy farms in Tianjin, China (Different colors in the map are used for visual distinction among administrative districts in Tianjin and have no quantitative meaning).
Agriculture 16 00965 g001
Figure 2. Quantification strategy for sample-contextual information.
Figure 2. Quantification strategy for sample-contextual information.
Agriculture 16 00965 g002
Figure 3. Architecture of the MultiScaleSE-GatedCNN model.
Figure 3. Architecture of the MultiScaleSE-GatedCNN model.
Agriculture 16 00965 g003
Figure 4. Frequency distribution of TN.
Figure 4. Frequency distribution of TN.
Agriculture 16 00965 g004
Figure 5. Raw near-infrared spectral curves of manure slurry samples.
Figure 5. Raw near-infrared spectral curves of manure slurry samples.
Agriculture 16 00965 g005
Figure 6. Prediction scatter plots of the training set and test set for MultiScaleSE-GatedCNN under the optimal feature combination.
Figure 6. Prediction scatter plots of the training set and test set for MultiScaleSE-GatedCNN under the optimal feature combination.
Agriculture 16 00965 g006
Figure 7. Training and validation loss curves of MultiScaleSE-GatedCNN under the optimal feature combination.
Figure 7. Training and validation loss curves of MultiScaleSE-GatedCNN under the optimal feature combination.
Agriculture 16 00965 g007
Figure 8. Radar chart of TN prediction performance for single-source models, multi-source fusion models, and the MultiScaleSE-GatedCNN model. Note: For comprehensive comparison, RMSEP was direction-aligned before plotting so that, consistent with the other indicators, larger values indicate better performance, and all indicators were subsequently normalized.
Figure 8. Radar chart of TN prediction performance for single-source models, multi-source fusion models, and the MultiScaleSE-GatedCNN model. Note: For comprehensive comparison, RMSEP was direction-aligned before plotting so that, consistent with the other indicators, larger values indicate better performance, and all indicators were subsequently normalized.
Agriculture 16 00965 g008
Table 1. Structural configuration of the MultiScaleSE-GatedCNN model.
Table 1. Structural configuration of the MultiScaleSE-GatedCNN model.
ModuleComponentSetting
Spectral branchInputCARS-selected spectral variables
Multi-scale convolutionThree parallel 1D convolution branches
Kernel sizes3, 5, and 9
Output channels per branch16
Spectral fusionConv1d(48 → 64) → Conv1d(64 → 96)
Attention mechanismSE block
Spectral projectionGlobal average pooling +
Linear(96 → 64 → 32)
Numerical branchInputNumerical sample-contextual features
Fully connected layersLinear → 32 → Linear → 32
Categorical branchInputCategorical sample-contextual features
EmbeddingEmbedding dimension = 8 for each categorical variable
Fully connected layersLinear → 32 → Linear → 32
Fusion moduleFeature fusionGated fusion unit
Gate networkLinear(96 → 32) → Linear(32 → 3) + Softmax
Regression headOutput mappingLinear(96 → 64) → Linear(64 → 32) → Linear(32 → 1)
Table 2. Final training configuration of MultiScaleSE-GatedCNN.
Table 2. Final training configuration of MultiScaleSE-GatedCNN.
ItemValue
Train/test split8:2
Validation split within training set0.2
Maximum epochs160
Batch size16
Initial learning rate0.0008
Weight decay0.0005
Dropout ratio0.18
Huber loss parameter δ1.0
Gradient clipping threshold1.0
Evaluation intervalevery 5 epochs
Early stopping patience15
Table 3. Summary statistics of TN in manure slurry samples.
Table 3. Summary statistics of TN in manure slurry samples.
Physicochemical IndicatorSample SizeRange (mg/L)Mean ± Standard Deviation (mg/L)Coefficient of Variation (%)
Total nitrogen (TN)74714.160–5858.4101687.448 ± 1223.97372.534
Table 4. Performance of traditional machine learning models based only on spectral features.
Table 4. Performance of traditional machine learning models based only on spectral features.
ModelPreprocessing MethodRMSECRc2RMSEPRp2RPD
PLSRNone486.8120.846526.3230.8502.584
RFSG_1st216.710.968533.5510.8172.337
SVRSG_1st682.1870.686731.1660.6561.706
KNNSG_1st38.5490.999582.3870.7822.141
MLPSG_1st618.4420.742774.0530.6151.611
Note: SG_1st denotes Savitzky–Golay first-derivative preprocessing with polynomial order 2 and an adaptive odd window length selected from 15, 11, 9, 7, and 5 according to the number of retained spectral variables.
Table 5. Performance of traditional machine learning models under their optimal multi-source feature combinations.
Table 5. Performance of traditional machine learning models under their optimal multi-source feature combinations.
ModelPreprocessing MethodNumber of FeaturesSample-Contextual FeaturesRMSECRc2RMSEPRp2RPD
PLSRNone3Spectra + farm name + season474.9190.853526.2290.8512.585
RFSG_1st3Spectra + longitude + season194.9070.974475.8510.8542.621
SVRSG_1st2Spectra + season643.6870.720703.5200.6821.773
KNNSG_1st3Spectra + latitude + season35.5990.999522.3890.8252.387
MLPSG_1st3Spectra + farm name + season292.9770.942571.2340.7902.183
Table 6. Ablation results of different feature combinations for MultiScaleSE-GatedCNN, together with the normalized gate weights of the active branches.
Table 6. Ablation results of different feature combinations for MultiScaleSE-GatedCNN, together with the normalized gate weights of the active branches.
ModelNumber of Spectral Variables + Contextual FeaturesFeature CombinationRMSECRc2RMSEPRp2RPDNormalized Gate Weight of Spectral BranchNormalized Gate Weight of Numerical BranchNormalized Gate Weight of Categorical Branch
MultiScaleSE-GatedCNN258 + 4Spectra + farm name + longitude + latitude + season434.4090.875421.5760.8752.8250.4910.2250.284
MultiScaleSE-GatedCNN258 + 3Spectra + farm name + longitude + season381.7220.904367.3890.9053.2420.4940.2170.289
MultiScaleSE-GatedCNN258 + 3Spectra + farm name + latitude + season365.9350.912374.0070.9013.1850.5050.2150.280
MultiScaleSE-GatedCNN258 + 3Spectra + longitude + latitude + season481.0140.847497.0150.8262.3970.4800.2380.282
MultiScaleSE-GatedCNN258 + 2Spectra + farm name + season430.5940.878395.2220.8903.0140.610N/A0.390
MultiScaleSE-GatedCNN258 + 2Spectra + longitude + season488.4670.843524.5750.8062.2710.6020.2250.173
MultiScaleSE-GatedCNN258 + 2Spectra + latitude + season489.0020.842525.8610.8052.2650.5950.2310.174
MultiScaleSE-GatedCNN258 + 1Spectra + season517.6460.823535.9860.7982.2220.635N/A0.365
Note: In expressions such as “258 + 4”, the first number denotes the number of CARS-selected spectral variables, which was fixed across all ablation experiments, and the second number denotes the number of contextual feature types included in the corresponding combination, gate weights were normalized over the active branches within each feature combination. Inactive branches are marked as N/A; therefore, the displayed gate weights of the active branches sum to 1 within each row.
Table 7. Comparison of representative NIRS-based studies related to TN prediction.
Table 7. Comparison of representative NIRS-based studies related to TN prediction.
StudyMatrix/TargetnScopeModelMetric Summary
This studyManure slurry/TN74736 farmsMultiScaleSE-GatedCNNRp2 = 0.905, RMSEP = 367.389 mg/L, RPD = 3.242
[29]Dairy slurry/TN82833 farmsPLSRp2 = 0.85, RMSEP = 443.39 mg/L, RPD = 2.38
[54]Liquid manure/TN5113 farmsPLSRR2 = 0.66, RMSE = 0.70 g/kg, RPD = 1.68
[55]Soil/TN10713 farmsSST-PLSRRp2 = 0.81–0.82, RMSEP = 0.09–0.10 g/kg, RPD = 2.32–2.40
[56]Cropland soil/TN10210 regionsGBRT + EPOr = 0.925 *, RMSEP = 0.013 mg/kg, RPD = 2.635
Note: * r denotes the correlation coefficient reported in the cited study.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Liang, H.; Li, J.; Zhang, Q.; Liu, Z.; Han, B.; Lou, X.; Wang, N.; Lin, Y. Enhancing Near-Infrared Estimation of Total Nitrogen in Manure Slurry by Integrating Contextual Farm Information with MultiScaleSE-GatedCNN. Agriculture 2026, 16, 965. https://doi.org/10.3390/agriculture16090965

AMA Style

Liang H, Li J, Zhang Q, Liu Z, Han B, Lou X, Wang N, Lin Y. Enhancing Near-Infrared Estimation of Total Nitrogen in Manure Slurry by Integrating Contextual Farm Information with MultiScaleSE-GatedCNN. Agriculture. 2026; 16(9):965. https://doi.org/10.3390/agriculture16090965

Chicago/Turabian Style

Liang, Hao, Jinwu Li, Qiang Zhang, Ziyu Liu, Beihan Han, Xiongwei Lou, Nan Wang, and Yufei Lin. 2026. "Enhancing Near-Infrared Estimation of Total Nitrogen in Manure Slurry by Integrating Contextual Farm Information with MultiScaleSE-GatedCNN" Agriculture 16, no. 9: 965. https://doi.org/10.3390/agriculture16090965

APA Style

Liang, H., Li, J., Zhang, Q., Liu, Z., Han, B., Lou, X., Wang, N., & Lin, Y. (2026). Enhancing Near-Infrared Estimation of Total Nitrogen in Manure Slurry by Integrating Contextual Farm Information with MultiScaleSE-GatedCNN. Agriculture, 16(9), 965. https://doi.org/10.3390/agriculture16090965

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop