Next Article in Journal
Intelligent Fruit Localization and Grasping Method Based on YOLO VX Model and 3D Vision
Previous Article in Journal
Inversion of County-Level Farmland Soil Moisture Based on SHAP and Stacking Models
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Color-Sensitive Sensor Array Combined with Machine Learning for Non-Destructive Detection of AFB1 in Corn Silage

by
Daqian Wan
,
Haiqing Tian
*,
Lina Guo
,
Kai Zhao
,
Yang Yu
,
Xinglu Zheng
,
Haijun Li
and
Jianying Sun
College of Mechanical and Electrical Engineering, Inner Mongolia Agricultural University, Hohhot 010018, China
*
Author to whom correspondence should be addressed.
Agriculture 2025, 15(14), 1507; https://doi.org/10.3390/agriculture15141507
Submission received: 1 May 2025 / Revised: 3 July 2025 / Accepted: 11 July 2025 / Published: 13 July 2025
(This article belongs to the Section Agricultural Product Quality and Safety)

Abstract

Aflatoxin B1 (AFB1) contamination in corn silage poses significant risks to livestock and human health. This study developed a non-destructive detection method for AFB1 using color-sensitive arrays (CSAs). Twenty self-developed CSAs were employed to react with samples, with reflectance spectra collected using a portable spectrometer. Spectral data were optimized through seven preprocessing methods, including Standard Normal Variate (SNV), Multiplicative Scatter Correction (MSC), first-order derivative (1st D), second-order derivative (2nd D), wavelet denoising, and their combinations. Key variables were selected using five feature selection algorithms: Competitive Adaptive Reweighted Sampling (CARS), Principal Component Analysis (PCA), Random Forest (RF), Uninformative Variable Elimination (UVE), and eXtreme Gradient Boosting (XGBoost). Five machine learning models were constructed: Light Gradient Boosting Machine (LightGBM), XGBoost, Support Vector Regression (SVR), RF, and K-Nearest Neighbor (KNN). The results demonstrated significant AFB1-responsive characteristics in three dyes: (2,3,7,8,12,13,17,18-octaethylporphynato)chloromanganese(III) (Mn(OEP)Cl), Bromocresol Green, and Cresol Red. The combined 1st D-PCA-KNN model showed optimal prediction performance, with determination coefficient ( R p 2 = 0.87), root mean square error (RMSEP = 0.057), and relative prediction deviation (RPD = 2.773). This method provides an efficient solution for silage AFB1 monitoring.

1. Introduction

Silage corn feed, valued for its high nutritional content and superior storability, has emerged as a critical roughage source for ruminant livestock. However, suboptimal production practices—including inadequate compaction and improper sealing—can lead to fungal proliferation and mycotoxin biosynthesis [1,2]. Mold contamination in corn silage typically refers to the secondary fermentation triggered by exposure to air during feed retrieval, leading to the production of mycotoxins such as aflatoxins, zearalenone, and deoxynivalenol (vomitoxin). Among these, aflatoxin B1 (AFB1) is the most prevalent and toxic, recognized as one of the most potent naturally occurring carcinogens [3]. The ingestion of contaminated feed by livestock may compromise immune function, induce pathological conditions, and ultimately pose zoonotic risks through bioaccumulation in the food chain [4,5]. Current quality assessment protocols for silage corn feed primarily rely on organoleptic evaluation, with chemical and microbiological analyses serving as supplementary methodologies [6]. While sensory examination facilitates rapid quality determination through visual (moisture content, coloration) and olfactory indicators, this approach suffers from significant subjectivity. Chemical assays provide quantitative measurements of pH, organic acid profiles, and nutritional composition with enhanced precision, whereas microbiological testing evaluates populations of beneficial (e.g., Lactobacillus spp.) and pathogenic microorganisms (e.g., toxigenic molds). Nevertheless, these laboratory-based methods are constrained by protracted analysis timelines and substantial operational costs [7]. The predominant mycotoxins identified in silage corn include aflatoxin B1, deoxynivalenol (vomitoxin), and T-2 toxin—all exhibiting high toxicity thresholds. Conventional detection techniques such as enzyme-linked immunosorbent assay (ELISA) and high-performance liquid chromatography (HPLC), despite their respective advantages, present practical limitations including methodological complexity, elevated reagent costs, and time-intensive protocols [8]. Therefore, the development of a rapid, accurate, and scientific method for the detection of mycotoxins in corn silage feed has become a key issue to be solved.
Hyperspectral and near-infrared spectroscopy techniques have made significant progress in the field of mycotoxin detection in agricultural and sideline products [9]. Earlier studies [10] confirmed that this technique can effectively capture the molecular vibrational information of mycotoxins, laying the foundation for subsequent applications. Among the chemometric methods, the Partial Least Squares Regression (PLS) model was outstanding in the detection of fumonisin B1 in beans (R2 = 0.92) [11], while the detection error of aflatoxin B1 in rice could be controlled at 2.691 μg/kg by the Standard Normal Variate (SNV)-PLS combination [12]. A more in-depth study [13] developed an online corn mold monitoring system by fusing hyperspectral and computer vision. The application of machine learning algorithms further enhanced the detection performance, with Support Vector Machine (SVM) achieving an accuracy of 3.57 μg/kg in the detection of maize aflatoxin precursor Ver A [14], and the Uninformative Variable Elimination (UVE) algorithm enabling the peanut aflatoxin detection model to achieve R2 = 0.9577 [15]. Recent breakthroughs include the 95.7% classification accuracy of the Short-Wave Infrared (SWIR)-SVM combination for toxins in maize [16] and the 98.6% composite detection accuracy of the Random Forest algorithm for five toxin classes [17]. Existing studies have shown that short-wave hyperspectral [14] and spectral preprocessing [18] can significantly improve model stability, but the detection of complex structures such as Fusarium toxins is still challenging [17]. In the future, novel algorithms need to be developed, and a standardized framework needs to be established to optimize the detection performance.
The color-sensitive sensor technology generates RGB signals through the specific color responses of arrayed materials, which are combined with pattern recognition algorithms to achieve rapid detection of mycotoxins [19]. At the technical application level, the olfactory visualization system obtained 100% training set discrimination accuracy in wheat mold detection through the synergy of principal component dimensionality reduction and machine learning algorithms (e.g., SVM) [20]. Innovative applications of electronic nose technology have shown that its combination with lateral flow immunoassay can effectively identify aflatoxins (81% accuracy) and fumonisins (85% accuracy) in maize, and the multivariate discrimination model has a combined determination accuracy of 65% of the contamination status [21]. Leggieri et al. used an electronic nose system with artificial neural network (ANN) algorithms to achieve a high level of accuracy in the identification of aflatoxin B1 and fumonisins, with improved identification accuracy of 78% and 77%, respectively [22]. The latest technological breakthrough is reflected in the development of nanocomposite colorimetric sensor arrays, which have significantly improved the identification of AFB1/AFB2-producing strains through characteristic metabolite capture combined with Principal Component Analysis (PCA)/Linear Discriminant Analysis (LDA) modeling [23]. Existing studies have shown that the color-sensitive sensor technology has demonstrated good potential for application in the field of aflatoxin B1 (AFB1) detection, but the relevant studies for the specific substrate of corn silage feed are still relatively limited.
Different detection techniques present significant differences in technical characteristics in the field of mycotoxin detection. Andueza et al. [24] found that the calibration model established based on dried samples has significant limitations in silage applications, which suggests the importance of matrix specificity for the detection method. The nanoparticle-based colorimetric assay developed by Sheini [25] innovatively realizes the simultaneous detection of the three mycotoxins, and its high sensitivity and anti-interference properties provide a new solution for food and feed safety screening. In the comparison of spectroscopic techniques, Kim et al. [26] systematically showed that both fluorescence-QSVM and SWIR-LSVM combinations could achieve 95.7% detection accuracy at the 10 μg/kg threshold and maintain zero false negatives, and this performance was significantly better than the other combinations of techniques. The study of Deng [27], on the other hand, through the SVM model constructed by Particle Swarm Optimization (PSO)-Combined Moving Window (CMW) optimization algorithm, achieved high-precision quantitative detection of maize AFB1 (R2 = 0.9707), providing a feasible solution for field detection. With optimized machine learning algorithms, spectral technology attains sufficient detection accuracy to enable practical on-site feed analysis applications.
While researchers worldwide have successfully applied hyperspectral imaging, near-infrared spectroscopy, colorimetric sensors, and electronic nose technologies to mycotoxin detection in agricultural products (e.g., maize, wheat), studies on feedborne mycotoxins remain scarce. To address this gap, we developed a non-destructive detection method based on color-sensitive sensing technology for quantitative prediction of AFB1 content. The main work of this study is as follows: (1) Screening 20 color-sensitive dyes to prepare 4 × 5 sensor arrays. (2) After the reaction of the self-developed color-sensitive sensor arrays (CSAs) with silage samples, the Maya 2000 portable spectrometer was used to collect the spectral reflectance data of silage maize feed, and the values of aflatoxin B1 (AFB1) content of different samples were obtained by physicochemical tests. (3) For the spectral data of different chromatic sites, seven preprocessing methods—SNV, Multiplicative Scatter Correction (MSC), first-order derivative (1st D), second-order derivative (2nd D), wavelet denoising (WD), SNV+1st D, and MSC+WD—were used to determine the optimal preprocessing methods for different chromatic sites. (4) After the implementation of the seven preprocessing methods for the different chromogenic loci after reaction with silage samples, the prediction analysis of AFB1 content was carried out based on the three machine learning models—Support Vector Regression (SVR), Random Forest (RF), and K-Nearest Neighbor (KNN). Next, the model performance indexes were systematically evaluated (the coefficient of determination for the calibration set ( R c 2 ), root mean square error of calibration (RMSEC), prediction set coefficient of determination ( R p 2 ), root mean square error of prediction (RMSEP), and relative predictive deviation (RPD)). Finally, three dye components with significant specific response characteristics to AFB1 were screened out. (5) Two preprocessing methods, MSC and 1st D, were selected. After preprocessing, the features were screened by five algorithms: Competitive Adaptive Reweighted Sampling (CARS), PCA, RF, UVE, and eXtreme Gradient Boosting (XGBoost), and the optimal feature data were outputted by five algorithmic models: Light Gradient Boosting Machine (LightGBM), KNN, XGBoost, RF, and SVR. (6) The best combination of AFB1 toxin content prediction models was screened by comparing the R p 2 , RMSEP, and RPD as the main evaluation parameters.

