## 3 Methodology
### iForest Outlier Detection  
iForest works by constructing an ensemble of isolation trees (_iTrees_) for each dataset, where outliers are defined as instances with short average lengths in the _iTrees_[33]. The _iTrees_ are recursively built by dividing the dataset until all instances are isolated or a specific tree height is reached. Algorithm 1 provides pseudocode for _iForest_. Given \(D\) (input data), _MaxSample_ (subsample size), and _NumTree_ (number of trees to build), the algorithm generates many _iTrees_ and returns a _Forest_. The _iTree_ is generated by using sample data from \(D\). ```
Input \(D\), NumTree, MaxSample Output Set of iTrees
1: Initialize Forest
2: set height limit h = ceiling(\(\log_{2}(MaxSample)\))
3: for i = 1 to NumTree do
4:\(D^{\prime}\longleftarrow\) sample(\(D\), MaxSample)
5: Forest \(\longleftarrow\) Forest \(\cup\) iTree (\(D^{\prime}\), 0, h)
6: end for
7: return Forest

Figure 1: Proposed ML model to detect movement and direction of tagged products. Figure 3: Application of RFID to track the products. Figure 2: Possible tag movement types. During _iTrees_ generation, the next process is randomly select a feature \(q\) from each _iTree_ and select a random value \(p\) within the range. The data is then split into two parts, they are left branch (data points \(q<p\)) and right branch (data points \(q\geq p\)). This process is iterated until there is only one data point in the branch or the _iTree_ has reached the maximum depth. This process is repeated many times for each _iTree_ and finally, a Forest is produced. The last step is finding data points from each _iTree_ which has a shorter path length and is labeled as an outlier. We used the Scikit-learn Python library to implement iForest. We found 120 outliers' data and eliminated them from the RFID readings dataset and retained the remaining data for further analysis. ### Feature Extraction

RSS attributes, which are used to distinguish between moving and stationary tags, have been used in previous studies [10; 11; 13; 17]. The strength of the RSS signal is determined by the distance between the antenna and the tag, with closer tags producing stronger signals. The timestamp information, which is used to determine the direction of the tags, is also an important parameter [10; 13; 17]. Table 1 shows our statistical features extracted from a single antenna. Since this study utilizes two antennas, 36 attributes (including RSS and Timestamps) are extracted in total from both antennas. The statistical attributes were generated from the RFID readings dataset after outlier data were removed by iForest. We used all statistical features in [17] and add other features such as _median_, _kurtosis_, _skewness_, and _count_ for both RSS and timestamps. Finally, the extracted features from the dataset were used as input \(X\), while the label of tag movement was used as output \(y\). Machine-learning algorithms are utilized to learn from this pair of \(X\) and \(y\) in the training set, thus generating predictions. In our study, we use RF to detect the direction of RFID tags. ### Smote

The SMOTE (Synthetic Minority Over-sampling Technique) is a method used to increase the number of minority class instances in a dataset by generating new synthetic instances of the minority class [29]. This is done by randomly selecting the nearest neighbors of each minority class sample and creating new synthetic samples between them