Particle Swarm Optimization and Multiple Stacked Generalizations to Detect Nitrogen and Organic-Matter in Organic-Fertilizer Using Vis-NIR

Organic fertilizer is a key component of agricultural sustainability and significantly contributes to the improvement of soil fertility. The values of nutrients such as organic matter and nitrogen in organic fertilizers positively affect plant growth and cause environmental problems when used in large amounts. Hence the importance of implementing fast detection of nitrogen (N) and organic matter (OM). This paper examines the feasibility of a framework that combined a particle swarm optimization (PSO) and two multiple stacked generalizations to determine the amount of nitrogen and organic matter in organic-fertilizer using visible near-infrared spectroscopy (Vis-NIR). The first multiple stacked generalizations for classification coupled with PSO (FSGC-PSO) were for feature selection purposes, while the second stacked generalizations for regression (SSGR) improved the detection of nitrogen and organic matter. The computation of root means square error (RMSE) and the coefficient of determination for calibration and prediction set (R2) was used to gauge the different models. The obtained FSGC-PSO subset combined with SSGR achieved significantly better prediction results than conventional methods such as Ridge, support vector machine (SVM), and partial least square (PLS) for both nitrogen (R2p = 0.9989, root mean square error of prediction (RMSEP) = 0.031 and limit of detection (LOD) = 2.97) and organic matter (R2p = 0.9972, RMSEP = 0.051 and LOD = 2.97). Therefore, our settled approach can be implemented as a promising way to monitor and evaluate the amount of N and OM in organic fertilizer.


Introduction
Organic fertilizers (biofertilizers) are biodegradable and environmentally friendly, which makes better nutrient sources. The amount of nitrogen (N) and organic matter (OM) in biofertilizers may directly affect the physical and chemical properties of soil and play a positive role in crop development [1]. However, many industrial or even homemade biofertilizers fail to meet nutritional requirements, posing environmental risks. A high level of nitrogen (N) can evaporate into the atmosphere and result in serious environmental issues such as ammonia (NH 3 ) and ozone (O 3 ), limiting our ability to breathe, limiting visibility, and affecting plant growth. At the same time, excessive use of organic matter (OM) can result in the release of chemicals that delay plant growth and may promote the development of some unwanted plants. Therefore, rapid, cost-effective, and reliable determination is needed to improve local agricultural production, sustainability, and environmental protection.
Visible near-infrared spectroscopy (Vis-NIR) is an alternative tool for determining N and OM in biofertilizers as it offers more and better advantages than standard chemistry methods. It is a non-invasive procedure with high penetration of radiation beams, suitable for inline use, and requires no (minimum) sample preparation. It has been widely used for food-quality assessment and in various fields, such as agriculture [2], medicine [3], and environmental uses [4]. The Vis-NIR technique is built on the connection between electromagnetic radiation and the material within the 350-2500 nm wavelength range.
In the visible part of the electromagnetic spectrum (400-700 nm), molecular electron transitions prevail, while in the near-infrared field (700-2500 nm), overtone and molecular vibration variations of the mid-infrared spectrum dominate. Different properties may be correlated with the absorbed radiation, providing qualitative and quantitative information [5]. The visible range resulting absorption spectrum is mainly related to OM or oxides [6] and iron in minerals. Usually, the obtained spectra have extensive absorption features and overlapping bands, making them challenging to interpret. Therefore, it is crucial to execute a feature selection process to automatically pick the significant feature subset and apply a robust chemometrics technique to predict the different properties [7].
Feature selection is the process of minimizing the number of features in a dataset and making the model as compact as possible. It could be divided into three methods: wrapper, embedded, and filter method [8,9]. Wrapper and embedded methods are more efficient than the filter method but are computationally more costly. However, it is challenging for all three strategies to find an optimal feature subset using the objective function. Various search meta-heuristics were proposed to resolve this problem, e.g., genetic algorithms (GA) [10,11], particle swarm (PSO) [12], and ant colony optimization (ACO) [13]. These techniques have been proven to solve challenging computational problems.
PSO has been used with many machine-learning techniques for feature selection [14,15]. Still, there is no study in combining multiple-stacked generalization and PSO for feature selection to the best of our knowledge. Furthermore, our approach to combining Vis-NIR data, PSO, and two multiple-stacked generalizations to determine N and OM can be considered a novel strategy.
Recently, there have been a number of low-quality biofertilizers on the market that exceed the nutrient value requirements. This issue could jeopardize the long-term viability of agriculture and the environment.
The main goal of this research was to prove that Vis-NIR can evaluate N and O.M. in biofertilizers. The specific objectives of this research were to: (1) propose a novel way for best subset selection using an ensemble method (first multiple stacked generalizations for classification, FSGC) and PSO; (2) improve the detection of N and OM through the construction of a second ensemble method for regression (SSGR), and (3) evaluate the performance with conventional techniques.