2. Materials and Methods

2.1. Sample Acquisition

Inner Mongolia is rich in straw resources and has a lot of silage. This experiment took the silage corn feed from dairy farms in Inner Mongolia as the research object, and selected silage corn feed from seven dairy farms in Baotou City (latitude 40°15′~42°43′ N, longitude 109°15′~110°26′ E), Ulanqab City (latitude 40°29′~40°32′ N, longitude 112°28′~112°30′ E), and Hohhot City (39°58′~40°41′ N, 111°26′~112°18′ E). A total of five batches of silage maize feed were tested in two groups per batch, with each sample from the first two batches coming from a different farm, and the last three batches coming from the same farm in each batch. The corn silage at the farm was pit-stored in September 2023 after being chopped to 1–2 cm particle size, compacted to a density of ≥700 kg/m3 fresh matter, and sealed with oxygen-barrier film. The silage was unsealed in March 2024 following a 6-month fermentation period. The corn silage at the farm was pit-stored in September 2023 and unsealed in March 2024. The trial period was from April to July 2024. After the silage was delivered to the laboratory, it was divided into polyethylene boxes (approximately 4 kg per box, 2 boxes per sample) using the tetrad method [28], which ensures the stability of the samples by using polyethylene’s chemical inertness and lightness; the lids of the boxes were covered with a perforated aluminum foil to meet the needs of evaporation prevention and air permeability. Each batch was subjected to a 7-day aerobic exposure test (0D–6D), with 3 samples taken daily from each box (total of 6 samples/batch), divided into two portions for the color sensor response and two portions for the refrigerated retention samples. At the end of each batch (7 days), the refrigerated samples were removed for testing of AFB1 toxin levels. A total of 42 samples were prepared from each batch, for a total of 210 samples from the five batches for subsequent testing. The test and data analysis processes are shown in Figure 1.

2.2. Preparation of CSAs

Color-sensitive sensors achieve detection by producing color changes through the interaction of the materials with the target. After several rounds of comparison before the test, 11 metal porphyrins and their derivatives and 9 PH indicators—a total of 20 color-sensitive materials—were finally selected for this test. Information on these 20 color-sensitive materials is shown in Table 1.
The selected 11 metal porphyrins and their derivatives (8 mg each) were dissolved in 4 mL of dichloromethane, and 9 pH indicators (8 mg each) were dissolved in 4 mL of ethanol, all formulated into 2 mg/mL solutions. After ultrasonic treatment for 30 min, the solutions were stored in the dark for later use. Subsequently, within a fume hood, 0.1 μL capillaries were used to spot each of the 20 solutions onto C2 reversed-phase silica gel plates (4 cm × 5 cm), controlling the diameter of each colorimetric spot to be 3 mm, arranged in a 4 × 5 matrix. After drying the sensor for 15 min and allowing the colorimetric sensor array to stabilize, they were individually sealed in sample bags for future use.

2.3. Spectral Data Acquisition from Color-Sensitive Sensor Array

This study utilized a custom-built spectral acquisition system consisting of a computer, spectrometer, Y-type optical fiber, single-hole cold light source, and a self-made, door-opening dark box. The spectrometer used was the Maya2000Pro produced by Ocean Optics, with a spectral collection range from 200 nm to 1100 nm, a resolution of up to 0.035 nm, and an adjustable integration time from 17 ms to 10,000 ms. The light source was a single-hole halogen lamp. Spectral data acquisition was carried out using Ocean Optics’ Ocean View 2.0.16 software. For spectral data collection, 50 ± 0.1 g of silage corn feed samples were placed in a beaker with a diameter of 60 mm. The back side of the color-sensitive sensor array was fixed to the cling film using double-sided tape, ensuring its front faced the silage corn feed sample. The beaker was then sealed with cling film, allowing the silage corn feed to react with the color-sensitive sensor for 18 min. After the reaction, the spectral data of the color-sensitive sensor array was collected using the self-built spectral acquisition system. Before collection, the spectrometer and light source were preheated for 30 min at 34–38 °C to reach a stable state. The lights were turned off, and the curtains were drawn to ensure the room was in a dim state. The dark box was installed, and the color-sensitive sensor, which had reacted with the sample, was placed on the carrier platform. The fiber optic probe was fixed in position using a clamp, maintaining a constant height of 1.5 cm from the color-sensitive sensor, and the spectral data of the 20 dye points on the reacted color-sensitive sensor were collected sequentially.

2.4. Determination of AFB1 Content in Silage Corn Feed

According to the standards set by the Codex Alimentarius Commission (CAC), the limit for AFB1 in corn and its products is 20 μg/kg. This study, based on the standard GB/T 17480-2008 “Determination of Aflatoxin B1 in Feed—Enzyme Linked Immunosorbent Assay,” employed the enzyme-linked immunosorbent assay (ELISA) method using the Pribolab® ELISA test kit to determine the AFB1 content in 210 samples of silage corn feed prepared during the experiment. The limits of quantification (LOQ) were 1 μg/kg, and the detection limit (LOD) was 0.3 μg/kg. The microplate wells (12 strips × 8 wells) were placed in the ELX808 microplate reader (BioTek Instruments, Winooski, VT, USA) for absorbance measurement.
Before conducting the ELISA assay, a series of AFB1 standard solutions was prepared according to the instructions provided with the Pribolab® ELISA test kit. A stock solution of AFB1 was diluted with the appropriate diluent to obtain standard concentrations of 0, 0.5, 1, 2, 5, and 10 μg/kg. These standard solutions were used to generate a standard curve, which was used to calculate the AFB1 concentration in the corn silage samples.
Before the determination of AFB1 content, sample pretreatment was performed. Firstly, 2.50 ± 0.01 g of sample was accurately weighed using an electronic balance with an accuracy of 0.01 g, and placed in a 15 mL centrifuge tube for spare use. Then, the sample was transferred to a homogenizer preheated to 37 °C, and 20 mL of 60% methanol solution was added, and homogenization was carried out for 30–45 s until the sample was completely homogenized (a homogeneous green suspension was observed by the naked eye). In order to ensure that the sample was completely recovered, the probe and residues on the wall of the homogenizer were rinsed with 5 mL of methanol solution of the same concentration. In order to ensure the complete recovery of the sample, 5 mL of the same concentration of methanol solution was used to rinse the probe of the homogenizer and the residues on the wall of the tubes; the centrifuge tubes were sealed and placed in a constant temperature shaker at 25 ± 1 °C for 5 min to promote the full dissolution of the solutes; finally, the centrifuge was centrifuged at 4000 rpm for 5 min, and the supernatant was filtered through a Whatman No.1 filter paper and then collected in a 10 mL glass test tube. The AFB1 toxin assay was performed according to the ELISA method. Firstly, 200 μL of filtrate was mixed with 300 μL of diluent I to prepare the test solution, and the pH was adjusted to the range of 6.0–8.0, then 50 μL of the test solution, the enzyme marker and the antireagent were sequentially added to the plate equilibrated at room temperature for a 30-min room-temperature reaction, and then 300 μL of the wash solution was used to wash the plates for 3–4 times to remove the unbound material. After the reaction was completed, the reaction was repeated 3–4 times with 300 μL/well of washing solution to remove the unbound material, then 100 μL of color development solution was added to the plate to avoid light for 15 min, and the reaction was terminated by adding 50 μL of termination solution, and then the absorbance value was determined by using an enzyme marker that had been pre-warmed for 30 min, and the actual amount of AFB1 in the samples to be tested was calculated according to the standard curve.

