Detecting dairy cows’ lying behaviour using noisy 3D ultra-wide band positioning data

In precision livestock farming, technology-based solutions are used to monitor and manage livestock and support decisions based on on-farm available data. In this study, we developed a methodology to monitor the lying behaviour of dairy cows using noisy spatial positioning data, thereby combining time-series segmentation based on statistical changepoints and a machine learning classiﬁcation algorithm using bagged decision trees. Position data (x, y, z -coordinates) collected with an ultra-wide band positioning system from 30 dairy cows housed in a freestall barn were used. After the data pre-processing and selection, statistical changepoints were detected per cow-day (no. included = 331) in normalized ’distance from the centre of the barn’ and (z) time series. Accelerometer-based lying bout data were used


Introduction
Precision livestock farming solutions typically aim at supporting monitoring and decision taking by farmers using on-farm sensors measuring animal behaviour, performance and production (Banhazi et al., 2012). The raw data used to generate decision support are often noisy time series, prone to errors and variation caused not only by sensor failure or the harsh and changing farm environments in which they operate, but also by the animals' specific physiology itself. The resulting complexity and magnitude of the raw data render them hard to interpret as such by farmers or other end-users. Consequently, these data have little value without proper (pre-) processing algorithms that translate the raw measures in information informative for the targeted endusers.
In dairy production, precision technologies are vastly deployed and implemented (Lovarelli et al., 2020;Stygar et al., 2021). The reason for the dairy sector being pacesetter in this area, is groups of animals are typically much less homogeneous (e.g. animals with different age, lactation stages and parities are kept in the same barn) compared to other livestock species and therefore management at group level is less applicable. Additionally, dairy cows are highly valuable but rather vulnerable, rendering individual monitoring crucial to optimize production, welfare and sustainability. Because of the physiological stress these animals endure during lactation, timely and specific interventions obviate animal suffering and financial losses. As modern dairy farms grew larger over the past decade, investments in sensor technology to guide these interventions became increasingly justifiable (Borchers & Bewley, 2015). Out of the many technologies available, a system monitoring cow position and its derived behavioural features not only promises to disclose cow health, but might also reveal welfare and social interactions -aspects that become increasingly important in the livestock production landscape (Boyland et al., 2016;Chopra et al., 2020). To this end, many technologies such as radio frequency identification, wireless local area network systems, ultrasound positioning systems, etc. have been proposed, as compared by Huhtala et al., (2007). Today's commercialized positioning systems mainly serve to locate cows for e.g., treatment or when they don't go milking. Monitoring specific cow behaviours offers new paths both for research and commercial decision support systems that can help the farmer manage their herd, optimize production and quickly act upon disease or welfare problems. A continuous and essential step to better unlock the potential of cow behavioural analyses is the development of new ways to process data from sensor technologies that allow precise and timely interpretation and extraction of actionable information (Eckelkamp & Bewley, 2020). As such, extra value can be created from existing technology.
Lying behaviour has been shown to change upon a changing health and welfare status (Tucker et al., 2021). For example, lameness will lower the number of times an animal gets up or lies down and increases general lying bout duration (Barker et al., 2018;Weigele et al., 2018). Similarly, udder infections in which an animal becomes very sick, or metabolic problems affecting rumination time, will alter the lying behaviour (Piñeiro et al., 2019). Accurate detection and monitoring over time of lying thus has potential to reveal health and welfare status, contribute to new precision phenotypes, and evaluate e.g., housing situations or management practices in an accurate and non-invasive manner. One technology to do so is via 3-dimensional spatial data, such as provided via modern ultra-wide band (uwb) positioning systems currently being developed and commercialized.
Ultra-wide band technology allows the transmission of high amounts of data over small distances with very low energy in a large frequency spectrum, giving it advantages over technologies such as global positioning systems that have lower battery life and accuracy (Huhtala et al., 2007). In an indoor positioning system based on uwb, Radio-Frequency identification signals are transmitted across a wide bandwidth and captured by an antenna. The tags worn by the individual cows allow precise and frequent localization of the animals with low power usage, even in cluttered indoor environments (Zhou et al., 2012). Upon development of appropriate data interpretation algorithms, indoor positioning systems allow studying and monitoring cow behaviour, including general activity, resting, feeding, drinking and social interactions with a single sensor system, giving it a relative advantage over e.g. commercially available accelerometer systems. Similarly, video-based systems (e.g. McDonagh et al., 2021) have the challenge of cow-identification, sufficient spatial covering, and high computation power requirements. Despite its continuous development and high potential for animal monitoring, uwb-based positioning is yet sparingly adopted for livestock applications. As for many new sensor technologies, the main reason for this is the lack of algorithms that translate raw data into information valuable to the farmer (García et al., 2020). In case of indoor positioning systems, data interpretation is complicated by the inaccuracy and noise in the time series, missing data, and its (unpredictable) heteroscedasticity (Pastell et al., 2018;Ren et al., 2021). The latter partly results from differences in behaviour, but previous research also highlighted dependency on the position of the animal in the barn with regard to the antenna and interactions of the signal with metal (e.g. the feeding rack) and water bodies (e.g., other cows) (Ren et al., 2022). These aspects hinder straightforward interpretation of the positioning data and its derivatives (e.g., distance travelled), also preventing wider adoption. Nonetheless, as dedicated processing of these data would tremendously increase data interpretation potential, for example for the classification of behaviour, several studies on this topic have been published in the past few years (Porto et al., 2013;Borchers et al., 2016;Maselyne et al., 2017;Hendriks et al., 2020).
There is a high need for new methods that elegantly integrate and interpretation-farm collected longitudinal data on which decision support can be based. Additionally, automated, continuous and noninvasive detection of lying behaviour for health and welfare monitoring based on spatial data has not been described in the past. In this study, a two-step methodology to identify lying behaviour of dairy cows using a uwb-based indoor positioning system was developed and validated against the lying bouts returned by a commercial accelerometer-based system. The methodology relies on segmentation via the detection of changepoints, which are in a second step classified as 'lying' or 'non-lying' based on a set of their statistical properties.

