## 7 Using Machine Learning for Grading Mangoes
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Types**} & **Volume Range** & **Length Range** & **Width Range** & \multirow{2}{*}{**Defect (cm2)**} & **Density (g/mL)** \\  & **(mL)** & **(cm)** & **(cm)** & & \\ \hline G3 & 250–400 & 10–12 & 6–8 & \textgreater{}5 & \textless{}1 \\ G2 & 401–650 & 12.1–14 & 8–9 & 3–5 & 1–1.1 \\ G1 & 651–800 & 14.1–16 & 9–10 & 0–3 & \textgreater{}1.1 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Standard type mango. Figure 10: The process of classification system using machine learning. Using z-score normalization, four features are reshaped to be between \(-3\) and \(3\). Data points outside this range are eliminated from data. The effectiveness of data normalization and elimination of outliers to the performance of the four models is illustrated in the experiment section. The supervised ML models and implementation platforms suitable for the prediction of types of mango are determined by comparing prediction accuracies. Additionally, the optimized parameters of each model to fit the data of mango are discussed. Following analysis of the data to determine the relationship of variables, models are fitted into their parameters to achieve the most effective performance. In the previous studies, several classification models demonstrate the efficiency in grading mango as _SVM_[3; 5; 8], _LDA_[5; 6; 9], _RF_[10], and _KNN_[11]. Hence, in this paper, _SVM_, _LDA_, _RF_, and _KNN_ models are applied and compared to find the most accurate model in mango classification. The framework of the training process is shown in Figure 11, which includes six parts: Input, output, Random Forest (_RF_), K-Nearest Neighbors (_KNN_), Linear Discriminant Analysis (_LDA_), and Support Vector Machine (_SVM_). Model _RF_: in _RF_ model, training data consists of k subset randomly selected with replacement. Hence, the set of k subset is denoted \(B=\{b_{i}\): \(0<i\leq k\}\), where \(b_{i}\) is the \(i\)th subset. The predicted label is determined by majority vote method from k decision tree in _RF_. In training process, _RF_ model separates four features into nodes to lead the final decision node. Low correlation and reasonable strength of the trees are two criteria to improve the performance of _RF_[23]. Consulting many parameters of _RF_, two criteria can be achieved by the parameters such as the number of observations that are drawn for each tree (sample_size), splitting criteria in the nodes (splitting_rule), the number of trees in the forest (n_estimators), and the maximum depth of each tree (max_depth). In sample_size, decreased sampling size produces more separate trees and hence a lower correlation between the trees, which positively affects the accuracy of aggregated prediction from trees. However, the precision of individual trees decreases, as the training requires fewer observations. Therefore, Bootstrapping, which uses random samples with replacement to control the sample size of the trees. In splitting_rule, this is one of the main characterizing the RF. There are two rules, such as _Gini impurity_ or Entropy, but Gini impurity is the better option for this analysis, as _Gini_ can minimize misclassification and find the largest class while _Entropy_ finds class groups that account for about 50% of data. Hence, the computing time of _Gini impurity_ is faster than _Entropy_. Each tree in the forest is created by _Gini impurity_[24]. In the maximum depth of each tree and the number of trees in the forest, increasing max_deep and n_estimators lead to deeper trees and more trees, respectively thereby longer computation time. Nevertheless, the prediction  
Figure 11: Framework of training process based on models of Support Vector Machine (SVM), Linear Discriminant Analysis (LDA), Random Forest (RF), and K-Nearest Neighbors (KNN). efficiency grows up with their increase. Hence, the choice of max_deep and n_estimators can be seen as a trade-off between strength and the accuracy of the trees.