Comparative analysis of artificial neural networks and classical machine learning models for predicting subclinical mastitis in dairy cows, with SHAP-based interpretation of predictions.
A Satoła, K Satoła
Department of Genetics, Animal Breeding and Ethology, Faculty of Animal Science, University of Agriculture in Krakow, al. Mickiewicza 24/28, 30-059 Krakow, Poland. Electronic address: alicja.satola@urk.edu.pl. · Independent researcher, 31-416 Krakow, Poland.
Key points
From the paper's conclusion- The data set contained 19,768 test day records for 2,225 Polish Holstein-Friesian cows from 3 herds.
Abstract
Subclinical mastitis, one of the most common disorders in dairy cattle farming, affects both milk yield and milk quality. While it causes no visible changes to the udder or milk, it may be either chronic or progress to clinical mastitis. This increases the costs of milk production and herd management, and it is therefore important to devise a means of early identification of cows at risk of subclinical mastitis. The aim of the study was to develop and evaluate models based on artificial neural networks and designed for the identification of cows at risk of subclinical mastitis. Neural networks can recognize complex data patterns; however, the process of building a model, selecting hyperparameters and training a network is a time-consuming and computationally intensive task, and therefore neural network-based models were compared with classical machine learning (ML) models: Support Vector Machines (SVM), Random Forest and Gradient Boosting. The data were collected between 2010 and 2011 as part of routine milk recording procedures. The data set contained 19,768 test day records for 2,225 Polish Holstein-Friesian cows from 3 herds. All the models were trained and evaluated using an 80:20 train-test split ratio according to animal ID. Cows were classified as healthy or at risk of subclinical mastitis based on data from the test day preceding the test day for which the prediction was made. The neural network that achieved the highest mean F1-score in the cross validation (0.763) and for the testing data set (0.760) was optimized using the BayesianOptimization tuner, and the data were rescaled using RobustScaler before calculations. However, the mean F1-scores from the cross validation for 3 classical ML models: SVM, Random Forest and Gradient Boosting, were higher (0.769, 0.769 and 0.766 respectively) than the F1-score obtained for the best performing neural network. SVM and Random Forest models also achieved higher F1-scores (0.763 and 0.761 respectively) for the testing data set as compared with the best performing neural network. As far as ML models are concerned, an increasing importance is also being placed on the interpretation and evaluation of the impact of individual variables on model-derived predictions. This is where SHAP (SHapley Additive exPlanations) values can become useful. For the best performing classical ML models: SVM, Random Forest and Gradient Boosting, and the best performing neural network, somatic cell score (SCS) from previous test day had the greatest impact on predictions, and a higher SCS was associated with a greater probability of subclinical mastitis occurring in subsequent test day. The second variable with the greatest impact on the risk of subclinical mastitis was lactation number. Depending on the model, the third most influential variable was milk yield, lactose percentage or fat percentage. Classical ML models with good predictive performance can support farmers in making decisions concerning the health of cows' udders, and the use of model interpretation tools can help understand why a particular model generates a particular prediction.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Detecting subclinical mastitis in dairy cattle by using machine learning techniques to analyse automated milking system data.The Veterinary record · 2026
- Supervised machine learning approaches for early detection of metabolic and udder health disorders in dairy cows using sensor-derived dataFrontiers in Veterinary Science · 2025
- Evaluation of machine learning models for predicting mastitis in dairy cows using dielectric properties and other milk quality parameters.Research in veterinary science · 2026
- Use of infrared thermography and machine learning to predict the infectious etiology of subclinical bovine mastitis in a robotic milking system.Tropical animal health and production · 2026
- Performance of a Sensor-Based Health Monitoring System for the Detection of Clinical Mastitis in Dairy Cows.Animals : an open access journal from MDPI · 2026
- Assessment of reproductive performance in dairy cows using explainable machine learning.Archives animal breeding · 2026