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

Institutions

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
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Machine learning–based prediction of clinical mastitis in dairy cows: A comparative analysis of 9 algorithms using production and management data

Chengyuan Liu, M. Q. Li, Gaoping Zhao, Dengke Zhang et al.
Journal of Dairy Science
Milk Quality and Mastitis in Dairy Cows
article

Machine learning–based prediction of clinical mastitis in dairy cows: A comparative analysis of 9 algorithms using production and management data

Chengyuan Liu, M. Q. Li, Gaoping Zhao, Dengke Zhang, Xiao‐Xue Yan, Yong Zhang, Yunxia Li, Xu Liu, Zixin Wang, Yao Lu, Meng Cui
article en

Abstract

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.

Journal of Dairy Science
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)
Openalex Percentile: Top 50%
Milk Quality and Mastitis in Dairy Cows
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.