## 5 ML Setup and Results Analysis  
### ML Experimental Setup  
The operating idea of the system is illustrated in this section. The ML system operates in two modes, a training phase and a detection phase, as shown in Figure 8. The training phase involves the collection of the dataset of our chosen features in each of the pre-defined geofences for training the ML models by a smartphone admin application. Then, we apply the TSMF preprocessing to generate our required GDS datasets to train our chosen ML models. On the other hand, in the detection phase, each user's associated geofences would have their own ML model deployed locally on their smartphone client application. This would detect the user's location periodically at a defined time interval. So, we will detect  
Figure 7: Convolution neural networks.  
if the user is inside their cluster or not. Each of the assigned clusters will be set to cover certain rooms or halls to manage the density of the people for monitoring the movement of employees in the workplaces. The real-time detected locations and the GDS of the users are uploaded to the web management system for tracking them automatically. Each group of users will be assigned by the system admin to a cluster of geofences based on the nature and the requirement of the work and the workplace environment.  
The detection of the user's location occurs by the ML prediction function on the mobile application. It is invoked periodically at regular time intervals to collect the wireless metrics and outputs a location. If the user is a student in a university, as an example, they will be assigned with the cluster of certain lecture halls 1, 2, and 3, where they take most of their lectures in hall 1. However, certainly, they are not assigned to the workers' offices. The prediction function will have high priority weights for detecting their location with the model of lecture hall 1 than the other two. Therefore, the sequence of checking would be lecture hall 1, 2 then 3. If there is a matching, the generated output is the geofence name for any geofence in that user's cluster. This implies that this person is inside their cluster, but if the output is outside each one of them after a predefined violation time interval, this indicates that the person is outside their pre-defined cluster. Then, an alarm will be produced to the user through the mobile application and an alert will be generated in the web management platform to inform the supervisors and authorized personnel of this violation to take proper action. The number of persons inside a certain geofence is calculated in the web management platform to monitor the density of people and for the implementation of our idea of dynamic clustering. The system admins set some pre-defined control measures so that the clusters change over time according to the density of individuals. For testing the system, we chose three different buildings with five lecture halls and two labs to represent the proposed buildings and indoor geofences in the Faculty of Engineering, Helwan University, Cairo, Egypt (FE-HU) as a workplace geofence to represent a real practical implementation of our system. The proposed approach was tested on three buildings: Communication Department, Mechanical Department, and the Neo Lecture Halls Building. Inside them, we chose five lecture halls: Lecture Hall 1, Lecture Hall 2, Maraa'shly Lecture Hall, Mech 606 Lecture Hall and Lecture Hall 26. Two other labs were chosen, the Wireless Research Lab (WRL) and Innovation and Product Development Support Center (IPDSC). Figure 9 shows the buildings and the chosen locations inside them. Figures 10 and 11 have some images of the indoor and outdoor locations we tested in.  
Figure 8: ML system operation diagram.  
Figure 11: Images of outdoor/buildings locations.  
Figure 10: Images of indoor locations.  
Figure 9: FE-HU top-view map.