Samples
Nine varieties of commercial organic fertilizers from various companies in China were used to conduct this experiment. The different varieties of fertilizers were made of earthworm manure (variety 1), fungi (variety 2 and 5), fermented sheep manure (variety 3), a mix between sheep fat, chicken manure, grass charcoal, and bean cake (variety 4), black chicken fat (variety 6), biochar (variety 7), fulvic potassium acid and tobacco powder (variety 8) and rice straw for variety 9.
Each variety was composed of 30 samples, which led to a total of 270 samples. Sample preparation was not conducted to keep the experiment original and practicable. The true concentration of organic matter (OM) and nitrogen (N) was measured by inductively coupled plasma optical emission spectrometry (ICP-OES). Samples were first weighed into TFM vessels, and 5 mL of nitric acid (HNO 3 ) and 1 mL of hydrogen peroxide (H 2 O 2 ) were added. Second, microwave digestion (MARS 6, CEM, Mathews, VA, USA) was used to digest the solution. After digestion, the solutions were mounted in a volumetric flask and diluted with deionized distilled water (H 2 O). Finally, the concentration of N and OM was  Table 1.

Visible Near-Infrared Spectroscopy (Vis-NIR) Measurements and Preprocessing
The Vis-NIR spectra were measured in ambient light using an ASD (Analytical Spectral Devices) FieldSpec3 spectrometer over the reflective domain of 350-2500 nm. The radiation was estimated at 1.4 nm interludes for the 350-1000 nm spectral area and m intervals for the 1000-2500 nm wavelength range by a spectrometer. Finally, the reflectance output to users was resampled with ViewSpecPro (Version 6.20 Malvern Panalytical Ltd., Malvern, UK).
Biofertilizer samples were placed in a Petri dish and then smoothed with a ruler to homogenize the surface [16]. Furthermore, A 50 W halogen lamp was hung directly above each experimental Petri dish. The spectrometer was then calibrated with a Spectralon (Malvern Panalytical Ltd., Malvern, UK) white plate once every 15 measurements. Each soil sample was repeatedly measured three times. Finally, 810 spectra were obtained and preprocessed with the Savitzky-Golay smoothing filter introduced in 1964 [17]. Apart from this smoothing method, any other one has been conducted.

Construction of the Multiple Stacked Generalizations
Stacked generalization is a method of combining numerous models in order to perform a classification task [18,19]. In this work, several stacked layers have been generated by assigning the final estimator to the stacked generalization, and various models such as SVM, L.R., KNN, R.F., MLP, NB, and Ridge were used. The best parameter settings of each model were obtained after performing parameter tuning optimization using a grid search cross-validation five folds. After comparing the accuracy and the running time for all the classifiers, the best four models were chosen to form the FSGC model.

