*3.2. K-Nearest Neighbour Algorithm (KNN)*

The smart home environment uses a robot named Cyborg, which is used to assist elderly people by switching off unnecessary lights, watering plants, gas control, monitoring for intruders, providing alerts in emergency situations, etc. Sensor signals are collected from various electronic home appliances

$$s = \{ea\_1, ea\_2, ea\_3, \dots, ea\_n\},\tag{1}$$

where *s* represents the sensor signal values and *ea*1,*ea*2,*ea*3, ... ,*ean* represent the various electronic home appliances.

The sensor signals of electronic home appliances are used to detect the ON/OFF states of appliances perform other functions such as intruder detection using the KNN algorithm. If an intruder is detected, the sensor signal values of electronic home appliances and coordinate value of the safer place are collected and stored in the system as a dataset. When the KNN-ABC system model is activated, it analyzes and detects the nearest coordinate value from the stored is dataset and predicts a safe place for the residents to go. The steps involved in the implementation of KNN algorithm are provided below:

**Figure 2.** Working framework of smart home system for assisting elderly people.


$$dist(p\_1, p\_2) = \sqrt{\sum\_{i=1}^{n} (p1\_i - p1\_t)^2 + (p2\_i - p2\_t)^2} \tag{2}$$

Here, *dist*(*p*1, *p*2) is the Euclidean distance between the current location and the targeted location in the dataset.