Data collection
Data were collected at the Dairy Campus research facilities of Wageningen University and Research in Leeuwarden, the Netherlands, during two periods of five days in two successive weeks in 2019 (July 3 to 8 and July 10 to 15, both periods with normal weather conditions with temperatures between 10 and 20°C). Two groups of cows, one housed in a freestall barn with a straw deep litter bedding and one in a freestall with synthetic flooring, were equipped with uwb-positioning tags on the upside of a neck collar (Ubisense, Cambridge, UK and Noldus, Wageningen, the Netherlands) and accelerometers attached to right hind leg (IceQube® pedometers, IceRobotics, Edinburgh, United Kingdom). It is important to note that the Ubisense technology relies on different methods to determine (x,y)-position compared to (z)-position, affecting accuracy of the measurements. The first is calculated based on time difference of arrival, whereas the latter is derived from the axis of arrival, which makes the (z) more dependent on e.g., orientation of the tags. For the (x)-and (y) position, an accuracy of around 0.2m was found, whereas the (z)-accuracy was found to vary between 0.5 and 1m. Each group consisted of 16 cows selected based on production level, age and lactation stage such that the characteristics were comparable across each group. The cows were milked twice daily in a rotary parlour and fed ad libitum with a partial mixed ration complemented with concentrates individually rationed based on production level.

Lying behaviour
As continuous visual observation of the animals' behaviour is too laborious over a longer period of time, the lying bouts returned by the IceQube accelerometers were used as the benchmark 'ground truth' for lying behaviour. Despite this is a sensor-based measure and not visual observation which would be the true gold standard, it allows to include multiple cows simultaneously, with minimal labour and for a longer period of time, and it has been shown to have sufficient accuracy to detect the actual lying behaviour, with r > 0.99 (Borchers et al., 2016). For each cow, the timestamp of each lying down or getting up event was retrieved from the IceQube software. These data were visually assessed to verify time synchronization and cow identity across the different sensor systems. Only data for which in that time period both uwb and IceQube data were available were retained. More specifically, for each cow, data were kept from the first available IceQube lying bout onward until the end of the last lying bout registered, such that the analysis was carried out on the data for which accelerometers were certainly attached to the animals. This prevented that a lack of lying bout registrations was not caused by cows not wearing a sensor. Two out of the 32 cows were excluded from the study because no ground truth lying bouts were registered due to a technical problem with the IceQube sensors.

