Classification of cow ’ s behaviors based on 3-DoF accelerations from cow ’ s movements

Phung Cong Phi Khanh, Kieu Thi Nguyen, Nguyen Dinh-Chinh, Tran Duc-Nghia, Hoang Quang Trung, Nguyen Van Thang, Tran Duc-Tan 1,3,7Electronics and Telecommunication Faculty, VNU, Hanoi University of Engineering and Technology, Viet Nam 1Hanoi National University of Education, Viet Nam 2Faculty of Mechanical, Electrical, and Electronic Engineering, Nguyen Tat Thanh University, Viet Nam 4Institute of Information Technology, Vietnamese Academy of Science and Technology, Viet Nam 5University of Information and Communication Technology, Viet Nam 6Thuy Loi University, Viet Nam


INTRODUCTION
Demand for clean beef and cow's milk on the world in general and VIETNAM in particular is increasing.To meet that demand, dairy farming requires a high technique and a large investment [1].However, farmers encountered a lot of difficulties because of small, scattered breeding, unskilled, full households and using traditional breeding methods.This is the main reason made to a high in the costs of production.Therefore, dairy breeding needs to apply modern technology in the world to improve productivity and product quality [2].Aware of the importance of this issue, some of milk processing companies in Vietnam that implement advanced technology such as TH true milk applying Israel's technology (AFIMILK).
In the world, most of monitoring of systems is based on accelerometer data of sensor [3], [4].The reason is that acceleration data can reflect how fast an object changes its velocity [5], [6].To classify behavior, we need to choose a suitable machine-learning algorithm.Complex machine learning may offer a good result of classification [7], [8], [9].However, the computation would be large which cannot be embedded to the device [10].The device needs to send the acceleration data to the server, and classification algorithm must be installed and run on the server.
In the paper, we choose the decision tree algorithm to classify behavioral state of cow because we can embed the classification process in the device (we do not need to send the acceleration data to the server).Moreover, it also offers other advantages such as automatic feature selection, little data prep effort, handles 1657 data non-linearity, easy to interpret.We consider four important activities of cows: standing, lying, feeding and walking.

SYSTEM IMPLEMENTATION
Figure 1 shows a block diagram of the analyzing system.There are two data streams in this system: the first stream is acceleration data from MPU6050 sensor [11] and the second is the video recorded cow's activities from a camera.Data from these streams are then synchronized for the performance evaluation.Figure 2 shows the device that acquires the acceleration data from the cow's neck.MPU6050 is used to sense the acceleration from the cow's movement, and send to the microcontroller PIC18F45K20 [12].PIC18F45K20 send the data to a mobile phone via a Bluetooth module.The camera that recorded the cow's activities is also from built-in camera of this mobile phone.The device is quite compact and light, thus, it is suitable for the cow to wear.After the analyzing procedure, a classifying algorithm will be embedded into PIC18F45K20 in order to provide the real-time status of the cow (standing, lying, feeding, and walking).

Data processing
Firstly, the acceleration signal is brought to a low pass filter (LPF) to smooth the acceleration data.The acceleration data can be divided into the static and the dynamic components.The static component of the acceleration is caused by the orientation of the sensor relative to the gravity field of the earth which determine the body posture.We extract the static acceleration component for each axis µ , (i=X, Y, Z) by using a running mean filter: where t is time index, win_size is the window size, and  , * is the acceleration data, respectively.The dynamic component of the acceleration Ai,t is caused directly by the movement of the cow.
The L2-norm of Ax,t , Ay,t , and Az,t provide us In this study, we use two features µ , and  , to classsify the cow's behavior.

Flowchart
Four different states of the cow are classified by using the flowchart as shown in Figure 3.This is a decision tree algorithm where two features µ , and  , are applied. , is used to classify between the high and the low dynamic activities.If the cow is in the high dynamic, the mean of µ , is applied to classify between the feeding and the walking status.In the case of a low activity, we compare the values of µ , .To predefine optimal thresholds B1, B2 for classifying the standing and lying status.

RESULTS AND DISCUSSION
Figure 4 shows the position of the device on the cow's neck.The device has small size, light weights, and it's comforting to the cow. Figure 5 presents the samples of acceleration  , *  , *  , * acquired from the experiments which includes standing, lying, feeding and walking activities.We can see that when the cow is standing or lying, the signal on each axis have changed a little because both behaviors show small movement.If the cow is fed or walking, its movement is larger.Specifically, head of the cow will continuously shake left, right.Thus, we can clearly observe the change of acceleration.There is also the large difference in the component of y-axis between lying and standing, feeding and walking.
Figure 6 shown two features µ , and  , which corresponds to the acceleration data in Figure 5.We see that the value of  , in standing and lying of state is smaller than in feeding and walking activities.The values of µ , in feeding and walking are clearly different, the value of µ , in feeding is larger than 0 mg while in walking is smaller than 0 mg).Therefore, we can classify quite accurate behaviors of cows by choosing optimal threshold values.Three thresholds A, B1 and B2 determine the classification performance.Thus, we need to find these optimal values for these thresholds [13], [14].In this study, ROC curve is used to choose A, B1 and B2. Figure 7 shows the ROC curve obtained with the resolution of 1mg (1 mg=10-3 g).The optimal threshold value is the one that generates a pair of TPR and FPR value closest to the top left corner that represents the value that separates perfectly the positives from the negatives.The square points are chosen for determining A, B1 and B2.We found threshold A, B1, B2 are 48mg, -133mg, -108mg, respectively.The system's performance of our system is shown in the Table 1.For overall performance corresponding to this dataset, sensitivity, precision and specificity are 99%, 91.02%, and 75.08%, respectively.Note that, we can compromise among these factors by adjusting three thresholds (A, B1, and B2).By using the decision tree algorithm, this work can classify 4 different activities of cows (in [15], the authors only concerned to classify 3 activities which are standing, lying, and feeding).

CONCLUSION
In this paper, we have successfully built a device that is able to classify four important activities of cows (standing, lying, feeding, and walking).This device can work in real-time manner because it used the simple and effective decision tree algorithm.It offers a good result of classification such as the sensitivity of 99%, the specificity of 86.7%, and the precision of 88.5%.In the decision tree algorithm, we used three thresholds A, B1, B2 to classify the cow's activities.It also provides a flexible scheme to adjust the performance indexes and customize the most suitable thresholds for each cow (e.g.small or big cows).The device has small size, and light weights (i.e.under 0.3 kg).Therefore, it can apply to real farms.In the future, we will continue to trains more cow to wear our devices, enhance the classification performance by combining the decision tree algorithm with SVM algorithm, and classify more behaviors such as cripple, evolution, etc.Moreover, we will develop a solution to help to farm owner always to follow the situations of cows while sitting in their room or travelling.

Figure 1 .
Figure 1.Block diagram of the analyzing system

Figure 2 .
Figure 2. A photo of the device

Figure 4 .Figure 5 .
Figure 4.A cow is wearing the device on its neck

Table 1 .
Performance Evaluation of the Classification