Abstract
Modern methods of monitoring help cow farmers save significantly monitoring time and improve cow health care efficiency. Behavioral changes when cows are sick may include increased or decreased daily activities such as increased lying or decreased walking time. Accelerometer advantages are low power consumption, small size, and lightweight. Thus, accelerometers have been widely used to monitor cow behavior. A cow monitoring system usually includes a central processor for receiving and processing information according to a behavioral classification algorithm through the cows’ movements. This paper introduces an effective classification system for Southern Yellow cow behavior using three degrees of freedom (3-DoF) accelerometers. The proposed classifier applied GBDT algorithm (16 seconds window) with five features, offers the good performance while investigating with four Southern Yellow cattle. The classification achievement was assessed and compared to existing ones regarding sensitivity, accuracy, and positive predictive value.
Introduction
Cow farm management can be improved by early detection of diseases based on the monitoring of changes in animals’ behavior [1, 34]. E.g., Arcidiacono et al. [4] used feeding behavior changes to indicate animals’ health; cattle well-being can be guessed from analyzing lying behavior [1, 26]. So, an indication of animal comfort is behavior activity; by analyzing changes in animal behavior on a daily basis, animal well-being can be assessed [1].
In the past, the observation of animal behavior was made by a human without technology support. It isn’t practical on a vast farm that is common nowadays. Moreover, when the cattle contact people (they respond to human interaction), this might alter their behavior. Thus, it isn’t easy to evaluate animals’ normal behavior to realize abnomal of health [1, 26]. With the appearance of systems based on radio frequency identification (RFID) technology and video-recording systems, the visual analysis of images can be used for the monitoring of animals’ behavior. However, these systems are expensive and complicated in setting up [4].
Sensors advantages are low power consumption, small size, lightweight, low cost, and easy integration with other ICT (information and communications technology) devices, they are being utilized more and more widely [2, 25]. Some cow behavior monitoring systems were developed based on sensors [20, 29].
In the study [4], the authors also used pressure sensors and accelerometers to monitor crawling behavior. The advantage of a pressure sensor is that it can detect feeding behavior very precisely. Also, in the study [35], the pressure sensor is also used in the RumiWatch system.
Accelerometers, with all the advantages of sensors, have been widely used to monitor cow behavior. 3-DoF accelerometers are proved that suitable to provide a non-invasive method to classify cow behavior [2, 28]. The device can be mounted on the leg, neck, nose, or cheek, acting as a sensor node collecting data for monitoring and transmit wirelessly to the gateway device [1, 30].
Features and data windows are significant for the implementation of classification algorithms [22, 36]. The features of the extracted data are based on the time window. In this machine learning study, each feature is a measurable property of the acceleration data. Designing features is an essential step for effective classification. A new contribution in this study is the proposition of an efficient set of features to classify four cow behaviors.
In this paper, an efficient classification system was built for the behavior of Southern Yellow cows by using a three-axis accelerometer to classify the foot-mounted accelerometer data and improve the classification performance. The contribution is to provide an optimized method for classifying four main cow behaviors (feeding, standing, lying, and walking). Specifically, five features have been proposed (mean, standard deviation-SD, root mean squared-RMS, median, and range), a 16-second data window (a sample/sec), and a GBDT (Gradient Boosted Decision Tree) algorithm for classification. The evaluation is made to a new dataset, then compared with works with a similar data set (foot mounted accelerometer data) [19]. Furthermore, the performance of the system was compared to other results [3, 30].
Materials and methods
Animals and farm condition
In developing countries, one of the primary sources of beef production is Vietnam Yellow Cattle. They have body weights (of an adult cow) from 180 to 300 kg. They can adapt to the local tropical environment of Vietnam.
Four cows of a farm in Ba-Vi, Hanoi, Vietnam were chosen for the experiment. These selected cows have ages ranging from 2 to 4 years. They are free to move in a large area (about 3.5 hectares as shown in Fig. 1). The experiment was done in 10 days (April 01-10, 2020).

Field studied area.
The device is mounted on the front leg of the cow, as shown in Fig. 2. Wearing the device in this position makes it possible for the sensor to sense three-dimensional motion conveniently.