Ultra-wide band data editing
Raw binary data were extracted from daily Tracklab back-up _les (.tlp) (Noldus, Wageningen, the Netherlands) and converted with Python 3.7 into (x,y,z)-position time series containing one measurement per second per cow. All further data processing was done using Matlab 2018b and 2020b (The MathWorks Inc., Natick, Massachusetts, USA). The (x,y,z)-position was expressed relative to a pre-specified origin (x,y,z)=(0,0,0), which is a intrinsic characteristic of the technology hardware. In the barns at Dairy Campus, the (x)-co-ordinate gives the position in the direction of the feeding racks (range 0 to 23m in the first barn and 23 to 46m in the second barn), whereas the (y)-coordinate represents the position perpendicular to the feeding alley (range 0 to 14m). A plan of the barn is shown in Figure 1. Codes are available at https://doi.org/10.5281/zenodo.7016493. The (z)-position can be considered the height of the tag on the neck collar. When the (y)-value was larger than 11.5m, the animals were in the slatted flooring (feeding) area, in which it was considered they did not lie down (as formally confirmed by the IceQube data). To interpret the raw position time series and derive cow behaviour from them, multiple data editing steps were implemented to deal with noise and missing data (missing data = on average 43% per day, small gaps and absent data due to milking included, shown in Figure  A 1 of the appendix). First, outliers indicating a position outside the barn edges were replaced with the edge value when it were single measurements likely caused by normal measurement inaccuracy. When multiple successive measurements were registered out of the barn edges, they probably resulted from a lost tag that was put aside by the animal caretakers (in our dataset, this happened during 11 cow-days. An example is shown in Figure A 2 of the appendix). These measurements were replaced by missing values (on top of the 43% on average in the raw data), by retaining the time-stamps in the dataset, but replacing (x,y,z)-value by "NaN = Not a Number". Second, based on a data exploration step (not further detailed in this paper, but for which the code can be found in the repositories linked to this manuscript, Adriaens et al. (2022), https://doi.org/10.5281/zenodo.7016493), a methodology to manage missing data was developed and implemented. More specifically, how we dealt with the missing data depended on (1) the gap size and (2) the amount of non-missing data in predefined window preceding the gap. When data of a day were available and the sensor was attached to the cow, no extra data were deleted before the analysis, only data imputation was done. Missing data always occurred at cow-measurement level, i.e., if data were unavailable, both the (x,y)and (z)-position lacked. For gaps smaller than 60 seconds, we assumed that the cow's behaviour would remain constant, or the error made when this assumption was untrue would be negligible. In this case, the missing data were imputed by sampling them from a normal distribution with mean and standard deviation calculated from the data preceding the gap in a window of twice the gap size in each dimension. For gaps between 60 and 180 seconds, making assumptions on the consistency of the behaviour was more tricky but these gaps could still be due to failure of the sensor system or interference with the barn environment. For these gaps, we used a simple linear interpolation with added noise based on the average standard deviation of the data.
Missing data in gaps longer than 180 seconds were left without data, as these often resulted from the animals not being in the barn e.g. during milking. Assumptions on these longer lasting gaps could not be made and were not of interest for this study, as in these cases cows are not expected to lie down. A third data editing step consisted in smoothing the (x)-, (y)-and (z)-data with a moving median filter in a window of 45 seconds to reduce noise. In order to make sensible assumptions for the settings of the changepoint analysis, data of each cow-day were analysed separately (i.e., a separate segmentation was implemented per cow-day time series). Datasets can be found at https://doi.org/10.5281/zenodo.6373645.