2.5. Spectral Data Preprocessing

Due to the performance issues of the spectrometer or light source, resulting in large threshold ranges and unsmooth bands in the initial and final spectral bands, this study only selects the stable band of 450–1000 nm for analysis and modeling. The spectral range is concentrated in the visible and shortwave near-infrared bands, encompassing 1252 dimensions of information within this range. With a sample size of 210, an initial data matrix of (210, 1252) is formed. Initially, Z-score standardization is applied to the spectral matrix data to eliminate the dimensional differences between features and improve the performance and stability of the model. The formula for the Z-score calculation is as follows:
s k = s k μ δ
where s k represents the standardized data, s k represents the original data, μ represents the mean, and δ represents the standard deviation.
Locate the coordinates where the absolute value of the Z-score standardized values is greater than 3, and replace the values at these coordinates in the original data with the column mean. After modifying all outliers, complete the initial data cleaning process. Seven preprocessing methods commonly used for processing spectral data, SNV, MSC, 1st D, second-order derivative, wavelet denoising, SNV+1st D, MSC+wavelet denoising, were used to preprocess the 20 dye points, respectively, which included two combination methods. The preprocessed data were output through SVR, RF, and KNN3 models, respectively, which were used to filter out the best dye points.

2.6. Data Preprocessing, Feature Selection, and Model Establishment Algorithms

Due to the characteristics of the data in this experiment, which include a small sample size and high dimensionality, it is necessary to perform 5-fold cross-validation to compensate for the insufficiency of training data. In each iteration, 80% of the data is used for training and 20% for validation. The final performance is averaged, reducing the chance of random bias caused by a single data split and more reliably detecting whether the model is overfitting. For high-dimensional spectral data, this study adopts a data screening strategy to reduce the dimensionality in order to improve the model efficiency and prediction accuracy. In terms of algorithm selection, the principle of diversity is followed, covering different types of unsupervised learning and supervised learning, kernel methods and non-kernel methods, integrated models, and monolithic algorithms. By selecting a combination of algorithms with different principles, it is more conducive to finding the optimal modeling scheme. The following is a brief description of each of the five feature screening algorithms selected for this study.
CARS is a spectral feature wavelength selection method based on the Partial Least Squares Regression (PLS) model, with its core principle simulating a “survival of the fittest” competition mechanism. It employs an exponential decay function and adaptive reweighting techniques to progressively eliminate wavelength points with low information content, ultimately retaining the subset of features most strongly correlated with the target variable [29]. The advantages of this algorithm lie in its effectiveness in overcoming collinearity issues in high-dimensional spectral data, significantly enhancing the model’s prediction accuracy and robustness, while dynamically optimizing the wavelength selection process to balance computational efficiency with the reliability of feature selection.
UVE distinguishes informative variables from uninformative ones by introducing artificial noise variables as references and utilizing the stability analysis of regression coefficients (such as the mean/standard deviation ratio). It then sets thresholds based on the stability distribution of the noise variables to eliminate irrelevant features. The advantages lie in its efficiency in reducing the dimensionality of high-dimensional data like spectra, enhancing model computational efficiency and prediction accuracy, improving anti-interference capability through noise comparison, and enabling automated feature selection without prior knowledge. However, it is important to note the limitation that highly correlated variables may be mistakenly removed.
PCA is an unsupervised dimensionality reduction algorithm that projects high-dimensional data onto a lower-dimensional principal component space with the largest variance through orthogonal transformation. Its core principle involves performing eigenvalue decomposition on the data’s covariance matrix and retaining the top k eigenvectors with the highest cumulative contribution rate as new feature axes. The advantages of this algorithm lie in its effectiveness in eliminating data redundancy, reducing computational complexity, while maximally preserving the variability of the original information.
RF is a machine learning algorithm based on the integration of decision trees. Its core principle involves generating diverse training subsets through Bootstrap sampling and randomly selecting a subset of features for splitting during the construction of each tree, thereby enhancing the diversity of the model [30]. The algorithm performs classification prediction through a collective voting mechanism of multiple decision trees or conducts regression prediction by averaging, possessing an inherent resistance to overfitting. Its main advantages include the effective handling of high-dimensional data, strong robustness against outliers and missing values, and the ability to provide feature importance assessment. This algorithm is widely applicable to classification and regression tasks, but it also has limitations such as higher computational cost and the potential to generate overly complex tree structures in noisy data [31,32].
XGBoost, as an advanced gradient-boosted ensemble learning framework, constructs decision tree models through multiple rounds of iterations at its core. During the optimization process, it simultaneously considers first-order gradient information and second-order Hessian matrices, coupled with meticulously designed regularization terms to continuously enhance prediction accuracy. The algorithm innovatively implements a parallelized computing architecture and incorporates built-in feature importance evaluation capabilities, endowing it with significant advantages in engineering practice. XGBoost achieves efficient data processing through block storage and cache optimization, employs regularization constraints to prevent overfitting, and offers extensible interfaces that support custom loss functions and missing value handling.
This study selected five algorithms for model output. Among them, RF and XGBoost have already been introduced in the feature selection section, so they will not be repeated here. The other three algorithms are SVR, KNN, and LightGBM. Below is a brief introduction to these three algorithms.
SVR is a regression method based on the SVM framework. By introducing the ε-insensitive band and kernel function techniques, it maps the input space to a high-dimensional feature space for linear regression, achieving high-precision fitting of nonlinear relationships while ensuring the sparsity of the model solution [33]. Its core advantages lie in its strong robustness against outliers, effective handling of high-dimensional small sample data, and ensuring good generalization performance through structural risk minimization, making it particularly suitable for scenarios with high requirements for regression accuracy.
KNN is a type of instance-based supervised learning method. Its core principle involves calculating the distance metrics, such as Euclidean distance or Manhattan distance, between the target sample and the training samples in the feature space. It then selects the K nearest neighboring samples and uses a majority voting mechanism for classification prediction or calculates the mean for regression analysis [34]. As a representative of lazy learning algorithms, it does not require an explicit model training process and makes no prior assumptions about the data distribution. It has strong adaptability and naturally supports multi-class classification tasks. This method is particularly suitable for problem scenarios with distinct local feature patterns. However, its computational complexity grows linearly with the sample size, and it is relatively sensitive to high-dimensional data and imbalanced samples. In practical applications, it is necessary to carefully choose the value of K and the distance metric method.
LightGBM is an efficient machine learning framework based on gradient boosting decision trees. Its core principle involves the use of a histogram algorithm combined with a depth-limited Leaf-wise growth strategy to accelerate training, and it optimizes computational efficiency through one-sided gradient sampling and mutually exclusive feature bundling techniques. It has significant advantages, such as being more than ten times faster in training speed, low memory consumption, support for direct input of categorical features, efficient parallel computation, and maintaining high accuracy while handling large-scale data. However, it may be prone to overfitting on small sample datasets [35,36].

2.7. Quantitative Forecasting Model Evaluation Metrics

This study evaluates the quantitative prediction model through R c 2 , RMSEC, R p 2 , RMSEP, and RPD. The relevant calculation formulas are as follows:
R c 2 = 1 i = 1 n c ( y i y i ^ ) 2 i = 1 n c ( y i y c ¯ ) 2
where n c is the number of samples in the calibration set, y i ^ is the predicted value of the ith sample in the calibration set, y i is the measured value of the ith sample in the calibration set, and y c ¯ is the average of the measured values of all samples in the calibration set.
R M S E C = 1 n c i = 1 n c ( y i y i ^ ) 2
where n c is the number of samples in the calibration set, y i ^ is the predicted value of the ith sample in the calibration set, and y i is the measured value of the ith sample in the calibration set.
R p 2 = 1 i = 1 n p ( y i y i ^ ) 2 i = 1 n p ( y i y p ¯ ) 2
where n p is the number of samples in the prediction set, y i ^ is the predicted value of the ith sample in the prediction set, y i is the measured value of the ith sample in the prediction set, and y p ¯ is the average of the actual measured values of all samples in the prediction set.
R M S E P = 1 n p i = 1 n p ( y i y i ^ ) 2
where n p is the number of samples in the prediction set, y i ^ is the predicted value of the ith sample in the prediction set, and y i is the measured value of the ith sample in the prediction set.
R P D = S D R M S E P
where SD is the standard deviation of the prediction set, and the RMSEP is the root mean square error of the prediction set.
The model’s predictive capability is mainly evaluated using R p 2 , RMSEP, and RPD [37,38]. The closer the value is to 1, the higher the goodness of fit between the model’s predicted values and the actual observed values, and the lower the RMSEP value, indicating higher prediction accuracy. RPD reflects the generalization performance of the evaluation model on unknown data. If RPD < 1.5, the model cannot achieve sample prediction. When 1.5 ≤ RPD < 2.0, the model can perform a rough assessment of the samples; when 2.0 ≤ RPD < 3.0, the model can make excellent predictions on the samples.

3. Analysis of Test Results

3.1. AFB1 Content Analysis

