Vol. 6, No. 1 | January – June 2022 SJCMS | P-ISSN: 2520-0755| E-ISSN: 2522-3003 | Vol. 6 No. 1 January – June 2022 26 Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning Asif Ali1, Rashid Jahangir1, Muhammad Asif Nauman2, Faiqa Hanif1 Abstract: Accurate and timely detection of estrus in cows is very important for reproduction, health, and milk production. Traditional estrus detection methods like manual observation and chin head chalking are outdated and not suitable for the dairy farm because of large number of animals. A lot of automated estrus detection methods have been proposed such as milk yield fluctuation, milk progesterone detection. However, these methods are either too complex to implement or have low detection rate. Therefore, this study proposed a novel estrus detection method that can be implemented easily with enhanced detection rate. This method extracted features from 3D acceleration data, collection from accelerometer attached to cow’s neck. The collected data was clustered using k-means into 3 clusters. Categories were assigned based on data variance. As a result, the three clusters were categorized as: low activity, medium activity, or high activity. Based on this information, activity index was calculated and then it was used for the estrus detection. Two machine learning classifiers namely SVM, and D-trees were employed for the activity recognition. SVM and D-tree achieved an accuracy of 96% and 86% respectively. Keywords: Dairy Cow; Automatic Estrus Detection; Standing Heat; Missed Heat; Accelerometer; Artificial insemination; Barn and Estrus 1 Introduction Thereby Livestock reproduction plays important role in a country economic and overall growth therefore increasing the health quality of livestock also yields the economy. Like many aspects of Pakistani industry, livestock also lacks automation and largely depends on manual labor. Manual detection of disease is very expensive and time taking. In case of reproductive issues like estrus, it requires experts to visit the farm three times a day and observe the cow for at least thirty minutes. This is a costly and labor-intensive work for large dairy farms. If farmers 1Department of Computer Science, COMSATS University Islamabad—Vehari Campus, Pakistan. 2Department of Computer Science, University of Engineering and Technology Lahore, Pakistan. Corresponding Author: (rashidjahangir@ciitvehari.edu.pk) automate this system, they will not only save time, but they will also cut their expenses. With such a system, a farmer can get more reproduction of livestock and increase the daily production of milk. This way, they can improve the country’s economy. Estrus is sign of reproductivity in female mammals. During estrus they are sexually active. They are ready for male mate to mount on them and performed insemination. Some female mammals can be inseminated by artificially insemination methods as well like cows and buffalos. In our countries this practice is common. When a cow comes into estrus this activity mailto:rashidjahangir@ciitvehari.edu.pk Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 27 continues till 24 hours from standing of estrus, but the average standing time is 12 to 24 hours [1]. The average calving interval of cow is 10 to 12 months [2]. Calving interval means the period from successful pregnancy to next estrus. When cow is in estrus and not performed AI then the estrus loss called missed heat [1]. When the cow is in estrus it will show changes in behavior that are very different from normal behavior. Some signs of estrus in the cow are: cow shows restlessness, mount on other cows, when mail mate mounts on her she stays calm, swollen vulva, sniffing urine of other cows, clear mucus discharge from her vagina and making loud sounds. When one estrus is missed then it will again occur after 21 days, so the normal estrus cycle is of 21 days [2]. The standing estrus time is 18 to 30 hours, and the average standing estrus time is 18 hours. The environmental temperature like high or low temperature also affects the estrus cycle. Very high and very low temperature reduces the time of standing estrus and are also difficult to detect estrus. Successful insemination depends on the correct identification of estrus. If one estrus is missed it means the calving interval increased, and it also reduced milk production. There are two basic techniques of estrus detection first one is manual estrus detection that require to visit every animal by an expert person for thirty minutes and three times daily which is very time consuming and labor intensive task. For a very large dairy farm it’s difficult to visit every cow three times daily for 30 minutes so due to this difficulty second method is proposed which is called automatic estrus detection. In automatic estrus detection multiple devices like pedometer, accelerometer and gyroscope have been used that measure the motion of cow and send this data to base station wirelessly or store data into SD memory card. After getting this data different machine learning algorithms like support vector machine, decision tree, K- mean clustering and linear regression are applied and analyze the data that the cow is normal or is in heat. There are a lot of automatic estrus detection methods, but some are inaccurate, and some are expensive. In this work, problem of automatic estrus detection and analysis of reproductivity signs from the motion of animals like cow has been considered. The device that measures activity called data- logger which is low power device that contains 3D accelerometer, GPS, and GSM module. Data logger installed on the neck collar of cow that measures activity of cow then data send to base station. Different machine learning algorithms will apply on data and data will be analyzed and decision will be taken based on activity index that the cow is in estrus or normal. The manual detection of estrus is very difficult task because it requires an expert person for detection of estrus. In manual detection of estrus every animal has to be visited two to three times a day for 25 to 30 minutes. When correct estrus is not detected then the average calving interval increased, and milk production is also decreased. Making a system that understands data that was collected by data-logger and decision will be taken on the basis on acceleration (activity) data. Hence, the main motivation behind this work is to lay the foundations of a practical system which can be used to detect estrus automatically. When early estrus is detected then insemination is performed on time in this way farmers can get more milk and child production. To the best of our knowledge there is no data set available publically for the analysis and detection of estrus. First challenge is data collection which requires extensive labor work as well as technical work like the packing of data-logger that save it from environmental as well as harmful effects. The second challenge is travelling because the dairy farm is very away from university. The single side distance is around 35 kilometers because dairy farms are not allowed in Lahore city area. The third challenge was video recording system Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 28 installation which consists of Raspberry Pi and Pi cam that are taking and saving videos with time stamp of one second. Furthermore, as discussed earlier, the estrus is not a normal event that occurs on daily basis. When estrus occurs and not detected then it will occur again between 18 to 24 days, but the normal cycle is of 21 days. The fourth challenges were to save all system from environmental effects like rain as well as from harmful effects like stress on data logger by cow. When collecting data, I ended up watching video feeds of cameras that monitored the cow. Using the videos and accelerometer data, I tagged the data with high, low, or medium activity. This process of annotation is very time consuming, complex, and error-prone because of the probability of mismatch in time stamps etc. Further the structure of this paper is as follows. Section 2 present the literature review in detail, describes existing estrus detection techniques. Section 3 presents the data-logger installation, packing and methodology of our estrus detection method and data analysis. Finally result is discussed in section 4 of this paper. 2 Literature Review The reproduction cycle of healthy dairy cows repeats after every 12-14 months. Wrong detection of estrus is one of the major factors that affect the reproduction cycle and milk production of cows[3]. Timely breeding (Artificial insemination) is very important for reproduction and milk production. Estrus detection is the key for the successful artificial insemination [1]. The most common problem in poor estrus detection is failure to observe cows for long periods of time. Cows should be observed at least three to four times in a day, for a period of at least 30 minutes. With advent of monitoring technology, a lot of monitoring systems have been proposed for estrus detection [2]. However, expensive methods show satisfactory results, while simpler methods show high error rates and none of them is completely automatic. Cows go into heat with an average cycle of 21 days (normal cycle may vary from 18 to 24 days). The average duration of standing estrus is 12 to 18 hours. Environment and weather conditions also effects estrus cycle. Very hot and cold temperature reduces the length of estrous periods, and also increases the difficulty in detecting heat [1]. Successful artificial insemination fully relies on correct estrus identification because it is only possible when estrus is detected correctly [4, 5]. Some symptoms that show signs of estrus are as follows: (a) Cow will mount on other animals and also stand when male mate mount on her. (b) Cow will make loud sounds [4]. (c) Cow will move fast with respect to normal routine. (d) The behavior of cow is nervous, and cow will feel restless. (e) Swollen vulva; when cows are restrained, check the vulva lips for swelling, reddening (bright cherry pink), and mucus discharge as an indicator for estrus [6]. Missing estrus will delay the next reproduction cycle that also effects the economic growth. When a cow is in estrus it exhibits change in behavioral patterns which are distinctly different from the rest of the estrous cycle. Some signs of heat are nervousness and restlessness which result in more physical activity, cow mount on other cows, and make groups with sexually active cows [1]. Visual detection of estrus behavior is also possible but requires an expert person. Some more famous signs of estrus are that cow makes loud sounds and mucus discharge from cow’s vagina. In recent years a lot of heat detection methods have proposed to measure activity of animals such as standing, sitting, walking, and eating, to detect estrus but they are still not functional. There are many machine learning algorithms like K-mean, Decision tree(D- tree), multi-layer perceptron (MLP) applied on the accelerometer collected measured data, but efficient results are not achieved [1]. For example, in [4] a change detection Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 29 algorithm was proposed by combining information from step count and lying time. Acceleration signals have been found as a good source for automated identification of behavior patterns in animals and humans [7] [8] [9], however, no attempts to automatically detect heat from acceleration data have been reported. In [7] and [9] they presented a strategy that has shown promising results and has several advantages, but the data collection methodology is very difficult, and device is also expensive. Data measuring device and data processing devices, for 3d acceleration activity, are not expensive. Data processing is fast, results can be obtained in seconds after that data is downloaded. Expert can focus only on those animals that show change in behaviors [10]. Acceleration data are filtered and divided into segments. After that, simple attributes are extracted from each segment and different machine learning algorithms like K-mean are applied to those extracted features. The accuracy of this method was 85% and error rate was 23% [11, 12]. The Dairymaster MooMonitor [9] is a nanotechnology based device in which accelerometer and microcontroller are major components. Dairymaster MooMonitor is a device that is used to measure cow’s activity for the purpose of detecting estrus of indoor and outdoor cows [13]. The sensor (MooMonitor) is tied around the neck by strap, and it records the acceleration of cow. The information that is measured by MooMonitor is received by base station after every fix cycle of time. The base station is directly connected to computer system or by using mobile phone the data is sent to base system. The system analyzes the data and results are generated that determining whether the cow is in heat or not. The downside of this method is its error rate of 40%. Efficient heat detection [14] without automatic system requires extra effort and time. Animals come into heat mostly at night (before 6:00 am and after 08:00 pm). Cattle comes into heat in hot weather but detection in hot weather is very difficult because it cannot show more activity in hot weather. The standing heat period is also short in hot weather. For efficient detection, it is necessary to visit the animals two to three times daily and observe animals at least 30 minutes. Charlton, Bouffard, Gibbons, Vasseur, Haley, et al. [15] discussed a lot of estrus sign like roughened tail head, dirty steaks marks on lower hips, grouping with male mate and ride on other animals. If cow has been ridden by other animal, her hairs on tail could be standing up or completely missing. She will show restlessness and bawls loudly. Clear mucus discharge from the vagina of animals. Swollen vulva is also a sign of heat [2]. The sign of missed heat is blood discharge at the end of estrus. One must make sure cow eats according to routine and farmers should mark it because it will come in heat after 18 to 24 days. We have to make record book of animals that is helpful for estrus detection and device installation in large dairy farm. Animals have many behaviors like eating, walking, standing, drinking, mounting and sitting [16]. There have been a lot of research conducting for behavior monitoring but for estrus detection, we do not need these behaviors to monitor exactly but we need to record the increased level of cow activity from normal routine for the detection of estrus [16, 17]. The estrus cycle repeat until the successful insemination has done and cow goes into pregnancy [18]. When a cow is in estrus, she accepts male mate to mount on her. This is due to estradiol in central nervous system [19]. They also define some protocols for successful estrus detection like tracking of individual cow on daily basis and morning time is very important for estrus[20]. They also explained some factors that affect the efficiency of estrus like heredity, peri- partum disease season, light, feeding and body condition[21]. They also explained thirty estrus detection methods some are manual and some of them are automatic, but Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 30 all are not efficient for estrus detection. In [22] estrus they proposed estrus detection method by unsupervised learning and change detection method, but the accuracy of the system was 82%. In [23] they presented the behavior analysis of cattle. They did analysis temporally and spatially. They observed that when feed is present, farm cattle spent time around the feed but when feed was not available, they spent time roaming and sitting but in the day of estrus they show restlessness and spent most of the time by walking and roaming around. 3D accelerometer used for behavior monitoring and decision tree algorithm used for the classification of behavior, but the accuracy of the system was 87% [24]. Roelofs, Krijnen and Van Erp-van der Kooij [13] discussed that the routine of cow behavior disturbed during estrus with respect to non-estrus. He analyzed the indoor and pastured based cow farm for estrus detection. He installed accelerometer based meter on cow leg and neck. They collect data for 2 months from household dairy farm and two months on pastured based dairy cows. Rahman, Smith, Little, Ingham, Greenwood, et al. [25] presented behavior monitoring method of cattle. They used accelerometer based device for recording acceleration data of cattle. They installed devices in neck collar and other device installed back of head. They classify the activities of animals[26]. They stated that by installing devices on different positions we can achieve good accuracy. M. Stewart and M. T. Wilson [27] presented remotely health and welfare monitoring system for dairy cows. They used infrared thermography and accelerometer for data collection. They tagged the data by video that have recorded in time series as accelerometer data recorded. The tagged data are classified using machine learning algorithms[28]. The estrus is detected by milk progesterone level. When cow is artificially inseminated then calmed. The success of AI can be checked after the 50 days of AI [29]. Grzesiak, Zaborski, Sablik, Żukiewicz, Dybus, et al. [30] presented the study that cow feel a lot of difficulties during artificial insemination. The sensitivity and specificity of estrus detection was around 85% of the overall system. Fig. 1. Data-logger circuitry with mounted GPS. We have used hybrid machine learning methodology in our system. First, we use K- mean machine learning algorithms that is used for dividing the data into three groups and we assigned class label to corresponding data. K-mean[21] used for the preparation of training dataset for support vector machine (SVM) [31]. When we have trained SVM the new incoming data activities are predicted by SVM. 3 Proposed Methodology The data-logger contains 3-axis accelerometer for recording acceleration, GPS module that records position of cow and GSM module that transmits data wirelessly. These modules are fabricated on single chip that contain controller. We use rechargeable battery cell 186650 for power supply to data-logger Fig. 1. There is a port for SD card. SD card is used to store the recorded data from sensors. The frequency of data-logger is 100 HZ. 3.1 Data Collection Data collection is very difficult and challenging task. In data collection process, first of all data-logger installation is important because in field deployment we have to save it from water as well as from animal stroke, making sure cow does not sit Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 31 on it etc. The second task is to design a neck strap that will carry data-logger effectively, without irritating the cow significantly. The last challenging task in data collection is to change battery of data-logger on daily basis. Fig. 2. Axes direction of data-logger installed under neck of cow [32]. To save module from external forces, like other animals hitting it or cow scratching its neck with a rough surface, the data logger was covered with hard material. A small box was used for packing of module. The packing consisted of multiple layers. The internal layers are of soft plastic and foam which were installed to save data- logger from vibration and movement etc. The cell batteries are also placed in same box as shown in Fig 2. The batteries can be replaced by opening the box. Along with data-logger based heat detection a visual monitoring system is also used to capture cow’s videos. The video monitoring system is designed using Raspberry Pi and Pi camera module. This is low power video monitoring system. The raspberry pi will make videos of animals that are used for verifying the events predicted from data- logger data. The collected data was stored in SD card integrated with data-logger and was copied on daily basis at evening time. After getting this data we processed it for checking the cow is in estrus or not. The formats of data that have recorded are shown is Fig 3. The recorded data contained three-dimension acceleration in X, Y and D format. The X and Y axis are parallel to ground and Z axis is perpendicular to earth. When cow sits or stands, the Z axis shows significant change. The accelerometer readings are in 3 dimensional axis but GPS readings have more parameters like time, date, latitude, longitude, directions and speed as well. In our data set we have the accelerometer and GPS parameters. The parameters are explained with example in Table 1. and Tabl 2. This space is intentionally left blank to adjust the images. Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 32 TABLE I. DETAIL OF ACCELEROMETER DATA Name of Axis Example Detail X-axis 486 The X-axis is parallel to ground Y-axis 503 The Y-axis is parallel to ground Z-axis 562 The Z-axis is perpendicular to ground TABLE II. DETAIL OF GPS DATA WITH EXAMPLE Name of Axis Example Unit Detail Message ID $GPRMC RMC protocol head Time in UTC 163527.00 hhmmss.ss Status A A=valid data and V=invalid data Latitude 3135.45554 Ddmm.mmmmm North/South direction N N=north, S=south Longitude 07427.32500 Dddmm.mmmmm East/West direction E E=east , W=west Speed on the ground 0.594 Knot Direction 308.26 Degree Data 240817 Magnetic variable Checksum A*78 Fig. 3. The recorded data of data-logger in textual format. 3.2 Methodology and Data Analysis After getting the data, the first step is to pre-process it, calculate features from the data and use classification algorithms that were applied on that data. The methodology of proposed estrus detection system is explained in Fig. 4. For the analysis of normal and estrus behavior of cow, first of all we prepared the dataset. The dataset have 13 estrus events and more than 80 normal events. When we had the dataset, the first step was to preprocess the data and remove noisy and faulty data from all files. Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 33 The second step was to extract features from the preprocessed data and finally we applied classification algorithms for analysis of the behavior of cow. After getting the data, we removed empty and missing values from the data and removed entries containing noisy values. Sometimes, the noisy data is recorded when the power of battery is low. We analyzed each file to remove noisy data. We removed missing values and NA’s from data. We wrote code that converts the textual data into CSV format which contain only accelerometer data because there is not much need of data location for detection of estrus. We also removed all other parameters of GPS like speed, directions, data, and checksum etc. because they are not useful for estrus detection. After the preprocessing, we have written a script that convert the text file into CVS file. The CSV files contain only the accelerometer data because for estrus detection there is no need of GPS reading. When data was cleaned, and noise had been removed, we extracted features form the preprocessed data. We wrote code in RStudio that read CSV file. As we have defined that the normal estrus standing period is 18 to 24 hours. We were not able to detect estrus in single reading of data. So, we defined 1-hour window size to classify whether the cow is in estrus or not. We classified all data points into relative activity but for detection of estrus we calculated the total activity in 1-hour time slice. Now we had to define features that are helpful for estrus detection. We defined seven features like Area (A) =X+Y+Z, which is the sum of X, Y and Z axis for every entry in data, calculated R= √(X^2+Y^2+Z^2 ) for every single entry, calculated mean of three axes and also defined average value of X-axis, Y-axis and Z-axis for every window and finally we calculated the sum of average values of X, Y and Z axes. Fig. 4. System flow diagram of estrus detection. 3.3 Classification When we have featured data, we have to apply classifier on data for estrus detection. Cow has different behaviors like siting, standing, walking, and eating but these behaviors are not needed for estrus detection. In estrus detection, we divide activity into three levels like low, medium, and high activity and the increased activity of cow is the major sign of estrus by automatic technique. In standing estrus time, the cow shows restlessness and high activity most of the time and restless can be checked by the ratio of each activity type. Support vector machine algorithm is used for activity prediction, but training example can be prepared by K-mean clustering approach. Data splitting involves partitioning the dataset into an explicit training dataset used to train the model and for an unseen test dataset used to evaluate the model Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 34 performance. We used 70% data as training dataset and 30% as test dataset. K-mean clustering is an unsupervised algorithm first used by James MacQueen [9] in 1967 which was used for the classification of cow activities for the preparation of training set for SVM classifier. It calculates the cluster centers that have very minimum squared error and activity of cow assigned to each row of featured data after applying K-mean. K-mean algorithm is used for the purpose of automatically partitioning data into k groups. In our case k=3 like low, medium, and high activity. Low activity is defined by 2, medium by 1 and the high activity is defined by cluster label 3. After successfully clustering the data into 3 groups, we assigned specific cluster number to respective entry. The percentage of activities during estrus and non-estrus has shown in Fig. 5. Fig. 5. The percentage of activities in estrus and normal behavior We have used multi-class support vector machine learning algorithm for the classification of activity level. (X, Y, Z, R, mean(XYZ), Sum(XYZ) and K) are the training set where K means activity class and here k can be 1,2 or 3 according to medium, low and high activity. The best results are achieved at cost=1, kernel=radial and gamma=1.The efficiency of SVM is 95% for activity prediction. When we predict activity from the cow acceleration data, we have to find that the cow is in estrus or not, for this purpose we need very good statistical analysis of the activity categorized data. The results of SVM classifier are shown by Fig. 6 (a). The accuracy of SVM classifier is also 95% for activity prediction as represented by Table 8.2. Out of 78807 medium activities, 653 are misclassified into low and only 3 are misclassified into high activity and from 16261 low activities, 258 are misclassified into medium and from high activity out of 104932 only 328 are misclassified. Decision tree is a supervised machine learning classifier. It selects feature imperially for the classification. It is easy to implement and requires little struggle from user side for data preparation. Here we also used for activity prediction, but the results of Decision tree are not good as shown by Fig. 6 (b). The overall results of SVM and Decision tree are shown by Fig. 7. The accuracy of SVM is good as compared to D-tree. Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 35 Acceleration data of cow activity has been classified in different activities which are defined earlier using SVM classifier of defined window which is 1 hour. We cannot detect that the cow is in estrus or normal by single activity. We had to count the activity index at least of 1 hour which is equal to window size. We also measured activity index level of normal activity and store it in comparison variable called threshold activity index. We also assigned weight w to each activity. First, we calculated the separate activity index for each class by using the following equations. 𝐿𝑜𝑤 𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝐼𝑛𝑑𝑒𝑥 (𝐿𝐴𝐼) = 𝑊2 ∗ 𝑁2 𝑀𝑒𝑑𝑖𝑢𝑚 𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝐼𝑛𝑑𝑒𝑥 (𝑀𝐴𝐼) = 𝑊1 ∗ 𝑁1 𝐻𝑖𝑔ℎ 𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝐼𝑛𝑑𝑒𝑥 (𝐻𝐴𝐼) = 𝑊3 ∗ 𝑁3 𝑇𝑜𝑡𝑎𝑙 𝐴𝑐𝑡𝑖𝑣𝑖𝑡𝑦𝐼𝑛𝑑𝑒𝑥(𝑇𝐴𝐼) = 𝐿𝐴𝐼 + 𝑀𝐴𝐼 + 𝐻𝐴𝐼 Where W stands for weight of specific activity and N stands for count of specific activity in window size. We calculated the total activity index of normal data and set its value as threshold value for activity detection. The new measured data were brought, features were calculated. TABLE III. THE RESULTS OF SVM CLASSIFIER (a) (b) Fig. 6. The Results of SVM classifier (b) Confusion matrix of Decision tree Fig. 7. Comparison of results of decision tree and SVM Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 36 3.4 Experimental Results In estrus detection, there is no need for the exact classification of cow behavior like standing, sitting, ruminating, walking, and eating but here we behavior analysis as well to differentiate the estrus from the non- estrus behavior of cow. We have recorded estrus and non-estrus behavior by self- observation as well and camera. The Fig. 5 shows the sitting behavior of cow that was recorded under my observation. We can see in Figure that there is no high activity in sitting duration. The value of Z axes is less than 1 during sitting. During sitting, cow only move her head and ruminate due to this there is significant change in Y axes. Fig. 8. Sitting behavior of cow. The standing behavior have shown in Fig. 6. The value of Z axes during standing is greater than 1. During standing cow also do ruminating. The value of all axes is not stable. She can move her neck left and right due to the movement of neck the values of X and Y axe are also changing. The eating and drinking behavior of non-estrus cow have clearly shown in Fig. 7. The figure show that the values of all axes are changing quickly because during eating cow eats from left, right. During eating cow also moves from one side of the barn to the other side. There is significant fluctuation in values during eating. The walking behavior of cow also looks like eating because during waking it also moves like as she moves for eating from one side of the barn to the other side, but fluctuation is more during walking with respect to eating. The value of Z axes shown some time more than and sometime less than one because in moving with the movement of body she also moves her neck up and down. Detail have showed in Fig 8. Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 37 Fig. 9. Standing behavior of cow. Fig. 10. Eating behavior of cow Fig. 11. Estrus behavior of cow. The results of estrus and normal activities have been compared. During normal behavior most of the time cow showed low and medium activity while during estrus time the more activities were high and medium because during the estrus the cow shows restlessness behavior. Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 38 After calculating the features, the data was divided into three clusters according to low, medium, and high activity and activity rates were also measured as shown in Table 8.1. The sampling rate was 100 Hz and duration of window size to compare the activities of estrus and non-estrus was 1 hour, 2 hours and 1 day. There was significant increase in high activity in all windows as represented by Table 4.1. In 1-hour window, the high activity increased from 14.5% to 82.28% and in 10 hours window it increased from 15.29% to 69.59%. The activities were not exactly calculated in 1 second and 2 second window, so estrus is also not predicted by 1 second, 2 second or 10 second windows and data of 1s, 2s and 10 s are not enough for prediction of estrus. We used at least one-hour data and calculated the features and after prediction of activity we calculated activity index and compared it with normal activity that had already been calculated by previous 3 days activity. If the newly calculated activity is 2 times or greater than normal activity, then cow was in estrus. The activity index of cow in estrus and non-estrus were also analyzed. It shows the significant change in behavior during estrus and non-estrus. We have explained three types of activity classes in our estrus detection method. Lower activity represents a little movement like siting, medium activity represents a bit more activity like eating and standing while high activity shows more increase in activity, and it is more helpful in determining estrus behavior in cows because during estrus most of the activities are high. Different weight has been assigned in for estrus detection [6]. We assigned weight to each activity type like 0.1 assigned to low, 0.2 to medium and 0.7 assigned to high activity. Activity index of window size like 1 hour had been calculated and compared with normal activity index that was calculated by taking the average of last five days of activity index. If the newly calculated weight was 2 times more than the normal activity index, then the cow was in estrus otherwise normal as shown in Fig 10. Fig. 12. The activity index of cow during estrus and non-estrus We have installed data-logger into 10 different cows and recorded 13 estrus events. Out of 10, three cows came into estrus again after the 21 days because estrus cycle repeats after 18 to 24 days when AI was not performed at the appropriate time. We have more than 50 normal events which we analyzed all by activity index. In our analysis the true positive rate of estrus is 100% and false positive rate is 0% but in case of normal activity prediction only 2 activities are Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 39 wrongly predicted as estrus. The true positive rate of non-estrus events is 96% and false positive rate is only 4%. The overall accuracy of our system is 96% The activity index has shown in Fig 10. There is significant difference between normal and estrus behavior. During non- estrus behavior the maximum value of activity index is 7 while in estrus behavior the activity index touched 15. This shows that during estrus, the activity of cow is 2 times more than the normal behavior. Table 7. shows the average values and standard deviation axes wise. We can see that the maximum value of Z-axes occurs during eating behavior while minimum during sitting behavior. TABLE IV. THE STANDARD DEVIATION (𝜎) AND MEAN 𝜇 VALUES DURING ACTIVITIES. 𝝁(X) 𝝁 (Y) 𝝁 (Z) 𝝈(X) 𝝈 (Y) 𝝈 (Z) Sitting 460 411 507 4.98 7.04 5.05 Standing 469 453 533 4.63 11.03 3.9 Eating 432 425 501 39 21.26 27.21 Walking 470 443 520 29 16.76 21.56 Estrus 518 475 602 16.63 9.6 5.6 4 Discussion Place figures and tables at the top and bottom of columns. Avoid placing them in the middle of columns. Large figures and tables may span across both columns. Figure captions should be below the figures; table heads should appear above the tables. Insert figures and tables after they are cited in the text. Use the abbreviation “Fig. 1,” even at the beginning of a sentence. The already existing estrus detection methods with electronic technologies get up to 94% sensitivity and the rate also up to 53% [33]. There are many factors that affect estrus detection. Løvendahl and Chagunda [33]. noted that the estrus detection rate and error rate are depending on the threshold value like activity index level. Roelofs, López- Gatius, Hunter, Van Eerdenburg and Hanzen [34] pointed out that the estrus representation mostly affected by many factors likes number of days of puerperal period, heritability, milk production, health factors like body size and also affected by weather conditions like temperature and season etc. [30]. Wilhelm et al. also presented an estrus detection technique which reported 85% sensitivity and also discussed that average calving interval and body health condition are most important for estrus detection [29]. Here in our proposed methodology the sensitivity of estrus detection is 96.8 % and error rate is 4%. 5 Conclusion The paper presented an estrus detection technique in which we used low power data- logger that was designed by Bio-Inspired Simulation & Modeling of Intelligent Lab (BISMIL lab) of Information Technology university Lahore. The data-logger consisted of 3D accelerometer, GPS and controller. There is SD card slot for data storage. Accelerometer and GPS data was recorded and saved in SD card. First, we preprocessed the dataset, we removed noisy and missing values. After the preprocessing we extracted features from dataset. Initially we used unsupervised machine learning algorithm for data-tagging. We apply K-mean on dataset and divide the data into three clusters. The data have tagged into three clusters based on data variance. The K-mean tagged data have used as training dataset for SVM and D-tree. After the training SVM and D-tree used for activity prediction. The SVM performed better than decision tree. The accuracy of SVM is 96% while the decision tree accuracy is 86%. After the successful prediction of activity, the activity index level is calculated and compared with normal activity level. If the new calculated Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 40 activity index is 2 times or higher than the normal activity index, then the cow is in estrus. Our estrus detection method accurately detects estrus among the 10 cows. There were 13 estrus events and more than 50 normal events. The sensitivity of our estrus detection method is 100 % while the specificity is 96% and false positive rate is 4%. The overall accuracy of proposed estrus detection method is 96.86%. This estrus detection method does not need behavior monitoring, video recording and manual observation on daily basis. Currently the data loggers were installed for small farms, with limited cow movement area. The main step in future is to install these data-loggers into open and big dairy farms. I also experimented with limited number of cows. I believe good results can be achieved when the system is extended to bigger dairy farms. Here the data set was limited and was not balanced. In future, one can use deep learning algorithms because when data is collected from large dairy farms, large dataset can be collected. Apart from cows, the data-logger can also be installed on buffalos and other animals for estrus, disease and behavior monitoring purpose. References [1] S. R. Vanrell, J. O. Chelotti, J. Galli, H. L. Rufiner and D. H. Milone, "3d acceleration for heat detection in dairy cows," in XLIII Jornadas Argentinas de Informática e Investigación Operativa (43JAIIO)-VI Congreso Argentino de AgroInformática (CAI)(Buenos Aires, 2014), 2014 [2] B. Harris, K. Hempstalk, B. de le Rue, J. Jago and J. McGowan, "Improving the power of activity-based heat detection using additional automatically captured data," in Proceedings of the New Zealand Society of Animal Production, pp. 299-302, 2010 [3] L. Yin, T. Hong and C. Liu, "Estrus detection in dairy cows from acceleration data using self-learning classification models," J. Comput., vol. 8, no. 10, pp. 2590-2597, 2013. [4] D. Hanson and C. Mo, "Monitoring cattle motion using 3-axis acceleration and GPS data," Journal of Research in Agriculture and Animal Science, vol. 2, no. 10, pp. 01-08, 2014. [5] R. Jahangir, Y. W. Teh, G. Mujtaba, R. Alroobaea, Z. H. Shaikh et al., "Convolutional neural network-based cross-corpus speech emotion recognition with data augmentation and features fusion," Machine Vision and Applications, vol. 33, no. 3, pp. 1-16, 2022. [6] R. Dulyala, S. Kuankid, T. Rattanawong and A. Aurasopon, "Classification system for estrus behavior of cow using an accelerometer," in Signal and Information Processing Association Annual Summit and Conference (APSIPA), 2014 Asia-Pacific, pp. 14-14, 2014 [7] K. Smith, A. Martinez, R. Craddolph, H. Erickson, D. Andresen et al., "An integrated cattle health monitoring system," in 2006 International Conference of the IEEE Engineering in Medicine and Biology Society, pp. 4659-4662, 2006 [8] D. Fraser, I. J. Duncan, S. A. Edwards, T. Grandin, N. G. Gregory et al., "General principles for the welfare of animals in production systems: the underlying science and its application," The Veterinary Journal, vol. 198, no. 1, pp. 19-27, 2013. [9] M. W. DuPonte, "The basics of heat (estrus) detection in cattle," 2007. [10] B. Robert, B. White, D. Renter and R. Larson, "Evaluation of three-dimensional accelerometers to monitor and classify behavior patterns in cattle," Computers and Electronics in Agriculture, vol. 67, no. 1-2, pp. 80-84, 2009. [11] D. H. Milone, J. R. Galli, C. A. Cangiano, H. L. Rufiner and E. A. Laca, "Automatic recognition of ingestive sounds of cattle based on hidden Markov models," Computers and electronics in agriculture, vol. 87, pp. 51-55, 2012. [12] Y. Mehta and B. Mishra, "Performance Evaluation of IoT Enabled Pedometer for Estrus Detection in Dairy Cows in India," in Artificial Intelligence Driven Circuits and Systems: Springer, 2022, pp. 17-28. [13] J. Roelofs, C. Krijnen and E. Van Erp-van der Kooij, "The effect of housing condition on the performance of two types of activity meters to detect estrus in dairy cows," Theriogenology, vol. 93, pp. 12-15, 2017. [14] C. Cornou and S. Lundbye-Christensen, "Classifying sows’ activity types from acceleration patterns: an application of the multi-process kalman filter," Applied Animal Behaviour Science, vol. 111, no. 3-4, pp. 262- 273, 2008. [15] G. L. Charlton, V. Bouffard, J. Gibbons, E. Vasseur, D. B. Haley et al., "Can automated Estrus Detection in Dairy Cows from Location and Acceleration Data using Machine Learning (pp. 26 - 41) Sukkur IBA Journal of Computing and Mathematical Science - SJCMS | Vol. 6 No. 1 Januray – June 2022 41 measures of lying time help assess lameness and leg lesions on tie-stall dairy farms?," Applied Animal Behaviour Science, vol. 175, pp. 14-22, 2016. [16] C. Cornou and S. Lundbye-Christensen, "Classification of sows’ activity types from acceleration patterns using univariate and multivariate models," Computers and electronics in agriculture, vol. 72, no. 2, pp. 53-60, 2010. [17] J. Xie, S. Jiang, W. Xie and X. Gao, "An Efficient Global K-means Clustering Algorithm," J. Comput., vol. 6, no. 2, pp. 271- 279, 2011. [18] P. Kumar, T. K. Shankar Rao, N. Kumar, S. Chaurasia and N. B. Patel, "Heat detection techniques in cattle and buffalo," Veterinary World, vol. 6, no. 6, 2013. [19] M. S. Shahriar, D. Smith, A. Rahman, M. Freeman, J. Hills et al., "Detecting heat events in dairy cows using accelerometers and unsupervised learning," Computers and electronics in agriculture, vol. 128, pp. 20-26, 2016. [20] R. Firk, E. Stamer, W. Junge and J. Krieter, "Oestrus detection in dairy cows based on serial measurements using univariate and multivariate analysis," Archives Animal Breeding, vol. 46, no. 2, pp. 127-142, 2003. [21] Y. Zong, P. Jin, D. Xu and R. Pan, "A Clustering Algorithm based on Local Accumulative Knowledge," J. Comput., vol. 8, no. 2, pp. 365-371, 2013. [22] Y. Guo, P. Corke, G. Poulton, T. Wark, G. Bishop-Hurley et al., "Animal behaviour understanding using wireless sensor networks," in Proceedings. 2006 31st IEEE Conference on Local Computer Networks, pp. 607-614, 2006 [23] P. C. P. Khanh, N. D. Chinh, T. T. Cham, P. T. Vui and T. D. Tan, "Classification of cow behavior using 3-DOF accelerometer and decision tree algorithm," in 2016 International Conference on Biomedical Engineering (BME-HUST), pp. 45-50, 2016 [24] R. Caruana and A. Niculescu-Mizil, "An empirical comparison of supervised learning algorithms," in Proceedings of the 23rd international conference on Machine learning, pp. 161-168, 2006 [25] A. Rahman, D. Smith, B. Little, A. Ingham, P. Greenwood et al., "Cattle behaviour classification from collar, halter, and ear tag sensors," Information processing in agriculture, vol. 5, no. 1, pp. 124-133, 2018. [26] J. Pfeiffer, M. Gandorfer and J. Ettema, "Evaluation of activity meters for estrus detection: A stochastic bioeconomic modeling approach," Journal of dairy science, vol. 103, no. 1, pp. 492-506, 2020. [27] M. Stewart, M. Wilson, A. Schaefer, F. Huddart and M. Sutherland, "The use of infrared thermography and accelerometers for remote monitoring of dairy cow health and welfare," Journal of dairy science, vol. 100, no. 5, pp. 3893-3901, 2017. [28] J. Wu, J. Xia, J. Chen and Z. Cui, "Moving Object Classification Method Based on SOM and K-means," J. Comput., vol. 6, no. 8, pp. 1654-1661, 2011. [29] E. Garcia, J. Hultgren, P. Fällman, J. Geust, B. Algers et al., "Oestrous intensity is positively associated with reproductive outcome in high- producing dairy cows," Livestock Science, vol. 139, no. 3, pp. 191-195, 2011. [30] W. Grzesiak, D. Zaborski, P. Sablik, A. Żukiewicz, A. Dybus et al., "Detection of cows with insemination problems using selected classification models," Computers and electronics in agriculture, vol. 74, no. 2, pp. 265-273, 2010. [31] X. Liu, S. Yuan and L. Li, "Prediction of Temperature Time Series Based on Wavelet Transform and Support Vector Machine," J. Comput., vol. 7, no. 8, pp. 1911-1918, 2012. [32] J. Wang, M. Bell, X. Liu and G. Liu, "Machine-Learning Techniques Can Enhance Dairy Cow Estrus Detection Using Location and Acceleration Data," Animals, vol. 10, no. 7, p. 1160, 2020. [33] P. Løvendahl and M. Chagunda, "On the use of physical activity monitoring for estrus detection in dairy cows," Journal of Dairy Science, vol. 93, no. 1, pp. 249-259, 2010. [34] J. Roelofs, F. López-Gatius, R. Hunter, F. Van Eerdenburg and C. Hanzen, "When is a cow in estrus? Clinical and practical aspects," Theriogenology, vol. 74, no. 3, pp. 327-344, 2010.