Changepoint analysis for segmentation
Changepoints are time instants or samples in which the statistical properties (i.e. statistical distribution) of a (time) series abruptly change. In this study, we detected and combined the individual changepoints per cow per day in two time series of (x,y,z)-coordinate positioning data. Intuitively, one could argue to mainly rely on the position in the vertical (z) direction (height), as a cow that lies down is expected to remain in a lower and more stable position compared to when she is not lying down. However, the (z)-position was found (unpublished data exploration step) to be the most unreliable and noisy (range, variability,...) of all three coordinates. Its inaccuracy was variable in time and space, and depended on e.g., the position in the barn, the behaviour and speed of the animals, the collar attachment, the calibration settings and individual interactions between tags. Similarly, relying on detection of a relatively stable position in the (x,y)-direction (which is unmistakably true during lying bouts) is imprecise and insufficient for lying behaviour detection as well, as cow activity varies over the day, and oftentimes animals stand still for a longer period of time apart from their lying bouts, for example when grooming other animals, feeding, drinking or ruminating. These periods of 'standing' inactivity might additionally depend on accessibility lying places, hierarchy, climate of the barn, etc. In this study, we chose to work on a combination of two position-derived time series. The first is the (z)-coordinate (height) of the animals, as this is the most straightforward one and because the distributions differ during lying and non-lying behaviour, despite the noise in the data (see also Figure A 3 in the appendix). The second time series is the `centre distance' (CD), i.e. the position relative to the centre of the barn. The main advantages of using CD and not the raw (x,y)-position is that it summarizes position and movement of the animals in a single signal, is less dependent on the actual direction of movement, and has a lower variability and range. Should a cow move in a perfect circle around the centre of the barn, however, CD remains constant (as is the case when a cow stands still or lies down). We assumed that this would be extremely rare, and when it would happen for a short period of time, this would not impair the analysis because movement as such causes the signal to be more variable, which also changes the statistical properties of the time series. Before the segmentation, the CD and (z ) time series were normalized with a min-max standardization per cow over the entire dataset as follows: (1) in which K is the number of changepoints, dividing the time series in K+1 segments, β is the penalty function, here restrained such that at most 60 changepoints are found per cow-day, because otherwise the number of changepoints would equal the number of data points as this minimizes the total cost. As adding changepoints in general lowers the cost function, it is normal that the number of changepoints found is equal to the maximum set beforehand. Because the variability in the data was high and thereby unpredictable, a mathematical penalty function for restricting the number of changepoints detected could not be found. xkr is the r th z or CD value in segment k. Besides in 'number', also a restriction was set to the minimum distance between two changepoints: they needed to be at least 300 measurements apart (i.e. the lying or non-lying duration was at least 5 minutes). Other data-based algorithms (i.e., using variability and expected minimal cost reduction) have been explored, but because of the heteroscedastic nature of the data, could not be used for this study. The changepoint search algorithm used is based on a pruned exact linear time algorithm using dynamic programming, as proposed by Killick et al. (2012), having the advantage that it is mathematically exact and has a linear computational cost with the number of data points.

Data split
To evaluate the performance of the classification algorithm, its performance was evaluated using two different data splits, one based on time and one based on cow identity. For both, we chose to use a smaller portion of the data for training than for testing (approximately 33-66%), unlike what is usual in machine learning practices. We preferred this data split as (1) the method described here is very robust, so a minimal amount of training data sufficed to achieve accurate predictions and adding more data did not improve the accuracy, as formally tested but not included in this manuscript, and (2) this situation mimics an on-farm situation where little training data is available. The first data split (alike the more classical machine learning approach) uses data from 10 randomly chosen cows (33%) for the model training, and 20 animals (66%) as the independent test set. The second approach corresponds to a situation on farm in which current and historical data are used for training and the algorithm needs to perform well in a future situation. Here, data of the 3 first days of the dataset (25.7% of the segments, 5138 in total) were assigned to training set, after which classification performance was evaluated on the remaining 9 days of data (74.3%, 14 888 segments). One cow's data only started at day 4, and was therefore not included in this training set as the animal would not have been present in the training period.

Segment classification
To move from segments to lying behaviour, we classified each segment as 'lying' or 'non-lying' based on its (statistical) properties, including the level and variability for the normalized data, a categorical variable to indicate whether the cow was in the slatted flooring area, the length of the segment, the number of outliers, the gap size, and the segment range. An overview of these features is given in the table in the appendix (Table  A 1). The classification was done using a 'bagged' (i.e., bootstrap-aggregated, Breiman, 1996) tree algorithm which consistently performed best on our data independently of input data and split. As opposed to individual decision trees (which tend to over fit, Dietterich, 1995), bagged trees combine (i.e., use an ensemble) the results of many trees, improving generalization. Other machine learning classification techniques were also tested, but no further information is provided in this manuscript, as this is not considered as truly novel and, by extension, might depend on farm context and sensor settings. The algorithm uses a random subset of predictors at each decision split (similar to random forest classification) and minimizes the classification error at each split. The model was trained with 5-fold cross-validation to determine the optimal hyper parameters for the number of learning cycles (i.e., 30) and trees. For the bootstrapping, each time one segment was sampled with replacement to grow a new tree. As in some cases a 'true' change happened within a segment, a threshold of 50% was applied to calculate the binary outcome variable: if more the 50% of the segment's data corresponded to a lying bout, it's ground truth was taken as 'lying' and vice versa. The features were selected such that there was no multicollinearity across them.

Performance evaluation
Two aspects of the methodology are important to achieve a good performance: (1) the segmentation accuracy, i.e. are the true changes from lying to non-lying and vice versa accurately detected; and (2) the classification performance in terms of accuracy per segment and corresponding total lying duration per cow-day. For the first, we calculated how many of the true changes have a changepoint associated with them within a window of 5 minutes. Given the length of the lying bouts, this is considered as an acceptable margin for detection. When no detected changepoint was associated with the true change, we assessed potential causes, including e.g., missing data. The second was assessed using the confusion matrix comparing true and false classifications and the total accuracy, for the entire dataset as well as at cow and at cow-day level. We additionally compared the total lying down duration per cow-day in a similar way.

Data overview
A total of 30 cows, with each having between 4 and 12 days of data available were included in the study. These cows had parities between 1 and 7, and were on average 188 (range 119 to 243) days in lactation. An overview of the cow characteristics is given in Table 1. Over the measurement period, in total 2720 lying bouts were detected with the IceQube sensors. From these, 97 bouts were shorter than 10 minutes. Per cow, an average number of 90.6±24.4 lying bouts per cow were included, with an average duration of 85.3±19.8 minutes per bout across cows. Cows had on average 8.2±1.8 lying bouts per day (range: 4.5 to 11.3) and spent 8.23 hours lying down in total. The within-bout level and standard deviation of the z time series, and the standard deviation of the CD across lying and non-lying bouts are given in Table 2. From this, it is clear that statistical properties of the chosen time series differ across lying and non-lying behaviour, which is the basis of our analysis.

Changepoint detection
Of all 5443 ground truth changes in the dataset, 85.5% had a changepoint detected within 5 minutes. Per cow-day, this corresponds to 2.3 changes not identified accurately with the changepoint analysis. From these unidentified changes, 50.3% were linked to changes at a moment that there were more than 15 minutes of missing values in the surrounding hour, and 62.2% of these 50.3% were in a segment with at least 20% missing data. Additionally, 23.9% of these false negatives were within less than 20 minutes from another ground truth change, and thus associated with a very short segment length (Table 3). At cow level, the performance remained more or less constant, with 14.2% of the changes not detected within 5 minutes of the ground truth and up to 93% associated with missing data. Based on our experience with sensors in an on-farm environment and the fact no sensor is faultless, it is expected that part of the changes not being correctly identified with the changepoint analysis is also due to the ground truth not being perfect but this can, with the current dataset, not be verified. Classification performance for cow identity-based data split The first split was based on cow identity, and the training dataset consisted of 7024 segments (35%) from 10 animals, from which 3206 segments represented non-lying behaviour (45.64%). The independent test set contained 13002 segments. The cross-validation accuracy on the training dataset was 91.7%, and the overall prediction accuracy of the test set was 92.8%. The confusion matrix is shown in Figure 2. In total, the test set contains 5625 non-lying segments, from which 5162 were correctly classified, rendering a non-lying classification accuracy of 91.8%. From the 7377 lying segments in the test set, 6901 were correctly classified, corresponding to a classification accuracy of 93.5% for the lying behaviour. In terms of lying duration, the total predicted non-lying time was 2480h, being 115h different from the ground truth non-lying time of 2595h (percent deviation = 4.4%). The total lying time was estimated as 2327h, which is 141h less than the actual lying time of 2468h in the test set (difference 5.7%). Per cow-day, the average classification accuracy at the segment level was 92.8% with a minimum accuracy of 78.7% and a maximum accuracy of 100% (Figure 3

Classification performance for time-based data split
In the second split based on time, 5138 segments were included in the training dataset of day 0,1 and 2, from 29 cows. The confusion matrix is shown in Figure 4. In the training set, 2229 (i.e. 43.4%) segments represented 'non-lying' behaviour. The test set contained 14888 segments from 30 cows. The cross-validation accuracy on the training set was 92.3%. In the test set, 6102 out of 6602 segments were correctly classified as non-lying (accuracy 92.4%), whereas 7634 out of 8286 segments were correctly classified as lying (accuracy 92.1%). The total predicted non-lying duration over the entire dataset was 2853h, whereas the ground truth was a non-lying duration of 2980h, giving a difference of 127h (4.27% over the entire test set). The predicted and ground truth lying duration in the test set were 2612h and 2830h respectively, corresponding to a deviation of 217h or 7.7%.

Figure 4 -Confusion matrix
showing the classification performance of the bagged tree algorithm of each segment belonging to either lying or non-lying behaviour, using a training-test split of the data based on time.
Per cow-day, the average classification accuracy at the segment level was 92.3% with a minimum accuracy of 78.3% and a maximum accuracy of 100% ( Figure 5, left panel). This corresponded to an average error of 7.8% in the estimation of lying duration at cow-day level ( Figure 5, right panel).

Discussion
In this study, a methodology was developed to distinguish lying from non-lying behaviour of dairy cows based on spatial uwb (x,y,z)-positioning data in a freestall barn, combining a segmentation and classification step. A high segmentation performance overall was reached, with many of the true changes indeed resulting in an alteration of statistical properties and corresponding changepoint in the selected time series. Previous (unpublished) results showed that a combination of time series, and finding simultaneous changepoints was necessary to achieve good results, which supports the general idea that more data integration is needed to achieve good performance in on-farm situations in which data are often noisy and prone to many kinds of errors. This was confirmed by the fact that mainly data-quality issues related to missing data and atypical lying behaviour (i.e. short lying and non-lying bouts) prevented reaching a higher performance in the segmentation step. The overall and at cow-day level classification performance was high, with accuracies above 91% independent of data split, demonstrating that our methodology is robust and has high practical value. We evaluated the performance of the methodology based on a data split that contained most data in the independent test set and not in the training set to mimic practical on-farm situation. Robustness of the algorithm is demonstrated by the fact that both the cow identity-based split and the time-based split performed equally well. Future research can investigate the performance of the model when using different position-measuring technologies or in other farm settings and over a longer period of time.
By cross-comparing sensor-based predictions instead of using visual observation, we could validate the methodology with quite an extensive dataset in contrast to what is usual when visual observations are used (e.g., Vázquez Diosdado et al., 2015). For example Kok et al. (2015) used a similar approach for validation of the IceQube accelerometers for lying behaviour, comparing the prediction results of two sensors attached to the same cow. Working with spatial data has proven challenging, and e.g., attempts to implement data-based penalty functions for restricting the number of changepoints, failed. This is mainly due to the enormous heteroscedasticity in these data, which depends on multiple factors such as the cow, the time of the day, the behaviour, factors interfering with the sensor system, etc., for which we can not account mathematically. Applying purely black-box approaches generally results in insufficient robustness, interpretability and generalisability (Wathes et al., 2008;Hermans et al., 2018;Niloofar et al., 2021). Therefore, introducing expert knowledge in animal monitoring algorithms, for example for the data pre-processing steps, remains essential to make them useful for the end-users. An example of this for other data sources such as 3D accelerometers is using the static component of acceleration in the y direction (Vázquez Diosdado et al., 2015). In the current study, expert knowledge was used to pre-process and impute the data, to decide how to combine the spatial data into time series of interest for lying behaviour and set the number and distance of changepoints.
Other algorithms have been developed to automatically detect lying behaviour in dairy cows, for example using machine vision solutions (Porto et al., 2013). The latter study reported a high sensitivity of 92% as well, but this was not based on lying duration, but on whether there were or weren't animals lying in a cubicle in a specific frame, ignoring the longitudinal importance of the data and restricting its current applicability on farm. Additionally, our algorithm was developed in a freestall barn without cubicles. In cubicle barns, position of the cows in the lying places could be considered as a variable as well, which allows tailoring the algorithm to different barn circumstances. In this study, we demonstrated how correct processing of aspecific positioning data (i.e., the system is not designed as such for lying behaviour only) allows to use one system for multiple purposes, maximizing the value of a single investment. In a practical setting, the developed methodology shows sufficient performance for monitoring lying behaviour of dairy cows over time. For example, the algorithm could be used to create time-series data of lying behaviour (duration, bout length), which can be assessed with additional interpretation tools such as individual control charts (Huybrechts et al., 2014;Adriaens et al., 2018). Combining these at group or at herd level, for example into time budgets allocated to certain behaviours of interest, can also indicate cow health and welfare dynamics of the animals (Tucker et al., 2021) and allows automated monitoring with little manual labour. We believe that our methodology can be generalized to other sensor data sources as well.

Conclusions
In this study, we developed a methodology to predict certain aspects of the lying behaviour of dairy cows from spatial data with the use of time-series segmentation and a subsequent classification algorithm. The methodology relies on differences in statistical properties across the behaviour of interest. The overall performance, both when considering a cow-based and a time-based data split to train and evaluate the methodology, was above 92%. Missing data pose the main challenge to reach even higher accuracies, but this doesn't necessarily impair the interpretation of the current results and usability of the method in a practical setting. Generalization of the segmentation-classification method to other behaviours and other sensors was identified as a potential route to improve on-farm data interpretation for decision support.