•
Support vector machine (SVM): this selects important instances to create a separating surface between data instances [20]. After performing a grid search, the obtained optimized learning parameters for SVM were C = 1, gamma = 0.01, kernel = rbf. • Logistic regression (L.R.): this is used to define variables and illustrate a relationship between one dependent variable and one or more independent variables [21]. After examining a wide collection of options using a grid search, the best parameter settings were C = 100, penalty = l2, solver = newton-cg. • K-nearest neighbor (KNN): this model is among the simplest of all ML methods, and it is used to define and for prediction. The best hyperparameters for this model were metric = Euclidean, n neighbors = 1, weights = uniform [22]. • Random forest (RF): this approach is better than a single decision tree since it eliminates over-fitting by averaging the answer. The optimized learning parameters of SVM were max_depth = 80, max_features = 2, min_samples_leaf = 3, min_samples_split = 10, n_estimators = 200 [23].

•
Multilayer perceptron (MLP): this is made of three layers of nodes that use a nonlinear activation function [24]. The best parameters for this model after running 5 folds were Ridge: this is a straightforward linear regression that applies a slight degree of bias to obtain a significant decrease in volatility. Using grid search cross-validation, it has been found that the best bias value is 0.1.

Feature Selection
When using wrapper methods for feature selection, the significant problems are selecting the model and selecting a proper set of parameters for the used model. These problems can be surpassed by choosing an adequate model and optimizing the parameters. Thus, this section presents a new wrapper method by combining multiple-stacked generalizations and a PSO algorithm. The proposed method was called PSO-FSGC and can be divided into the following steps:
The FSGC presented in Section 2.4 was used. Each model in FSGC was optimized by performing grid search hyperparameter tuning.

•
Step 2: Evaluate each particle in the swarm.
In this step, the stacked generalization created above was generated to find the feature subset corresponding to the particle position.

•
Step 3: Verification of the best values of swarm and particle.
The following two equations achieve the verification: With x pb correspond to the position of the particle that had the best fitness f and x sb is the best swarm.

•
Step 4: Update velocities of the movement in the search space.
The update must take into consideration the performance of the own particle and the swarm. The velocity is updated as follows: The term w is the inertia weight, and it controls the influence of the previous velocity in the new velocity. ∆t is the time step of each iteration. c 1 , c 2 are called cognitive and social components. The first tests the degree of self-confidence of a particle, while the second depends on the capacity of the swarm to identify better candidate solutions. q and r are uniform random numbers ∈ [0, 1].

•
Step 5: Update the position of the particle by using the logistic function of the velocity.
Thus, the particle position is calculated for each variable by: S v ij is the sigmoid function defined as: Step 6: Continue the iterative process.
Return to Step 2 if convergence or iteration limit is not achieved. There is a possibility that premature convergence arises if the velocity reaches a high value (5) and (6). In that case, we apply the reset swarm that could allow each particle to adjusts its position according to two values: its own best solution x pb and the swarm best solution x sb [26,27].

Model Evaluation and Software
The performances were estimated according to their predictions. Thus, the computation of root means square error of calibration set (RMSEC), root means square error of prediction set (RMSEP) and limit of detection (LOD) helped gauge the performance. Furthermore, to measure other variables' detectability, the coefficient of determination for calibration (R 2 c) and prediction (R 2 p) were computed. Generally, a good model should have high values of R 2 . The Savitzky-Golay smoothing was done with viewSpec software, the computation of the different algorithms was made using python with sci-kit-learn and PySwarms library, and Origin 2021 served to design the graph.

Spectra Analysis and Visualization
The average spectra of the nine varieties of biofertilizer samples were presented in Figure 1. Almost all the varieties have a similar profile curve. The loading density and particle size were attributed to the broad disparity of baseline shifts in the spectra. It can be observed that all the spectra show absorption at the range 1887−2200 nm. For variety 1, 3, 8, 9, peaks were observed at 1388-1549 nm, while three others peaks (844, 1733, and 2310 nm) were only observed for variety 9. T-distributed stochastic neighbor embedding (t-SNE) was used to map all the features into two-dimensional space to visualize the nine varieties of samples. The Vis-NIR datasets structure was preserved during the transformation, and it was seen that nine distinct clusters were formed ( Figure 2). The visualization of t-SNE further proved the probability of classifying different biofertilizers using the Vis-NIR technique.