The device is mounted on the front leg of the cow.
From the sensor’s data, the conversion formula to determine the acceleration value
where
R: voltage reference;
O i : offset;
S i : value after sampling of axis k (k = X, Y, Z);
A k : acceleration value in axis-k;
Se i : sensitivity on the axis-k [33].
In this study, the data acquisition device has dimensions of 85×60×35 mm, and a weight of 300 g (see Fig. 3). The device uses a microcontroller ATMega328 to process the accelerometer signal from the MPU-6050 and transmit the data to the LoRawan RA-02 module. Each cow has a unique identifier to pack this data without confusion.

A photo of sensor MPU6050 (a), and the bangle (b).
The steps of using the GBDT classifier (16 seconds window), giving the best overall performance, are presented in Fig. 4.

Behavior recognition processing pipeline.
Training data and test data were selected randomly from all data. The training/test ratio of data at 60% /40% was used for leg-mounted acceleration data [6, 19]; the results were good. This ratio also provided the best results with the experiment data. The proposed features set (the details in Section 2.5) were calculated for all windowed records (Fig. 4) to train the classification model by ML algorithm (GBDT) based on labeled training data [17, 19]. This classification model would be used to predict the classes (behaviors) of test data. In other words, all records of test data would be labeled (as feeding, lying, standing, or walking), with only one label for each record. In the evaluation step, the labeled data from real observations were be used to evaluate the labeled data by the classification model (the details in Section 2.6) to check the effectiveness of the proposed classification model. Figure 5 shows the steps of the proposed classification.

