# Research on Innovative Apple Grading Technology Driven by Intelligent Vision and Machine Learning
## 2 Materials and Methods
### Apple Grading Model  
The integration of machine learning classification designs into smart agriculture is a promising area with several representative cases. Mainstream classification models include linear models, K-Nearest Neighbors (KNN) [28], Support Vector Machines (SVMs) [29], the Multi-Layer Perceptron (MLP) [30], and ensemble learning methods, such as Random Forests (RFs) [31], Bagging Classifiers (BCs) [32], and Gradient Boosted Decision Trees (GBDTs) [33]. Each of these models has unique advantages and limitations. Linear Models: They are simple and easy to interpret, making them widely used. However, they perform poorly on non-linearly separable data. Decision trees offer good interpretability but tend to overfit on low-dimensional data when used alone. Ensemble learning enhances overall model accuracy and stability by combining predictions from multiple models. Random forests and gradient boosting machines can capture complex patterns in data due to their construction of multiple tree models, providing robustness and generalizability. In an operational pipeline, rapidly and accurately determining the grade of apples is crucial. The performance of the apple grading model directly affects the grading accuracy. In this study, image processing techniques were utilized to extract three key features: the color ratio, diameter, and shape of apples. These features were used for grading labels, and a  
Figure 9: Distribution of apple quantities across different grades.  
dataset for apple grading was constructed. The GBDT algorithm was selected to develop an efficient apple grading model.  
GBDT is an ensemble learning algorithm that uses classification and regression trees (CARTs) as weak learners. For each new learner, the residuals from the current learners are used as labels for training the next learner. By fitting the negative gradient of the current model's loss function, it incrementally minimizes the loss through multiple rounds of iterative training. The result is a GBDT model with strong generalization capabilities. The input apple feature dataset is described by \(D=\big{\{}((x_{c},x_{d},x_{s})_{i},(y_{g})_{i}\big{)}\big{|}i=1,2,\cdots,N \big{\}}\), where \(x_{c}\) represents the color ratio feature, \(x_{d}\) represents the diameter feature, \(x_{s}\) represents the shape feature, and \(y_{g}\) represents the apple's grade. Since apple grading is a classification problem, the log-likelihood loss function was chosen to evaluate the model. The specific classification process is shown as Algorithm 2.  
```
Input: Apple feature data D. Output: Powerful learner \(\hat{f}(x)\).
1: Initialize \(f_{0}(x)=argmin_{\rho}\sum\limits_{n=1}^{N}L(y_{n},\rho)\) // Initialize the weak learner.
2: For m = 1 to M: (a) For i = 1, 2, 3, \(\ldots\), N compute // Calculate the negative gradient. \(r_{mi}=-\Big{[}\frac{\partial L(y_{i},f_{i}(x_{i}))}{\partial f(x_{i})}\Big{]} _{f(x)=f_{m-1}(x)},i=1,\cdots,N\) (b) The mth CART regression tree is constructed based on \(r_{mi}\) and \((x_{c},x_{d},x_{s})_{i}\) and the regions corresponding to its leaf nodes. \(R_{mj},j=1,2,\cdots,J\) (c) For j = 1, 2, 3, \(\ldots\), Jm compute // Calculate its best fit for leaf node regions. \(\rho_{mj}=argmin\sum\limits_{x_{i}\in R_{mj}}L(y_{i},f_{m-1}(x_{i})+\rho)\) (d) Update \(f_{m}(x)=f_{m-1}(x)+\sum\limits_{j=1}^{J}\rho_{mj}I(x\in R_{mj})\) // Progressively stronger weak learners.
3: Output \(\hat{f}(x)=f_{M}(x)=f_{0}(x)+\sum\limits_{m=1}^{M}\sum\limits_{j=1}^{J}\rho_{ jm}I(x\in R_{jm})\) // After M rounds of iterative training until the model converges, the strong learner is obtained.
```  
**Algorithm 2**GBDT