Models for the Stacked Generalization
The choice of the models and their best parameters are essential when creating a stacked generalization. Several models such as SVM, R.F., NB, KNN, L.R., MLP, and Ridge were computed with grid search hyperparameter tuning. The sample was split using cross-validation five folds. The obtained results showed that SVM, KNN, L.R., MLP, and Ridge outperformed with an accuracy of 100% ( Figure 3). However, the running time comparison illustrated that MLP uses more time to be computed with 6.77 ns ± 0.00577 ns per loop, contrary to other models. (Figure 3). The comparison of both accuracy and time showed that SVM, KNN, L.R., and Ridge were suitable to be used as a model of the FSGC.

Models for the Stacked Generalization
The choice of the models and their best parameters are essential when creating a stacked generalization. Several models such as SVM, R.F., NB, KNN, L.R., MLP, and Ridge were computed with grid search hyperparameter tuning. The sample was split using cross-validation five folds. The obtained results showed that SVM, KNN, L.R., MLP, and Ridge outperformed with an accuracy of 100% ( Figure 3). However, the running time comparison illustrated that MLP uses more time to be computed with 6.77 ns ± 0.00577 ns per loop, contrary to other models. (Figure 3). The comparison of both accuracy and time showed that SVM, KNN, L.R., and Ridge were suitable to be used as a model of the FSGC.

Models for the Stacked Generalization
The choice of the models and their best parameters are essential wh stacked generalization. Several models such as SVM, R.F., NB, KNN, L.R., ML were computed with grid search hyperparameter tuning. The sample wa cross-validation five folds. The obtained results showed that SVM, KNN, L Ridge outperformed with an accuracy of 100% (Figure 3). However, the

