Cow behavior classification: The optimal set of parameters for the random Forest algorithm



  • Do Viet Manh Institute of Information Technology, Vietnam Academy of Science and Technology
  • Tran Duc Tan Faculty of Electrical and Electronics Engineering, Phenikaa University
  • Nguyen Thi Thanh Huyen Faculty of Information Technology, Hanoi University of Industry
  • Tran Duc Nghia (Corresponding Author) Institute of Information Technology, Vietnam Academy of Science and Technology



Classification; Monitoring; Accelerometer; Behavior; Cow; Random forest.


Accelerometer data are key in animal behavior classification systems using pet-mounted accelerometers. Behavioral data reflecting the health status, early detection of some diseases of cows, monitoring the health of cows through behavior are effective support tools for ranchers to help improve performance and save money cost. In the previous study, we proposed feature sets, data windows and used a random forest algorithm to classify four important cow behaviors, including: eating, lying, standing and walking. In this study, in order to improve the performance of the classification system, we propose to use suitable values ​​for the important parameter set of the random forest algorithm on the experimental data set. The experimental results show that with the value of the parameter set: number of trees = 25 and depth = 15, the classification performance is good with an accuracy of 95,9%.


[1]. Rutten, C.J., Steeneveld, W., Vernooij, J.C.M., Huijps, K., Nielen, M., Hogeveen, H., "A prognostic model to predict the success of artificial insemination in dairy cows based on readily available data", J. Dairy Sci., Vol. 99, No. 8, pp. 6764–6779, (2016). https://doi. org/10.3168/jds.2016-10935 DOI:

[2]. Benaissa, S., Tuyttens, F.A.M., Plets, D., Cattrysse, H., Martens, L., Vandaele, L., Joseph, W., Sonck, B., "Classification of ingestive-related cow behaviours using RumiWatch halter and neck-mounted accelerometers", Appl. Animal Behaviour Sci., Vol. 211, pp. 9–16, (2018). DOI:

[3]. Borchers, M.R., Chang, Y.M., Tsai, I.C., Wadsworth, B.A., Bewley, J.M., "A validation of technologies monitoring dairy cow feeding, ruminating, and lying behaviors", J. Dairy Sci., Vol. 99, No. 9, pp. 7458–7466, (2016). 10843. DOI:

[4]. Khanh, P.C.P., Dinh Chinh, N., Cham, T.T., Vui, P.T., Tan, T.D., "Classification of cow behavior using 3-DOF accelerometer and decision tree algorithm", In: 2016 International Conference on Biomedical Engineering (BME-HUST), IEEE, Hanoi, Vietnam, pp. 45–50, (2016). DOI:

[5]. I. Halachmi, "Precision livestock farming applications", Wageningen Academic Publishers, vol. 10:9, pp. 1482– 1483, (2016). DOI:

[6]. K. Fogsgaard, C. Røntved, P. Sørensen, M. Herskin, "Sickness behavior in dairy cows during Escherichia coli mastitis", Int. J. Dairy Sci., vol. 95, pp. 630–638, (2012). DOI:

[7]. J. Siivonen, S. Taponen, M. Hovinen, M. Pastell, B. J. Lensink, S. Pyörälä, L. Hänninen, "Impact of acute clinical mastitis on cow behaviour", Appl. Anim. Behav. Sci., vol. 132, pp. 101–106, (2011). DOI:

[8]. T. Halasa, K. Huijps, O. Østerås, H. Hogeveen, "Economic effects of bovine mastitis and mastitis management: a review", Veterinary Quarterly, Vol. 29, No. 1, pp. 18–31, (2011). DOI:

[9]. P. Sepulveda-Varas, K. L. Proudfoot, D. M. Weary, M. A.G. von Keyserlingk, "Changes in behaviour of dairy cows with clinical mastitis", Appl. Anim. Behav. Sci., Vol. 175, pp. 8– 13, (2016). DOI:

[10]. Watanabe, N., Sakanoue, S., Kawamura, K., Kozakai, T., “Development of an automatic classification system for eating, ruminating and resting behavior of cattle using an accelerometer”, Grassland Sci., Vol. 54, No. 4, 231–237, (2008). DOI:

[11]. Cong Phi Khanh, P., Tran, D. T., Van Duong, T., Hong Thinh, N., and Tran, D. N., "The new design of cows' behavior classifier based on acceleration data and proposed feature set", Mathematical Biosciences and Engineering, Vol. 17, No. 4, pp. 2760-2780, (2020). DOI:

[12]. Duc-Nghia Tran, Phung Cong Phi Khanh, Vijender Kumar Solanki, and Duc-Tan Tran, "A robust classification system for Southern Yellow cow behavior using 3-DoF accelerometers", Journal of Intelligent & Fuzzy Systems, Vol. 43, No. 2, pp. 2211-2218, (2022), DOI: 10.3233/JIFS-219319 DOI:

[13]. Vazquez ´ Diosdado, J.A., Barker, Z.E., Hodges, H.R., Amory, J.R., Croft, D.P., Bell, N.J., Codling, E.A., “Classification of behaviour in housed dairy cows using an accelerometer-based activity monitoring system”, Anim. Biotelem. Vol. 3, No. 1, (2015), https://doi. org/10.1186/s40317-015-0045-8. DOI:

[14]. Nguyen Thi Thu, To-Hieu Dao, Bo Quoc Bao, Duc-Nghia Tran, Pham Van Thanh and Duc-Tan Tran, “Real-Time Wearable-Device Based Activity recognition Using Machine Learning Methods”, International Journal of Computing and Digital Systems, Vol. 5, No.3, pp. 189–201, (2022).

[15]. J. Wang, Z. He, "Development and validation of an ensemble classifier for real-time recognition of cow behavior patterns from accelerometer data and location data", PLoS One, vol. 13, (2018). DOI:



How to Cite

Do, V.-M., D.-T. Tran, T.-H. Nguyen-Thi, and D.-N. Tran. “Cow Behavior Classification: The Optimal Set of Parameters for the Random Forest Algorithm”. Journal of Military Science and Technology, vol. 88, no. 88, June 2023, pp. 34-41, doi:10.54939/1859-1043.j.mst.88.2023.34-41.