## 4 ML-Based Models for GDS Generation and Matching
### TSMF Data Preprocessing  
The datasets for the tested geofences are collected as time-series data at 20 Hz from the magnetometer and accelerometer sensors, and the Wi-Fi metrics were nearly at 0.3 Hz. Before going into details, it is worth mentioning that the reason for increasing and expanding our features from just the traditional magnetic field strength to having nine features of magnetic data was for achieving the possibility of using them on their own. Due to the low dimensionality of magnetic field strength alone, this is done mainly for covering the case of the absence of Wi-Fi signals in any location.  
Different statistical operations were applied differently to our metrics in what is called the Time-Series Metrics Fusion (TSMF). There are three preprocessing TSMF situations in which the datasets of our system architecture are tested: magnetic data only; Wi-Fi metrics only; and Wi-Fi with magnetic data. At each time point we tested a different portion of the features.  
First, the magnetic field and orientation TSMF. This is done by processing our 20 samples into one reading using two statistical operations, the Mean and Interquartile range. So, 20 samples of the nine features are taken each second and their mean is calculated to diminish the 20 samples into one single reading. The IQR is calculated in the same manner. Then, the nine means and nine IQRs are concatenated together to get 18 features with the addition of the IO indication label. These two operations were chosen specifically after some conducted tests between some other statistical operations such as variance, kurtosis, etc. The final preprocessing steps are done by splitting the data into 80% training dataset and the rest is used as a testing dataset. The traditional encoding of the IO state into 0 and 1 is as inside and outside labels, respectively. The last step before training the model is to standardize the data or use the StandardScaler, which standardizes the features by subtracting the mean and then scaling it to unit variance [26]. Unit variance means dividing all the values by the standard deviation and this method is applied to all our features of magnetic data.  
Secondly, the Wi-Fi metrics TSMF. The features have the first five BSSIDs and their RSSIs which form 10 features, then the IO label is added to each sample. The number of samples were in the range of 600-900. As the RSSI varies from 0 to \(-\)100 dBm, the absence of the measurement of any of the top five Wi-Fi's RSSI is marked as \(-\)100 dBm to make our model converge to higher results [27]. The corresponding missing BSSID of an RSSI would also get a value of \(-\)100 dBm to indicate its absence. During GDS matching, if an unseen Wi-Fi network BSSID is detected as a new input to the trained model, it is treated as the missing one with a value of \(-\)100 to prevent the confusion of the model and the tests showed the expected results. To prevent and overcome the problem of unseen Wi-Fi networks after training on certain data and the addition of new permanent Wi-Fi signals to a geofence location, a technique is applied by retraining the model at certain time points (e.g., during idle state, every night) using a new batch of collected wireless metrics so the model can identify them in future inferences. The last part is the encoding and labeling of the BSSIDs features in each row in the dataset, followed by the same steps of encoding the IO state, splitting the dataset, and the standardization of it.  
Thirdly, the usage of the two types of features after the preprocessing steps were evaluated. We ended up with a total of 18 magnetic data features in addition to 10 Wi-Fi metrics features for a total of 28 features with the IO label.