By collecting samples from each batch for chemical testing, the AFB1 content of each sample was measured, and a heatmap illustrating the changes in AFB1 content was created as shown in Figure 2. In the figure, warm colors represent high concentrations, while cool colors indicate low concentrations.

3.2. Data Preprocessing and Selection of Optimal Dye Points

Due to the significant differences in toxin values among the five batches of samples and the uneven data distribution, randomly selecting test samples may not ensure that samples with different concentrations are included in the training, leading to poor training results. Therefore, the data sampling is first sorted by time period, with every 42 samples belonging to the same time period, dividing the samples into five time periods. Within each time period, stratified random sampling is conducted. The test set and prediction set are divided at a ratio of 4:1, totaling 210 samples, with 147 samples in the test set and 63 samples in the prediction set. At the same time, 5-fold CV cross-validation is carried out to compensate for the defect of having few samples.
Twenty dye points were preprocessed using seven methods: SNV, MSC, 1st D, 2nd D, WD, SNV+1st D, and MSC+WD. The original unprocessed data was used as a reference. After preprocessing, the data was analyzed using three models: SVR, RF, and KNN to generate outputs. The R c 2 , RMSEC, RMSEP, R p 2 and RPD for each preprocessing method were collected. The model outputs for filtering different dye points show significant differences in evaluation metrics, with the predictive performance of most dye points being significantly insufficient ( R p 2 < 0.5). Therefore, the 19th dye point, which performed the best, was selected for comparative analysis of indicators. Table 2 summarizes the AFB1 prediction indicators for the 19th dye point under seven preprocessing conditions, as output by the SVR, RF, and KNN models. The optimal preprocessing methods and indicator values under each model are shown in bold.
According to the data analysis in Table 2, the optimal preprocessing method for Dye 19 is MSC in both SVR and RF models, while 1st D preprocessing yields the best results in the KNN model. It is noteworthy that the KNN model exhibits the highest predictive performance on this dye point, with a determination coefficient R P 2 of 0.8662. In contrast, the 2nd D preprocessing method performs suboptimally across all models, possibly because it significantly amplifies high-frequency noise while eliminating baseline drift, leading to a reduced signal-to-noise ratio.
The study also found that the predictive performance of combined preprocessing algorithms did not outperform that of a single preprocessing method. This result indicates that, for this dataset, using a single preprocessing algorithm is sufficient to fully extract the key features of the data, while the combination algorithm not only increases computational complexity but may also introduce unnecessary noise or information redundancy. Based on the above analysis, and according to the evaluation index data of each dye point under different preprocessing algorithms, the optimal dye points corresponding to each algorithm model were selected. Dye points with an R P 2 greater than 0.6 and an RPD greater than 1.5 after each preprocessing method were prioritized, and a selection chart for the best dye points was drawn, as shown in Figure 3.
As shown in Figure 3, dye spots No. 11, No. 12, and No. 19 were ultimately selected as the best, corresponding to (2,3,7,8,12,13,17,18-octaethylporphynato)chloromanganese(III)(Mn(OEP)Cl), Bromocresol Green, and Cresol Red, respectively. One of these is a metal porphyrin derivative, and two are pH indicators. This indicates that these dyes exhibit excellent spectral response characteristics within a specific wavelength range, enabling more precise detection of minute changes in AFB1 concentration. The actual screening process for selecting the dye spots is depicted in Figure 4.
List the optimal pretreatment methods and R P 2 and RPD index values after the optimal dye points are output by SVR, RF, and KNN models, as shown in Table 3.
Analysis of the optimal preprocessing methods in Table 3 indicates that MSC is the most frequently used, appearing a total of five times, including four instances on its own and one instance within a combined preprocessing algorithm. The 1st D appears a total of two times, while SNV, WD, and MSC+WD each appear once. Notably, the preprocessing method corresponding to the maximum R P 2 value after the output of the SVR and RF models is MSC, and the preprocessing method corresponding to the maximum R P 2 value after the output of the KNN model is 1st D. This is because MSC processing not only eliminates physical interference but also retains the key chemical information of the samples [36]. After MSC preprocessing, the performance indicators are high, suggesting that the data processed by MSC more directly reflects the chemical composition differences of the samples, enabling the model to more accurately establish a quantitative relationship between the spectrum and the target properties. After preprocessing with the 1st D, the KNN model outputs the highest R P 2 value for dye No. 19, reaching 0.8662. Based on the above analysis, the subsequent feature selection and modeling will, respectively, adopt the MSC method, which appears most frequently, and the 1st D method, which has the highest R P 2 value.
The original spectra of dyes No. 11, No. 12, and No. 19 are shown in Figure 5. The spectra after 1st D processing are displayed in Figure 6, and the spectra after MSC preprocessing are shown in Figure 7. In all figures, the x-axis represents wavelength, and the y-axis represents reflectance.

3.3. Feature Selection Algorithms and Determination of the Optimal Model

Read the data of dye points 11, 12, and 19, and divide the test set and prediction set in a 4:1 ratio. The 210 samples are divided into five time periods, and stratified random sampling is carried out within each time period, while performing 5-fold cross-validation. The data is preprocessed with either MSC or 1st D, and then subjected to feature selection using five algorithms: CARS, PCA, RF, UVE, and XGBoost. The feature selection process uses GridSearchCV with 5-fold cross-validation for parameter search, with the R p 2 as the evaluation metric to select the optimal number of features and determine the best model parameters. The optimal feature data is then output through five algorithm models: LightGBM, KNN, XGBoost, RandomForest, and SVR. Statistics R p 2 , RMSEP, and RPD are used as the main evaluation parameters, and the optimal number of features is also output. The above algorithms and evaluation metrics are summarized in Table 4.
In order to increase the visualization effect and facilitate the comparison of evaluation indexes, the radar chart of different model output evaluation indexes under each feature screening is drawn, as shown in Figure 8, Figure 9, Figure 10, Figure 11, Figure 12, Figure 13, Figure 14, Figure 15, Figure 16 and Figure 17 below. The MSC preprocessing group and the 1st D of the two types of preprocessing groups are set out of the chart for comparison, respectively. In the chart, the longer the R P 2 and RPD lines, the better the model is, and the shorter the RMSEP line is, the better the model is.
Analyzing the results of the above figure, it can be seen that the feature screening results based on the CARS algorithm show that different spectral preprocessing methods have a significant impact on the selection of the optimal number of features. When MSC preprocessing is used, the optimal number of features determined by the system’s automatic optimization is 1001. Meanwhile, when 1st D preprocessing is used, the optimal number of features decreases to 218. It is worth noting that the increase in the number of features did not significantly improve the model prediction performance; on the contrary, the optimal prediction was obtained in the combination of the 1st D-CARS-KNN algorithm ( R P 2 = 0.866).
In the UVE feature screening algorithm, the system stably selects 187 optimal features regardless of the preprocessing method, showing strong consistency in feature selection. In contrast, the XGBoost algorithm selects the maximum number of features (1252) under all preprocessing conditions, while the feature selection results of the Random Forest (RF) algorithm show large fluctuations: 792 under the MSC preprocessing, increasing to 1122 under the 1st D preprocessing. It should be noted in particular that the performance of the prediction models constructed by all three algorithms (UVE, XGBoost, RF) did not reach the desired level ( R P 2 < 0.8).
The PCA dimensionality reduction analysis showed that 76 principal components were extracted by the MSC preprocessing and 67 principal components were extracted by the 1st D preprocessing. Under both preprocessing conditions, KNN was the optimal modeling method, with the 1st D-PCA-KNN combination achieving the best prediction ( R P 2 = 0.87). This result further validates the important impact of the synergy between feature selection methods, preprocessing techniques, and modeling algorithms on model performance.

4. Discussion

4.1. Performance Comparison of CARS-Based Feature Selection Under Stepwise Preprocessing Strategies

Experimental results indicate that the 1st D-CARS-KNN model achieves an R P 2 of 0.866. To investigate whether model performance could be further improved by applying dye-specific preprocessing followed by CARS-based feature selection, we systematically evaluated three dye datasets, each preprocessed with their respective optimal methods (determined via KNN performance) before CARS screening. While maintaining the automated parameter optimization mechanism of KNN, key performance metrics ( R P 2 , RMSEP, RPD) were analyzed with dynamically selected optimal feature numbers. Table 5 compares the model performance between stepwise-optimized preprocessing and uniform 1st D preprocessing under CARS feature selection.
Analysis of Table 5 reveals that when applying dye-specific optimal preprocessing methods, the CARS algorithm selected 779 optimal features (with the KNN optimal neighbor parameter adjusted to 5), significantly exceeding the 218 features obtained under uniform preprocessing. Notably, this approach resulted in degraded predictive performance (R = 0.695). The underlying mechanism may stem from dye-specific preprocessing inducing heterogeneous distributional shifts across datasets, which could obscure or distort the “globally significant wavelengths” identified by CARS, ultimately compromising prediction accuracy. This interaction between preprocessing and feature selection highlights a critical trade-off: while localized optimization enhances feature representation, it must be balanced against the need for global data consistency to maintain model robustness.

