Soft Computing Approaches for Predicting Shade-Seeking Behavior in Dairy Cattle Under Heat Stress: A Comparative Study of Random Forests and Neural Networks
Abstract
1. Introduction
2. Materials and Methods
2.1. Dataset Description, Processing, and Tuning
- Number of cows in the shade.
- Exact time of observation.
- The current THI.
- The average THI of the previous night.
- The accumulated THI.
2.2. Soft Computing Decision Tree Algorithm
2.3. Soft Computing Random Forest Algorithm
2.4. Soft Computing Neural Networks Algorithm
3. Results
3.1. Global Model Performance
3.2. Error Distribution Analysis
3.3. Case Studies
4. Discussion
5. Conclusions
- Early warning capability: The models anticipate shade-seeking peaks within one hour, with a median daily RMSE of cows.
- Interpretability: A 10-tree Random Forest (depth ) achieves an average RMSE of while retaining a transparent rule structure, making it the recommended choice for on-farm deployment.
- Minimal feature set: Three easily derived thermal features—the current THI, the accumulated day-time THI, and the mean night-time THI—are sufficient for a low-cost decision-support system that can trigger ventilation, sprinkling, or shading strategies in real-time.
Limitations and External Validation
- Explicit statement of scope: The present dataset represents one Mediterranean region—Titaguas, Spain—during a single summer—June–September 2023. As such, it does not include colder seasons, other housing layouts (as, for instance, composting barns) or different breeds, nor does it capture climatic extremes, such as monsoonal humidity or continental heat waves. While the model performs well on the source farm, its generalizability beyond Mediterranean summer conditions remains to be demonstrated.
- Potential sources of bias:
- (i)
- Management practices: Shade availability, stocking density, and cooling protocols vary widely across farms; these factors could shift the threshold at which cows seek shade.
- (ii)
- Regional weather patterns: Diurnal THI dynamics in arid or tropical zones differ from those in Mediterranean climates, possibly altering the relative importance of the accumulated vs. the instantaneous THI.
- Need for external validation: Future work will involve external validation on at least three additional farms. Following the guidelines of Steyerberg [38], we will report calibration curves and domain-transfer metrics.
- Practical field applications: Finally, the current work stops short of detailing real-time deployment aspects—such as latency budgeting, sensor-fault mitigation, and farmer-oriented user interfaces—because its primary aim is the methodological proof-of-concept. Although preliminary benchmarks show the full inference pipeline runs on basic CPUs in a short time and relies only on readily available temperature and humidity inputs, these engineering questions will be tackled in a dedicated follow-up field study.
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Calabuig, J.M.; Falciani, H.; Sánchez-Pérez, E.A. Dreaming machine learning: Lipschitz extensions for reinforcement learning on financial markets. Neurocomputing 2020, 398, 172–184. [Google Scholar] [CrossRef]
- Arnau Notari, A.R.; Calabuig, J.M.; Catalan, C.; Garcia Raffi, L.M.; Pardo Gila, J.; Pons Anaya, R.; Sánchez Pérez, E. Using neural networks and hierarchical cluster analysis to study goal kicks in football. Int. J. Sport. Sci. Coach. 2024, 19, 1723–1737. [Google Scholar] [CrossRef]
- Akintan, O.; Gebremedhin, K.G.; Uyeh, D.D. Animal Feed Formulation—Connecting Technologies to Build a Resilient and Sustainable System. Animals 2024, 14, 1497. [Google Scholar] [CrossRef]
- Slob, N.; Catal, C.; Kassahun, A. Application of machine learning to improve dairy farm management: A systematic literature review. Prev. Vet. Med. 2021, 187, 105237. [Google Scholar] [CrossRef]
- Zadeh, L. Soft computing and fuzzy logic. IEEE Softw. 1994, 11, 48–56. [Google Scholar] [CrossRef]
- Ji, B.; Banhazi, T.; Phillips, C.J.; Wang, C.; Li, B. A machine learning framework to predict the next month’s daily milk yield, milk composition and milking frequency for cows in a robotic dairy farm. Biosyst. Eng. 2022, 216, 186–197. [Google Scholar] [CrossRef]
- Luo, W.; Dong, Q.; Feng, Y. Risk prediction model of clinical mastitis in lactating dairy cows based on machine learning algorithms. Prev. Vet. Med. 2023, 221, 106059. [Google Scholar] [CrossRef] [PubMed]
- Chapman, N.H.; Chlingaryan, A.; Thomson, P.C.; Lomax, S.; Islam, M.A.; Doughty, A.K.; Clark, C.E.F. A Deep Learning Model to Forecast Cattle Heat Stress. Comput. Electron. Agric. 2023, 211, 107932. [Google Scholar] [CrossRef]
- Tsai, Y.C.; Hsu, J.T.; Ding, S.T.; Rustia, D.J.A.; Lin, T.T. Assessment of Dairy Cow Heat Stress by Monitoring Drinking Behaviour Using an Embedded Imaging System. Biosyst. Eng. 2020, 199, 97–108. [Google Scholar] [CrossRef]
- Woodward, S.J.R.; Edwards, J.P.; Verhoek, K.J.; Jago, J.G. Identifying and Predicting Heat Stress Events for Grazing Dairy Cows Using Rumen Temperature Boluses. JDS Commun. 2024, 5, 431–435. [Google Scholar] [CrossRef]
- Shirzadifar, A.; Miar, Y.; Plastow, G.; Basarab, J.; Li, C.; Fitzsimmons, C.; Riazi, M.; Manafiazar, G. A machine learning approach to predict the most and the least feed–efficient groups in beef cattle. Smart Agric. Technol. 2023, 5, 100317. [Google Scholar] [CrossRef]
- Hempstalk, K.; McParland, S.; Berry, D. Machine learning algorithms for the prediction of conception success to a given insemination in lactating dairy cows. J. Dairy Sci. 2015, 98, 5262–5273. [Google Scholar] [CrossRef]
- Valletta, J.J.; Torney, C.; Kings, M.; Thornton, A.; Madden, J. Applications of machine learning in animal behaviour studies. Anim. Behav. 2017, 124, 203–220. [Google Scholar] [CrossRef]
- Grzesiak, W.; Błaszczyk, P.; Lacroix, R. Methods of predicting milk yield in dairy cows—Predictive capabilities of Wood’s lactation curve and artificial neural networks (ANNs). Comput. Electron. Agric. 2006, 54, 69–83. [Google Scholar] [CrossRef]
- Naqvi, S.A.; King, M.T.M.; Matson, R.D.; DeVries, T.J.; Deardon, R.; Barkema, H.W. Mastitis detection with recurrent neural networks in farms using automated milking systems. Comput. Electron. Agric. 2022, 192, 106618. [Google Scholar] [CrossRef]
- Lin, D.; Kenéz, Á.; McArt, J.A.A.; Li, J. Transformer neural network to predict and interpret pregnancy loss from activity data in Holstein dairy cows. Comput. Electron. Agric. 2023, 205, 107638. [Google Scholar] [CrossRef]
- Molnar, C. Interpretable Machine Learning, 2nd ed.; Independently Published, 2022; Available online: https://christophm.github.io/interpretable-ml-book (accessed on 14 August 2025).
- Polsky, L.; von Keyserlingk, M.A. Invited review: Effects of heat stress on dairy cattle welfare. J. Dairy Sci. 2017, 100, 8645–8657. [Google Scholar] [CrossRef]
- West, J.W. Effects of Heat Stress on Production in Dairy Cattle. J. Dairy Sci. 2003, 86, 2131–2144. [Google Scholar] [CrossRef]
- Berman, A. Indices for Environmental Heat Stress. Int. J. Biometeorol. 2005, 49, 189–196. [Google Scholar] [CrossRef]
- Dikmen, S.; Hansen, P.J. Is the Temperature–Humidity Index the Best Indicator of Heat Stress in Dairy Cattle? J. Dairy Sci. 2009, 92, 109–116. [Google Scholar] [CrossRef]
- Bovo, M.; Agrusti, M.; Benni, S.; Torreggiani, D.; Tassinari, P. Random Forest Modelling of Milk Yield of Dairy Cows under Heat Stress Conditions. Animals 2021, 11, 1305. [Google Scholar] [CrossRef]
- Becker, C.A.; Aghalari, A.; Marufuzzaman, M.; Stone, A.E. Predicting Dairy Cattle Heat Stress Using Machine Learning Techniques. J. Dairy Sci. 2021, 104, 501–524. [Google Scholar] [CrossRef]
- Guarnido-Lopez, P.; Pi, Y.; Tao, J.; Mendes, E.D.M.; Tedeschi, L.O. Computer vision algorithms to help decision-making in cattle production. Anim. Front. 2025, 14, 11–22. [Google Scholar] [CrossRef]
- Schütz, K.E.; Rogers, A.R.; Cox, N.R.; Webster, J.R.; Tucker, C.B. Dairy cattle prefer shade over sprinklers: Effects on behavior and physiology. J. Dairy Sci. 2011, 94, 273–283. [Google Scholar] [CrossRef] [PubMed]
- Habeeb, A.A.; Gad, A.; Atta, M.A.A. Temperature-Humidity Indices as Indicators to Heat Stress of Climatic Conditions with Relation to Production and Reproduction of Farm Animals. Int. J. Recent Adv. Biotechnol. 2018, 1, 35–50. [Google Scholar] [CrossRef]
- Committee on Physiological Effects of Environmental Factors on Animals; Agricultural Board; National Research Council. A Guide to Environmental Research on Animals; National Academy of Sciences: Washington, DC, USA, 1971. [Google Scholar]
- Kohavi, R. A Study of Cross-Validation and Bootstrap for Accuracy Estimation and Model Selection; Morgan Kaufman Publishing: Burlington, MA, USA, 1995. [Google Scholar]
- Stone, M. Cross-validatory choice and assessment of statistical predictions. J. R. Stat. Soc. Ser. B (Methodol.) 1974, 36, 111–133. [Google Scholar] [CrossRef]
- Quinlan, J.R. C4.5: Programs for Machine Learning; Morgan Kaufmann: Burlington, MA, USA, 1993. [Google Scholar]
- Safavian, S.R.; Landgrebe, D. A survey of decision tree classifier methodology. IEEE Trans. Syst. Man, Cybern. 1991, 21, 660–674. [Google Scholar] [CrossRef]
- Breiman, L. Random forests. Mach. Learn. 2001, 45, 5–32. [Google Scholar] [CrossRef]
- Liaw, A.; Wiener, M. Classification and regression by Random Forest. R News 2002, 2, 18–22. [Google Scholar]
- Goodfellow, I.; Bengio, Y.; Courville, A. Deep Learning; MIT Press: Cambridge, MA, USA, 2016. [Google Scholar]
- LeCun, Y.; Bengio, Y.; Hinton, G. Deep learning. Nature 2015, 521, 436–444. [Google Scholar] [CrossRef] [PubMed]
- Apicella, A.; Donnarumma, F.; Isgrò, F.; Prevete, R. A survey on modern trainable activation functions. Neural Netw. 2021, 138, 14–32. [Google Scholar] [CrossRef] [PubMed]
- Sharma, S.; Sharma, S.; Athaiya, A. Activation functions in neural networks. Towards Data Sci. 2017, 6, 310–316. [Google Scholar] [CrossRef]
- Steyerberg, E.W. Clinical Prediction Models, 2nd ed.; Chapter Model Validation and Updating; Springer: Berlin/Heidelberg, Germany, 2019. [Google Scholar]
Variable | Current THI | Accumulated THI | Average THI Night | Time |
---|---|---|---|---|
VIF |
Depth | 1 | 3 | 5 | 10 | 15 | 25 | 50 |
---|---|---|---|---|---|---|---|
RMSE | 16.027 |
lr | Neurons | Layers | Parameters | Time (s) | RMSE | |
---|---|---|---|---|---|---|
1 | 16 | 5 | 1185 | |||
2 | 10−3 | 16 | 3 | 641 | 17.41 | 14.783720 |
3 | 256 | 3 | 133,121 | |||
4 | 64 | 5 | 17,025 | |||
5 | 1024 | 1 | 8705 | |||
6 | 64 | 3 | 8705 | |||
7 | 64 | 1 | 385 | |||
8 | 256 | 1 | 1537 | |||
9 | 256 | 1 | 1537 | |||
10 | 64 | 1 | 385 |
Model | Time (s) | RMSE | Interpretability | Explainability |
---|---|---|---|---|
Decision Tree | Very High | High | ||
Random Forest | 0.07 | 14.97 | Medium/High | Medium |
Neural Network | Low | Low |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Sanjuan, S.; Méndez, D.A.; Arnau, R.; Calabuig, J.M.; Díaz de Otálora Aguirre, X.; Estellés, F. Soft Computing Approaches for Predicting Shade-Seeking Behavior in Dairy Cattle Under Heat Stress: A Comparative Study of Random Forests and Neural Networks. Mathematics 2025, 13, 2662. https://doi.org/10.3390/math13162662
Sanjuan S, Méndez DA, Arnau R, Calabuig JM, Díaz de Otálora Aguirre X, Estellés F. Soft Computing Approaches for Predicting Shade-Seeking Behavior in Dairy Cattle Under Heat Stress: A Comparative Study of Random Forests and Neural Networks. Mathematics. 2025; 13(16):2662. https://doi.org/10.3390/math13162662
Chicago/Turabian StyleSanjuan, Sergi, Daniel Alexander Méndez, Roger Arnau, J. M. Calabuig, Xabier Díaz de Otálora Aguirre, and Fernando Estellés. 2025. "Soft Computing Approaches for Predicting Shade-Seeking Behavior in Dairy Cattle Under Heat Stress: A Comparative Study of Random Forests and Neural Networks" Mathematics 13, no. 16: 2662. https://doi.org/10.3390/math13162662
APA StyleSanjuan, S., Méndez, D. A., Arnau, R., Calabuig, J. M., Díaz de Otálora Aguirre, X., & Estellés, F. (2025). Soft Computing Approaches for Predicting Shade-Seeking Behavior in Dairy Cattle Under Heat Stress: A Comparative Study of Random Forests and Neural Networks. Mathematics, 13(16), 2662. https://doi.org/10.3390/math13162662