Particle Swarm Optimization (PSO) Parameters Optimization
Besides the parameters of the classifier, the alpha value (constant weigh off classifier performance), the number of particles, and iteration also n attention. Thus, to obtain their best numbers, PSO was computed b possibilities. N and OM were simultaneously determined for each trial usi model, a simple model that can bear prediction with many outputs. comparison of R 2 and RMSE of the calibration set for all the different results a find the optimal values. The more the model is efficient, the more the parameter is optimal. An efficient model should have R 2 closer to 1 and RMS 0.
In this experiment, the optimal alpha value was determined after try values (Figure 4a). The values of iteration and particle value have been initial 50 as default values. For each given value of alpha, N and O.M. we simultaneously using the Ridge model. The lowest value of RMSEC and the h of R 2 C were found when alpha was initialized to 0.5 (Figure 4a). This point the optimal value of alpha.
The best particle value was obtained among five different values (Figur predicting N and O.M., the alpha value was set to the obtained optimal val the iteration value has remained constant. The result has shown that the best p was 50 as it has the lowest RMSEC and the highest R 2 C.

Particle Swarm Optimization (PSO) Parameters Optimization
Besides the parameters of the classifier, the alpha value (constant weight for trading off classifier performance), the number of particles, and iteration also needed more attention. Thus, to obtain their best numbers, PSO was computed by trying all possibilities. N and OM were simultaneously determined for each trial using the Ridge model, a simple model that can bear prediction with many outputs. Finally, the comparison of R 2 and RMSE of the calibration set for all the different results allowed us to find the optimal values. The more the model is efficient, the more the value of the parameter is optimal. An efficient model should have R 2 closer to 1 and RMSE value near 0.
In this experiment, the optimal alpha value was determined after trying different values (Figure 4a). The values of iteration and particle value have been initialized to 5 and 50 as default values. For each given value of alpha, N and O.M. were predicted simultaneously using the Ridge model. The lowest value of RMSEC and the highest value of R 2 c were found when alpha was initialized to 0.5 (Figure 4a). This point was used as the optimal value of alpha.

Prediction of Nitrogen (N) and Organic Matter (OM) Using Second Stacked Generalizations for Regression (SSGR)
The Ridge method was used during the whole process because it considers several outputs (multi-output regressor) and simultaneously predicts N and OM. However, in this step, a new multiple-stacked generalization model was built to improve the prediction results. Compared to the first stacked generalization (FSGC) used as the PSO classifier, the second multiple-stacked generalization was used for regression purposes (SSGR).
All models and parameters used to build FSGC were used for SSGR except LR, only applicable when the dependent variable is dichotomous (binary). Therefore, it has been replaced by MLP. The samples were scaled using the standardization method (strategy for scaling data in which the values are centered around the mean with a unit standard deviation) and split into 607 samples for the calibration set and 203 samples for the prediction set using cross-validation. To check the reliability of the model, it has been compared with traditional methods such as Ridge, support vector machine for regression (SVR), and partial least square (PLS). The SVR computation was undertaken using the best parameter obtained after the grid search. The PLS model was computed with different latent variables (Lv = 3, Lv = 6, and Lv = 9) using the entire dataset.  The best particle value was obtained among five different values (Figure 4b). Before predicting N and O.M., the alpha value was set to the obtained optimal value (0.5), and the iteration value has remained constant. The result has shown that the best particle value was 50 as it has the lowest RMSEC and the highest R 2 c.
Finally, different values of iteration were tried during the computation of PSO-FSGC. The results of the prediction of N and O.M. illustrated that the ideal iteration value is 10 as it has the minor values of RMSEC and the maximum value of R 2 c (Figure 4c).

Comparison between the Proposed Method with Lasso, Genetic Algorithm (GA), PSO-Support Vector Machine (SVM)
PSO-FSGC-Ridge, Lasso-Ridge, GA-Ridge, PSO-SVM-Ridge were computed to predict N and OM simultaneously. The best subset must have higher R 2 and lower RMSE for calibration and prediction set. PSO-FSGC has obtained excellent results for the calibration set R 2 c = 0.9923, RMSEC = 0.087 and for prediction set R 2 p = 0.9892, RMSEP = 0.1. Good prediction was also obtained using PSO-SVM and GA for both calibration (R 2 c = 0.9920, 0.9922 and RMSEC = 0.089, 0.088) and prediction set (R 2 p = 0.9986, 0.9890 and RMSEP = 0.103, 0.101). However, lasso has obtained slightly lower results compared to other previous techniques for both calibrations set (R 2 c = 0.9835, RMSEC = 0.128) and prediction set (R 2 p = 0.9767, and RMSEP = 0.148).
Overall, the PSO-FSGC method outperformed all three techniques and has been shown to be efficient for finding the best subset. Figure 5 displays the number of feature variables of each selection technique. deviation) and split into 607 samples for the calibration set and 203 samples for the prediction set using cross-validation. To check the reliability of the model, it has been compared with traditional methods such as Ridge, support vector machine for regression (SVR), and partial least square (PLS). The SVR computation was undertaken using the best parameter obtained after the grid search. The PLS model was computed with different latent variables (Lv = 3, Lv = 6, and Lv = 9) using the entire dataset.

Prediction of Nitrogen (N)
The results of the models for N with the selected bands obtained by PSO-FSGC are listed in Table 2. The best prediction for N was obtained when using the SSGR model for both calibrations set (R 2 c = 0. 9990, and RMSEC = 0.03) and prediction set (R 2 p = 0. 9989, and RMSEP = 0.031). Figure 6 shows the prediction error and the residuals plot of SSGR.

