# Detection of Bovine Mastitis in Raw Milk, Using a Low-Cost NIR Spectrometer and k-NN Algorithm
## 4 Discussion  
High accuracies were achieved for both models, as shown in Table 2. According to [PERSON] [14], these models detect changes in milk constituents which are related to mastitis. For example, levels of protein, chloride and sodium tend to increase along with SCC, while the levels of potassium and lactose tend to decrease. In [PERSON] et al. [60], the authors reported a SEN of 90.3% and an SPC of 71.8% in the detection of SCC, with the laboratory manual test showing the best results. Comparing these results with those reported in this work, we can see that there is no significant difference in sensitivity, considering the intervals reported in this work, while the specificity is significantly increased. [PERSON] et al. [19] reported another direct calculation method based on NIR spectra by simply using a double threshold to determine the presence of SCC. This work reported 77.78% and 80.56% for SEN and SPC, respectively, by using a lab grade NIR spectrometer and a comparison with the SCC. These results are summarized in Table 3, together with the comparative results of the proposed method and the details of the different datasets. It may be highlighted that some of the relevant data are not available from the sources. Although [PERSON] et al. [26] argue that short range spectrometers (400-1000) are not good enough for accurate monitoring the composition of raw milk, this study has proved that udder health can be estimated using a low-cost spectrometer which operates in a range close to the aforementioned equipment, with similar results to those obtained using laboratory methods. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Performance Metric** & **Model 1: Positive—Negative** &
\begin{tabular}{c} **Model 2:** \\ **Clinical—Subclinical** \\ \end{tabular} \\ \hline
**Accuracy** & \(\overline{\kappa}=0.912\)\(\sigma=0.051\) & \(\overline{\kappa}=0.951\)\(\sigma=0.08\) \\
**Sensitivity** & \(\overline{\kappa}=0.858\)\(\sigma=0.129\) & \(\overline{\kappa}=0.95\)\(\sigma=0.158\) \\
**Specificity** & \(\overline{\kappa}=0.94\)\(\sigma=0.064\) & \(\overline{\kappa}=0.957\)\(\sigma=0.096\) \\
**Positive Predictive Value** & \(\overline{\kappa}=0.89\)\(\sigma=0.11\) & \(\overline{\kappa}=0.917\)\(\sigma=0.18\) \\
**Negative Predictive Value** & \(\overline{\kappa}=0.925\)\(\sigma=0.072\) & \(\overline{\kappa}=0.978\)\(\sigma=0.07\) \\
**F1 Score** & \(\overline{\kappa}=0.867\)\(\sigma=0.089\) & \(\overline{\kappa}=0.913\)\(\sigma=0.144\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Performance metrics of models on the test set, 10-fold nested cross-validation. Figure 5: Processed spectra and relevant bands: SNV for model 1 (**left**), detrend and Beer–Lambert for model 2 (**right**). **Author Contributions:** Conceptualization, I.R.-M. and D.R. ; methodology, E.F.-B. ; software, I.R.-M.; validation, I.R.-M., J.P. and L.A.; formal analysis, L.A.; investigation, L.A.; resources, J.P. and A.P. ; data curation, I.R.-M.; writing--original draft preparation, I.R.-M.; writing--review and editing, E.F.-B. ; visualization, D.R. ; supervision, A.P. ; project administration, J.P.; funding acquisition, J.P. and A.P. All authors have read and agreed to the published version of the manuscript. This work is part of DINTA-UTMACH and RNASA-UDC research groups. This work is partially supported by Instituto de Salud Carlos III, grant number PI17/01826. It was also partially supported by different grants and projects from the Xunta de Galicia [ED431D 2017/23; ED431D 2017/16; ED431G/01; ED431C 2018/49; IN845D-2020/03]. Another source of support was the CYTED network (PCI2018_093284) funded by the Spanish Ministry of Innovation and Science.