Machine learning–based prediction of clinical mastitis in dairy cows: A comparative analysis of 9 algorithms using production and management data
Mastitis represents one of the most formidable challenges in modern dairy farming, posing significant threats to individual cow health and causing substantial economic losses throughout the dairy production chain. Traditional disease diagnosis methods are often reactive and costly, creating an urgent need for advanced predictive technologies. To address these issues, we proposed a novel machine learning-based mastitis prediction system that breaks through conventional diagnostic paradigms by deeply integrating data science with veterinary medicine. We analyzed 177,493 dairy cow records from Nanjing Weigang Dairy Farm, implementing 9 distinct machine learning algorithms for model development and evaluation: Random forest, multilayer perceptron, support vector machine, decision tree, gradient boosting, AdaBoost, linear discriminant analysis, logistic regression, and Naive Bayes. The dataset included comprehensive production metrics, physiological parameters, and management variables, with models trained on both standardized and nonstandardized datasets using rigorous cross-validation techniques. Random forest demonstrated superior predictive performance, significantly outperforming other algorithms with the highest F<sub>1</sub>-score (0.804) and area under the receiver operating characteristic curve value (0.884, 95% CI: 0.883-0.885), achieving a sensitivity of 80.6%, specificity of 80.0%, and overall accuracy of 80.3%. Feature importance analysis revealed month_age as the most critical predictor (relative importance: 0.165), followed by milk_yield (0.138), protein_percentage (0.138), and fat_percentage (0.135). The Z-standardization consistently enhanced model performance across all algorithms, with random forest maintaining optimal calibration between predicted probabilities and actual outcomes. Leveraging the predictive model, we quantified key risk factors and developed an early warning system capable of identifying high-risk animals, providing a robust foundation for precision dairy farming and improved mastitis management strategies. This research successfully develops a data-driven technological solution that substantially reduces disease spread risk and economic losses while driving the transformation of dairy farming toward digitalization and precision management.
Authors
- Chengyuan Liu (ORCID: https://orcid.org/0000-0002-8690-8698)
- M. Q. Li
- Gaoping Zhao (ORCID: https://orcid.org/0000-0001-5899-9230)
- Dengke Zhang (ORCID: https://orcid.org/0000-0001-5373-0881)
- Xiao‐Xue Yan (ORCID: https://orcid.org/0000-0002-8266-0613)
- Yong Zhang (ORCID: https://orcid.org/0000-0003-1024-5741)
- Yunxia Li (ORCID: https://orcid.org/0000-0002-0626-2584)
- Xu Liu (ORCID: https://orcid.org/0000-0001-7986-8520)
- Zixin Wang (ORCID: https://orcid.org/0000-0002-2180-7204)
- Yao Lu (ORCID: https://orcid.org/0000-0003-3760-1638)
- Meng Cui (ORCID: https://orcid.org/0000-0003-2916-4618)
Institutions
- Inner Mongolia University (CN)
- University of Surrey (GB)
- North West Agriculture and Forestry University (CN)
- Yangzhou University (CN)
- Northwest A&F University (CN)
- Ministry of Agriculture, Livestock, and Food Supply (BR)
Publication Details
- Journal
- Journal of Dairy Science
- Published
- 2025-12-01
- DOI
- https://doi.org/10.3168/jds.2025-27483
- Primary Topic
- Milk Quality and Mastitis in Dairy Cows
- Type
- article
- Field-Weighted Citation Impact
- 0.00