Machine learning-based prediction of subclinical mastitis in large-scale dairy herds using a locally established somatic cell count threshold

preprint OA: closed CC-BY-4.0

Abstract

Abstract This study aims to establish a somatic cell count threshold to identify cows with subclinical mastitis (SCM) and to develop a machine learning model to predict the incidence of SCM using individual cow data, milk production data and composition data. Milk samples were collected from 2420 cows, for CMT, SCC determination and milk composition analysis. Information on individual cows and their milk production was obtained from farm records. The diagnostic SCC threshold was identified on the basis of CMT scores using the Youden’s index. Two sets of models; one with all the variables (M1) and another with five selected variables (M2) were trained. The SCC threshold yielding the highest Youden’s index was 353,000 cells/mL. For Model 1 (M1), CatBoost achieved the highest accuracy (74.5%) and precision (0.716), while naïve bayes attained the highest recall (0.780) and the decision tree produced the highest F1 score (0.662). CatBoost also recorded the highest AUC (0.801). Milk conductivity (mS/cm) consistently emerged as the most influential predictor across nearly all the algorithms. In Model 2 (M2), the overall performance decreased, with logistic regression achieving the highest accuracy (67.7%) and AUC (0.686), support vector machine demonstrating the highest precision (65.8%), and naïve bayes outperforming the others methods in terms of the recall and F1 score.
Full text 125,536 characters · extracted from preprint-html · click to expand
Machine learning-based prediction of subclinical mastitis in large-scale dairy herds using a locally established somatic cell count threshold | Research Square window.SnipcartSettings = { analytics: { enabled: false } }; (function() { var accessVector = localStorage.getItem('access_vector') || ''; window.dataLayer = window.dataLayer || []; if (accessVector) { window.dataLayer.push({ user: { profile: { profileInfo: { snid: accessVector } } } }); } })(); (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-K279D39R'); Browse Preprints In Review Journals COVID-19 Preprints AJE Video Bytes Research Tools Research Promotion AJE Professional Editing AJE Rubriq About Preprint Platform In Review Editorial Policies Our Team Advisory Board Help Center Sign In Submit a Preprint Cite Share Download PDF Article Machine learning-based prediction of subclinical mastitis in large-scale dairy herds using a locally established somatic cell count threshold R. M.C.O. Rathnayake, K. M. Devindi, M. P. Saiju, A. P. Ajitha, and 3 more This is a preprint; it has not been peer reviewed by a journal. https://doi.org/ 10.21203/rs.3.rs-7519712/v1 This work is licensed under a CC BY 4.0 License Status: Published Journal Publication published 28 Apr, 2026 Read the published version in Scientific Reports → Version 1 posted 11 You are reading this latest preprint version Abstract This study aims to establish a somatic cell count threshold to identify cows with subclinical mastitis (SCM) and to develop a machine learning model to predict the incidence of SCM using individual cow data, milk production data and composition data. Milk samples were collected from 2420 cows, for CMT, SCC determination and milk composition analysis. Information on individual cows and their milk production was obtained from farm records. The diagnostic SCC threshold was identified on the basis of CMT scores using the Youden’s index. Two sets of models; one with all the variables (M1) and another with five selected variables (M2) were trained. The SCC threshold yielding the highest Youden’s index was 353,000 cells/mL. For Model 1 (M1), CatBoost achieved the highest accuracy (74.5%) and precision (0.716), while naïve bayes attained the highest recall (0.780) and the decision tree produced the highest F1 score (0.662). CatBoost also recorded the highest AUC (0.801). Milk conductivity (mS/cm) consistently emerged as the most influential predictor across nearly all the algorithms. In Model 2 (M2), the overall performance decreased, with logistic regression achieving the highest accuracy (67.7%) and AUC (0.686), support vector machine demonstrating the highest precision (65.8%), and naïve bayes outperforming the others methods in terms of the recall and F1 score. Biological sciences/Computational biology and bioinformatics Health sciences/Diseases Subclinical mastitis threshold SCC ML models dairy cows Figures Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 Introduction Subclinical mastitis (SCM) is a significant production-related disease in dairy cows that is associated with decreased milk yield and diminished milk quality. SCM is characterized by elevated somatic cell counts (SCC) in milk; however, it presents without visible abnormalities in milk or the udder and without detectable clinical signs in cows. In addition to reduced milk production and quality, SCM leads to substantial economic losses due to increased treatment costs, additional labor, milk discarding following treatment, and premature culling 1 – 3 . In Sri Lanka, during the third quarter of 2023, mastitis cases were reported across all nine provinces of the country, totaling 3702 cases, a 6.7% increase compared with the same period in the previous year 4 . In response, the Department of Animal Production and Health (DAPH) has implemented a mastitis control program through veterinary investigation offices in each district, providing field and laboratory mastitis identification tests, microbial culture, isolation and antibiotic susceptibility testing. Early detection of SCM remains essential for effective mastitis control in the country. Establishing a threshold level for SCC is critical for distinguishing infected cows from uninfected cows. A SCC less than 100,000 cells/mL of milk is considered indicative of a healthy quarter 5 , whereas counts exceeding 200,000 cells/mL strongly suggest the presence of infection 6 – 7 . However, global studies have reported varying SCC threshold values for SCM identification 8 – 10 , and specific SCC threshold information applicable to Sri Lanka is lacking. In large Sri Lankan dairy herds, the SCC for individual cows is not recorded during milk collection. Instead, the California Mastitis Test (CMT), which is routinely conducted in these herds, provides an indirect estimate of the presence of somatic cells in milk. Thus, establishing a SCC threshold to identify SCM in Sri Lankan dairy cows is essential. Machine learning (ML), a branch of artificial intelligence, encompasses methods that allow machines (computers) to automatically perform tasks on the basis of data and experience without explicit programming. ML is often considered a valuable decision-support tool, especially in situations where conventional algorithms are challenging or infeasible to apply. Studies have shown that ML algorithms can effectively predict udder health status, aiding in decision-making for dairy farmers 11 . An example of an ML application in mastitis prediction is MasPA, an open-source software that uses the random forest algorithm to assess mastitis risk in cattle 12 . Different data sources have been utilized in developing ML models for SCM, including AMS (Automatic Milking Systems) sensor data 8 , 12 and SCC 11 . To date, no studies have investigated data relevant to the Sri Lankan context. Therefore, the present study aimed to establish an SCC threshold for identifying cows with SCM based on CMT scores and to develop a machine learning model that can predict the incidence of subclinical mastitis using the estimated SCC threshold. The model considers individual cow data, milk production, milk composition, and the SCC, which are tailored to the Sri Lankan dairy sector. Results Threshold somatic cell count Several threshold values between 353 000 and 550 000 cells/mL were associated with the highest Youden’s index of 0.81. To minimize the harmful consequences of false negative diagnoses, where SCM cases might go undetected, the threshold with the highest sensitivity within this range, 353 000 cells/mL was selected. This value ensures a greater likelihood of identifying cows positive for SCM while maintaining diagnostic accuracy. Considering the above threshold, the overall prevalence of SCM was 39.8% on the three farms studied. Model development Metrics, M I The performance of the evaluated ML models was assessed across multiple classification metrics, as presented in Fig. 1 . The highest accuracy was observed with the CatBoost model, with a value of 0.745, indicating that it correctly classified 74.5% of SCM cases, followed closely by XGBoost (74.1%), neural networks (NN) (72.5%), random forest (RF) (72.2%) and logistic regression (LR) and support vector machines (SVM) (71.1%). Naïve Bayes (NB) yielded the lowest accuracy (61.2%), indicating limited predictive power compared with the other models. The precision peaked at 0.716, reflecting the ability of the CatBoost model to minimize false positives. Significantly outperforming other models in this metric, the highest recall was recorded for the NB model at 0.780, showing its effectiveness in identifying actual positive instances. For the F1 score, which provides a harmonic mean of precision and recall, decision tree (DT) ranked the highest at 0.662, suggesting a well-rounded performance with gradual improvement over time. Among all the models evaluated, CatBoost exhibited the most consistent and well-rounded performance across all the metrics, particularly excelling in accuracy and precision while maintaining strong F1 scores. The NB model showed surprising strength in terms of the recall and F1 score despite its lower accuracy, whereas XGBoost demonstrated good performance in all categories. These results collectively indicate that CatBoost is likely the best overall model for this classification task, with NB and XGBoost serving as strong alternatives depending on which metric is prioritized. ROC curve analysis, M I The area under the curve (AUC) metric quantifies each model’s ability to distinguish between positive and negative classes at different classification thresholds and is useful when dealing with imbalanced datasets, where accuracy alone can be misleading. As shown in Fig. 2 , CatBoost demonstrated the highest AUC of 0.801, indicating superior discriminating ability in balancing true positive rates against false positive rates. XGBoost followed closely with an AUC of 0.797, confirming the strength of gradient boosting methods for this classification task. NB (AUC = 0.705) and K-nearest neighbors (KNN) (AUC = 0.712) demonstrated the lowest discriminative power among the evaluated models, with NB clearly underperforming relative to the other approaches. The curves visually confirmed these rankings, with CatBoost and XGBoost consistently achieving higher true positive rates while maintaining lower false positive rates across most threshold values. Overall, ensemble methods (particularly boosting algorithms) emerged as the most effective approaches for this classification task, with CatBoost providing the optimal balance of sensitivity and specificity. Feature Importance, M 1 On the basis of all the ML models analyzed, conductivity (mS/cm) consistently emerged as the most significant predictor for the detection of SCM (Fig. 3 ). This finding was particularly pronounced in all the models, where conductivity demonstrated substantially higher importance scores than the other features did. The second most important feature varied between the models but generally included lactation number (Lac. No.), milk production metrics such as test-day milk yield (Testday MY), and composition parameters such as fat and density. The KNN model uniquely prioritized Lac. No. is its primary feature, suggesting that different algorithms may identify complementary indicators of infection. Notably, breed-related features consistently demonstrated minimal importance across all the models. The ensemble methods (RF, XGBoost and CatBoost) showed more balanced feature importance distributions than single models such as DT and SVM did, suggesting that they leveraged multiple indicators more effectively. Metrics, M 2 The performance of the M2 models was evaluated across multiple classification metrics similar to those of M1 (Fig. 4 ). The accuracy across the models ranged from 0.596–0.677, with the LR model achieving the highest accuracy of 67.7%, followed by NB at 67.1% and NN at 66.7%. In terms of precision, which quantifies the proportion of true positive predictions among all positive predictions, the SVM performed best at 65.8%, closely followed by the NN at 65.6% and the LR at 65.5%. These similar values indicate comparable effectiveness in minimizing false positives across these three models. Recall the model’s ability to identify actual positive instances, ranging from 0.340 to 0.545, with the NB model clearly outperforming others at 54.5%. This represents a significant advantage in capturing positive cases, although all the models showed relatively low recall overall. The F1 score peaked at 0.569 with the NB model, followed by DT at 0.535. Overall, while LR delivered the best accuracy and strong precision, the NB model demonstrated the highest recall and F1 score. ROC curve analysis, M 2 The ROC curve comparison for the M2 models revealed important differences in their discriminative abilities (Fig. 5 ). The AUC metric showed that LR achieved the highest performance with an AUC of 0.686, closely followed by CatBoost with an AUC of 0.683. KNN clearly underperformed with the lowest AUC of 0.576, approaching random classification in some regions of the curve. The visual representation confirmed that LR, CatBoost, NB and SVM maintain the most favorable balance between sensitivity and specificity across different threshold values. Overall, LR emerges as the most effective model for this particular classification task, with CatBoost being a very close second-class model, demonstrating better discrimination ability than the ensemble method XGBoost, which performed relatively poorly in this comparison. Feature importance, M 2 In M2, the comparative analysis of feature importance across multiple ML models is shown in Fig. 6 . Lac. No. emerged as a particularly influential feature in several models (LR, SVM, NN, XGBoost, CatBoost and NB). However, the magnitude of this dominance varies substantially between models, from overwhelming in SVM to more balanced in ensemble methods. In contrast, tree-based models including DT and RF prioritize milk production metrics with average daily milk yield over the preceding seven days [Avg (7 days) Daily MY] ranking highest, followed closely by Testday MY. Similarly, the KNN model assigned the greatest importance to production metrics which are Avg (7 days) Daily MY and Lac. No. the lowest. Days in milk (DIM) consistently ranked as the least important feature across most models, with the exception of KNN where it surpassed Lac. No. However, its relative contribution varied from negligible in SVM to modest in ensemble methods such as XGBoost and CatBoost. This variation in feature importance across algorithms highlights the value of employing multiple modeling approaches when analyzing dairy production data. The ensemble methods (RF, XGBoost, catBoost) demonstrated more balanced feature utilization overall, suggesting that they may capture more complex interactions between animal characteristics and production metrics than simple algorithms do. Discussion The aim of the current study was to establish a threshold somatic cell count to identify cows affected with SCM and to develop a model to predict SCM in dairy cows using ML techniques. Given the high prevalence of subclinical mastitis in dairy cows the application of the SCC as a diagnostic screening tool for detecting SCM at the individual cow level is highly relevant for both dairy farmers and veterinarians. However, a SCC threshold for accurately identifying SCM in dairy cows has not been established in the country. This study demonstrated how predictive models can be applied across multiple bovine herds to identify subclinical mastitis, with the goal of determining which model provides the most accurate predictions. The outcome of this from this study revealed the importance of the EC of milk as a predictor for early subclinical mastitis detection. The primary objective of selecting an appropriate threshold for defining SCM is to identify cows that are positive for SCM. Employing lower threshold values enhances the sensitivity of detection, thereby reducing the likelihood of false negative results. Conversely, applying higher thresholds increases the specificity of the test, which minimizes the occurrence of false positive diagnoses 13 . Various somatic cell count thresholds have been proposed across different countries for the identification of SCM in dairy cows. A commonly accepted cow level SCC threshold is 200 000 cells /mL, which is widely used to indicate intramammary infections at the individual cow level 7 . However, a lower threshold (100, 000 cells/mL) has also been suggested to detect intramammary infections in lactating dairy cows in Bangladesh where mastitis pathogens are abundant 10 and in a Hessian dairy cow population.in Germany 14 . Similarly, higher threshold levels such as 150, 000 cells/mL in South African dairy herds 15 , 250 000 cells/mL in Ireland 16 or 300 000 cells/mL in Belgium 17 have been reported. Considering these regional variations in somatic cell count thresholds, we were motivated to establish an appropriate threshold relevant to the Sri Lankan context. In the present study, the optimal SCC threshold for identifying subclinical mastitis was 353,000 cells/mL, which is slightly higher than the thresholds reported in previous studies. At this threshold, the sensitivity and specificity were 91.7% and 88.8%, respectively. The sensitivity achieved was notably greater than those reported by Sumon et. al. 10 and Sargeant et. al. 18 , who reported sensitivities of 53.1% and 57.4%, respectively, using a lower threshold of 100,000 cells/mL. While the specificity in the current study was lower than that reported by Sumon et. al. 10 i.e. 95.7%, which probably had daily observations of milk yield, milk component measurement, and SCC, it exceeded the specificity reported by Sargeant et. al. 18 , which was 72.3%. A comparable study by Souza et. al. 19 , which employed a higher SCC threshold (> 500,000 cells/mL) for composite milk samples, reported a lower Youden index (0.536) and sensitivity and specificity values of 65.7% and 87.9%, respectively. Considering the above findings, a SCC threshold of 353,000 cells/mL may be deemed an appropriate benchmark for identifying SCM in Sri Lankan dairy herds. The application of ML algorithms has introduced advanced data-driven approaches for analysing complex datasets of dairy production systems. These methods have shown considerable potential in improving decision support tools, particularly for the early detection and prediction of mastitis. Various ML techniques have been employed to detect both clinical and subclinical mastitis and these models are capable of capturing complex, nonlinear relationships among variables, thereby improving diagnostic accuracy and facilitating timely interventions. In the present study, we attempted to predict the SCM status of cows on the day of data collection using individual cow data, milk production data and composition data. Generally, several evaluation metrics such as accuracy, precision, recall and F1 score, are used to evaluate the performance of ML methods. Accuracy, one of the most commonly used metrics, represents the number of correct predictions made by the model over the total number of predictions. However, accuracy alone may not be sufficient to evaluate model performance. If it aims to minimize false negatives or false positives, evaluation on the basis of metrics such as recall or precision, respectively, may be needed. Furthermore, the F1 score which is the harmonic mean of both precision and recall, is useful for obtaining the model with the best performance 20 , 21 . In the current study, considering accuracy and precision, CatBoost appeared to be the best model and NB and DT showed the best performance in terms of recall and F1, respectively, in identifying the SCM in M1. In M2, LR and SVM demonstrated the best accuracy and strong precision, respectively and the NB model showed superior recall and F1 score, suggesting that it might be the better choice for applications where identifying positive cases is critical. The models of M2 generally exhibited moderate accuracy and precision but showed limitations in recall, suggesting challenges with imbalanced classes or detecting positive cases. The prediction accuracies in the present study were 74.5% and 67.7% for M1 and M2, respectively. These values are relatively low compared with those of previous studies. A possible explanation for these comparatively lower accuracies could be the limited dataset size and the likelihood of model overfitting which may have constrained the model’s ability to generalize effectively. Bobbo et. al. 11 reported more than 75% prediction accuracies for all the best performing models: the NN, RF, linear discriminant analysis and generalized linear model. An accuracy of 84.9% was reported by Ebrahimi et. al. 8 for the model gradient boosted tree model based on milking parameters. A study performed by Hyde et. al. 22 revealed that the RF model was the best performing model, with an accuracy of 98% for contagious vs. environmental mastitis and 78% for mastitis during the dry environment period and the environmental lactation period as assessed by accuracy, positive predictive value (PPV) and negative predictive value (NPV). SCM was detected with an accuracy of 81% using SVM or RF models in a study conducted by Motohashi et. al. 23 , in Japan. The precision, recall and F1 scores reported in the current study were lower than those reported in previous studies 8 , 22 . The AUC is another widely used metric for the evaluation of classification problems, and it has the advantages of being independent of the outcome rate, as does Matthew’s correlation coefficient (MCC). In the present dataset, in M1, CatBoost demonstrated the highest AUC of 0.801. Ebrahimi et. al. 8 reported a higher AUC value of 0.826 for the DT model and Ullomi 24 reported lower AUC values than did the current study (0.686). The performance of the ML models was evaluated via several metrics, and the results revealed that the models with the best performance included all the collected parameters (M1). The models with selected parameters (M2) presented lower values for accuracy, precision, recall and F1. This finding is in agreement with that of Bobbo et. al. 11 , who reported that all 15 selected features were relevant in predicting the outcome and recursive feature elimination revealed that the accuracy increased with increasing number of features included. The Sri Lankan dairy industry is composed of mainly medium and small-scale dairy farms and large commercial dairies are few in number. Most of the former farms do not have automated milk recording systems and do not measure the milk composition or other features considered in this study. Therefore, we intend to develop a prediction model for SCM that considers mostly available features such as 'Lac. No.', 'DIM', 'Avg (7 days) Daily MY' and 'Testday MY' (M2), yet the accuracy was low. In M1, which was based on all the ML models analyzed, conductivity emerged as the most significant predictor for the detection of the SCM across nearly all the algorithms. Ebrahimi et. al. 8 also reported that electrical conductivity has the highest weight in the prediction of SCM. In another study of feature selection, the selected top eight features were related to electrical conductivity 23 . This finding aligns with the established knowledge that the electrical conductivity of milk increases with mastitis due to elevated ion concentrations resulting from inflammatory processes. This multifeatured approach provides a more comprehensive detection system than does relying on a single parameter. Notably, breed-related features consistently demonstrated minimal importance across all the models, indicating that SCM detection is largely independent of cow genetics. However, this contrasts with some previous studies that reported associations between factors such as breed 25 and parity 26 and subclinical mastitis. This comprehensive analysis supports development of multiparameter screening tools for dairy farmers, with electrical conductivity serving as the primary but not exclusive indicator for SCM detection. The Lac. No. has emerged as a particularly influential feature in several models, suggesting that the physiological maturity and reproductive history of dairy animals play fundamental roles in production outcomes. In contrast, tree-based models include prioritized milk production metrics, with ( Avg (7 days) Daily MY ) ranking highest, followed closely by Testday MY. This pattern indicates that recent production history may contain more relevant information for these algorithms than may animal characteristics. These discrepancies between linear and nonlinear models suggest that different mathematical approaches capture distinct aspects of the complex relationships within dairy production data. This variation in feature importance across algorithms highlights the value of employing multiple modeling approaches when analyzing dairy production data. The ensemble methods (Random Forest, XGBoost and CatBoost) demonstrated more balanced feature utilization overall, suggesting they may capture more complex interactions between animal characteristics and production metrics than simpler algorithms do. These findings emphasize that model selection significantly influences which factors are identified as most predictive in dairy science research. The traditional methods of SCM detection such as CMT and SCC, are widely used; they are relatively low-tech, moderate-cost and effective, but can be time-consuming, subjective, or require lab facilities. The ML approach uses existing farm data and once developed and implemented, can provide rapid, low-cost predictions with consistent accuracy and potential for earlier detection, although initial investments in data collection and digital infrastructure are needed. In Sri Lanka, CMT is widely used for screening SCM, but it is subjective and influenced by the person. SCC is more objective but less accessible for small scale dairy farmers. Well trained ML models can achieve accuracy levels comparable to or exceeding those of CMT and approach the SCC level performance, especially when trained with high quality farm specific data. ML also offers greater consistency as it avoids human interpretation bias. The developed ML model will be deployed in large scale dairy farmers through integration into farm management software if available or as a mobile application for small scale farmers enabling on-farm decision making. It will also be necessary to collect input data such as individual cow data, milk production data and milk composition data regularly.. Implementation requires basic digital infrastructure, including a computer or smartphone and internet access. When the cost benefit analysis is considered, although an initial investment is needed, early detection of SCM ultimately results in a greater return on investment through improved health and productivity of cows. In Sri Lanka, current limitations of the machine learning approach for predicting SCM include reliance on the quality and quantity of available farm data, potential bias when data are collected from a limited number of farms, and reduced accuracy when management or environment factors differ from the training dataset. To overcome current limitations, data quality can be improved by standardizing collection methods and expanding datasets through the inclusion of several farms. Model generalizability can be enhanced via external validation, transfer learning, and the inclusion of farm-specific context features. The pipeline can be strengthened with automated feature selection, continuous model monitoring, and scheduled retraining. The current study identified an optimal somatic cell count threshold of 353,000 cells/mL for detecting SCM in Sri Lankan dairy cows. Additionally, the application of ML techniques provides a promising avenue for developing predictive models for SCM. Among the tested algorithms, CatBoost exhibited the highest performance in terms of accuracy and AUC, whereas other models, such as NB, LR, and SVM, presented strengths across different evaluation metrics. The models trained on all the available features in the dataset (M1) outperformed the reduced-feature models (M2), reinforcing the importance of comprehensive data collection in improving the predictive accuracy. Electrical conductivity has emerged as the most consistent and influential predictor across models, validating its utility as a key indicator of SCM. Given the limited access to automated data collection in many Sri Lankan dairy farms the development of simplified, yet effective, ML models hold significant potential for practical implementation. Overall, this study highlights the value of integrating diagnostic thresholds with data-driven ML tools for enhancing mastitis detection and control strategies in the local dairy industry. Methods Study Locations and Animals The study was designed as a cross sectional epidemiological investigation involving three commercial dairy herds located in the Nuwaraeliya district of the Central Province of Sri Lanka. Herds were selected on the basis of the accessibility of data and willingness to participate in the study. A total of 2420 lactating cows (A: n = 1002; B: n = 898; and C: n = 520) were included over a six-month period from December 2022 to May 2023. The cows were primarily Holstein-Friesian, Ayrshire, and their crosses, housed in free-stall barns and managed under an intensive system (cows were kept in barns for 24 h while supplying feed). Each herd was milked three times daily using machine milking, with average milk yields of 17, 27, and 30 L per cow across the three farms. All the cows were provided cut-and-carry feed along with supplemental concentrates, vitamins, and mineral mixtures tailored to their production levels. Cows displaying visible udder or milk abnormalities, clinical mastitis, or other diseases at the time of examination were excluded from the study. Sampling and data collection Two 15 mL centrifuge tubes were prepared one with potassium dichromate preservative for somatic cell count analysis, and one without the preservative for pH and milk composition measurements for each composite milk sample collected. The preservative solution was prepared, employing safety precautions, by dissolving I g of potassium dichromate in 5.05 mL of deionized water. Fifty microliters of this mixture were dispensed into each tube at room temperature and allowed to air dry in a ventilated area at room temperature (20–25°C) for 5–6 days. The tubes were labeled with cow ID using waterproof markers. Each farm was visited during the noon milking period for sample and data collection. Before the milk samples were collected, the teats were thoroughly washed with a 0.5% iodine solution, wiped clean, and dried using sterile towels. Next, the teats were disinfected with 70% ethanol-soaked cotton to ensure aseptic conditions. The first few streams of milk were discarded to remove potential contaminants. Composite foremilk samples (30 ml) were then aseptically collected from all quarters into sterilized pre-labeled plastic cups. CMT was performed onsite immediately after collection. The samples were subsequently divided into two portions: one aliquot was transferred to a 15 ml centrifuge tube containing potassium dichromate as a preservative, while the other was placed in a preservative-free centrifuge tube. Both samples were mixed thoroughly, labeled, and stored in a cool box with ice packs to maintain low temperatures during transport to the Laboratory of Dairy Technology, Department of Animal Science, Faculty of Agriculture, University of Peradeniya. The transport process was completed within 5 hours of collection to ensure sample integrity. In the laboratory, the samples were stored at 4°C until analysis, during which they were thawed at room temperature. Data from individual cows, including breed, Lac. No., DIM, Avg (7 days) Daily MY and Testday MY, were retrieved from the farm’s digital record-keeping system. Herd and management-related information was gathered through interviews with farm managers via a pretested, structured questionnaire. All experimental procedures involving cows were conducted in full compliance with the ethical guidelines established by the Ethics Review Committee, Faculty of Veterinary Medicine and Animal Science. Approval for the study was obtained prior to commencement, ensuring adherence to internationally accepted standards for animal welfare and research ethics (Proposal ID - VERC-23-02). California Mastitis Test (CMT) and identification of animals with SCM CMT was used to detect cows with SCM 27 . The test was conducted by adding 3 mL of CMT reagent to 3 mL of milk in each well of the CMT paddle. The paddle was then rotated gently in a horizontal circular motion for 60 seconds to thoroughly mix the reagent with the milk and allow gel formation; The results were assessed on the basis of the observed changes in the mixture’s consistency and scored according to the following criteria: 0 (negative): normal consistency with no gel formation, 1 (trace/positive): slight gel formation with a purplish-gray colour, 2 (positive): light but persistent gel formation with a purple-gray colour, 3 (positive): immediate thickening, forming a viscous cluster at the bottom of the well, and 4 (positive): thick gel with a consistency similar to egg white and a dark purple color. 28 , 29 To reduce variability in scoring and ensure consistency, all CMT tests were performed by the second author, who was trained in the procedure. Measurement of pH and milk composition parameters After thawing, the pH of each milk sample was measured using a calibrated pH meter. The composition of milk, including fat, protein, lactose, solid-non-fat (SNF), density, conductivity, salt content and freezing point was analyzed using a LACTOSCAN SP milk analyzer (Milkotronic Ltd). All analyses were conducted following the manufacturer’s instructions, with regular calibration and maintenance of the equipment to ensure reliable results. Measurement of Somatic Cell Count (SCC) SCC was determined using a LACTOSCAN SCC analyzer (Milkotronic Ltd.) following the manufacturer’s protocol. The milk samples were first equilibrated to room temperature before being placed in a water bath at 40°C for 20 minutes. The samples were then cooled to 20°C to optimize dye interactions. After cooling, the milk was thoroughly mixed using a vortex mixer for uniform dispersion of somatic cells. One hundred microliters of milk were carefully pipetted into prelabeled Eppendorf tubes containing Sofia Green dye. The milk-dye mixture was vortexed for 10 seconds to ensure homogeneity and allowed to stand for one minute to facilitate dye-cell binding. Subsequently, 8 µL of the prepared sample was precisely pipetted onto the measurement chips. The chips were inserted into the LACTOSCAN SCC device, and SCC were automatically recorded from the digital display. Data Management and Statistical Analyses Calculation of threshold somatic cell count Among the 2420 samples collected, 1661 were subjected to the CMT test to determine the SCC. The CMT could not be performed on the remaining samples because of time limitations during the milking process. Cows with a CMT score of 0 were classified as negative for SCM. In contrast, cows with a CMT score of 1 or higher, accompanied by a visibly normal udder and normal milk, were categorized as positive for SCM. For each somatic cell count value, sensitivity, specificity and Youden’s index 15 , were calculated using the formulas provided below. The SCC threshold value with the highest Youden’s index was identified as the optimal cutoff value for diagnosing SCM positive cows. Sensitivity (Se): The proportion of infected cows whose SCC values were above the selected threshold [equation (1)]. (1) Se = TP/(TP + FN) Specificity (Sp): The proportion of uninfected cows whose SCC values were below the selected threshold [equation (2)]. (2) Sp = TN/(TN + FP) TP = true-positive test result (infected cows above the SCC threshold) FP = false-positive test result (uninfected cows above the SCC threshold) TN = true-negative test result (uninfected cows below or equal to the SCC threshold) FN = false-negative test result (infected cows below or equal to the SCC threshold) Youden’s index (J) is a metric commonly used to determine the optimal threshold value for a diagnostic test. Typically, thresholds with high sensitivity and high specificity are preferred to balance diagnostic accuracy. However, sensitivity and specificity may not carry equal importance in every instance. For example, if false-negative results have more serious consequences than false-positive results do, a threshold value prioritizing higher sensitivity over specificity might be selected. Conversely, when avoiding false positives is critical, a threshold with comparatively higher specificity may be preferred. Youden’s index is particularly valuable for selecting a threshold that balances both sensitivity and specificity. It is calculated using the following formula [Equation (3)]: (3) J = sensitivity + specificity – 1 The value of J ranges from 0–1. A test with excellent diagnostic performance achieves a maximum J value of 1, indicating perfect sensitivity and specificity. In contrast, a value of 0 reflects a test with no diagnostic utility. The SCC threshold value with the highest Youden’s index was identified as the optimal cutoff value for diagnosing SCM positive cows. Model development The development of the ML model followed a structured workflow, including data preprocessing, exploratory data analysis (EDA), model selection via cross-validation, performance evaluation and final validation on test data. The data preprocessing pipeline included the following steps. First, initial data cleaning was performed by removing nonpredictive columns (identification number and sample number) to focus on biologically relevant features. A critical quality control step involved filtering invalid entries in the conductivity (mS/cm) feature, where 97 rows containing nonnumeric values (e.g., “out of range”) were removed. The final dataset retained 2403 samples after cleaning. Second, missing value imputations were performed. Missing values were identified for four features: Avg (7 days) Daily MY (L): 20 missing values (0.83% of samples); Testday MY (L): 71 missing values (2.95% of samples); conductivity (mS/cm): 62 (2.58% of samples); and freezing point (⁰C): 4 (0.17% of samples). Median imputation for these features was employed after verifying right-skewed distributions through exploratory analysis. The median robustness to outliers makes imputation preferable for preserving the integrity of milk yield and sensor-derived measurements. Third, in feature engineering, categorical encoding includes label encoding for the farm variable to convert farm IDs into ordinal representations and one-hot encoding for breeds to create six binary features representing cattle breeds. The column SCC (10 3 cells/mL) was replaced by diseased or not diseased considering the threshold SCC estimated in the current study. The integrity of the dataset was confirmed by identifying 0 duplicate cows postprocessing. The target variable SCM showed a 60:40 class imbalance (1446 negative vs. 957 positive cases), which informed subsequent stratification during data splitting. Fourth, for feature scaling, a dual-scaling approach, the standard scaler for freezing points (⁰C) to center the feature around zero mean (± 1 SD) and the MinMax scaler for remaining numerical features to normalize values between 0–1 was implemented so that no variable dominated due to larger scales. This hybrid strategy addresses the presence of negative values in freezing point measurements while maintaining consistent scaling for other physiological parameters. In this way, small differences in the freezing point were preserved relative to the overall variability instead of being squashed. Finally, the data were partitioned using an 80:20 stratified training: test split (random state = 42) to preserve class proportions. The training set included 1922 samples (1157 negative and 765 positive samples) and the test set included 481 samples (289 negative and 192 positive samples). Stratification mitigated bias in model evaluation given the observed class imbalance. The feature matrices (X train, X test) and target vectors (Y train, Y test) were stored separately, with scaling parameters derived exclusively from training data to prevent information leakage. Summary statistics, correlation matrices, and data distribution visualizations were used in EDA to evaluate data quality, analyze feature relationships and identify potential issues necessitating further preprocessing or feature engineering. Two sets of ML models were developed and assessed. M1: Models considering all the variables: Lac. No.’, ‘DIM’, ‘Avg (7 days) Daily MY’, ‘Testday MY’, ‘Fat’, ‘SNF’, ‘Density’, ‘Protein’, ‘Conductivity’, ‘pH’, ‘Freezing point (⁰C)’, ‘Salt (%)’, ‘Lactose (%) and M2: A set of models considering only ‘Lac. No.’, ‘DIM’, ‘Avg (7 days) Daily MY’, ‘Testday MY’ variables. M2 was developed on the basis of variables (Lac. No.’, ‘DIM’, ‘Avg (7 days) Daily MY’, and ‘Testday MY’) that can be readily and feasibly collected from Sri Lankan dairy farms. A set of best performing classifiers selected on the basis of, previous studies 8 , 11 was evaluated for predictive performance. These included nine models ranging from simple and interpretable approaches such as LR, NB, DT, and KNN to more advanced techniques such as SVM, NN, RF, XGBoost and CatBoost. They addressed the dataset’s 60:40 class imbalance through techniques such as class weighing and boosting, capturing both linear and nonlinear patterns. While models such as DT and RF offer high interpretability, advanced methods such as XGBoost and CatBoost enhance detection accuracy by modeling complex feature interactions. These nine models were optimized through hyperparameter tuning to balance interpretability, accuracy and handling of the class imbalance. Simple models such as LR, DT and NB apply class weighting or oversampling, whereas ensemble methods such as RF, XGBoost, and CatBoost use tuned depths, learning rates and iterations to increase stability and capture complex patterns. Advanced methods such as SVM incorporate architecture or kernel tuning, with normalization and oversampling ensuring robust performance on small-to-medium datasets. The study employed a 5-fold stratified cross-validation scheme to evaluate model performance for detecting SCM with accuracy, precision, recall and F1 as metrics. Stratification was used to maintain the original class distribution in each fold, preserving the minority mastitis class representation and addressing potential overfitting. The 5-fold choice balances computational efficiency with reliability, providing five independent train-test splits while leveraging the full dataset, which is critical given the moderate sample size. When a sample labeled true is predicted true it is defined as a true positive (TP) and when a sample labeled false is predicted true it is defined as a false positive (FP). The precision is defined as follows: [equation (4)]. (4) precision = TP/ (TP + FP). Declarations Data availability statement The dataset analyzed in the current study is available from the corresponding author upon reasonable request. Acknowledgement The cooperation of the farm managers and staff is sincerely appreciated. Funding The authors gratefully acknowledge the financial support provided by the University Research Council, University of Peradeniya, Sri Lanka (Grant No. MRG-199). Author contributions R.M.C.O.R, M.P.S., A.P.A. and K.K. developed the machine learning algorithms. R.M.C.O.R. analyzed the results. K.M.D., R.M.C.D. and R.M.S.B.K.R was involved in farm visits and data collection. K.M.D. conducted all the laboratory experiments. R.M.S.B.K.R. conceived the study, wrote the proposal, obtained the grant and supervised the project. R.M.C.O.R and R.M.S.B.K.R. wrote the manuscript. All the authors reviewed the manuscript. Competing interests The authors declare that they have no competing interests. References Losinger, W. C. Economic impacts of reduced milk production associated with an increase in bulk-tank somatic cell count on US dairies. J. Am. Vet. Med. Assoc. 226 , 1652-1658, DOI: http://dx.doi.org/ 10.2460/javma.2005.226.1652 (2005). Halasa, T., Huijps, K., Osteras, O. & Hogeveen, H. Economic effects of bovine mastitis and mastitis management: A review. Vet. Q. 29 , 18–31, DOI: https://doi.org/10.1080/01652176.2007.9695224 (2007). Hogeveen, H., Huijps, K. & Lam, T. J. G. M. Economic aspects of mastitis: New developments. N. Z. Vet J. 59 (1), 16–23, DOI: https://doi.org/10.1080/00480169.2011.547165 (2011). Veterinary Epidemiological Bulletin. 2023. Department of Animal Production and Health, P.O. Box 13, Peradeniya, Sri Lanka. Accessed Nov. 13, 2024. https://daph.gov.lk/files/uploads/documents/downloads/Bulletine%20-2023-3rd%20Q.pdf. Hillerton, J. E. Redefining mastitis based on somatic cell count. Bulletin of the International Dairy Federation, 345 , 4-6 (1999). Gülzari, Ş. Ö., Ahmadi, B. V. & Stott, A.W. Impact of subclinical mastitis on greenhouse gas emissions intensity and profitability of dairy cows in Norway. Prev. Vet. Med. 150 , 19–29, DOI: https://doi.org/10.1016/j.prevetmed.2017.11.021 (2018). Smith, K. L., Hillerton, J. E. & Harmon, R. J. National Mastitis Council Guidelines on normal and abnormal milk based on somatic cell counts and signs of clinical mastitis. National Mastitis Council, Madison WI, pp3 (2001). Ebrahimi, M., Mohammadi-Dehcheshmeh, M., Ebrahimie, E. & Petrovski, K.R. Comprehensive analysis of machine learning models for prediction of sub-clinical mastitis: Deep Learning and Gradient-Boosted Trees outperform other models. Comput. Biol. Med. 114 , 103456, DOI: https://doi.org/10.1016/j.compbiomed.2019.103456 (2019). Jadhav, P. V., Das, D. N., Suresh, K. P. & Shome, B. R. Threshold Somatic Cell count for delineation of subclinical mastitis cases. Vet. World. 11 (6), 789-793, DOI: https://doi.org/10.14202/vetworld.2018.789-793 (2018). Sumon, S. M. M. R., Parvin, M. S., Ehsan, M. A. & Islam, T. 2020. Relationship between somatic cell counts and subclinical mastitis in lactating dairy cows. Vet. World 13 (8), 1709-1713, DOI: https://doi.org/ 10.14202/vetworld.2020.1709-1713 (2020). Bobbo, T., Biffani, S., Taccioli, C., Penasa, M. & Cassandro, M. Comparison of machine learning methods to predict udder health status based on somatic cell counts in dairy cows. Sci. Rep. 11 , 13642, DOI: https://doi.org/10.1038/s41598-021-93056-4 (2021). Abdul Ghafoor, N. & Sitkowska, B. MasPA: A machine learning application to predict risk of mastitis in cattle from AMS sensor data. Agric. Eng. 3 (3), 575-583, DOI: https://doi.org/10.3390/agriengineering3030037 (2021). Pantoja, J. C., Hulland, C. & Ruegg, P. L. Dynamics of somatic cell counts and intramammary infections across the dry period. Prev. Vet. Med. 90 (2), 43–54, DOI: https://doi.org/10.1016/j.prevetmed.2009.03.012 (2009). Schwarz, D. et al. Somatic cell counts and bacteriological status in quarter foremilk samples of cows in Hesse, Germany—A longitudinal study. J. Dairy Sci. 93 , 5716–5728, DOI: https://doi.org/10.3168/jds.2010-3223 (2010). Petzer, I-M., Karzis, J., Donkin, E. F., Webb E. C. & Etter, E. M. C. Somatic cell count thresholds in composite and quarter milk samples as indicator of bovine intramammary infection status. Onderstepoort J. Vet. Res. 84 (1), e1-e10, DOI: https://doi.org/10.4102/ojvr.v84i1.1269 (2017). Berry, D. P. & Meaney, W. J. Interdependence and distribution of subclinical mastitis and intramammary infection among udder quarters in dairy cattle. Prev. Vet. Med. 75 , 81–91, DOI: https://doi.org/10.1016/j.prevetmed.2006.02.001 (2006). Deluyker, H. A., Oye, S. N. V. & Boucher, J. F. Factors affecting cure and somatic cell count after pirlimycin treatment of subclinical mastitis in lactating cows. J. Dairy Sci. 88 , 604–614, DOI: https://doi.org/ 10.3168/jds.S0022-0302(05)72724-7 (2005). Sargeant, J. M., Leslie, K. E., Shirley, J. E., Pulkrabek, B. J. & Lim, G. H. Sensitivity and specificity of somatic cell count and California Mastitis Test for identifying intramammary infection in early lactation. J. Dairy Sci. 84 , 2018–2024, DOI: https://doi.org/10.3168/jds.S0022-0302(01)74645-0(2001). Souza F. N. et al. Somatic cell count and mastitis pathogen detection in composite and single or duplicate quarter milk samples. Pesq. Vet. Bras. 36 (9), 11-818, DOI: https://doi.org/10.1590/S0100-736X2016000900004 (2016). Cabot, J. H. & Ross, E. G. Evaluating prediction model performance. Surgery. 174 (3), 723-726, DOI: https://doi.org/10.1016/j.surg.2023.05.023 (2023). Gleckler, P. J., Taylor, K. E. & Doutriaux, C. Performance metrics for climate models. J. Geophys. Res. 113 , D06104, DOI: https://doi.org/10.1029/2007JD008972 (2008). Hyde, R. M. et al. Automated prediction of mastitis infection patterns in dairy herds using machine learning. Sci. Rep. 10 , 1-8, DOI: https://doi.org/10.1038/s41598-020-61126-8 (2020). Motohashi, H., Ohwada, H. & Kubota, C. Early detection method for subclinical mastitis in auto milking systems using machine learning. in IEEE 19 th International Conference on Cognitive Informatics and Cognitive Computing (ICCI*CC), Beijing, China. 76-83, DOI: https://doi.org/10.1109/iccicc50026.2020.9450258 (2020). Ullomi, J. O. Subclinical Mastitis Detection by Machine Learning . Thesis. Centre for Bioinformatics University of Veterinary Medicine Budapest, Hungary. (2023). Salamanca-Carreño, A. et al. Breed and non-genetic risk factors associated with the prevalence of subclinical mastitis in livestock systems of Arauca, Colombian orinoquia. Int. J. Vet. Sci. Med. 12 (1), 1-10, DOI: https://doi.org/ 10.1080/23144599.2024.2310451 (2024). Ranasinghe, R.M. S. B. K., Deshapriya, R. M. C., Abeygunawardana, D. I., Rahularaj, R. & Dematawewa, C. M. B. Subclinical mastitis in dairy cows in major milk-producing areas of Sri Lanka: prevalence, as sociated risk factors, and effects on reproduction. J. Dairy Sci. 104 , 12900–12911, DOI: https://doi.org/10.3168/jds.2021-20223 (2021). Quinn, P. J., Carter, M. E., Markey, B. & Carter, G. R. Mastitis in Clinical Veterinary Microbiology . (First edition), Elsevier Ltd, Philadelphia, USA. 327-335 (1999). Gunawardana, S. et al. Risk factors for bovine mastitis in the Central Province of Sri Lanka. Trop. Anim. Health Prod. 46 (7), 1105–1112, DOI: https://doi.org/10.1007/s11250-014-0602-9 (2014). Kayesh, M. E. H., Talukder, M. & Anower, A. K. M. M. Prevalence of subclinical mastitis and its association with bacteria and risk factors in lactating cows of Barisal district in Bangladesh. Int. J. Biol. Res. 2 (2), 35-38, DOI: https://doi.org/10.14419/ijbr.v2i2.2835(2014). Additional Declarations No competing interests reported. Cite Share Download PDF Status: Published Journal Publication published 28 Apr, 2026 Read the published version in Scientific Reports → Version 1 posted Editorial decision: Revision requested 17 Nov, 2025 Reviews received at journal 14 Nov, 2025 Reviewers agreed at journal 10 Nov, 2025 Reviews received at journal 30 Sep, 2025 Reviewers agreed at journal 12 Sep, 2025 Reviewers agreed at journal 10 Sep, 2025 Reviewers invited by journal 09 Sep, 2025 Editor invited by journal 05 Sep, 2025 Editor assigned by journal 05 Sep, 2025 Submission checks completed at journal 04 Sep, 2025 First submitted to journal 02 Sep, 2025 You are reading this latest preprint version Research Square lets you share your work early, gain feedback from the community, and start making changes to your manuscript prior to peer review in a journal. As a division of Research Square Company, we’re committed to making research communication faster, fairer, and more useful. We do this by developing innovative software and high quality services for the global research community. Our growing team is made up of researchers and industry professionals working together to solve the most critical problems facing scientific publishing. Also discoverable on Platform About Our Team In Review Editorial Policies Advisory Board Help Center Resources Author Services Accessibility API Access RSS feed Manage Cookie Preferences © Research Square 2026 | ISSN 2693-5015 (online) Privacy Policy Terms of Service Do Not Sell My Personal Information {"props":{"pageProps":{"initialData":{"identity":"rs-7519712","acceptedTermsAndConditions":true,"allowDirectSubmit":false,"archivedVersions":[],"articleType":"Article","associatedPublications":[],"authors":[{"id":515970428,"identity":"eeb018e4-6337-44c3-b491-68a666489d0f","order_by":0,"name":"R. M.C.O. Rathnayake","email":"","orcid":"","institution":"Informatics Institute of Technology","correspondingAuthor":false,"prefix":"","firstName":"R.","middleName":"M.C.O.","lastName":"Rathnayake","suffix":""},{"id":515970431,"identity":"8423af99-d729-4498-8cb3-431515fd46ad","order_by":1,"name":"K. M. Devindi","email":"","orcid":"","institution":"University of Peradeniya","correspondingAuthor":false,"prefix":"","firstName":"K.","middleName":"M.","lastName":"Devindi","suffix":""},{"id":515970432,"identity":"e3277f82-0428-4565-8e7c-8db072686aa2","order_by":2,"name":"M. P. Saiju","email":"","orcid":"","institution":"Texas A\u0026M University","correspondingAuthor":false,"prefix":"","firstName":"M.","middleName":"P.","lastName":"Saiju","suffix":""},{"id":515970435,"identity":"2be5928f-b17f-48d1-8932-af7430ab5f43","order_by":3,"name":"A. P. Ajitha","email":"","orcid":"","institution":"Texas A\u0026M University","correspondingAuthor":false,"prefix":"","firstName":"A.","middleName":"P.","lastName":"Ajitha","suffix":""},{"id":515970437,"identity":"7b509d9e-6222-481d-ae23-05875468b880","order_by":4,"name":"K. Kaniyamattam","email":"","orcid":"","institution":"Texas A\u0026M University","correspondingAuthor":false,"prefix":"","firstName":"K.","middleName":"","lastName":"Kaniyamattam","suffix":""},{"id":515970438,"identity":"328e1a5e-53c0-410b-b723-ab19d5eb67d8","order_by":5,"name":"R. M. C. Deshapriya","email":"","orcid":"","institution":"University of Peradeniya","correspondingAuthor":false,"prefix":"","firstName":"R.","middleName":"M. C.","lastName":"Deshapriya","suffix":""},{"id":515970444,"identity":"e8fbeb55-30cd-465c-8f2e-612947dc87a9","order_by":6,"name":"R. M. S. B. K. Ranasinghe","email":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAAyAQMAAABI0h/eAAAABlBMVEX///8AAABVwtN+AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA8UlEQVRIiWNgGAWjYBACA2Yg8eAAgxyEywYmGQ82ENKScIDBmIGBGa6FAb8WBoiWxAaitZizcyd+SDhjl77heP8B5oKyOwz87QcYDs7Ao8WymXezRMKN5NwNZw4zMM8494xB4kwCw8EN+Bx2mHeDRMIH5tyZM5IZmHnbDjMw3AA67AF+LZt/JHyoT5ec/xiiRZ4ILduADjucwC/BDNFiANKCz2FAv2yzSDhz3LCfJ9ng8Ixzh3kMzyQ24PW+Of/ZzTc+HKuWZ2M/+PBxQdlhObnjhw8+7MGjBQUA/c7AA4z8BmI1QOJ/FIyCUTAKRgEGAABnv1QxmCLnWAAAAABJRU5ErkJggg==","orcid":"","institution":"University of Peradeniya","correspondingAuthor":true,"prefix":"","firstName":"R.","middleName":"M. S. B. K.","lastName":"Ranasinghe","suffix":""}],"badges":[],"createdAt":"2025-09-02 16:23:11","currentVersionCode":1,"declarations":"","doi":"10.21203/rs.3.rs-7519712/v1","doiUrl":"https://doi.org/10.21203/rs.3.rs-7519712/v1","draftVersion":[],"editorialEvents":[{"content":"https://doi.org/10.1038/s41598-026-50467-5","type":"published","date":"2026-04-28T15:58:35+00:00"}],"editorialNote":"","failedWorkflow":false,"files":[{"id":91630949,"identity":"326ce1cc-dad4-4700-b363-a7236f499a14","added_by":"auto","created_at":"2025-09-18 13:03:06","extension":"png","order_by":1,"title":"Figure 1","display":"","copyAsset":false,"role":"figure","size":88942,"visible":true,"origin":"","legend":"\u003cp\u003eThe comparison of accuracy, precision, recall and F1 for nine predictive models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in prediction of subclinical mastitis in M1.\u003c/p\u003e","description":"","filename":"1.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/6378a03d71a00eebdcd7d9c9.png"},{"id":91630950,"identity":"dc03e9cb-c57e-44c8-9744-0d3ee186fafb","added_by":"auto","created_at":"2025-09-18 13:03:06","extension":"png","order_by":2,"title":"Figure 2","display":"","copyAsset":false,"role":"figure","size":107202,"visible":true,"origin":"","legend":"\u003cp\u003eComparing Receiver Operating Characteristic (ROC) curves of nine machine learning models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in prediction of sub-clinical mastitis in M1\u003c/p\u003e","description":"","filename":"2.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/5214576a2b2f6eea46423edf.png"},{"id":91631948,"identity":"093d01ac-a824-4a80-ab18-2a4b0a3a1dbe","added_by":"auto","created_at":"2025-09-18 13:11:06","extension":"png","order_by":3,"title":"Figure 3","display":"","copyAsset":false,"role":"figure","size":58487,"visible":true,"origin":"","legend":"\u003cp\u003eOverall weights of milk production, composition parameters and cow factors in prediction of sub-clinical mastitis based on nine machine learning models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in M1\u003c/p\u003e","description":"","filename":"3.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/076c46c47a359f7f342665ea.png"},{"id":91630952,"identity":"0eb27fd6-3c2e-4f3e-b883-ecb28c116a3c","added_by":"auto","created_at":"2025-09-18 13:03:06","extension":"png","order_by":4,"title":"Figure 4","display":"","copyAsset":false,"role":"figure","size":138468,"visible":true,"origin":"","legend":"\u003cp\u003eThe comparison of accuracy, precision, recall and F1 for nine predictive models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in prediction of subclinical mastitis in M2.\u003c/p\u003e","description":"","filename":"4.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/fa24efd44fe122375deba15c.png"},{"id":91630957,"identity":"a7d268fc-6b22-4ffb-a4c1-a56155fa82d3","added_by":"auto","created_at":"2025-09-18 13:03:06","extension":"png","order_by":5,"title":"Figure 5","display":"","copyAsset":false,"role":"figure","size":144191,"visible":true,"origin":"","legend":"\u003cp\u003eComparing Receiver Operating Characteristic (ROC) curves of nine machine learning models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in prediction of sub-clinical mastitis in M2\u003c/p\u003e","description":"","filename":"5.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/9d20a0d266b1077504bd31a6.png"},{"id":91631949,"identity":"dd435c54-94dc-4d0b-8723-c01287895e1f","added_by":"auto","created_at":"2025-09-18 13:11:06","extension":"png","order_by":6,"title":"Figure 6","display":"","copyAsset":false,"role":"figure","size":43317,"visible":true,"origin":"","legend":"\u003cp\u003eOverall weights of lactation number, test day milk yield, average (7 days) daily milk yield and days in milk in prediction of sub-clinical mastitis based on nine machine learning models [logistic regression (LR), decision tree (DT), random forest (RF), k-nearest neighbors (KNN), support vector machine (SVM), neural network (NN), XGBoost, CatBoost and Naïve Bayes (NB)] in M2\u003c/p\u003e","description":"","filename":"6.png","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/ed0a50be41b9e1d74c749160.png"},{"id":108437948,"identity":"f2838399-b902-4afa-b1c7-199e34de2085","added_by":"auto","created_at":"2026-05-04 16:04:41","extension":"pdf","order_by":0,"title":"","display":"","copyAsset":false,"role":"manuscript-pdf","size":715956,"visible":true,"origin":"","legend":"","description":"","filename":"manuscript.pdf","url":"https://assets-eu.researchsquare.com/files/rs-7519712/v1/167a0746-5214-4205-b6fd-f081d27786e3.pdf"}],"financialInterests":"No competing interests reported.","formattedTitle":"Machine learning-based prediction of subclinical mastitis in large-scale dairy herds using a locally established somatic cell count threshold","fulltext":[{"header":"Introduction","content":"\u003cp\u003eSubclinical mastitis (SCM) is a significant production-related disease in dairy cows that is associated with decreased milk yield and diminished milk quality. SCM is characterized by elevated somatic cell counts (SCC) in milk; however, it presents without visible abnormalities in milk or the udder and without detectable clinical signs in cows. In addition to reduced milk production and quality, SCM leads to substantial economic losses due to increased treatment costs, additional labor, milk discarding following treatment, and premature culling\u003csup\u003e\u003cspan additionalcitationids=\"CR2\" citationid=\"CR1\" class=\"CitationRef\"\u003e1\u003c/span\u003e\u0026ndash;\u003cspan citationid=\"CR3\" class=\"CitationRef\"\u003e3\u003c/span\u003e\u003c/sup\u003e. In Sri Lanka, during the third quarter of 2023, mastitis cases were reported across all nine provinces of the country, totaling 3702 cases, a 6.7% increase compared with the same period in the previous year\u003csup\u003e\u003cspan citationid=\"CR4\" class=\"CitationRef\"\u003e4\u003c/span\u003e\u003c/sup\u003e. In response, the Department of Animal Production and Health (DAPH) has implemented a mastitis control program through veterinary investigation offices in each district, providing field and laboratory mastitis identification tests, microbial culture, isolation and antibiotic susceptibility testing. Early detection of SCM remains essential for effective mastitis control in the country.\u003c/p\u003e\u003cp\u003eEstablishing a threshold level for SCC is critical for distinguishing infected cows from uninfected cows. A SCC less than 100,000 cells/mL of milk is considered indicative of a healthy quarter\u003csup\u003e\u003cspan citationid=\"CR5\" class=\"CitationRef\"\u003e5\u003c/span\u003e\u003c/sup\u003e, whereas counts exceeding 200,000 cells/mL strongly suggest the presence of infection\u003csup\u003e\u003cspan citationid=\"CR6\" class=\"CitationRef\"\u003e6\u003c/span\u003e\u0026ndash;\u003cspan citationid=\"CR7\" class=\"CitationRef\"\u003e7\u003c/span\u003e\u003c/sup\u003e. However, global studies have reported varying SCC threshold values for SCM identification\u003csup\u003e\u003cspan additionalcitationids=\"CR9\" citationid=\"CR8\" class=\"CitationRef\"\u003e8\u003c/span\u003e\u0026ndash;\u003cspan citationid=\"CR10\" class=\"CitationRef\"\u003e10\u003c/span\u003e\u003c/sup\u003e, and specific SCC threshold information applicable to Sri Lanka is lacking. In large Sri Lankan dairy herds, the SCC for individual cows is not recorded during milk collection. Instead, the California Mastitis Test (CMT), which is routinely conducted in these herds, provides an indirect estimate of the presence of somatic cells in milk. Thus, establishing a SCC threshold to identify SCM in Sri Lankan dairy cows is essential.\u003c/p\u003e\u003cp\u003eMachine learning (ML), a branch of artificial intelligence, encompasses methods that allow machines (computers) to automatically perform tasks on the basis of data and experience without explicit programming. ML is often considered a valuable decision-support tool, especially in situations where conventional algorithms are challenging or infeasible to apply. Studies have shown that ML algorithms can effectively predict udder health status, aiding in decision-making for dairy farmers\u003csup\u003e\u003cspan citationid=\"CR11\" class=\"CitationRef\"\u003e11\u003c/span\u003e\u003c/sup\u003e. An example of an ML application in mastitis prediction is MasPA, an open-source software that uses the random forest algorithm to assess mastitis risk in cattle\u003csup\u003e\u003cspan citationid=\"CR12\" class=\"CitationRef\"\u003e12\u003c/span\u003e\u003c/sup\u003e. Different data sources have been utilized in developing ML models for SCM, including AMS (Automatic Milking Systems) sensor data\u003csup\u003e\u003cspan citationid=\"CR8\" class=\"CitationRef\"\u003e8\u003c/span\u003e,\u003cspan citationid=\"CR12\" class=\"CitationRef\"\u003e12\u003c/span\u003e\u003c/sup\u003e and SCC\u003csup\u003e\u003cspan citationid=\"CR11\" class=\"CitationRef\"\u003e11\u003c/span\u003e\u003c/sup\u003e. To date, no studies have investigated data relevant to the Sri Lankan context. Therefore, the present study aimed to establish an SCC threshold for identifying cows with SCM based on CMT scores and to develop a machine learning model that can predict the incidence of subclinical mastitis using the estimated SCC threshold. The model considers individual cow data, milk production, milk composition, and the SCC, which are tailored to the Sri Lankan dairy sector.\u003c/p\u003e"},{"header":"Results","content":"\u003cdiv id=\"Sec3\" class=\"Section2\"\u003e\u003ch2\u003eThreshold somatic cell count\u003c/h2\u003e\u003cp\u003eSeveral threshold values between 353 000 and 550 000 cells/mL were associated with the highest Youden\u0026rsquo;s index of 0.81. To minimize the harmful consequences of false negative diagnoses, where SCM cases might go undetected, the threshold with the highest sensitivity within this range, 353 000 cells/mL was selected. This value ensures a greater likelihood of identifying cows positive for SCM while maintaining diagnostic accuracy. Considering the above threshold, the overall prevalence of SCM was 39.8% on the three farms studied.\u003c/p\u003e\u003c/div\u003e\n\u003ch3\u003eModel development\u003c/h3\u003e\n\u003cdiv id=\"Sec5\" class=\"Section2\"\u003e\u003ch2\u003eMetrics, M I\u003c/h2\u003e\u003cp\u003eThe performance of the evaluated ML models was assessed across multiple classification metrics, as presented in Fig.\u0026nbsp;\u003cspan refid=\"Fig1\" class=\"InternalRef\"\u003e1\u003c/span\u003e. The highest accuracy was observed with the CatBoost model, with a value of 0.745, indicating that it correctly classified 74.5% of SCM cases, followed closely by XGBoost (74.1%), neural networks (NN) (72.5%), random forest (RF) (72.2%) and logistic regression (LR) and support vector machines (SVM) (71.1%). Na\u0026iuml;ve Bayes (NB) yielded the lowest accuracy (61.2%), indicating limited predictive power compared with the other models. The precision peaked at 0.716, reflecting the ability of the CatBoost model to minimize false positives. Significantly outperforming other models in this metric, the highest recall was recorded for the NB model at 0.780, showing its effectiveness in identifying actual positive instances. For the F1 score, which provides a harmonic mean of precision and recall, decision tree (DT) ranked the highest at 0.662, suggesting a well-rounded performance with gradual improvement over time. Among all the models evaluated, CatBoost exhibited the most consistent and well-rounded performance across all the metrics, particularly excelling in accuracy and precision while maintaining strong F1 scores. The NB model showed surprising strength in terms of the recall and F1 score despite its lower accuracy, whereas XGBoost demonstrated good performance in all categories. These results collectively indicate that CatBoost is likely the best overall model for this classification task, with NB and XGBoost serving as strong alternatives depending on which metric is prioritized.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\u003c/div\u003e\n\u003ch3\u003eROC curve analysis, M I\u003c/h3\u003e\n\u003cp\u003eThe area under the curve (AUC) metric quantifies each model\u0026rsquo;s ability to distinguish between positive and negative classes at different classification thresholds and is useful when dealing with imbalanced datasets, where accuracy alone can be misleading. As shown in Fig.\u0026nbsp;\u003cspan refid=\"Fig2\" class=\"InternalRef\"\u003e2\u003c/span\u003e, CatBoost demonstrated the highest AUC of 0.801, indicating superior discriminating ability in balancing true positive rates against false positive rates. XGBoost followed closely with an AUC of 0.797, confirming the strength of gradient boosting methods for this classification task. NB (AUC\u0026thinsp;=\u0026thinsp;0.705) and K-nearest neighbors (KNN) (AUC\u0026thinsp;=\u0026thinsp;0.712) demonstrated the lowest discriminative power among the evaluated models, with NB clearly underperforming relative to the other approaches. The curves visually confirmed these rankings, with CatBoost and XGBoost consistently achieving higher true positive rates while maintaining lower false positive rates across most threshold values. Overall, ensemble methods (particularly boosting algorithms) emerged as the most effective approaches for this classification task, with CatBoost providing the optimal balance of sensitivity and specificity.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\n\u003ch3\u003eFeature Importance, M 1\u003c/h3\u003e\n\u003cp\u003eOn the basis of all the ML models analyzed, conductivity (mS/cm) consistently emerged as the most significant predictor for the detection of SCM (Fig.\u0026nbsp;\u003cspan refid=\"Fig3\" class=\"InternalRef\"\u003e3\u003c/span\u003e). This finding was particularly pronounced in all the models, where conductivity demonstrated substantially higher importance scores than the other features did. The second most important feature varied between the models but generally included lactation number (Lac. No.), milk production metrics such as test-day milk yield (Testday MY), and composition parameters such as fat and density. The KNN model uniquely prioritized Lac. No. is its primary feature, suggesting that different algorithms may identify complementary indicators of infection. Notably, breed-related features consistently demonstrated minimal importance across all the models. The ensemble methods (RF, XGBoost and CatBoost) showed more balanced feature importance distributions than single models such as DT and SVM did, suggesting that they leveraged multiple indicators more effectively.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\u003cdiv id=\"Sec8\" class=\"Section2\"\u003e\u003ch2\u003eMetrics, M 2\u003c/h2\u003e\u003cp\u003eThe performance of the M2 models was evaluated across multiple classification metrics similar to those of M1 (Fig.\u0026nbsp;\u003cspan refid=\"Fig4\" class=\"InternalRef\"\u003e4\u003c/span\u003e). The accuracy across the models ranged from 0.596\u0026ndash;0.677, with the LR model achieving the highest accuracy of 67.7%, followed by NB at 67.1% and NN at 66.7%. In terms of precision, which quantifies the proportion of true positive predictions among all positive predictions, the SVM performed best at 65.8%, closely followed by the NN at 65.6% and the LR at 65.5%. These similar values indicate comparable effectiveness in minimizing false positives across these three models. Recall the model\u0026rsquo;s ability to identify actual positive instances, ranging from 0.340 to 0.545, with the NB model clearly outperforming others at 54.5%. This represents a significant advantage in capturing positive cases, although all the models showed relatively low recall overall. The F1 score peaked at 0.569 with the NB model, followed by DT at 0.535. Overall, while LR delivered the best accuracy and strong precision, the NB model demonstrated the highest recall and F1 score.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\u003c/div\u003e\n\u003ch3\u003eROC curve analysis, M 2\u003c/h3\u003e\n\u003cp\u003eThe ROC curve comparison for the M2 models revealed important differences in their discriminative abilities (Fig.\u0026nbsp;\u003cspan refid=\"Fig5\" class=\"InternalRef\"\u003e5\u003c/span\u003e). The AUC metric showed that LR achieved the highest performance with an AUC of 0.686, closely followed by CatBoost with an AUC of 0.683. KNN clearly underperformed with the lowest AUC of 0.576, approaching random classification in some regions of the curve. The visual representation confirmed that LR, CatBoost, NB and SVM maintain the most favorable balance between sensitivity and specificity across different threshold values. Overall, LR emerges as the most effective model for this particular classification task, with CatBoost being a very close second-class model, demonstrating better discrimination ability than the ensemble method XGBoost, which performed relatively poorly in this comparison.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e\n\u003ch3\u003eFeature importance, M 2\u003c/h3\u003e\n\u003cp\u003eIn M2, the comparative analysis of feature importance across multiple ML models is shown in Fig.\u0026nbsp;\u003cspan refid=\"Fig6\" class=\"InternalRef\"\u003e6\u003c/span\u003e. Lac. No. emerged as a particularly influential feature in several models (LR, SVM, NN, XGBoost, CatBoost and NB). However, the magnitude of this dominance varies substantially between models, from overwhelming in SVM to more balanced in ensemble methods. In contrast, tree-based models including DT and RF prioritize milk production metrics with average daily milk yield over the preceding seven days [Avg (7 days) Daily MY] ranking highest, followed closely by Testday MY. Similarly, the KNN model assigned the greatest importance to production metrics which are Avg (7 days) Daily MY and Lac. No. the lowest. Days in milk (DIM) consistently ranked as the least important feature across most models, with the exception of KNN where it surpassed Lac. No. However, its relative contribution varied from negligible in SVM to modest in ensemble methods such as XGBoost and CatBoost. This variation in feature importance across algorithms highlights the value of employing multiple modeling approaches when analyzing dairy production data. The ensemble methods (RF, XGBoost, catBoost) demonstrated more balanced feature utilization overall, suggesting that they may capture more complex interactions between animal characteristics and production metrics than simple algorithms do.\u003c/p\u003e\u003cp\u003e\u003c/p\u003e"},{"header":"Discussion","content":"\u003cp\u003eThe aim of the current study was to establish a threshold somatic cell count to identify cows affected with SCM and to develop a model to predict SCM in dairy cows using ML techniques. Given the high prevalence of subclinical mastitis in dairy cows the application of the SCC as a diagnostic screening tool for detecting SCM at the individual cow level is highly relevant for both dairy farmers and veterinarians. However, a SCC threshold for accurately identifying SCM in dairy cows has not been established in the country. This study demonstrated how predictive models can be applied across multiple bovine herds to identify subclinical mastitis, with the goal of determining which model provides the most accurate predictions. The outcome of this from this study revealed the importance of the EC of milk as a predictor for early subclinical mastitis detection.\u003c/p\u003e\n\u003cp\u003eThe primary objective of selecting an appropriate threshold for defining SCM is to identify cows that are positive for SCM. Employing lower threshold values enhances the sensitivity of detection, thereby reducing the likelihood of false negative results. Conversely, applying higher thresholds increases the specificity of the test, which minimizes the occurrence of false positive diagnoses\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e13\u003c/span\u003e\u003c/sup\u003e. Various somatic cell count thresholds have been proposed across different countries for the identification of SCM in dairy cows. A commonly accepted cow level SCC threshold is 200 000 cells /mL, which is widely used to indicate intramammary infections at the individual cow level\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e7\u003c/span\u003e\u003c/sup\u003e. However, a lower threshold (100, 000 cells/mL) has also been suggested to detect intramammary infections in lactating dairy cows in Bangladesh where mastitis pathogens are abundant\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e10\u003c/span\u003e\u003c/sup\u003e and in a Hessian dairy cow population.in Germany\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e14\u003c/span\u003e\u003c/sup\u003e. Similarly, higher threshold levels such as 150, 000 cells/mL in South African dairy herds\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e15\u003c/span\u003e\u003c/sup\u003e, 250 000 cells/mL in Ireland\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e16\u003c/span\u003e\u003c/sup\u003e or 300 000 cells/mL in Belgium\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e17\u003c/span\u003e\u003c/sup\u003e have been reported. Considering these regional variations in somatic cell count thresholds, we were motivated to establish an appropriate threshold relevant to the Sri Lankan context. In the present study, the optimal SCC threshold for identifying subclinical mastitis was 353,000 cells/mL, which is slightly higher than the thresholds reported in previous studies. At this threshold, the sensitivity and specificity were 91.7% and 88.8%, respectively. The sensitivity achieved was notably greater than those reported by Sumon et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e10\u003c/span\u003e\u003c/sup\u003e and Sargeant et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e18\u003c/span\u003e\u003c/sup\u003e, who reported sensitivities of 53.1% and 57.4%, respectively, using a lower threshold of 100,000 cells/mL. While the specificity in the current study was lower than that reported by Sumon et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e10\u003c/span\u003e\u003c/sup\u003e i.e. 95.7%, which probably had daily observations of milk yield, milk component measurement, and SCC, it exceeded the specificity reported by Sargeant et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e18\u003c/span\u003e\u003c/sup\u003e, which was 72.3%. A comparable study by Souza et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e19\u003c/span\u003e\u003c/sup\u003e, which employed a higher SCC threshold (\u0026gt;\u0026thinsp;500,000 cells/mL) for composite milk samples, reported a lower Youden index (0.536) and sensitivity and specificity values of 65.7% and 87.9%, respectively. Considering the above findings, a SCC threshold of 353,000 cells/mL may be deemed an appropriate benchmark for identifying SCM in Sri Lankan dairy herds.\u003c/p\u003e\n\u003cp\u003eThe application of ML algorithms has introduced advanced data-driven approaches for analysing complex datasets of dairy production systems. These methods have shown considerable potential in improving decision support tools, particularly for the early detection and prediction of mastitis. Various ML techniques have been employed to detect both clinical and subclinical mastitis and these models are capable of capturing complex, nonlinear relationships among variables, thereby improving diagnostic accuracy and facilitating timely interventions. In the present study, we attempted to predict the SCM status of cows on the day of data collection using individual cow data, milk production data and composition data. Generally, several evaluation metrics such as accuracy, precision, recall and F1 score, are used to evaluate the performance of ML methods. Accuracy, one of the most commonly used metrics, represents the number of correct predictions made by the model over the total number of predictions. However, accuracy alone may not be sufficient to evaluate model performance. If it aims to minimize false negatives or false positives, evaluation on the basis of metrics such as recall or precision, respectively, may be needed. Furthermore, the F1 score which is the harmonic mean of both precision and recall, is useful for obtaining the model with the best performance\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e20\u003c/span\u003e,\u003cspan class=\"CitationRef\"\u003e21\u003c/span\u003e\u003c/sup\u003e. In the current study, considering accuracy and precision, CatBoost appeared to be the best model and NB and DT showed the best performance in terms of recall and F1, respectively, in identifying the SCM in M1. In M2, LR and SVM demonstrated the best accuracy and strong precision, respectively and the NB model showed superior recall and F1 score, suggesting that it might be the better choice for applications where identifying positive cases is critical. The models of M2 generally exhibited moderate accuracy and precision but showed limitations in recall, suggesting challenges with imbalanced classes or detecting positive cases. The prediction accuracies in the present study were 74.5% and 67.7% for M1 and M2, respectively. These values are relatively low compared with those of previous studies. A possible explanation for these comparatively lower accuracies could be the limited dataset size and the likelihood of model overfitting which may have constrained the model\u0026rsquo;s ability to generalize effectively. Bobbo et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e11\u003c/span\u003e\u003c/sup\u003e reported more than 75% prediction accuracies for all the best performing models: the NN, RF, linear discriminant analysis and generalized linear model. An accuracy of 84.9% was reported by Ebrahimi et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e8\u003c/span\u003e\u003c/sup\u003e for the model gradient boosted tree model based on milking parameters. A study performed by Hyde et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e22\u003c/span\u003e\u003c/sup\u003e revealed that the RF model was the best performing model, with an accuracy of 98% for contagious vs. environmental mastitis and 78% for mastitis during the dry environment period and the environmental lactation period as assessed by accuracy, positive predictive value (PPV) and negative predictive value (NPV). SCM was detected with an accuracy of 81% using SVM or RF models in a study conducted by Motohashi et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e23\u003c/span\u003e\u003c/sup\u003e, in Japan. The precision, recall and F1 scores reported in the current study were lower than those reported in previous studies\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e8\u003c/span\u003e,\u003cspan class=\"CitationRef\"\u003e22\u003c/span\u003e\u003c/sup\u003e.\u003c/p\u003e\n\u003cp\u003eThe AUC is another widely used metric for the evaluation of classification problems, and it has the advantages of being independent of the outcome rate, as does Matthew\u0026rsquo;s correlation coefficient (MCC). In the present dataset, in M1, CatBoost demonstrated the highest AUC of 0.801. Ebrahimi et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e8\u003c/span\u003e\u003c/sup\u003e reported a higher AUC value of 0.826 for the DT model and Ullomi\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e24\u003c/span\u003e\u003c/sup\u003e reported lower AUC values than did the current study (0.686).\u003c/p\u003e\n\u003cp\u003eThe performance of the ML models was evaluated via several metrics, and the results revealed that the models with the best performance included all the collected parameters (M1). The models with selected parameters (M2) presented lower values for accuracy, precision, recall and F1. This finding is in agreement with that of Bobbo et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e11\u003c/span\u003e\u003c/sup\u003e, who reported that all 15 selected features were relevant in predicting the outcome and recursive feature elimination revealed that the accuracy increased with increasing number of features included. The Sri Lankan dairy industry is composed of mainly medium and small-scale dairy farms and large commercial dairies are few in number. Most of the former farms do not have automated milk recording systems and do not measure the milk composition or other features considered in this study. Therefore, we intend to develop a prediction model for SCM that considers mostly available features such as \u0026apos;Lac. No.\u0026apos;, \u0026apos;DIM\u0026apos;, \u0026apos;Avg (7 days) Daily MY\u0026apos; and \u0026apos;Testday MY\u0026apos; (M2), yet the accuracy was low.\u003c/p\u003e\n\u003cp\u003eIn M1, which was based on all the ML models analyzed, conductivity emerged as the most significant predictor for the detection of the SCM across nearly all the algorithms. Ebrahimi et. al.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e8\u003c/span\u003e\u003c/sup\u003e also reported that electrical conductivity has the highest weight in the prediction of SCM. In another study of feature selection, the selected top eight features were related to electrical conductivity\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e23\u003c/span\u003e\u003c/sup\u003e. This finding aligns with the established knowledge that the electrical conductivity of milk increases with mastitis due to elevated ion concentrations resulting from inflammatory processes. This multifeatured approach provides a more comprehensive detection system than does relying on a single parameter. Notably, breed-related features consistently demonstrated minimal importance across all the models, indicating that SCM detection is largely independent of cow genetics. However, this contrasts with some previous studies that reported associations between factors such as breed\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e25\u003c/span\u003e\u003c/sup\u003e and parity\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e26\u003c/span\u003e\u003c/sup\u003e and subclinical mastitis. This comprehensive analysis supports development of multiparameter screening tools for dairy farmers, with electrical conductivity serving as the primary but not exclusive indicator for SCM detection.\u003c/p\u003e\n\u003cp\u003eThe Lac. No. has emerged as a particularly influential feature in several models, suggesting that the physiological maturity and reproductive history of dairy animals play fundamental roles in production outcomes. In contrast, tree-based models include prioritized milk production metrics, with \u003cstrong\u003e(\u003c/strong\u003eAvg (7 days) Daily MY\u003cstrong\u003e)\u003c/strong\u003e ranking highest, followed closely by Testday MY. This pattern indicates that recent production history may contain more relevant information for these algorithms than may animal characteristics. These discrepancies between linear and nonlinear models suggest that different mathematical approaches capture distinct aspects of the complex relationships within dairy production data.\u003c/p\u003e\n\u003cp\u003eThis variation in feature importance across algorithms highlights the value of employing multiple modeling approaches when analyzing dairy production data. The ensemble methods (Random Forest, XGBoost and CatBoost) demonstrated more balanced feature utilization overall, suggesting they may capture more complex interactions between animal characteristics and production metrics than simpler algorithms do. These findings emphasize that model selection significantly influences which factors are identified as most predictive in dairy science research.\u003c/p\u003e\n\u003cp\u003eThe traditional methods of SCM detection such as CMT and SCC, are widely used; they are relatively low-tech, moderate-cost and effective, but can be time-consuming, subjective, or require lab facilities. The ML approach uses existing farm data and once developed and implemented, can provide rapid, low-cost predictions with consistent accuracy and potential for earlier detection, although initial investments in data collection and digital infrastructure are needed. In Sri Lanka, CMT is widely used for screening SCM, but it is subjective and influenced by the person. SCC is more objective but less accessible for small scale dairy farmers. Well trained ML models can achieve accuracy levels comparable to or exceeding those of CMT and approach the SCC level performance, especially when trained with high quality farm specific data. ML also offers greater consistency as it avoids human interpretation bias.\u003c/p\u003e\n\u003cp\u003eThe developed ML model will be deployed in large scale dairy farmers through integration into farm management software if available or as a mobile application for small scale farmers enabling on-farm decision making. It will also be necessary to collect input data such as individual cow data, milk production data and milk composition data regularly.. Implementation requires basic digital infrastructure, including a computer or smartphone and internet access. When the cost benefit analysis is considered, although an initial investment is needed, early detection of SCM ultimately results in a greater return on investment through improved health and productivity of cows.\u003c/p\u003e\n\u003cp\u003eIn Sri Lanka, current limitations of the machine learning approach for predicting SCM include reliance on the quality and quantity of available farm data, potential bias when data are collected from a limited number of farms, and reduced accuracy when management or environment factors differ from the training dataset. To overcome current limitations, data quality can be improved by standardizing collection methods and expanding datasets through the inclusion of several farms. Model generalizability can be enhanced via external validation, transfer learning, and the inclusion of farm-specific context features. The pipeline can be strengthened with automated feature selection, continuous model monitoring, and scheduled retraining.\u003c/p\u003e\n\u003cp\u003eThe current study identified an optimal somatic cell count threshold of 353,000 cells/mL for detecting SCM in Sri Lankan dairy cows. Additionally, the application of ML techniques provides a promising avenue for developing predictive models for SCM. Among the tested algorithms, CatBoost exhibited the highest performance in terms of accuracy and AUC, whereas other models, such as NB, LR, and SVM, presented strengths across different evaluation metrics. The models trained on all the available features in the dataset (M1) outperformed the reduced-feature models (M2), reinforcing the importance of comprehensive data collection in improving the predictive accuracy. Electrical conductivity has emerged as the most consistent and influential predictor across models, validating its utility as a key indicator of SCM. Given the limited access to automated data collection in many Sri Lankan dairy farms the development of simplified, yet effective, ML models hold significant potential for practical implementation. Overall, this study highlights the value of integrating diagnostic thresholds with data-driven ML tools for enhancing mastitis detection and control strategies in the local dairy industry.\u003c/p\u003e"},{"header":"Methods","content":"\u003ch2\u003eStudy Locations and Animals\u003c/h2\u003e\n\u003cp\u003eThe study was designed as a cross sectional epidemiological investigation involving three commercial dairy herds located in the Nuwaraeliya district of the Central Province of Sri Lanka. Herds were selected on the basis of the accessibility of data and willingness to participate in the study. A total of 2420 lactating cows (A: n\u0026thinsp;=\u0026thinsp;1002; B: n\u0026thinsp;=\u0026thinsp;898; and C: n\u0026thinsp;=\u0026thinsp;520) were included over a six-month period from December 2022 to May 2023. The cows were primarily Holstein-Friesian, Ayrshire, and their crosses, housed in free-stall barns and managed under an intensive system (cows were kept in barns for 24 h while supplying feed). Each herd was milked three times daily using machine milking, with average milk yields of 17, 27, and 30 L per cow across the three farms. All the cows were provided cut-and-carry feed along with supplemental concentrates, vitamins, and mineral mixtures tailored to their production levels. Cows displaying visible udder or milk abnormalities, clinical mastitis, or other diseases at the time of examination were excluded from the study.\u003c/p\u003e\n\u003ch2\u003eSampling and data collection\u003c/h2\u003e\n\u003cp\u003eTwo 15 mL centrifuge tubes were prepared one with potassium dichromate preservative for somatic cell count analysis, and one without the preservative for pH and milk composition measurements for each composite milk sample collected. The preservative solution was prepared, employing safety precautions, by dissolving I g of potassium dichromate in 5.05 mL of deionized water. Fifty microliters of this mixture were dispensed into each tube at room temperature and allowed to air dry in a ventilated area at room temperature (20\u0026ndash;25\u0026deg;C) for 5\u0026ndash;6 days. The tubes were labeled with cow ID using waterproof markers.\u003c/p\u003e\n\u003cp\u003eEach farm was visited during the noon milking period for sample and data collection. Before the milk samples were collected, the teats were thoroughly washed with a 0.5% iodine solution, wiped clean, and dried using sterile towels. Next, the teats were disinfected with 70% ethanol-soaked cotton to ensure aseptic conditions. The first few streams of milk were discarded to remove potential contaminants. Composite foremilk samples (30 ml) were then aseptically collected from all quarters into sterilized pre-labeled plastic cups. CMT was performed onsite immediately after collection. The samples were subsequently divided into two portions: one aliquot was transferred to a 15 ml centrifuge tube containing potassium dichromate as a preservative, while the other was placed in a preservative-free centrifuge tube. Both samples were mixed thoroughly, labeled, and stored in a cool box with ice packs to maintain low temperatures during transport to the Laboratory of Dairy Technology, Department of Animal Science, Faculty of Agriculture, University of Peradeniya. The transport process was completed within 5 hours of collection to ensure sample integrity. In the laboratory, the samples were stored at 4\u0026deg;C until analysis, during which they were thawed at room temperature. Data from individual cows, including breed, Lac. No., DIM, Avg (7 days) Daily MY and Testday MY, were retrieved from the farm\u0026rsquo;s digital record-keeping system. Herd and management-related information was gathered through interviews with farm managers via a pretested, structured questionnaire.\u003c/p\u003e\n\u003cp\u003eAll experimental procedures involving cows were conducted in full compliance with the ethical guidelines established by the Ethics Review Committee, Faculty of Veterinary Medicine and Animal Science. Approval for the study was obtained prior to commencement, ensuring adherence to internationally accepted standards for animal welfare and research ethics (Proposal ID - VERC-23-02).\u003c/p\u003e\n\u003ch2\u003eCalifornia Mastitis Test (CMT) and identification of animals with SCM\u003c/h2\u003e\n\u003cp\u003eCMT was used to detect cows with SCM\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e27\u003c/span\u003e\u003c/sup\u003e. The test was conducted by adding 3 mL of CMT reagent to 3 mL of milk in each well of the CMT paddle. The paddle was then rotated gently in a horizontal circular motion for 60 seconds to thoroughly mix the reagent with the milk and allow gel formation; The results were assessed on the basis of the observed changes in the mixture\u0026rsquo;s consistency and scored according to the following criteria: 0 (negative): normal consistency with no gel formation, 1 (trace/positive): slight gel formation with a purplish-gray colour, 2 (positive): light but persistent gel formation with a purple-gray colour, 3 (positive): immediate thickening, forming a viscous cluster at the bottom of the well, and 4 (positive): thick gel with a consistency similar to egg white and a dark purple color.\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e28\u003c/span\u003e,\u003cspan class=\"CitationRef\"\u003e29\u003c/span\u003e\u003c/sup\u003e To reduce variability in scoring and ensure consistency, all CMT tests were performed by the second author, who was trained in the procedure.\u003c/p\u003e\n\u003ch2\u003eMeasurement of pH and milk composition parameters\u003c/h2\u003e\n\u003cp\u003eAfter thawing, the pH of each milk sample was measured using a calibrated pH meter. The composition of milk, including fat, protein, lactose, solid-non-fat (SNF), density, conductivity, salt content and freezing point was analyzed using a LACTOSCAN SP milk analyzer (Milkotronic Ltd). All analyses were conducted following the manufacturer\u0026rsquo;s instructions, with regular calibration and maintenance of the equipment to ensure reliable results.\u003c/p\u003e\n\u003ch2\u003eMeasurement of Somatic Cell Count (SCC)\u003c/h2\u003e\n\u003cp\u003eSCC was determined using a LACTOSCAN SCC analyzer (Milkotronic Ltd.) following the manufacturer\u0026rsquo;s protocol. The milk samples were first equilibrated to room temperature before being placed in a water bath at 40\u0026deg;C for 20 minutes. The samples were then cooled to 20\u0026deg;C to optimize dye interactions. After cooling, the milk was thoroughly mixed using a vortex mixer for uniform dispersion of somatic cells. One hundred microliters of milk were carefully pipetted into prelabeled Eppendorf tubes containing Sofia Green dye. The milk-dye mixture was vortexed for 10 seconds to ensure homogeneity and allowed to stand for one minute to facilitate dye-cell binding. Subsequently, 8 \u0026micro;L of the prepared sample was precisely pipetted onto the measurement chips. The chips were inserted into the LACTOSCAN SCC device, and SCC were automatically recorded from the digital display.\u003c/p\u003e\n\u003ch2\u003eData Management and Statistical Analyses\u003c/h2\u003e\n\u003ch2\u003eCalculation of threshold somatic cell count\u003c/h2\u003e\n\u003cp\u003eAmong the 2420 samples collected, 1661 were subjected to the CMT test to determine the SCC. The CMT could not be performed on the remaining samples because of time limitations during the milking process. Cows with a CMT score of 0 were classified as negative for SCM. In contrast, cows with a CMT score of 1 or higher, accompanied by a visibly normal udder and normal milk, were categorized as positive for SCM. For each somatic cell count value, sensitivity, specificity and Youden\u0026rsquo;s index\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e15\u003c/span\u003e\u003c/sup\u003e, were calculated using the formulas provided below. The SCC threshold value with the highest Youden\u0026rsquo;s index was identified as the optimal cutoff value for diagnosing SCM positive cows.\u003c/p\u003e\n\u003cp\u003eSensitivity (Se): The proportion of infected cows whose SCC values were above the selected threshold [equation (1)].\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e(1) Se\u0026thinsp;=\u0026thinsp;TP/(TP\u0026thinsp;+\u0026thinsp;FN)\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eSpecificity (Sp): The proportion of uninfected cows whose SCC values were below the selected threshold [equation (2)].\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e(2) Sp\u0026thinsp;=\u0026thinsp;TN/(TN\u0026thinsp;+\u0026thinsp;FP)\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eTP\u0026thinsp;=\u0026thinsp;true-positive test result (infected cows above the SCC threshold)\u003c/p\u003e\n\u003cp\u003eFP\u0026thinsp;=\u0026thinsp;false-positive test result (uninfected cows above the SCC threshold)\u003c/p\u003e\n\u003cp\u003eTN\u0026thinsp;=\u0026thinsp;true-negative test result (uninfected cows below or equal to the SCC threshold)\u003c/p\u003e\n\u003cp\u003eFN\u0026thinsp;=\u0026thinsp;false-negative test result (infected cows below or equal to the SCC threshold)\u003c/p\u003e\n\u003cp\u003eYouden\u0026rsquo;s index (J) is a metric commonly used to determine the optimal threshold value for a diagnostic test. Typically, thresholds with high sensitivity and high specificity are preferred to balance diagnostic accuracy. However, sensitivity and specificity may not carry equal importance in every instance. For example, if false-negative results have more serious consequences than false-positive results do, a threshold value prioritizing higher sensitivity over specificity might be selected. Conversely, when avoiding false positives is critical, a threshold with comparatively higher specificity may be preferred. Youden\u0026rsquo;s index is particularly valuable for selecting a threshold that balances both sensitivity and specificity. It is calculated using the following formula [Equation (3)]:\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e(3) J\u0026thinsp;=\u0026thinsp;sensitivity\u0026thinsp;+\u0026thinsp;specificity \u0026ndash; 1\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eThe value of J ranges from 0\u0026ndash;1. A test with excellent diagnostic performance achieves a maximum J value of 1, indicating perfect sensitivity and specificity. In contrast, a value of 0 reflects a test with no diagnostic utility. The SCC threshold value with the highest Youden\u0026rsquo;s index was identified as the optimal cutoff value for diagnosing SCM positive cows.\u003c/p\u003e\n\u003ch2\u003eModel development\u003c/h2\u003e\n\u003cp\u003eThe development of the ML model followed a structured workflow, including data preprocessing, exploratory data analysis (EDA), model selection via cross-validation, performance evaluation and final validation on test data. The data preprocessing pipeline included the following steps. First, initial data cleaning was performed by removing nonpredictive columns (identification number and sample number) to focus on biologically relevant features. A critical quality control step involved filtering invalid entries in the conductivity (mS/cm) feature, where 97 rows containing nonnumeric values (e.g., \u0026ldquo;out of range\u0026rdquo;) were removed. The final dataset retained 2403 samples after cleaning. Second, missing value imputations were performed. Missing values were identified for four features: Avg (7 days) Daily MY (L): 20 missing values (0.83% of samples); Testday MY (L): 71 missing values (2.95% of samples); conductivity (mS/cm): 62 (2.58% of samples); and freezing point (⁰C): 4 (0.17% of samples). Median imputation for these features was employed after verifying right-skewed distributions through exploratory analysis. The median robustness to outliers makes imputation preferable for preserving the integrity of milk yield and sensor-derived measurements. Third, in feature engineering, categorical encoding includes label encoding for the farm variable to convert farm IDs into ordinal representations and one-hot encoding for breeds to create six binary features representing cattle breeds. The column SCC (10\u003csup\u003e3\u003c/sup\u003ecells/mL) was replaced by diseased or not diseased considering the threshold SCC estimated in the current study. The integrity of the dataset was confirmed by identifying 0 duplicate cows postprocessing. The target variable SCM showed a 60:40 class imbalance (1446 negative vs. 957 positive cases), which informed subsequent stratification during data splitting. Fourth, for feature scaling, a dual-scaling approach, the standard scaler for freezing points (⁰C) to center the feature around zero mean (\u0026plusmn;\u0026thinsp;1 SD) and the MinMax scaler for remaining numerical features to normalize values between 0\u0026ndash;1 was implemented so that no variable dominated due to larger scales. This hybrid strategy addresses the presence of negative values in freezing point measurements while maintaining consistent scaling for other physiological parameters. In this way, small differences in the freezing point were preserved relative to the overall variability instead of being squashed. Finally, the data were partitioned using an 80:20 stratified training: test split (random state\u0026thinsp;=\u0026thinsp;42) to preserve class proportions. The training set included 1922 samples (1157 negative and 765 positive samples) and the test set included 481 samples (289 negative and 192 positive samples). Stratification mitigated bias in model evaluation given the observed class imbalance. The feature matrices (X train, X test) and target vectors (Y train, Y test) were stored separately, with scaling parameters derived exclusively from training data to prevent information leakage.\u003c/p\u003e\n\u003cp\u003eSummary statistics, correlation matrices, and data distribution visualizations were used in EDA to evaluate data quality, analyze feature relationships and identify potential issues necessitating further preprocessing or feature engineering.\u003c/p\u003e\n\u003cp\u003eTwo sets of ML models were developed and assessed. M1: Models considering all the variables: Lac. No.\u0026rsquo;, \u0026lsquo;DIM\u0026rsquo;, \u0026lsquo;Avg (7 days) Daily MY\u0026rsquo;, \u0026lsquo;Testday MY\u0026rsquo;, \u0026lsquo;Fat\u0026rsquo;, \u0026lsquo;SNF\u0026rsquo;, \u0026lsquo;Density\u0026rsquo;, \u0026lsquo;Protein\u0026rsquo;, \u0026lsquo;Conductivity\u0026rsquo;, \u0026lsquo;pH\u0026rsquo;, \u0026lsquo;Freezing point (⁰C)\u0026rsquo;, \u0026lsquo;Salt (%)\u0026rsquo;, \u0026lsquo;Lactose (%) and M2: A set of models considering only \u0026lsquo;Lac. No.\u0026rsquo;, \u0026lsquo;DIM\u0026rsquo;, \u0026lsquo;Avg (7 days) Daily MY\u0026rsquo;, \u0026lsquo;Testday MY\u0026rsquo; variables. M2 was developed on the basis of variables (Lac. No.\u0026rsquo;, \u0026lsquo;DIM\u0026rsquo;, \u0026lsquo;Avg (7 days) Daily MY\u0026rsquo;, and \u0026lsquo;Testday MY\u0026rsquo;) that can be readily and feasibly collected from Sri Lankan dairy farms. A set of best performing classifiers selected on the basis of, previous studies\u003csup\u003e\u003cspan class=\"CitationRef\"\u003e8\u003c/span\u003e,\u003cspan class=\"CitationRef\"\u003e11\u003c/span\u003e\u003c/sup\u003e was evaluated for predictive performance. These included nine models ranging from simple and interpretable approaches such as LR, NB, DT, and KNN to more advanced techniques such as SVM, NN, RF, XGBoost and CatBoost. They addressed the dataset\u0026rsquo;s 60:40 class imbalance through techniques such as class weighing and boosting, capturing both linear and nonlinear patterns. While models such as DT and RF offer high interpretability, advanced methods such as XGBoost and CatBoost enhance detection accuracy by modeling complex feature interactions. These nine models were optimized through hyperparameter tuning to balance interpretability, accuracy and handling of the class imbalance. Simple models such as LR, DT and NB apply class weighting or oversampling, whereas ensemble methods such as RF, XGBoost, and CatBoost use tuned depths, learning rates and iterations to increase stability and capture complex patterns. Advanced methods such as SVM incorporate architecture or kernel tuning, with normalization and oversampling ensuring robust performance on small-to-medium datasets. The study employed a 5-fold stratified cross-validation scheme to evaluate model performance for detecting SCM with accuracy, precision, recall and F1 as metrics. Stratification was used to maintain the original class distribution in each fold, preserving the minority mastitis class representation and addressing potential overfitting. The 5-fold choice balances computational efficiency with reliability, providing five independent train-test splits while leveraging the full dataset, which is critical given the moderate sample size. When a sample labeled true is predicted true it is defined as a true positive (TP) and when a sample labeled false is predicted true it is defined as a false positive (FP). The precision is defined as follows: [equation (4)].\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e(4) precision\u0026thinsp;=\u0026thinsp;TP/ (TP\u0026thinsp;+\u0026thinsp;FP).\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e"},{"header":"Declarations","content":"\u003cp\u003e\u003cstrong\u003eData availability statement\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe dataset analyzed in the current study is available from the corresponding author upon reasonable request.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eAcknowledgement\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe cooperation of the farm managers and staff is sincerely appreciated.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eFunding\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe authors gratefully acknowledge the financial support provided by the University Research Council, University of Peradeniya, Sri Lanka (Grant No. MRG-199).\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eAuthor contributions\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eR.M.C.O.R, M.P.S., A.P.A. and K.K. developed the machine learning algorithms. \u0026nbsp;R.M.C.O.R. analyzed the results. K.M.D., R.M.C.D. and R.M.S.B.K.R was involved in farm visits and data collection. K.M.D. conducted all the laboratory experiments. R.M.S.B.K.R. conceived the study, wrote the proposal, obtained the grant and supervised the project. R.M.C.O.R and R.M.S.B.K.R. wrote the manuscript. All the authors reviewed the manuscript.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eCompeting interests\u0026nbsp;\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe authors declare that they have no competing interests.\u003c/p\u003e"},{"header":"References","content":"\u003col\u003e\n\u003cli\u003eLosinger, W. C. Economic impacts of reduced milk production associated with an increase in bulk-tank somatic cell count on US dairies. \u003cem\u003eJ. Am. Vet. Med. Assoc.\u003c/em\u003e\u003cstrong\u003e226\u003c/strong\u003e, 1652-1658, DOI: \u003cu\u003ehttp://dx.doi.org/\u003c/u\u003e10.2460/javma.2005.226.1652 (2005).\u003c/li\u003e\n\u003cli\u003eHalasa, T., Huijps, K., Osteras, O. \u0026amp; Hogeveen, H. Economic effects of bovine mastitis and mastitis management: A review. \u003cem\u003eVet. Q.\u003c/em\u003e\u003cstrong\u003e29\u003c/strong\u003e, 18\u0026ndash;31, DOI: https://doi.org/10.1080/01652176.2007.9695224 (2007).\u003c/li\u003e\n\u003cli\u003eHogeveen, H., Huijps, K. \u0026amp; Lam, T. J. G. M. Economic aspects of mastitis: New developments. \u003cem\u003eN. Z. Vet J.\u003c/em\u003e\u003cstrong\u003e59\u003c/strong\u003e(1), 16\u0026ndash;23, DOI: https://doi.org/10.1080/00480169.2011.547165 (2011).\u003c/li\u003e\n\u003cli\u003eVeterinary Epidemiological Bulletin. 2023. Department of Animal Production and Health, P.O. Box 13, Peradeniya, Sri Lanka. Accessed Nov. 13, 2024. https://daph.gov.lk/files/uploads/documents/downloads/Bulletine%20-2023-3rd%20Q.pdf.\u003c/li\u003e\n\u003cli\u003eHillerton, J. E. Redefining mastitis based on somatic cell count. Bulletin of the International Dairy Federation, \u003cstrong\u003e345\u003c/strong\u003e, 4-6 (1999). \u003c/li\u003e\n\u003cli\u003eG\u0026uuml;lzari, Ş. \u0026Ouml;., Ahmadi, B. V. \u0026amp; Stott, A.W. Impact of subclinical mastitis on greenhouse gas emissions intensity and profitability of dairy cows in Norway. \u003cem\u003ePrev. Vet. Med.\u003c/em\u003e\u003cstrong\u003e150\u003c/strong\u003e, 19\u0026ndash;29, DOI: https://doi.org/10.1016/j.prevetmed.2017.11.021 (2018).\u003c/li\u003e\n\u003cli\u003eSmith, K. L., Hillerton, J. E. \u0026amp; Harmon, R. J. National Mastitis Council Guidelines on normal and abnormal milk based on somatic cell counts and signs of clinical mastitis. National Mastitis Council, Madison WI, pp3 (2001).\u003c/li\u003e\n\u003cli\u003eEbrahimi, M., Mohammadi-Dehcheshmeh, M., Ebrahimie, E. \u0026amp; Petrovski, K.R. Comprehensive analysis of machine learning models for prediction of sub-clinical mastitis: Deep Learning and Gradient-Boosted Trees outperform other models. \u003cem\u003eComput. Biol. Med.\u003c/em\u003e\u003cstrong\u003e114\u003c/strong\u003e, 103456, DOI: https://doi.org/10.1016/j.compbiomed.2019.103456 (2019).\u003c/li\u003e\n\u003cli\u003eJadhav, P. V., Das, D. N., Suresh, K. P. \u0026amp; Shome, B. R. Threshold Somatic Cell count for delineation of subclinical mastitis cases. \u003cem\u003eVet. World.\u003c/em\u003e\u003cstrong\u003e11\u003c/strong\u003e(6), 789-793, DOI: https://doi.org/10.14202/vetworld.2018.789-793 (2018).\u003c/li\u003e\n\u003cli\u003eSumon, S. M. M. R., Parvin, M. S., Ehsan, M. A. \u0026amp; Islam, T. 2020. Relationship between somatic cell counts and subclinical mastitis in lactating dairy cows. \u003cem\u003eVet. World\u003c/em\u003e\u003cstrong\u003e13\u003c/strong\u003e(8), 1709-1713, DOI: \u003cu\u003ehttps://doi.org/\u003c/u\u003e10.14202/vetworld.2020.1709-1713 (2020).\u003c/li\u003e\n\u003cli\u003eBobbo, T., Biffani, S., Taccioli, C., Penasa, M. \u0026amp; Cassandro, M. Comparison of machine learning methods to predict udder health status based on somatic cell counts in dairy cows. \u003cem\u003eSci. Rep.\u003c/em\u003e\u003cstrong\u003e11\u003c/strong\u003e, 13642, DOI: https://doi.org/10.1038/s41598-021-93056-4 (2021). \u003c/li\u003e\n\u003cli\u003eAbdul Ghafoor, N. \u0026amp; Sitkowska, B. MasPA: A machine learning application to predict risk of mastitis in cattle from AMS sensor data. \u003cem\u003eAgric. Eng.\u003c/em\u003e\u003cstrong\u003e3\u003c/strong\u003e(3), 575-583, DOI: https://doi.org/10.3390/agriengineering3030037 (2021).\u003c/li\u003e\n\u003cli\u003ePantoja, J. C., Hulland, C. \u0026amp; Ruegg, P. L. Dynamics of somatic cell counts and intramammary infections across the dry period. \u003cem\u003ePrev. Vet. Med.\u003c/em\u003e\u003cstrong\u003e90\u003c/strong\u003e(2), 43\u0026ndash;54, DOI: https://doi.org/10.1016/j.prevetmed.2009.03.012 (2009).\u003c/li\u003e\n\u003cli\u003eSchwarz, D. et al. Somatic cell counts and bacteriological status in quarter foremilk samples of cows in Hesse, Germany\u0026mdash;A longitudinal study. \u003cem\u003eJ. Dairy Sci.\u003c/em\u003e\u003cstrong\u003e93\u003c/strong\u003e, 5716\u0026ndash;5728, DOI: https://doi.org/10.3168/jds.2010-3223 (2010).\u003c/li\u003e\n\u003cli\u003ePetzer, I-M., Karzis, J., Donkin, E. F., Webb E. C. \u0026amp; Etter, E. M. C. Somatic cell count thresholds in composite and quarter milk samples as indicator of bovine intramammary infection status. \u003cem\u003eOnderstepoort J. Vet. Res.\u003c/em\u003e\u003cstrong\u003e84\u003c/strong\u003e(1), e1-e10, DOI: https://doi.org/10.4102/ojvr.v84i1.1269 (2017).\u003c/li\u003e\n\u003cli\u003eBerry, D. P. \u0026amp; Meaney, W. J. Interdependence and distribution of subclinical mastitis and intramammary infection among udder quarters in dairy cattle. \u003cem\u003ePrev. Vet. Med.\u003c/em\u003e\u003cstrong\u003e75\u003c/strong\u003e, 81\u0026ndash;91, DOI: https://doi.org/10.1016/j.prevetmed.2006.02.001 (2006).\u003c/li\u003e\n\u003cli\u003eDeluyker, H. A., Oye, S. N. V. \u0026amp; Boucher, J. F. Factors affecting cure and somatic cell count after pirlimycin treatment of subclinical mastitis in lactating cows. \u003cem\u003eJ. Dairy Sci.\u003c/em\u003e\u003cstrong\u003e88\u003c/strong\u003e, 604\u0026ndash;614, DOI: \u003cu\u003ehttps://doi.org/\u003c/u\u003e10.3168/jds.S0022-0302(05)72724-7 (2005).\u003c/li\u003e\n\u003cli\u003eSargeant, J. M., Leslie, K. E., Shirley, J. E., Pulkrabek, B. J. \u0026amp; Lim, G. H. Sensitivity and specificity of somatic cell count and California Mastitis Test for identifying intramammary infection in early lactation. \u003cem\u003eJ. Dairy Sci.\u003c/em\u003e\u003cstrong\u003e84\u003c/strong\u003e, 2018\u0026ndash;2024, DOI: https://doi.org/10.3168/jds.S0022-0302(01)74645-0(2001). \u003c/li\u003e\n\u003cli\u003eSouza F. N. et al. Somatic cell count and mastitis pathogen detection in composite and single or duplicate quarter milk samples. \u003cem\u003ePesq. Vet. Bras.\u003c/em\u003e\u003cstrong\u003e36\u003c/strong\u003e(9), 11-818, DOI: https://doi.org/10.1590/S0100-736X2016000900004 (2016). \u003c/li\u003e\n\u003cli\u003eCabot, J. H. \u0026amp; Ross, E. G. Evaluating prediction model performance. \u003cem\u003eSurgery.\u003c/em\u003e\u003cstrong\u003e174\u003c/strong\u003e(3), 723-726, DOI: https://doi.org/10.1016/j.surg.2023.05.023 (2023).\u003c/li\u003e\n\u003cli\u003eGleckler, P. J., Taylor, K. E. \u0026amp; Doutriaux, C. Performance metrics for climate models. \u003cem\u003eJ. Geophys. Res.\u003c/em\u003e\u003cstrong\u003e113\u003c/strong\u003e, D06104, DOI: https://doi.org/10.1029/2007JD008972 (2008).\u003c/li\u003e\n\u003cli\u003eHyde, R. M. et al. Automated prediction of mastitis infection patterns in dairy herds using machine learning. \u003cem\u003eSci. Rep.\u003c/em\u003e\u003cstrong\u003e10\u003c/strong\u003e, 1-8, DOI: https://doi.org/10.1038/s41598-020-61126-8 (2020).\u003c/li\u003e\n\u003cli\u003eMotohashi, H., Ohwada, H. \u0026amp; Kubota, C. Early detection method for subclinical mastitis in auto milking systems using machine learning. in IEEE 19\u003csup\u003eth\u003c/sup\u003e International Conference on Cognitive Informatics and Cognitive Computing (ICCI*CC), Beijing, China. 76-83, DOI: https://doi.org/10.1109/iccicc50026.2020.9450258 (2020).\u003c/li\u003e\n\u003cli\u003eUllomi, J. O. \u003cem\u003eSubclinical Mastitis Detection by Machine Learning\u003c/em\u003e. Thesis. Centre for Bioinformatics University of Veterinary Medicine Budapest, Hungary. (2023).\u003c/li\u003e\n\u003cli\u003eSalamanca-Carre\u0026ntilde;o, A. et al. Breed and non-genetic risk factors associated with the prevalence of subclinical mastitis in livestock systems of Arauca, Colombian orinoquia. \u003cem\u003eInt. J. Vet. Sci.\u003c/em\u003e\u003cem\u003eMed. \u003c/em\u003e\u003cstrong\u003e12\u003c/strong\u003e(1), 1-10, DOI: \u003cu\u003ehttps://doi.org/\u003c/u\u003e10.1080/23144599.2024.2310451 (2024). \u003c/li\u003e\n\u003cli\u003eRanasinghe, R.M. S. B. K., Deshapriya, R. M. C., Abeygunawardana, D. I., Rahularaj, R. \u0026amp; Dematawewa, C. M. B. Subclinical mastitis in dairy cows in major milk-producing areas of Sri Lanka: prevalence, as sociated risk factors, and effects on reproduction. \u003cem\u003eJ. Dairy Sci.\u003c/em\u003e\u003cstrong\u003e104\u003c/strong\u003e, 12900\u0026ndash;12911, DOI: https://doi.org/10.3168/jds.2021-20223 (2021).\u003c/li\u003e\n\u003cli\u003eQuinn, P. J., Carter, M. E., Markey, B. \u0026amp; Carter, G. R. \u003cem\u003eMastitis in Clinical Veterinary Microbiology\u003c/em\u003e. (First edition), Elsevier Ltd, Philadelphia, USA. 327-335 (1999).\u003c/li\u003e\n\u003cli\u003eGunawardana, S. et al. Risk factors for bovine mastitis in the Central Province of Sri Lanka. \u003cem\u003eTrop. Anim. Health Prod.\u003c/em\u003e\u003cstrong\u003e46\u003c/strong\u003e(7), 1105\u0026ndash;1112, DOI: https://doi.org/10.1007/s11250-014-0602-9 (2014). \u003c/li\u003e\n\u003cli\u003eKayesh, M. E. H., Talukder, M. \u0026amp; Anower, A. K. M. M. Prevalence of subclinical mastitis and its association with bacteria and risk factors in lactating cows of Barisal district in Bangladesh. \u003cem\u003eInt. J. Biol. Res.\u003c/em\u003e\u003cstrong\u003e2\u003c/strong\u003e(2), 35-38, DOI: https://doi.org/10.14419/ijbr.v2i2.2835(2014).\u003c/li\u003e\n\u003c/ol\u003e"}],"fulltextSource":"","fullText":"","funders":[],"hasAdminPriorityOnWorkflow":false,"hasManuscriptDocX":true,"hasOptedInToPreprint":true,"hasPassedJournalQc":"","hasAnyPriority":false,"hideJournal":false,"highlight":"","institution":"","isAcceptedByJournal":true,"isAuthorSuppliedPdf":false,"isDeskRejected":"","isHiddenFromSearch":false,"isInQc":false,"isInWorkflow":false,"isPdf":false,"isPdfUpToDate":true,"isWithdrawnOrRetracted":false,"journal":{"display":true,"email":"[email protected]","identity":"scientific-reports","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":false,"externalIdentity":"scirep","sideBox":"Learn more about [Scientific Reports](http://www.nature.com/srep/)","snPcode":"","submissionUrl":"","title":"Scientific Reports","twitterHandle":"","acdcEnabled":true,"dfaEnabled":true,"editorialSystem":"stoa","reportingPortfolio":"Scientific Reports","inReviewEnabled":true,"inReviewRevisionsEnabled":true},"keywords":"Subclinical mastitis, threshold SCC, ML models, dairy cows","lastPublishedDoi":"10.21203/rs.3.rs-7519712/v1","lastPublishedDoiUrl":"https://doi.org/10.21203/rs.3.rs-7519712/v1","license":{"name":"CC BY 4.0","url":"https://creativecommons.org/licenses/by/4.0/"},"manuscriptAbstract":"\u003cp\u003eThis study aims to establish a somatic cell count threshold to identify cows with subclinical mastitis (SCM) and to develop a machine learning model to predict the incidence of SCM using individual cow data, milk production data and composition data. Milk samples were collected from 2420 cows, for CMT, SCC determination and milk composition analysis. Information on individual cows and their milk production was obtained from farm records. The diagnostic SCC threshold was identified on the basis of CMT scores using the Youden\u0026rsquo;s index. Two sets of models; one with all the variables (M1) and another with five selected variables (M2) were trained. The SCC threshold yielding the highest Youden\u0026rsquo;s index was 353,000 cells/mL. For Model 1 (M1), CatBoost achieved the highest accuracy (74.5%) and precision (0.716), while na\u0026iuml;ve bayes attained the highest recall (0.780) and the decision tree produced the highest F1 score (0.662). CatBoost also recorded the highest AUC (0.801). Milk conductivity (mS/cm) consistently emerged as the most influential predictor across nearly all the algorithms. In Model 2 (M2), the overall performance decreased, with logistic regression achieving the highest accuracy (67.7%) and AUC (0.686), support vector machine demonstrating the highest precision (65.8%), and na\u0026iuml;ve bayes outperforming the others methods in terms of the recall and F1 score.\u003c/p\u003e","manuscriptTitle":"Machine learning-based prediction of subclinical mastitis in large-scale dairy herds using a locally established somatic cell count threshold","msid":"","msnumber":"","nonDraftVersions":[{"code":1,"date":"2025-09-18 13:03:01","doi":"10.21203/rs.3.rs-7519712/v1","editorialEvents":[{"type":"communityComments","content":0},{"type":"decision","content":"Revision requested","date":"2025-11-17T15:13:47+00:00","index":"","fulltext":""},{"type":"editorInvitedReview","content":"","date":"2025-11-14T21:11:22+00:00","index":"hide","fulltext":""},{"type":"reviewerAgreed","content":"71939347020624105185099799875093201738","date":"2025-11-10T16:27:24+00:00","index":"hide","fulltext":""},{"type":"editorInvitedReview","content":"","date":"2025-09-30T21:22:09+00:00","index":"hide","fulltext":""},{"type":"reviewerAgreed","content":"196040851866434253818117761838720997746","date":"2025-09-13T01:14:55+00:00","index":"hide","fulltext":""},{"type":"reviewerAgreed","content":"151240933992972250964880052136204117705","date":"2025-09-10T12:15:58+00:00","index":"hide","fulltext":""},{"type":"reviewersInvited","content":"","date":"2025-09-10T00:54:19+00:00","index":"","fulltext":""},{"type":"editorInvited","content":"","date":"2025-09-05T18:33:19+00:00","index":"","fulltext":""},{"type":"editorAssigned","content":"","date":"2025-09-05T07:46:55+00:00","index":"","fulltext":""},{"type":"checksComplete","content":"","date":"2025-09-05T02:48:39+00:00","index":"","fulltext":""},{"type":"submitted","content":"Scientific Reports","date":"2025-09-02T16:08:56+00:00","index":"","fulltext":""}],"status":"published","journal":{"display":true,"email":"[email protected]","identity":"scientific-reports","isNatureJournal":false,"hasQc":true,"allowDirectSubmit":false,"externalIdentity":"scirep","sideBox":"Learn more about [Scientific Reports](http://www.nature.com/srep/)","snPcode":"","submissionUrl":"","title":"Scientific Reports","twitterHandle":"","acdcEnabled":true,"dfaEnabled":true,"editorialSystem":"stoa","reportingPortfolio":"Scientific Reports","inReviewEnabled":true,"inReviewRevisionsEnabled":true}}],"origin":"","ownerIdentity":"1a31d69f-6061-4435-9168-0acbb1b9f791","owner":[],"postedDate":"September 18th, 2025","published":true,"recentEditorialEvents":[],"rejectedJournal":[],"revision":"","amendment":"","status":"published-in-journal","subjectAreas":[{"id":54815199,"name":"Biological sciences/Computational biology and bioinformatics"},{"id":54815200,"name":"Health sciences/Diseases"}],"tags":[],"updatedAt":"2026-05-04T16:04:05+00:00","versionOfRecord":{"articleIdentity":"rs-7519712","link":"https://doi.org/10.1038/s41598-026-50467-5","journal":{"identity":"scientific-reports","isVorOnly":false,"title":"Scientific Reports"},"publishedOn":"2026-04-28 15:58:35","publishedOnDateReadable":"April 28th, 2026"},"versionCreatedAt":"2025-09-18 13:03:01","video":"","vorDoi":"10.1038/s41598-026-50467-5","vorDoiUrl":"https://doi.org/10.1038/s41598-026-50467-5","workflowStages":[]},"version":"v1","identity":"rs-7519712","journalConfig":"researchsquare"},"__N_SSP":true},"page":"/article/[identity]/[[...version]]","query":{"redirect":"/article/rs-7519712","identity":"rs-7519712","version":["v1"]},"buildId":"XKTyCvWXoU3ODBz1xrDgd","isFallback":false,"isExperimentalCompile":false,"dynamicIds":[84888],"gssp":true,"scriptLoader":[]}

Text is read by the "Ask this paper" AI Q&A widget below. Extraction quality varies by source — PMC NXML preserves structure cleanly, OA-HTML may include some navigation residue, and OA-PDF can have broken hyphenation. The publisher copy (via DOI) is the canonical version.

My notes (saved in your browser only)

Ask this paper AI returns verbatim quotes from the full text · source: preprint-html

Answers must be backed by verbatim quotes from this paper's full text. Hallucinated quotes are dropped automatically; if no verbatim passage answers the question, we say so. How this works

Citation neighborhood (no data yet)

We don't have any in-corpus citations linked to this paper yet. This is a recent paper (2025) — citers typically take a year or two to land, and the OpenAlex reference graph may still be filling in.

Source provenance

europepmc
last seen: 2026-05-20T01:45:00.602351+00:00
unpaywall
last seen: 2026-05-24T02:00:01.246996+00:00
License: CC-BY-4.0