4.2. Performance Comparison of PCA-Based Feature Selection Under Stepwise Preprocessing Strategies

Experimental results show that the 1st D-PCA-KNN model achieved an R P 2 of 0.87, prompting examination of potential performance improvement through dye-specific preprocessing combined with PCA-based feature selection. As a linear dimensionality reduction method, PCA performs an orthogonal transformation to project data along maximal variance directions. Considering PCA’s mathematical constraints, two approaches were evaluated for processing three independently preprocessed dye datasets: Merge-then-PCA Screening (consolidating data before PCA reduction) and PCA-then-Merge Screening (applying PCA individually, then merging). Table 6 compares the model performance between the stepwise-optimized preprocessing with the Merge-then-PCA screening strategy and the uniform 1st D preprocessing method.
Table 6 demonstrates that when employing the Merge-then-PCA strategy, the optimal number of principal components decreased to 20 (with KNN neighbor parameter simultaneously optimized to 5), yet the predictive performance metrics deteriorated significantly. This indicates that while the method maintains spectral data continuity, it introduces non-negligible noise interference due to multi-source data merging, confirming the infeasibility of this approach. Shifting to analyze the PCA-then-Merge method, its advantage lies in preserving the spectral specificity of each dye, but it faces the technical challenge of inconsistent feature dimensions after dimensionality reduction. This leads to a critical methodological choice—whether to output datasets with unified dimensions or maintain independent dimensional structures. This study first verifies the feasibility of the unified dimension approach by enforcing all dye points to undergo dimensionality reduction using the same number of principal components, ensuring feature space consistency. Table 7 presents the model performance metrics of the stepwise-optimized preprocessing combined with the PCA-then-Merge strategy under unified dimensionality output.
Table 7 demonstrates a performance metric ( R P 2 = 0.809) that significantly surpasses the Merge-then-PCA approach, with optimized KNN parameters shifting to Euclidean distance metric (n_neighbors = 5), though still not exceeding the 1st D-PCA-KNN model’s predictive capability. Subsequent analysis examines independent dimensionality output performance, where zero-padding aligns datasets to the maximum principal component count among three dyes while preserving individual dimensionality characteristics, with Table 8 detailing each dye’s principal component numbers and corresponding model performance metrics under this independent dimensionality condition.
According to the data analysis in Table 8, it can be seen that when using PCA for screening, the predictive ability of independent dimensions is not as good as that of unified dimensions. The reason for this may be that under independent PCA, the individual dimensionality reduction for each dye point disrupts the global correlation of the spectral data, leading to the loss of collaborative features across dye points. It could also be that zero-filling introduces invalid dimensions, diluting the concentration of effective features.

4.3. Performance Comparison of KNN-Based Feature Importance Screening Under a Stepwise Preprocessing Strategy

Since KNN achieves the best predictive performance regardless of whether CARS or PCA is used for feature selection, this study examines whether KNN-based direct feature selection can further improve model performance metrics. The validation proceeds as follows:
First, all three dye datasets are preprocessed using the first-derivative transformation. Feature importance is evaluated via KNN distance, where the average KNN distance of each wavelength across samples is calculated and converted to a normalized importance score (0–1 range). An automated test selects features from 50 to full dimensionality, using cross-validated R2 as the criterion to dynamically determine the optimal number of top-N features.
The model optimization process utilizes 5-fold cross-validated GridSearchCV with R2 as the primary evaluation metric. Two distinct strategies are systematically compared for scenarios necessitating dye-specific preprocessing: the Filter-then-Merge approach, which independently selects features per dye dataset through permutation importance assessment (quantified by performance degradation following feature value randomization), retaining the top 20% of features with prioritized inclusion of both stable features (exhibiting cross-dye consistency) and local features (dye-specific high-importance wavelengths); and the Merge-then-Filter strategy, which initially consolidates all datasets prior to feature selection, preserving the globally optimal 20% of features based on consensus importance while strategically incorporating dye-specific critical wavelengths to mitigate potential information loss. Comprehensive performance metrics and optimized parameters for these two methodologies, along with the baseline KNN model, are quantitatively compared and presented in Table 9, thereby facilitating a rigorous evaluation of their respective predictive capabilities under varying preprocessing configurations.
Analysis of Table 9 reveals that the Merge-then-Filter approach achieves the highest predictive performance ( R P 2 = 0.812). In contrast, applying a unified first-derivative preprocessing yields an R P 2 of 0.796, demonstrating moderate predictive efficacy. The Filter-then-Merge method performs the worst, likely because merging data prior to screening preserves the global distribution characteristics across dye samples, mitigating local biases induced by individual preprocessing steps. Additionally, KNN’s distance-based mechanics benefit from merged data, as neighborhood calculations incorporate comprehensive spatial relationships. Premature screening in Filter-then-Merge may disrupt critical feature correlations, leading to erroneous neighborhood assessments.
The analysis demonstrates that predictive performance marginally surpasses uniform preprocessing only when employing KNN-based feature importance with dye-specific preprocessing followed by the Merge-then-Filter strategy. Notably, dye-specific preprocessing consistently underperforms uniform preprocessing across all feature selection methods (CARS or PCA). Specifically, Merge-then-Filter achieves superior results with KNN-driven screening, whereas Filter-then-Merge proves more effective for PCA-based screening.

5. Conclusions

This study employed a colorimetric sensor array combined with spectral analysis to verify the feasibility of quantitative detection of AFB1 in silage corn feed. Seven preprocessing methods were applied to the spectral data from different colorimetric points, and model performance parameters were compared using the SVR, RF, and KNN models. It was found that single preprocessing methods outperformed combined preprocessing methods, with the 1st D preprocessing method showing the best performance. Preprocessing analysis also successfully identified three dye components—Mn(OEP)Cl, Bromocresol Green, and Cresol Red—that exhibited significant specific responses to AFB1. By employing various typical machine learning algorithms for spectral data screening and modeling, and comparing different model evaluation metrics, it was discovered that the combination of CARS and PCA for feature selection with the KNN model output resulted in the smallest error in predicting AFB1 toxin content. The optimal model for predicting AFB1 toxin content was found to be 1st D-PCA-KNN, which can effectively and rapidly predict the AFB1 content in silage feed. This study systematically compared the strategies of unified preprocessing and stepwise optimization preprocessing for the first time, confirming that adopting the optimal preprocessing methods for different chromogenic sites and using KNN importance screening has improved the model performance parameters. It provides new methodological guidance for the fusion analysis of multi-source spectral data, filling the research gap in this field.
Currently, due to the spectral data collected directly from samples not being timely introduced into the analysis, the performance indicators of the model can be steadily improved in the later stage by increasing the number of training samples. In addition, if this research method is to be used for on-site detection, it is also necessary to study the stability and repeatability of colorimetric sensors. These are all directions that our team will strive to research in the future.

Author Contributions

Conceptualization, D.W., K.Z. and H.T.; methodology, D.W. and H.T.; soft-ware, D.W., K.Z. and L.G.; validation, H.T., K.Z. and Y.Y.; formal analysis, D.W. and J.S.; investigation, Y.Y., H.L. and X.Z.; resources, H.L. and X.Z.; data curation, D.W.; writing—original draft preparation, D.W. and H.T.; writing—review and editing, D.W., H.T. and K.Z.; visualization, D.W.; supervision, H.T.; project administration, H.T.; funding acquisition, H.T. All authors have read and agreed to the published version of the manuscript.

Funding

This work was supported by the National Natural Science Foundation of China [32071893] and the Natural Science Foundation of Inner Mongolia Autonomous Region [2023MS03044, 2024MS03019, and 2025MS03015].

Institutional Review Board Statement

Not applicable.

Data Availability Statement

The data provided in this study are available upon request from the corresponding author. The data are not publicly available due to privacy restrictions.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
CSAsColor-sensitive arrays
SNVStandard Normal Variate
MSCMultiplicative Scatter Correction
1st DFirst-order derivative
2nd DSecond-order derivative
SVRSupport Vector Regression
RFRandom Forest
KNNK-Nearest Neighbor
(Mn(OEP)Cl)(2,3,7,8,12,13,17,18-octaethylporphynato)chloromanganese(III)
CARSCompetitive Adaptive Reweighted Sampling
PCAPrincipal Component Analysis
UVEUninformative Variable Elimination
XGBoosteXtreme Gradient Boosting
LightGBMLight Gradient Boosting Machine
SVMSupport Vector Machine
ANNArtificial neural network
LDALinear Discriminant Analysis
AFB1Aflatoxin B1
SWIRShort-Wave Infrared
PSOParticle Swarm Optimization
CMWCombined Moving Window
WDWavelet denoising

