[Paper Review] Predicting Illness for a Sustainable Dairy Agriculture: Predicting and Explaining the Onset of Mastitis in Dairy Cows
This paper presents a machine learning system that predicts sub-clinical mastitis in dairy cows up to seven days in advance using milking data and cow history, and generates actionable counterfactual explanations to guide farmers in preventing disease. The system uses constrained optimization to generate minimal, realistic changes to features—such as milk yield and protein content—highlighting how small adjustments could alter the prediction, thereby improving trust and enabling targeted, sustainable interventions.
Mastitis is a billion dollar health problem for the modern dairy industry, with implications for antibiotic resistance. The use of AI techniques to identify the early onset of this disease, thus has significant implications for the sustainability of this agricultural sector. Current approaches to treating mastitis involve antibiotics and this practice is coming under ever increasing scrutiny. Using machine learning models to identify cows at risk of developing mastitis and applying targeted treatment regimes to only those animals promotes a more sustainable approach. Incorrect predictions from such models, however, can lead to monetary losses, unnecessary use of antibiotics, and even the premature death of animals, so it is important to generate compelling explanations for predictions to build trust with users and to better support their decision making. In this paper we demonstrate a system developed to predict mastitis infections in cows and provide explanations of these predictions using counterfactuals. We demonstrate the system and describe the engagement with farmers undertaken to build it.
Motivation & Objective
- To develop a machine learning model that predicts the onset of sub-clinical mastitis in dairy cows up to seven days in advance using milking and cow history data.
- To generate human-understandable, actionable explanations for model predictions using counterfactual reasoning to support farmer decision-making.
- To ensure model explanations are trustworthy and practical by incorporating stakeholder input on feature actionability and realistic change levels.
- To minimize unnecessary antibiotic use and reduce economic losses by enabling early, targeted interventions based on explainable predictions.
- To evaluate the system’s effectiveness through farmer engagement and counterfactual generation on a real-world dataset from Irish research farms.
Proposed method
- A binary classification model is trained on a dataset of over 2,300 cows from seven Irish farms over 10 years, using milking records, infection history, and genetic data.
- Counterfactual explanations are generated using COBYLA constrained optimization to find minimal feature perturbations that flip a 'healthy' prediction to 'mastitis risk'.
- Feature perturbations are constrained to change no more than three features, with domain-specific bounds on magnitude and actionability (e.g., milk yield changes in 0.5–1.5 L increments).
- A Manhattan distance weighted by inverse median absolute deviation is used to promote sparse, robust, and interpretable changes.
- Features are categorized as actionable (e.g., milk yield, fat content) or confidence-building (e.g., somatic cell count), with the latter included to enhance model trust even if not modifiable.
- The system is validated on a hold-out test set of 10,000 instances predicted as healthy with high confidence (score >0.8), generating counterfactuals to assess prediction shift.
Experimental results
Research questions
- RQ1Can a machine learning model accurately predict sub-clinical mastitis in dairy cows up to seven days in advance using routine milking data?
- RQ2How can counterfactual explanations be generated to make model predictions actionable and trustworthy for farmers?
- RQ3Which features are both actionable and meaningful for farmers to modify in order to prevent mastitis?
- RQ4To what extent do minimal, realistic feature changes in counterfactuals effectively reverse the model’s prediction from 'healthy' to 'at risk'?
- RQ5How can stakeholder-informed constraints on feature changes improve the practicality and trustworthiness of model explanations?
Key findings
- The system successfully generated counterfactual explanations that consistently shifted prediction scores from high confidence in 'healthy' (e.g., 0.979) to low scores (e.g., 0.368) in the counterfactuals.
- Only three features were changed in the counterfactuals on average, ensuring explanations remained sparse and interpretable.
- The model identified actionable changes such as a 1.5 L increase in milk yield or a 1-unit increase in fat content as sufficient to flip the prediction to 'mastitis risk'.
- Somatic cell count, though not directly actionable in the short term, was included in counterfactuals to build trust by aligning with farmers’ mental models of mastitis.
- Farmer engagement confirmed that features like milk yield, fat content, and protein percentage were both actionable and meaningful for preventive management.
- The system demonstrated that minimal, realistic perturbations could effectively explain model predictions while maintaining high fidelity to real-world farming constraints.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.