## 2 Materials and Methods
### Data Processing and Analysis Methods
#### 2.3.3 Classification Model Construction and Evaluation  
To evaluate the spectral classification capability across different levels of cumulative bruise damage in prunes, three widely used machine learning algorithms were applied:SVM, RF, and XGBoost. These three classifiers were chosen to represent distinct modeling paradigms: SVM for its strong performance in high-dimensional small-sample settings through margin maximization, RF for its ensemble-based robustness against overfitting, and XGBoost for its capacity to capture nonlinear interactions via gradient boosting. These algorithms are particularly suitable for nonlinear classification problems in high-dimensional datasets such as near-infrared spectra [33; 34].  
The dataset was partitioned into training and validation sets at a 70:30 ratio using the Kennard-Stone (KS) algorithm, which selects samples to maximize spectral diversity and ensure an even distribution [35]. All modeling procedures were conducted in Python 3.8, utilizing the scikit-learn and XGBoost libraries.  
SVM constructs an optimal separating hyperplane in the feature space and is known for its robustness in small-sample, high-dimensional classification tasks. In this study, the radial basis function (RBF) kernel was used to capture nonlinear relationships between spectral features and bruise categories [36].  
RF is an ensemble learning technique based on decision trees, where multiple classifiers are trained on bootstrapped data subsets and their outputs are aggregated. RF is particularly robust to noise and performs well with redundant or high-dimensional features [37].  
XGBoost, an enhanced gradient-boosting framework, sequentially builds decision trees and optimizes a regularized objective function to minimize overfitting. Due to its high computational efficiency and predictive accuracy, XGBoost has been widely adopted in agricultural spectral classification tasks [38].  
In this study, default or empirically chosen hyperparameter values were adopted for the SVM, RF, and XGBoost classifiers without performing exhaustive tuning. This decision was made to emphasize the feasibility and general effectiveness of spectral modeling strategies under a standardized pipeline. Further performance improvements could potentially be achieved through advanced hyperparameter optimization, which may be explored in future work.  
To further evaluate model robustness and mitigate sampling bias, five-fold cross validation was conducted within the training set during model development. The final model performance was evaluated on the independent 30% validation set. Specifically, the cross_val_score() function from scikit-learn was employed to compute the average classification accuracy across five folds for each classifier. This strategy complements the initial Kennard-Stone split and enhances the reliability of performance assessment.  
Model performance was assessed using four standard metrics: accuracy, defined as (TP + TN)/(TP + TN + FP + FN), indicating the proportion of correctly classified samples; precision, calculated as TP/(TP + FP), reflecting the proportion of correctly predicted positive cases; recall, computed as TP/(TP + FN), measuring the model's ability to detect true positives; and F1-score, given by 2 \(\times\) (Precision \(\times\) Recall)/(Precision + Recall), which balances precision and recall and is especially useful for imbalanced datasets. Here, TP, TN, FP, and FN represented true positives, true negatives, false positives, and false negatives, respectively.