References

  1. Keady, T.W.J.; Hanrahan, J.P. Effects of grass and maize silage feed value, offering soybean meal with maize silage, and concentrate feed level in late pregnancy, on ewe and lamb performance. Animal 2021, 15, 100068. [Google Scholar] [CrossRef] [PubMed]
  2. Pereira, C.S.; Cunha, S.C.; Fernandes, J.O. Prevalent Mycotoxins in Animal Feed: Occurrence and Analytical Methods. Toxins 2019, 11, 290. [Google Scholar] [CrossRef] [PubMed]
  3. Guo, L.; Tian, H.; Wan, D.; Yu, Y.; Zhao, K.; Zheng, X.; Li, H.; Sun, J. Detection of Aflatoxin B1 in Maize Silage Based on Hyperspectral Imaging Technology. Agriculture 2025, 15, 1023. [Google Scholar] [CrossRef]
  4. Luo, S.; Du, H.; Kebede, H.; Liu, Y.; Xing, F. Contamination status of major mycotoxins in agricultural product and food stuff in Europe. Food Control 2021, 127, 108120. [Google Scholar] [CrossRef]
  5. Li, Z.; Yang, C.; Lu, W.; Chu, Z.; Zhang, J.; Li, M.; Wang, Q. Ultrasensitive immuno-PCR for detecting aflatoxin B1 based on magnetic separation and barcode DNA. Food Control 2022, 138, 109028. [Google Scholar] [CrossRef]
  6. Liu, Y.; Huang, J.; Li, M.; Chen, Y.; Cui, Q.; Lu, C.; Wang, Y.; Li, L.; Xu, Z.; Zhong, Y.; et al. Rapid identification of the green tea geographical origin and processing month based on near-infrared hyperspectral imaging combined with chemometrics. Spectrochim. Acta Part A 2022, 267, 120537. [Google Scholar] [CrossRef]
  7. Tyska, D.; Mallmann, A.O.; Vidal, J.K.; de Almeida, C.A.A.; Gressler, L.T.; Mallmann, C.A.; Gupta, V. Multivariate method for prediction of fumonisins B1 and B2 and zearalenone in Brazilian maize using Near Infrared Spectroscopy (NIR). PLoS ONE 2021, 16, e0244957. [Google Scholar] [CrossRef]
  8. Correa, J.A.F.; Orso, P.B.; Bordin, K.; Hara, R.V.; Luciano, F.B. Toxicological effects of fumonisin B1 in combination with other Fusarium toxins. Food Chem. Toxicol. 2018, 121, 483–494. [Google Scholar] [CrossRef]
  9. Levasseur-Garcia, C. Updated Overview of Infrared Spectroscopy Methods for Detecting Mycotoxins on Cereals (Corn, Wheat, and Barley). Toxins 2018, 10, 38. [Google Scholar] [CrossRef]
  10. Wu, Q.; Xie, L.; Xu, H. Determination of toxigenic fungi and aflatoxins in nuts and dried fruits using imaging and spectroscopic techniques. Food Chem. 2018, 252, 228–242. [Google Scholar] [CrossRef]
  11. Acuna-Gutierrez, C.; Schock, S.; Jimenez, V.M.; Müller, J. Detecting fumonisin B1 in black beans (Phaseolus vulgaris L.) by near-infrared spectroscopy (NIRS). Food Control 2021, 130, 108335. [Google Scholar] [CrossRef]
  12. Shen, F.; Huang, Y.; Jiang, X.; Fang, Y.; Li, P.; Liu, Q.; Hu, Q.; Liu, X. On-line prediction of hazardous fungal contamination in stored maize by integrating Vis/NIR spectroscopy and computer vision. Spectrochim. Acta Part A Mol. Biomol. Spectrosc. 2020, 229, 118012. [Google Scholar] [CrossRef]
  13. Zheng, S.Y.; Wei, Z.S.; Li, S.; Zhang, S.J.; Xie, C.F.; Yao, D.S.; Liu, D.L. Near-infrared reflectance spectroscopy-based fast versicolorin A detection in maize for early aflatoxin warning and safety sorting. Food Chem. 2020, 332, 127419. [Google Scholar] [CrossRef]
  14. Putthang, R.; Sirisomboon, P.; Sirisomboon, C.D. Shortwave Near-Infrared Spectroscopy for Rapid Detection of Aflatoxin B1 Contamination in Polished Rice. J. Food Prot. 2019, 82, 796–803. [Google Scholar] [CrossRef] [PubMed]
  15. Li, Z.; Tang, X.; Shen, Z.; Yang, K.; Zhao, L.; Li, Y. Comprehensive comparison of multiple quantitative near-infrared spectroscopy models for Aspergillus flavus contamination detection in peanut. J. Sci. Food Agric. 2019, 99, 5671–5679. [Google Scholar] [CrossRef] [PubMed]
  16. Kim, Y.-K.; Baek, I.; Lee, K.-M.; Kim, G.; Kim, S.; Kim, S.-Y.; Chan, D.; Herrman, T.J.; Kim, N.; Kim, M.S. Rapid Detection of Single- and Co-Contaminant Aflatoxins and Fumonisins in Ground Maize Using Hyperspectral Imaging Techniques. Toxins 2023, 15, 472. [Google Scholar] [CrossRef] [PubMed]
  17. Ghilardelli, F.; Barbato, M.; Gallo, A. A Preliminary Study to Classify Corn Silage for High or Low Mycotoxin Contamination by Using near Infrared Spectroscopy. Toxins 2022, 14, 323. [Google Scholar] [CrossRef]
  18. Hetta, M.; Mussadiq, Z.; Wallsten, J.; Halling, M.; Swensson, C.; Geladi, P. Prediction of nutritive values, morphology and agronomic characteristics in forage maize using two applications of NIRS spectrometry. Acta Agric. Scand. Sect. B Soil Plant Sci. 2017, 67, 326–333. [Google Scholar] [CrossRef]
  19. Zhao, K.; Tian, H.; Ren, X.; Yu, Y.; Guo, L.; Li, Y.; Tao, Y.; Liu, F. Screening of key volatile compounds characterizing the deterioration of maize silage during aerobic exposure. Rev. Bras. Zootec. 2024, 53, e20230042. [Google Scholar] [CrossRef]
  20. Wang, J.; Jiang, H.; Chen, Q. High-precision recognition of wheat mildew degree based on colorimetric sensor technique combined with multivariate analysis. Microchem. J. 2021, 168, 106468. [Google Scholar] [CrossRef]
  21. Ottoboni, M.; Pinotti, L.; Tretola, M.; Giromini, C.; Fusi, E.; Rebucci, R.; Grillo, M.; Tassoni, L.; Foresta, S.; Gastaldello, S.; et al. Combining E-Nose and Lateral Flow Immunoassays (LFIAs) for Rapid Occurrence / Co-Occurrence Aflatoxin and Fumonisin Detection in Maize. Toxins 2018, 10, 416. [Google Scholar] [CrossRef]
  22. Leggieri, M.C.; Mazzoni, M.; Fodil, S.; Moschini, M.; Bertuzzi, T.; Prandini, A.; Battilani, P. An electronic nose supported by an artificial neural network for the rapid detection of aflatoxin B1 and fumonisins in maize. Food Control 2021, 123, 107722. [Google Scholar] [CrossRef]
  23. Chen, Z.; Lin, H.; Wang, F.; Adade, S.Y.-S.S.; Peng, T.; Chen, Q. Discrimination of toxigenic and non-toxigenic Aspergillus flavus in wheat based on nanocomposite colorimetric sensor array. Food Chem. 2024, 430, 137048. [Google Scholar] [CrossRef] [PubMed]
  24. Andueza, D.; Picard, F.; Martin-Rosset, W.; Aufrère, J. Near-Infrared Spectroscopy Calibrations Performed on Oven-Dried Green Forages for the Prediction of Chemical Composition and Nutritive Value of Preserved Forage for Ruminants. Appl. Spectrosc. 2016, 70, 1321–1327. [Google Scholar] [CrossRef]
  25. Sheini, A. Colorimetric aggregation assay based on array of gold and silver nanoparticles for simultaneous analysis of aflatoxins, ochratoxin and zearalenone by using chemometric analysis and paper based analytical devices. Microchim. Acta 2020, 187, 167. [Google Scholar] [CrossRef]
  26. Kim, Y.-K.; Baek, I.; Lee, K.-M.; Qin, J.; Kim, G.; Shin, B.K.; Chan, D.E.; Herrman, T.J.; Cho, S.-K.; Kim, M.S. Investigation of reflectance, fluorescence, and Raman hyperspectral imaging techniques for rapid detection of aflatoxins in ground maize. Food Control 2022, 132, 108479. [Google Scholar] [CrossRef]
  27. Deng, J.; Jiang, H.; Chen, Q. Characteristic wavelengths optimization improved the predictive performance of near-infrared spectroscopy models for determination of aflatoxin B1 in maize. J. Cereal Sci. 2022, 105, 103474. [Google Scholar] [CrossRef]
  28. Tharangani, R.; Yakun, C.; Zhao, L.; Ma, L.; Liu, H.; Su, S.; Shan, L.; Yang, Z.; Kononoff, P.; Weiss, W.P.; et al. Corn silage quality index: An index combining milk yield, silage nutritional and fermentation parameters. Anim. Feed. Sci. Technol. 2021, 273, 114817. [Google Scholar] [CrossRef]
  29. Ji, R.; Ma, S.; Yao, H.; Han, Y.; Yang, X.; Chen, R.; Yu, Y.; Wang, X.; Zhang, D.; Zhu, T.; et al. Multiple kinds of pesticide residue detection using fluorescence spectroscopy combined with partial least-squares models. Appl. Opt. 2020, 59, 1524–1528. [Google Scholar] [CrossRef]
  30. Qian, L.; Daren, L.; Qingliang, N.; Danfeng, H.; Liying, C. Non-destructive monitoring of netted muskmelon quality based on its external phenotype using Random Forest. PLoS ONE 2019, 14, e0221259. [Google Scholar] [CrossRef]
  31. Tan, K.; Ma, W.; Wu, F.; Du, Q. Random forest-based estimation of heavy metal concentration in agricultural soils with hyperspectral sensor data. Environ. Monit. Assess. 2019, 191, 446. [Google Scholar] [CrossRef] [PubMed]
  32. Pullanagari, R.R.; Kereszturi, G.; Yule, I. Integrating Airborne Hyperspectral, Topographic, and Soil Data for Estimating Pasture Quality Using Recursive Feature Elimination with Random Forest Regression. Remote Sens. 2018, 10, 1117. [Google Scholar] [CrossRef]
  33. Nie, J.; Wen, X.; Niu, X.; Chu, Y.; Chen, F.; Wang, W.; Zhang, D.; Hu, Z.; Xiao, J.; Guo, L. Identification of different colored plastics by laser-induced breakdown spectroscopy combined with neighborhood component analysis and support vector machine. Polym. Test. 2022, 112, 107624. [Google Scholar] [CrossRef]
  34. He, Q.P.; Wang, J. Fault detection using the k-nearest neighbor rule for semiconductor manufacturing processes. IEEE Trans. Semicond. Manuf. 2007, 20, 345–354. [Google Scholar] [CrossRef]
  35. Zhao, K.; Tian, H.; Zhang, J.; Wan, D.; Xiao, Z.; Zhuo, C. Adaptive fusion of visible-near infrared spectroscopy and colorimetric sensor array using the slime mold algorithm and stacking ensemble: Application in silage quality detection. Measurement 2025, 247, 116785. [Google Scholar] [CrossRef]
  36. Zhao, K.; Tian, H.; Zhang, J.; Guo, L.; Yu, Y.; Li, H. Adaptive modeling method integrating slime mould algorithm and cascade ensemble: Nondestructive detection of silage quality under VIS-NIRS. Comput. Electron. Agric. 2025, 234, 110247. [Google Scholar] [CrossRef]
  37. Zhang, Y.; Li, D.; Wang, X.; Lin, Y.; Zhang, Q.; Chen, X.; Yang, F. Fermentation quality and aerobic stability of mulberry silage prepared with lactic acid bacteria and propionic acid. Anim. Sci. J. 2019, 90, 513–522. [Google Scholar] [CrossRef]
  38. Xue, X.; Tian, H.; Zhao, K.; Yu, Y.; Zhuo, C.; Xiao, Z.; Wan, D. Non-Destructive Detection of pH Value During Secondary Fermentation of Maize Silage Using Colorimetric Sensor Array Combined with Hyperspectral Imaging Technology. Agronomy 2025, 15, 285. [Google Scholar] [CrossRef]
