Near-infrared prediction of tannin content in walnut kernels using wavelet transform combined with interpretable machine learning models - Xia, Qiuhao; Luo, Langqin; Yerzati, Yerhazi; Ahmed, Mian Muhammad; Chen, Yonghao; Wang, Shiwei; Qin, Jiangnan; Chen, Liping; Jin, Qiang; Guo, Zhongzhong; Zhang, Rui (Frontiers in Plant Science, 2026)
IntroductionTannin content is a key factor influencing the taste of walnuts and serves as an important index for evaluating walnut quality. Rapid and accurate detection of tannin levels in walnut kernels is therefore significant for quality assessment and management. This study aims to develop an efficient method for predicting tannin content in walnut kernels using near-infrared (NIR) spectroscopy combined with machine learning techniques.MethodsA total of 180 samples of ‘Wen 185’ walnut kernels were used as the research objects. The NIR reflectance spectra of the samples were measured within the range of 4000–10000 cm⁻¹. The spectral data were processed using mathematical transformations and continuous wavelet transform (CWT), both separately and in combination. Pearson correlation analysis was applied to extract characteristic bands related to tannin content. Based on these features, a random forest (RF) model was constructed to quantitatively predict tannin content. Additionally, the SHAP algorithm was employed to interpret and visualize the machine learning model.ResultsThe results indicated that within the spectral range of 4000–10000 cm⁻¹, the NIR reflectance of walnut kernels increased with tannin content under different orchard management modes. Both first-order differential transformation and CWT, as well as their combination, significantly enhanced the correlation between spectral data and tannin content. The combination of first-order differential transformation and CWT notably improved the model's prediction performance. The optimal prediction model was achieved using the feature lg’(1/R)_CWT_28, with training set metrics of R² = 0.880, RMSE = 1.188, RPD = 2.904, and validation set metrics of R² = 0.831, RMSE = 1.620, RPD = 2.459.DiscussionThe study demonstrates that combining mathematical transformations with wavelet transform can effectively improve the prediction accuracy of models for tannin content in walnut kernels. The RF model based on processed spectral data showed strong performance, indicating its potential for rapid and non-destructive tannin quantification. The use of SHAP algorithm further enhances model interpretability. These findings provide a valuable reference for the accurate prediction of tannin content in walnut kernels and may support quality control in walnut production and processing.