## 7 Using Machine Learning for Grading Mangoes  
The internal quality of mango is a nonlinear function of features such as length, width, defect, and weight. The quality of mango is graded based on the local standard (VietGAP) or international standards (Global GAP), which are implemented easily to classify according to each feature, but it is difficult to grade the fruits with combination of different features. The relationship of features is found in several methods such as regression, statistical, and machine learning. In this paper, ML is proposed to grade the internal quality of mango, because of its strong ability in calculating and analyzing repeated problems. The papers [2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12] looked particularly closely at the application of supervised ML techniques to mango classification. Hence, in this study, four supervised learning algorithms such as _SVM_, _LDA_, _KNN_, and _RF_ are proposed for grading and sorting mango. The trained models are based on the sampling mango surveys in many orchards in Vietnam. In detail, the samples of mango are randomly selected, and then their types are determined (Figure 10) by evaluating standards accurately. Dataset is generated by manually grading mango based on density (\(D\)), volume (\(V\)), and defect (\(de\)). This manual grading is carried out by agricultural experts from Vietnam. The labeled types including \(G_{1}\), \(G_{2}\), and \(G_{3}\) of mangoes are measured by \(D\), \(V\), and \(de\) from four extracted features \(de\), \(we\), \(wi\), and \(le\). Instead of estimating density and volume to classify mango type, in automatic classification, four models namely \(RF\), \(LDA\), \(KNN\), and \(SVM\) are trained and evaluated by the labeled dataset obtained from the manual grading. The hardware and software of the sorting system were presented in Section 2 and the grading standard is shown in Table 1.  
The dataset is divided into three parts as training, validating, and testing data. The ten-fold Nested CV (\(NCV\)) [21] was used to separate data. In the outer layer, 10% of the original data was separated for testing data to determine the performance of models. The rest of the data was used to develop a model. The rest of the 90% of the original data was used in the inner layer for the tuning of parameters. Such data are separated into training data for the model to provide a prediction or quality assessment, the validation data are to evaluate the model's accuracy and select the best parameters of the model based on the given output objectively. This process not only provides the best performance for algorithms but also controls overfitting. The classification of mango is implemented by four steps including normalizing data, eliminating outliers, fitting models, model evaluation. During the data collection process, there are some data points outside the distribution of a statistical dataset called outliers, these points cause a significant error in the classification model. Thus, the dataset needs to be eliminated outliers to create a better new dataset. The outliers can be detected and removed based on the normalization method such as feature scaling, min-max, and z-score, etc. Depending on the purpose, one of the above methods can be used most flexible. The best method for mango data is the z-score [22] because the normalizations are based on the mean and variance of each variable. The data points are optimized in the distribution of the variables. Because of the features are on significantly different ranges, the feature with a larger scale dominates the predicted results of machine learning. By the z-score normalization, the effect of different features scales is avoided on prediction.