Prediction of Nitrogen (N) and Organic Matter (OM) Using Second Stacked Generalizations for Regression (SSGR)
The Ridge method was used during the whole process because it considers several outputs (multi-output regressor) and simultaneously predicts N and OM. However, in this step, a new multiple-stacked generalization model was built to improve the prediction results. Compared to the first stacked generalization (FSGC) used as the PSO classifier, the second multiple-stacked generalization was used for regression purposes (SSGR).
All models and parameters used to build FSGC were used for SSGR except LR, only applicable when the dependent variable is dichotomous (binary). Therefore, it has been replaced by MLP. The samples were scaled using the standardization method (strategy for scaling data in which the values are centered around the mean with a unit standard deviation) and split into 607 samples for the calibration set and 203 samples for the prediction set using cross-validation. To check the reliability of the model, it has been compared with traditional methods such as Ridge, support vector machine for regression (SVR), and partial least square (PLS). The SVR computation was undertaken using the best parameter obtained after the grid search. The PLS model was computed with different latent variables (Lv = 3, Lv = 6, and Lv = 9) using the entire dataset. The results of the models for N with the selected bands obtained by PSO-FSGC are listed in Table 2. The best prediction for N was obtained when using the SSGR model for both calibrations set (R 2 c = 0. 9990, and RMSEC = 0.03) and prediction set (R 2 p = 0. 9989, and RMSEP = 0.031). Figure 6 shows the prediction error and the residuals plot of SSGR. There is a strong correlation between the predictions and their true values (Figure 6a). Moreover, a fairly random, uniform distribution of the residuals against the target in two dimensions (Figure 6b) can be noticed. This seems to indicate that our model is performing well. Table 2. Prediction results of SSGR, Ridge, support vector machine for regression (SVR), and partial least square (PLS) for the determination of nitrogen (N) and organic matter (OM). There is a strong correlation between the predictions and their true values ( Figure 6a). Moreover, a fairly random, uniform distribution of the residuals against the target in two dimensions ( Figure 6b) can be noticed. This seems to indicate that our model is performing well.

Prediction of Organic Matter (OM)
The OM values predicted using the four models with the selected bands obtained through the computation of PSO-FSGC are shown in Table 2. Among these models, SSGR produced an excellent result for calibration (R 2 c = 0. 9973, and RMSEC = 0.050) and prediction (R 2 p = 0. 9972, and RMSEP = 0.051). As for the prediction of N, it can be seen in Figure 7a that the prediction error also showed a strong correlation between predicted and true value. Moreover, the distribution of their difference demonstrated the good performance of SSGR.

Prediction of Organic Matter (OM)
The OM values predicted using the four models with the selected bands obtained through the computation of PSO-FSGC are shown in Table 2. Among these models, SSGR produced an excellent result for calibration (R 2 c = 0. 9973, and RMSEC = 0.050) and prediction (R 2 p = 0. 9972, and RMSEP = 0.051). As for the prediction of N, it can be seen in Figure 7a that the prediction error also showed a strong correlation between predicted and true value. Moreover, the distribution of their difference demonstrated the good performance of SSGR.

Discussion
This study proposed a novel approach for predicting and evaluating the amount of organic matter (OM) and nitrogen (N) in organic fertilizer using Vis-NIR. However, the extensive features of the Vis-NIR spectra can make the prediction hard. Thus, to obtain the best subset, we created a new ensemble model (FSGC), which is used as the PSO classifier. The proposed approach outperformed other feature selection strategies such as PSO-SVM, GA, and Lasso in terms of prediction outcomes for both prediction and calibration sets. This success could be attributed to the constructed classifier, which is made by combining several models (Figure 3). Many previous studies have shown that good predictions could be obtained using GA or PSO-SVM [28][29][30]. In this case, despite the difference being barely noticed, PSO-FSGC outperformed PSO-SVM.