The proposed classifier constructive process.
The model was evaluated using three performance indexes (Section 2.6) based on the behavior observations log. This work was implemented using Python 3.5.
The foot-mounted device has been attached to four cows. The sensor receives twenty data samples per axis every second, then sends them to the microcontroller. The raw acceleration data is averaged to smooth and store the data at one sample per second. To exploit the statistical properties of the collected data, 16 samples were concatenated into a window with 10 overlapping samples (Section 2.3). This frame is used to extract five proposed features. Table 1 presents the raw data summary in minute unit.
Raw behavior datasets collected from cows (minute)
Raw behavior datasets collected from cows (minute)
Table 2 is a summary of the definitions of behavior in the data set.
Behavior definitions. Stand.: standing, ly.: lying, feed.: feeding, walk.: walking
Table 3 is an example of acceleration data when the cow is walking. The numbers of observations (thus, the numbers of records) and their composition are listed in Table 4. The total observations for all cows in the experiment are 12911. The total observations for individual cows are not significantly different, from 2982 to 3603. The observations of standing (4527) are greater compare to other behaviors.
A walking record (16 samples)
Manual observation behavior: composition (16 samples/record). Stand.: standing, ly.: lying, feed.: feeding, walk.: walking
The proposed method for classifying cow behavior uses five accelerometer data characteristics: mean, median, SD, RMS, and range. The reason for choosing these five types of features is based on the nature of the signal used for classification [23, 31]. These are time-series signals (acceleration values obtained vary with time). With this type of signal, engineers can exploit information in the time domain or frequency domain. However, if choosing to exploit frequency domain features will lead to significant computational complexity. Therefore, the researcher decides to use the features on the time domain, namely the 1st and 2nd order measures, to reduce the computational complexity but still ensure the correct classification. Various tests have been carried out to estimate the ability to classify behavior based on the difference of the obtained metric values. Finally, the above five features are selected. A window selection and feature extraction scheme have proposed for the recognition process. The recognition process starts with the accelerometer data extraction feature [37].
All the formulae (2–6) are illustrated for X-axis acceleration:
where X are acceleration data;
X j : record j;
N: number of samples in a data frame;
x i : the ith sample of the record X j ;
min: X j minimum value;
max: X j maximum value;
range(X j ): distance from min to max.
In formular (4), x
i
values in X
j
is sorted.
The algorithm’s performance was evaluated based on accuracy, sensitivity, and positive predictive value. Table 5 is an example confusion matrix to use in classifying cow behavior.
Confusion matrix of a behavior
Confusion matrix of a behavior
Formulae of evaluation indicators:
Performance of GBDT for behavioral classification
The performance of classification in terms of accuracy, sensitivity, and PPV was calculated by Equations (7)–(9) for four behaviors. Table 6 presents the confusion matrix for four cows using GBDT classifier. The predicted behavior using the classification are compared to the true behavior. The bold values are the number of TP (when the predicted behavior and true behavior are the same). The other values (not bold) are FP, FN, and TN (see Section 2.6 for the details). The results of the individual cow are presented in four tables: Table 6(a-d) for cow ID01, ID02, ID03, and ID04, respectively.
Confusion matrix achieved by the GBDT algorithm (16 s window) for behaviors test data of cows (a:ID01, b:ID02, c:ID03, d:ID04)
Confusion matrix achieved by the GBDT algorithm (16 s window) for behaviors test data of cows (a:ID01, b:ID02, c:ID03, d:ID04)
The performance of the proposed model was examined using three indicators as shown in Equations (7)–(9). Table 7 shows the performance of the GDBT algorithm. It was calculated for all individual cows. From Table 7, lying and walking classification prediction were excellent (0.99-1 accuracy, 0.96-1 sensitivity and 0.98-1 PPV). Feeding and standing resulted in lower performance, the sensitivity of standing for cow ID03 was less than 0.50.
Performance of behavior prediction in terms of Acc (accuracy), Sen (sensitivity), and PPV (positive predictive value). Stand.: standing, ly.: lying, feed.: feeding, walk.: walking
In the dataset of this work, the proportion of behavior data was an imbalance. For example, Table 4.B&4.C show that feeding has 158 records while average is about 298 records for all behaviors. This problem is challenging, and difficult to be solved. So, the evaluation classification (Table 8) based on the micro-average method because this method computes average values by aggregating all classes’ contributions. Wang et al. [19] used this evaluation approach for the same reason.
Prediction performance for each cow using the micro-average. Acc (accuracy), Sen (sensitivity), and PPV (positive predictive value)
Prediction performance for each cow using the micro-average. Acc (accuracy), Sen (sensitivity), and PPV (positive predictive value)
Table 9 shows that the average performance of the proposed method was good: 0.91 accuracy, 0.85 sensitivity, and 0.85 PPV. The results proved that the proposed system provided good classification performance in the case of Southern Yellow cattle. The performance of this work (bold values) is better than Wang et al. [19] and P. Martiskainen and M. Jarvinen [30] for all evaluation indicators.
Overall performance using the micro-average. Acc (accuracy), Sen (sensitivity), and PPV (positive predictive value)
Grazing time was estimated using accelerometers in the work [12]. The performance of the estimation was 0.82 PPV and 0.7 sensitivity, not high, even with limited behaviors. It showed that for the behavior classification problem, working with grazing cows is more challenging than free-stall barn cows.
Accelerometer thresholds were proposed for the classifier of [3, 4]. That excellent approach saves the model training time, and still archive high accuracy. However, it may not work well if the cows have not similar conditions such as body size, age, sex, etc. In a real scenario, cows should have different parameters.
Four cows in the experiments were separated into two groups. ID01 and ID03 cows belonged to group 1, the rest (ID02 ID04) belonged to group 2. Table 8 shows that group 1 obtained better classification performance than group 2. The reason is cows in group 1 are accustomed to wearing devices.
Using leg tag sensors has the limit in the classification of standing and feeding. This was shown in this paper and [6, 19]. The problem of data imbalance should also be considered because the collected behavior data will be difficult to balance. This is also a common problem that all machine learning problems need to be solved [38].
The future work combines both leg sensor and collar sensor on the same animal in a sensor network to design an IoT based system for monitoring cow. In the future, there will have many improvements for the sensor network, such as self-organization, multi-protocol compatibility, high throughput [5], and prolonging lifetime [39]. It will support IoT (Internet of Things) technology. IoT is considered one of the keys to smart agriculture and many other fields [5].
This work proved behaviors of grazing cows (such as Southern Yellow cattle) can be effectively classified using acceleration data and machine learning. Using the GBDT algorithm, the proposed system accurately predicted four main behaviors by studying leg acceleration data. In the experiments, the performance of the system was 0.85 accuracy, 0.85 sensitivity, and 0.85 PPV. Feeding and standing were confused with each other, this can be significantly improved by combining leg and neck acceleration data. The results can also be improved by improving the quality of data, e.g., the adaptation of animals to attaching sensors will affect data quality. For the application in the real scenario, more behaviors should be considered to classify in the future.
Footnotes
Acknowledgment
This work was funded by Institute of Information Technology (IoIT - VAST) under project CS20.04.