Figure 1. Flowchart of the main sample collection and data analysis steps.
Figure 1. Flowchart of the main sample collection and data analysis steps.
Agriculture 15 01507 g001
Figure 2. Trend of AFB1 content in silage corn feed.
Figure 2. Trend of AFB1 content in silage corn feed.
Agriculture 15 01507 g002
Figure 3. Excellent dye point screening chart.
Figure 3. Excellent dye point screening chart.
Agriculture 15 01507 g003
Figure 4. Schematic illustration of the screening process for selecting optimal dye spots.
Figure 4. Schematic illustration of the screening process for selecting optimal dye spots.
Agriculture 15 01507 g004
Figure 5. Original spectrograms of dyes 11, 12, and 19. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Figure 5. Original spectrograms of dyes 11, 12, and 19. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Agriculture 15 01507 g005
Figure 6. Spectra of dyes 11, 12, and 19 after 1st D preprocessing. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Figure 6. Spectra of dyes 11, 12, and 19 after 1st D preprocessing. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Agriculture 15 01507 g006
Figure 7. Spectra of dyes 11, 12, and 19 after MSC pretreatment. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Figure 7. Spectra of dyes 11, 12, and 19 after MSC pretreatment. Note: The chromatic gradient (deep purple→blue→cyan→yellow→deep red, Turbo colormap) encodes the sequential order of five sample batches (Batch 1–5, n = 210), with cooler hues (e.g., purple/blue) indicating earlier batches and warmer hues (e.g., yellow/red) later batches.
Agriculture 15 01507 g007
Figure 8. Comparison of multi-model output metrics after MSC preprocessed CARS feature screening.
Figure 8. Comparison of multi-model output metrics after MSC preprocessed CARS feature screening.
Agriculture 15 01507 g008
Figure 9. Comparison of multi-model output metrics after 1st D preprocessed CARS feature screening.
Figure 9. Comparison of multi-model output metrics after 1st D preprocessed CARS feature screening.
Agriculture 15 01507 g009
Figure 10. Comparison of multi-model output metrics after MSC preprocessed PCA feature screening.
Figure 10. Comparison of multi-model output metrics after MSC preprocessed PCA feature screening.
Agriculture 15 01507 g010
Figure 11. Comparison of multi-model output metrics after 1st D preprocessed PCA feature screening.
Figure 11. Comparison of multi-model output metrics after 1st D preprocessed PCA feature screening.
Agriculture 15 01507 g011
Figure 12. Comparison of multi-model output metrics after MSC preprocessed RF feature screening.
Figure 12. Comparison of multi-model output metrics after MSC preprocessed RF feature screening.
Agriculture 15 01507 g012
Figure 13. Comparison of multi-model output metrics after 1st D preprocessed RF feature screening.
Figure 13. Comparison of multi-model output metrics after 1st D preprocessed RF feature screening.
Agriculture 15 01507 g013
Figure 14. Comparison of multi-model output metrics after MSC preprocessed UVE feature screening.
Figure 14. Comparison of multi-model output metrics after MSC preprocessed UVE feature screening.
Agriculture 15 01507 g014
Figure 15. Comparison of multi-model output metrics after 1st D preprocessed UVE feature screening.
Figure 15. Comparison of multi-model output metrics after 1st D preprocessed UVE feature screening.
Agriculture 15 01507 g015
Figure 16. Comparison of multi-model output metrics after MSC preprocessed XGBoost feature screening.
Figure 16. Comparison of multi-model output metrics after MSC preprocessed XGBoost feature screening.
Agriculture 15 01507 g016
Figure 17. Comparison of multi-model output metrics after 1st D preprocessed XGBoost feature screening.
Figure 17. Comparison of multi-model output metrics after 1st D preprocessed XGBoost feature screening.
Agriculture 15 01507 g017
Table 1. Color-sensitive dyes required for making the color-sensitive sensor array.
Table 1. Color-sensitive dyes required for making the color-sensitive sensor array.
NumberName
12,3,7,8,12,13,17,18-Octaethyl-21H,23H-porphine
25,10,15,20-Tetrakis(4-methoxyphenyl)-21H,23H-porphine iron (III) chloride
35,10,15,20-Tetrakis(4-methoxyhenyl)-21H,23H-porphine
45,10,15,20-Tetrakis(4-methoxyhenyl)-21H,23H-porphine cobalt (II)
55,10,15,20-Tetraphenyl-21H,23H-porphine
65,10,15,20-Tetraphenyl-21H,23H-porphine zinc
75,10,15,20-Tetraphenyl-21H,23H-porphine copper (II)
85,10,15,20-Tetraphenyl-21H,23H-porphine
iron (III) chloride
95,10,15,20-Tetraphenyl-21H,23H-porphine manganese(III) chloride
105,10,15,20-Tetraphenyl-21H,23H-porphine palladium(II)
11(2,3,7,8,12,13,17,18-octaethylporphynato)chloromanganese(III)
12Bromocresol Green
13Bromothymol Blue
14Bromophenol blue
15Congo red
16Methyl Red—Ethanol
17Bromocresol Purple
18Neutral Red
19Cresol Red
20Bromothymol Blue
Table 2. Comparison of the performance of AFB1 content prediction models for dye point 19 under different spectral preprocessing methods.
Table 2. Comparison of the performance of AFB1 content prediction models for dye point 19 under different spectral preprocessing methods.
ModelPreprocessing MethodsCalibrationPrediction
R C 2 RMSEC R P 2 RMSEPRPD
SVRRaw Data0.85560.05470.73210.07661.9427
SNV0.90760.04360.76740.07122.0952
MSC0.90770.04350.76880.07102.1041
1st D0.89950.04550.63910.08861.6849
2nd D0.90000.04540.48470.10621.4013
WD0.82150.06080.71440.07901.8814
SNV+1st D0.89820.04570.68190.08321.7951
MSC+WD0.90700.04380.75310.07332.0413
RFRaw Data0.92870.03850.75800.07292.0329
SNV0.93680.03620.78040.06942.1339
MSC0.96690.02620.82170.06262.3682
1st D0.94610.03350.63610.08941.6577
2nd D0.88340.04920.36770.11781.2576
WD0.93030.03810.74400.07501.9763
SNV+1st D0.93940.03550.74300.07511.9724
MSC+WD0.94500.03380.78980.06792.1811
KNNRaw Data0.99930.02640.70100.07331.8289
SNV0.99930.02640.84250.05322.5197
MSC0.99930.02640.81030.05842.2962
1st D0.99930.02640.86620.04722.8420
2nd D0.99930.02640.68050.07581.7690
WD0.99930.02640.70140.07331.8300
SNV+1st D0.99930.02640.83260.05492.4441
MSC+WD0.99930.02640.80130.05982.2436
Note: SVR (Support Vector Regression), RF (Random Forest), KNN (K-Nearest Neighbor), SNV (Standard Normal Variate), MSC (Multiplicative Scatter Correction), 1st D (first-order derivative), 2nd D (second-order derivative), WD (wavelet denoising), R C 2 (the coefficient of determination for the calibration set), RMSEC (root mean square error of calibration), R P 2 (prediction set coefficient of determination), RMSEP (root mean square error of prediction), RPD (relative predictive deviation).
Table 3. Optimal preprocessing method and R P 2 and RPD metric values for the optimal dye point after three model outputs of SVR, RF, and KNN.
Table 3. Optimal preprocessing method and R P 2 and RPD metric values for the optimal dye point after three model outputs of SVR, RF, and KNN.
ModelDye PointMethod R P 2 RPD
SVR19MSC0.76882.1041
12MSC+WD0.68681.7880
11MSC0.66291.7256
RF19MSC0.82172.3682
12MSC0.67791.7621
11WD0.69711.8169
KNN191st D0.86622.8420
12SNV0.78392.1513
111st D0.76952.0827
Note: Abbreviations as defined in Table 2.
Table 4. Performance comparison of hybrid feature selection-modeling approaches under MSC and 1st D preprocessing.
Table 4. Performance comparison of hybrid feature selection-modeling approaches under MSC and 1st D preprocessing.
Feature Selection AlgorithmPreprocessing MethodsNumber of Best Features (Where PCA Refers to the Number of Principal ComponentsModel R P 2 RMSEPRPD
CARSMSC1001LightGBM0.760.0772.042
KNN0.7650.0772.063
XGBoost0.7340.0821.937
RF0.730.0821.923
SVR0.7180.0841.882
1st D218LightGBM0.7220.0831.896
KNN0.8660.0582.733
XGBoost0.710.0851.857
RF0.6980.0871.82
SVR0.6670.0911.733
PCAMSC76LightGBM0.7580.0782.031
KNN0.7820.0742.141
XGBoost0.6950.0871.812
RF0.7270.0831.915
SVR0.7210.0841.892
1st D67LightGBM0.6520.0931.696
KNN0.870.0572.773
XGBoost0.580.1021.544
RF0.5640.1041.515
SVR0.7060.0861.844
RFMSC792LightGBM0.7570.0782.029
KNN0.7790.0742.128
XGBoost0.7440.081.977
RF0.7180.0841.883
SVR0.6010.11.583
1st D1122LightGBM0.7190.0841.886
KNN0.7220.0831.895
XGBoost0.7230.0831.9
RF0.6830.0891.776
SVR0.6080.0991.597
UVEMSC187LightGBM0.6990.0871.822
KNN0.7470.081.986
XGBoost0.6920.0881.802
RF0.6960.0871.815
SVR0.6630.0921.723
1st D187LightGBM0.7440.081.978
KNN0.7560.0782.026
XGBoost0.7350.0811.944
RF0.70.0871.825
SVR0.6620.0921.721
XGBoostMSC1252LightGBM0.7610.0772.045
KNN0.7470.081.988
XGBoost0.7250.0831.908
RF0.7180.0841.884
SVR0.5910.1011.563
1st D1252LightGBM0.7280.0831.916
KNN0.6640.0921.726
XGBoost0.7250.0831.909
RF0.6880.0881.789
SVR0.6080.0991.598
Note: CARS (Competitive Adaptive Reweighted Sampling), PCA (Principal Component Analysis), UVE (Uninformative Variable Elimination), XGBoost (eXtreme Gradient Boosting), LightGBM (Light Gradient Boosting Machine). For other abbreviations, see Table 2.
Table 5. Performance comparison of CARS-based feature selection across diverse preprocessing strategies.
Table 5. Performance comparison of CARS-based feature selection across diverse preprocessing strategies.
ModelPreprocessing MethodsOptimal Number of Features R P 2 RMSEPRPDOptimal Parameters
CARS-KNN11, 19-1st D
12-SNV
7790.6950.0871.812metric = manhattan, n_neighbors = 5, weights = ‘uniform’
1st D2180.8660.0582.733metric = manhattan, n_neighbors = 3, weights = distance
Note: Abbreviations as defined in Table 2 and Table 4.
Table 6. Model performance comparison: stepwise optimized preprocessing with Merge-then-PCA screening vs. uniform 1st-D preprocessing.
Table 6. Model performance comparison: stepwise optimized preprocessing with Merge-then-PCA screening vs. uniform 1st-D preprocessing.
ModelPreprocessing MethodsBest Primary Score R P 2 RMSEPRPDOptimal Parameters
PCA-KNN11, 19-1st D
12-SNV
200.6570.0931.707metric = Manhattan, n_neighbors = 5, weights = distance
1st D670.870.0572.773metric = Manhattan, n_neighbors = 3, weights = distance
Note: Abbreviations as defined in Table 2 and Table 4.
Table 7. Performance metrics of stepwise-optimized preprocessing combined with PCA-then-Merge strategy under unified dimensionality output.
Table 7. Performance metrics of stepwise-optimized preprocessing combined with PCA-then-Merge strategy under unified dimensionality output.
Harmonization of Principal Components R P 2 RMSEPRPDOptimal Parameters
990.8060.0692.274metric: euclidean, n_neighbors: 5, weights: distance
Note: Abbreviations as defined in Table 2.
Table 8. Performance metrics of stepwise-optimized preprocessing with PCA-then-Merge strategy under independent dimensionality output.
Table 8. Performance metrics of stepwise-optimized preprocessing with PCA-then-Merge strategy under independent dimensionality output.
The Number of Principal Components for Dye 19The Number of Principal Components for Dye 12The Number of Principal Components for Dye 11Maximum Filling Dimension R P 2 RMSEPRPD
114991201200.7790.0742.131
Note: Abbreviations as defined in Table 2.
Table 9. Performance comparison of KNN-based feature selection across different preprocessing strategies.
Table 9. Performance comparison of KNN-based feature selection across different preprocessing strategies.
ModelPreprocessing MethodsData Processing MethodsOptimal Number of Features R P 2 RMSEPRPDOptimal Parameters
KNN-KNN1st D 2160.7960.0871.807Metric: manhattan,
n_neighbors: 3,
weights: distance
11, 19-1st D
12-SNV
Merge-then-Filter2510.8120.0682.306metric: manhattan,
n_neighbors: 3,
weights: distance
Filter-then-Merge960.7210.0831.893metric: manhattan,
n_neighbors: 3,
weights: distance
Note: Abbreviations as defined in Table 2.
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

Wan, D.; Tian, H.; Guo, L.; Zhao, K.; Yu, Y.; Zheng, X.; Li, H.; Sun, J. Color-Sensitive Sensor Array Combined with Machine Learning for Non-Destructive Detection of AFB1 in Corn Silage. Agriculture 2025, 15, 1507. https://doi.org/10.3390/agriculture15141507

AMA Style

Wan D, Tian H, Guo L, Zhao K, Yu Y, Zheng X, Li H, Sun J. Color-Sensitive Sensor Array Combined with Machine Learning for Non-Destructive Detection of AFB1 in Corn Silage. Agriculture. 2025; 15(14):1507. https://doi.org/10.3390/agriculture15141507

Chicago/Turabian Style

Wan, Daqian, Haiqing Tian, Lina Guo, Kai Zhao, Yang Yu, Xinglu Zheng, Haijun Li, and Jianying Sun. 2025. "Color-Sensitive Sensor Array Combined with Machine Learning for Non-Destructive Detection of AFB1 in Corn Silage" Agriculture 15, no. 14: 1507. https://doi.org/10.3390/agriculture15141507

APA Style

Wan, D., Tian, H., Guo, L., Zhao, K., Yu, Y., Zheng, X., Li, H., & Sun, J. (2025). Color-Sensitive Sensor Array Combined with Machine Learning for Non-Destructive Detection of AFB1 in Corn Silage. Agriculture, 15(14), 1507. https://doi.org/10.3390/agriculture15141507

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