# Long Short-Term Memory (LSTM)-Based Dog Activity Detection Using Accelerometer and Gyroscope
## 3 Materials and Methods  
This section covers the methods and materials used to achieve our goal. We applied several methods and techniques to develop our proposed model such as data collection, data preprocessing, feature engineering, data balancing, model development, and evaluation. Data used in this research were gathered from 10 dogs of regardless of their ages, sexes, breeds, and sizes. After obtaining the dogs' owners' consent, we attached wearable sensor devices to the dogs' necks and tails for data collection. The accelerometer and gyroscope were the two fundamental sensors utilized in the wearable sensors set at a sampling frequency of 33.33 Hz, enabling the investigation of the dogs' activities. The sensors were capable of tracking the dogs' rotations and linear movements throughout all angles without discomforting them. The devices were lightweight as the device that were worn at neck is 16 g with a dimension of 52 \(\times\) 38 \(\times\) 20.5 mm. Additionally, the tail-worn device's weight is 13 g with a dimension of 35 \(\times\) 24 \(\times\) 15 mm. The devices were manufactured by Sweet Solution, a company located in Busan, South Korea. The scale factors were \(-\)4 to 4 and \(-\)2000 DPS to +2000 DPS for the accelerometer and the gyroscope, respectively. For this study, we selected trained dogs placed under the responsibility of trainers capable not only to determine the various pet activities but also to instruct the dogs to carry out a particular activity. The selected dogs were able to carry out the desired activity of the trainer accordingly as instructed. For each activity, the trainers make sure the sensors are well fitted on the dogs before staring to record the video and also the recordings of IMU data. The recording is performed in line with the sampling frequency. The sampling frequency were 33.33 Hz and in a second, there were 33 frames. We collected 493,144 data samples. Any machine learning or deep learning model must be trained with adequate data to meet its target. Obtaining an adequate dataset requires many techniques among which data preprocessing. Data preprocessing is a significant factor necessary for the optimal performance of a model, its role is to increase the quality of data by reducing noise and irrelevant information. Due to the nature of our data collection process, we have noisy, irrelevant, and inconsistent data from the sensor devices on which we applied a 6 th-order Butterworth low-pass filter with a cutoff frequency of 3.667 Hz as a remedy. We decided to apply for this filter order because it blocks maximum noise. Similarly, exploratory data analysis (EDA) were used to choose the cutoff frequency. This method lessens the impact of abrupt changes in accelerometer data while assisting in the filtering of sensor data that are impacted by gravity. It also helps make the data cleaner and less reliant. It requires feature engineering to raise an AI model's performance. This process consists of using domain knowledge to select the most relevant features from raw data to train the model aiming to improve its performance. In our case, feature engineering was applied by us onto the data gathered using the sensors. At first, we generated several features considering the number of samples. The generated features included mean, minimum, maximum, interquartile range, energy measure, skewness, kurtosis, standard deviation, and mean absolute deviation. A class weight technique was utilized by us to address data imbalance in our dataset [44]. Most algorithms are not very effective with biased data; therefore, it is necessary to apply a technique that can balance different weights to both the majority and the minority classes of the dataset.