Non-Destructive Prediction of Fruit Ripeness and Firmness Using Hyperspectral Imaging and Lightweight Machine Learning Models
Organizations: The Maersk Mc-Kinney Moller Institute, SDU Centre for Industrial Software, University of Southern Denmark, Sønderborg, 6400, Denmark · Mads Clausen Institute, SDU NanoSyd, University of Southern Denmark, Sønderborg, 6400, Denmark
Abstract
Post-harvest fruit quality assessment is essential for reducing food waste, yet reliable non-destructive methods typically depend on expensive hyperspectral cameras and computationally intensive deep learning models. These systems typically require GPU resources, large-scale training data, and domain expertise, limiting their feasibility for many real-world agricultural settings. This study systematically evaluates 20 classical machine learning algorithms on hyperspectral imaging data for simultaneous ripeness classification and firmness prediction across five fruit species, using cross-validated experimental design with Bayesian hyperparameter optimization. Data preprocessing strategy, particularly class balancing and spectral transformations, contributes as much to prediction accuracy as algorithm choice. Our results show that tree-based machine learning models can outperform state-of-the-art deep earning models reported in Fruit-HSNet. Moreover, the findings indicate that only three visible-range wavelengths are needed to recover over 94% of full-spectrum accuracy, demonstrating that low-cost multispectral sensors combined with lightweight machine learning models can serve as practical alternatives to expensive hyperspectral cameras and complex deep learning approaches for practical fruit quality sorting.
Figures & tables
| Rk | Model | Family | P1 | P2 | P2 Config | P3 | P3 CI | P4 CV (%) | Time | Size |
|---|---|---|---|---|---|---|---|---|---|---|
| OA | OA | OA | [95%] | (s) | (MB) | |||||
| 1 | XGBoost | Boosting | 67.4 | 67.4 | SMOTE / No PCA | 65.6 | [57.0, 72.7] | 82.3 5.4 | 5.9 | 0.72 |
| 2 | HistGradientBoosting | Boosting | 65.2 | 68.1 | SMOTE / No PCA | 67.4 | [59.2, 74.6] | 82.2 5.4 | 4.6 | 5.05 |
| 3 | LGBM | Boosting | 68.1 | 69.2 | Strat. Resplit / No PCA | 69.2 | [61.4, 76.6] | 82.2 4.9 | 4.7 | 1.64 |
| 4 | ExtraTrees | Tree-based | 71.7 | 75.0 | Strat. Resplit / No PCA | 75.0 | [67.6, 81.8] | 82.2 4.7 | 0.2 | 2.77 |
| 5 | SVC_RBF | SVM | 56.2 | 57.6 | SMOTE / No PCA | 56.9 | [48.2, 64.5] | 81.1 4.0 | 0.6 | 5.16 |
| Rank | Model | Avg. Rank | Mean F1 | Family |
|---|---|---|---|---|
| 1 | ET | 3.7 | 0.792 0.077 | Tree-based |
| 2 | SVM-R | 4.7 | 0.787 0.077 | SVM |
| 3 | KNN | 5.4 | 0.771 0.061 | Other |
| 4 | GBC | 5.8 | 0.760 0.064 | Boosting |
| 5 | RF | 6.2 | 0.758 0.063 | Tree-based |
| 6 | LGBM | 6.2 | 0.755 0.049 | Boosting |
| Comparison | Summary | Effect | |
|---|---|---|---|
| Friedman (20 classifiers) | , | — | — |
| Nemenyi pairs ( =0.05) | 46 of 190 pairs differ | — | — |
| Firmness Ripeness | 19/20 models; mean gap 25.0 pp | 1.84 | Large |
| (IQR: 21.4–32.8 pp; exception: LDA) | |||
| HSI vs. RGB | Cohen’s from Phase 4 fold F1 | 1.17 | Large |
| HSI vs. VIS-3 | Phase 3 OA, 20 models; | 0.32 | Small |
| Balancing strategy | No PCA | PCA | (pp) |
|---|---|---|---|
| Stratified resplit † | 59.08 9.26 | 57.41 4.57 | +1.67 |
| SMOTE | 57.14 10.61 | 53.84 7.18 | +3.30 |
| Original unbalanced | 58.32 9.38 | 56.29 6.59 | +2.03 |
| Random oversampling | 57.01 9.85 | 58.12 4.47 | 1.11 |
| Random undersampling | 46.56 8.93 | 40.13 7.47 | +6.43 |
| Overall mean | 55.62 | 53.16 | +2.46 |
| Full-spectrum | Reduced-band OA | ||||||
|---|---|---|---|---|---|---|---|
| Rk | Model | RA | FA | OA | VIS-3 | RGB | OA |
| 1 | ExtraTrees | 63.0 | 87.0 | 75.0 | 71.0 | 72.1 | +2.9 |
| 2 | RandomForest | 60.9 | 86.2 | 73.6 | 67.8 | 71.4 | +2.2 |
| 3 | LGBM | 58.0 | 80.4 | 69.2 | 68.1 | 68.8 | +0.4 |
| 4 | HistGradBoosting | 54.3 | 80.4 | 67.4 | 67.4 | 69.9 | 2.5 |
| 5 | XGBoost | 52.2 | 79.0 | 65.6 | 68.5 | 68.5 | 2.9 |
| Fruit ( ) | ExtraTrees | RandomForest | LightGBM | HistGradBoosting | XGBoost |
|---|---|---|---|---|---|
| Avocado (170) | 67.9 | 65.4 | 44.4 | 48.1 | 38.3 |
| Kaki (68) | 41.7 | 41.7 | 33.3 | 41.7 | 41.7 |
| Kiwi (162) | 58.3 | 54.2 | 62.5 | 70.8 | 50.0 |
| Mango (68) | 66.7 | 75.0 | 41.7 | 66.7 | 50.0 |
| Papaya (51) | 33.3 | 33.3 | 33.3 | 33.3 | 44.4 |
| Task | Class | Precision | Recall | F1 |
|---|---|---|---|---|
| Ripeness | Overripe | 0.561 | 0.696 | 0.621 |
| Ripeness | Perfect | 0.569 | 0.638 | 0.602 |
| Ripeness | Unripe ∗ | 1.000 | 0.471 | 0.640 |
| Firmness group | Ripeness accuracy | |||
| Soft ( =27) | 0.741 | |||
| Medium ( =68) | 0.544 | |||
| Strategy | Data State | Ripe | Firm | OA | ET |
|---|---|---|---|---|---|
| Hard Voting | Original | 52.9 | 85.5 | 69.2 | -5.8 |
| Soft Voting | Original | 50.0 | 84.8 | 67.4 | -7.6 |
| Stacking | Original | 31.2 | 75.4 | 53.3 | -21.7 |
| Blending | Original | 49.3 | 72.5 | 60.9 | -14.1 |
| Hard Voting | Strat. Resplit | 57.2 | 84.1 | 70.7 | -4.3 |
| Soft Voting | Strat. Resplit | 58.0 | 83.3 | 70.7 | -4.3 |
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
| Abbr. | Model | HP | FI | Lib. | Optuna Search Space |
| ET | Extra Trees | 5 | ✓ | sklearn | n_est [50,500], depth [3,30], split [2,20], leaf [1,20], crit {gini,ent} |
| RF | Random Forest | 6 | ✓ | sklearn | n_est [50,500], depth [3,30], split [2,20], leaf [1,20], feat {sqrt,log2, }, crit {gini,ent} |
| DT | Decision Tree | 4 | ✓ | sklearn | depth [3,30], split [2,20], leaf [1,20], crit {gini,ent} |
| XGB | XGBoost | 9 | ✓ | xgboost | n_est [50,500], lr [.01,.3], depth [3,10], child_w [1,10], [0,1], sub [.5,1], col [.5,1], [0,1], [0,1] |
| LGBM | LightGBM | 8 | ✓ | lightgbm | n_est [50,500], lr [.01,.3], depth [3,15], leaves [10,300], child [5,100], [0,1], [0,1], col [.5,1] |
| GBC | Gradient Boosting | 5 | ✓ | sklearn | n_est [50,500], lr [.01,.3], depth [3,10], split [2,20], leaf [1,20] |
| Rk | Model | Best Hyperparameters |
|---|---|---|
| 1 | ExtraTrees | n_estimators=277, max_depth=14, min_samples_split=6, min_samples_leaf=1, criterion=gini |
| 2 | RandomForest | n_estimators=285, max_depth=10, min_samples_split=5, min_samples_leaf=2, max_features=log2, criterion=entropy |
| 3 | LGBM | n_estimators=470, learning_rate=0.2874, max_depth=14, num_leaves=10, min_child_samples=90, reg_alpha=0.2373, reg_lambda=0.4189, colsample_bytree=0.6112 |
| 4 | HistGradientBoosting | learning_rate=0.1795, max_iter=123, max_depth=5, min_samples_leaf=41, l2_regularization=0.5475 |
| 5 | XGBoost | n_estimators=400, learning_rate=0.1357, max_depth=10, min_child_weight=8, gamma=0.1722, subsample=0.7181, colsample_bytree=0.5824, reg_alpha=0.3973, reg_lambda=0.5746 |
| 6 | KNeighbors | n_neighbors=3, weights=distance, algorithm=ball_tree, p=1 |
| Component | Specification |
|---|---|
| Hardware | |
| Processor | Apple M4 (10-core CPU: 4 performance + 6 efficiency) |
| Memory | 24 GB unified LPDDR5X |
| Storage | SSD |
| GPU | None (CPU-only training) |
| Software Environment | |