Discussion
This study proposed a novel approach for predicting and evaluating the amount of organic matter (OM) and nitrogen (N) in organic fertilizer using Vis-NIR. However, the extensive features of the Vis-NIR spectra can make the prediction hard. Thus, to obtain the best subset, we created a new ensemble model (FSGC), which is used as the PSO classifier. The proposed approach outperformed other feature selection strategies such as PSO-SVM, GA, and Lasso in terms of prediction outcomes for both prediction and calibration sets. This success could be attributed to the constructed classifier, which is made by combining several models (Figure 3). Many previous studies have shown that good predictions could be obtained using GA or PSO-SVM [28][29][30]. In this case, despite the difference being barely noticed, PSO-FSGC outperformed PSO-SVM.
High-ranking features are concentrated in the 400-600 nm, 900-1000 nm, 1400-1600 nm, and 1800-2300 nm ranges ( Figure 8). According to Reda et al. [31], the wavelength at 1400 nm could be associated with the vibration of OH and residual water in organic matter, while the spectrum field at 2130 nm could be related to a range of vibration forms, including a stretch of C-H, deformation of N-H, and the stretch combination C=O; N-H. In this experiment, the large part of PSO-FSGC selected variables were between 1400-1600 nm and 1800-2300 nm and, according to Leme et al. [32], the band 1386-1401 nm may contribute to the prediction of organic matter. Furthermore, the features from range 400-600 nm and 1800-2300 nm could contribute widely to the prediction of N, which has been demonstrated in [33].
However, although Lasso gave the smallest number of selected variables ( Figure 5), its prediction results were lower than the other three methods, which means that the number of variables chosen can affect the outcome. In other words, this finding could be explained by the fact that removing too many variables from the spectra can affect the prediction results.
Overall, the use of PSO-FSGA selected features is feasible to predict N and OM as it gives more insight into the spectral predictive mechanisms and can be suited for more efficient computation and storage [34].
This strong correlation could explain the robustness of our model to predict N and OM.
Finally, it could be seen that the points were overlapped with each other, which is due to the small number of varieties used in this experiment Although FSGC-PSO coupled with SSGR achieved excellent N and OM results, more samples with different varieties should be used in the future. Overall, Vis-NIR and the framework can play a crucial role in chemical components detection.  Four machine learning methods were combined with PSO-FSGC to predict OM and N. Based on R 2 and RMSE values, the SSGR achieved the highest performance in both calibration and prediction. At the same time, Ridge outperformed SVR and PLS slightly. The successful prediction performance of the SSGR might be the consequence of the ensemble models that were optimized with parameter tuning. It could also be the outcome of the proposed method (FSGC-PSO), which deleted some irrelevant features.
However, it could be noticed that the prediction results for N were barely more significant than the prediction results of OM. This result could be interpreted by the high number of features obtained from the 1800-2300 nm range, which contribute widely to N detection ( Figure 8).
The scatterplots of the predicted vs. true value and the residual plots illustrated in Figures 6 and 7 showed that the model performed well. A strong correlation between the prediction values (N and OM) and their actual values was observed in Figures 6a and 7a. This strong correlation could explain the robustness of our model to predict N and OM.
Finally, it could be seen that the points were overlapped with each other, which is due to the small number of varieties used in this experiment Although FSGC-PSO coupled with SSGR achieved excellent N and OM results, more samples with different varieties should be used in the future. Overall, Vis-NIR and the framework can play a crucial role in chemical components detection.

Conclusions
This study proposed a novel framework that combined a particle swarm optimization (PSO) and two multiple-stacked generalizations to determine the amount of organic matter (OM) and nitrogen (N) in organic fertilizer. The first multiple-stacked generalizations coupled with PSO (FSGC-PSO) were used to select the best features, while the second multiple-stacked generalizations (SSGR) improved the detection of N and OM. Compared to other feature selection approaches such as GA, Lasso, and PSO-SVM, PSO-FSGC was shown to be an effective method for finding the best subset. Meanwhile, the obtained FSGC-PSO subset combined with SSGR achieved more significant prediction results than conventional methods (Ridge, SVM, and PLS model) for the prediction of N (R 2 p = 0.9989, RMSEP = 0.031 and LOD = 2.97) and O.M. (R 2 p = 0.9972, RMSEP = 0.051 and LOD = 2.97). Therefore, this developed approach can be implemented as a promising way to determine N and O.M. in organic fertilizer, which has enormous benefits for rapid detection of chemical composition.