Improved pig behavior analysis by optimizing window sizes for individual behaviors on acceleration and angular velocity data

J Anim Sci. 2022 Nov 1;100(11):skac293. doi: 10.1093/jas/skac293.


This paper presents the application of machine learning algorithms to identify pigs' behaviors from data collected using the wireless sensor nodes mounted on pigs. The sensor node attached to a pig's back senses the acceleration and angular velocity in three axes, and the sensed data are transmitted to a host computer wirelessly. Two video cameras, one attached to the ceiling of the pigpen and the other one to a fence, provided ground truth for data annotations. The data were collected from pigs for 131 h over 2 mo. As the typical behavior period depends on the behavior type, we segmented the acceleration data with different window sizes (WS) and step sizes (SS), and tested how the classification performance of different activities varied with different WS and SS. After exploring the possible combinations, we selected the optimum WS and SS. To compare performance, we used five machine learning algorithms, specifically support vector machine, k-nearest neighbors, decision trees, naive Bayes, and random forest (RF). Among the five algorithms, RF achieved the highest F1 score for four major behaviors consisting of 92.36% in total. The F1 scores of the algorithm were 0.98 for "eating," 0.99 for "lying," 0.93 for "walking," and 0.91 for "standing" behaviors. The optimal WS was 7 s for "eating" and "lying," and 3 s for "walking" and "standing." The proposed work demonstrates that, based on the length of behavior, the adaptive window and step sizes increase the classification performance.

Keywords: data segmentation; labeling; pig behavior classification; pig behavior monitoring; window size; wireless sensor node.

Plain language summary

Analyzing the behavior of pigs provides great insights into animal welfare and health. Technologies that enable automatic, continuous, and real-time behavior monitoring have emerged as alternative solutions and have received considerable attention. Using sensor-based animal monitoring technology, we could provide objective and quantitative assessments of the health and continuous care of pigs. We extracted distinct characteristics/features of different activities over given segments of acceleration data to boost classification performance. Pigs have various behavior patterns with different durations; treating behaviors with a small duration the same as a long duration could ignore the minority behaviors in the window frame. Our study showed that by finding the adaptive window sizes customized for individual behaviors, we could reduce the chance of mixing activities and compute the feature for better classification performance.

MeSH terms

  • Acceleration*
  • Algorithms
  • Animals
  • Bayes Theorem
  • Machine Learning
  • Support Vector Machine*
  • Swine

Grants and funding