# Color Recognition of Transparent Plastic Based on Multi-Wavelength Transmission Spectrum
## 3 Results and Discussion
### Establishment and Validation of Color Recognition Model  
Naive Bayes model is one of the most widely used classification models in machine learning due to its simplicity, high efficiency and effectiveness [29; 30]. In this paper, a color recognition model was established by training the naive Bayes model using the labeled color features. The training and validation process of the model is as follows:  
Step 1, the 160 sets of color features were divided into a training set and validation set.  
Step 2, the prior probability of each color category \(P(C_{j})\) (\(j\) = 1, 2, 3, 4) was calculated using the labeled color features in the training set (Equation (5)).  
\[P(C_{j})=\frac{N_{C_{j}}}{N_{all}} \tag{5}\]  
where \(C_{j}\) (\(j\) = 1, 2, 3, 4) is the color category, which is colorless, light blue, light green and apple green in order. \(N_{C_{j}}\) is the number of color features belonging to the color category \(C_{j}\) in the training set and \(N_{all}\) is the total number of color features in the training set.  
Step 3, the conditional probabilities of the color parameters in each color category in the training set were calculated using Equation (6).  
\[P(\left.F^{(i)}\middle|C_{j}\right)=\frac{N_{F^{(i)}}}{N_{C_{j}}} \tag{6}\]  
where \(F^{(i)}\) (\(i\) = 1, 2, \(\ldots\), 12) is the color parameter in the color feature, which is \(\alpha BG_{\rm 381 mm}\), \(\alpha BG_{\rm 439 mm}\), \(\alpha BG_{\rm 620 mm}\), \(\alpha BG_{\rm white}\), \(\beta GR_{\rm 381 mm}\), \(\beta GR_{\rm 439 mm}\), \(\beta GR_{\rm 620 mm}\), \(\beta GR_{\rm white}\), \(\gamma RB_{\rm 381 mm}\), \(\gamma RB_{\rm 439 mm}\), \(\gamma RB_{\rm 620 mm}\) and \(\gamma RB_{\rm white}\) in order. Each color parameter possessed a conditional probability curve.  
Step 4, for a color feature \(F^{\prime}\) in the validation set, the posterior probability \(P(C_{j}\mid F^{\prime})\) of \(F^{\prime}\) belonging to the color category \(C_{j}\) (\(j\) = 1, 2, 3, 4) was calculated using Equations (7) and (8), and the color category with the largest posterior probability estimate value was the final category.  
\[P(C_{j}\middle|F^{\prime})=\frac{P(F^{\prime}\middle|C_{j})*P(C_{j})}{P(F^{ \prime})} \tag{7}\]  
\[P(F^{\prime}\middle|C_{j})=\prod_{i=1}^{n}P(F^{\prime(i)}\middle|C_{j}) \tag{8}\]  
where \(P(F^{\prime(i)}\mid C_{j})\) (\(i\) = 1, 2, 3, \(\ldots\), 12, \(j\) = 1, 2, 3, 4) is the conditional probability of the color parameter of color feature \(F^{\prime}\) in each color category, and it was calculated from the corresponding conditional probability curve obtained in step 3. \(P(C_{j})\) is the prior probability that was obtained in step 2. \(P(F^{\prime})\) is a constant, thus the largest posterior probability can be obtained by comparing the numerator of Equation (7) without calculating \(P(F^{\prime})\).  
A 10-fold cross validation was performed to evaluate the average recognition performance of the model, and the average confusion matrix is shown in Table 3, where colorless, light blue, light green and apple green transparent plastic are, respectively, labeled 1 to 4, and rows and columns represent actual and predicted values, respectively. It can be seen from the confusion matrix that the color recognition accuracy was 100%.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline  & \multicolumn{2}{c}{**Coefficient of Variation**} & \multicolumn{2}{c}{**Mean of Coefficient**} \\  & 381 nm & 439 nm & 620 nm & white & \\ \(BG\) & 0.095 & 0.073 & 0.021 & 0.054 & 0.061 \\ \(GR\) & 0.165 & 0.228 & 0.070 & 0.063 & 0.132 \\ \(RB\) & 0.185 & 0.267 & 0.080 & 0.060 & 0.148 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Coefficient of variation of the color parameters \(BG\), \(GR\) and \(RB\).