*3.3. Artificial Bee Colony Algorithm for Power Saving in Smart Home System*

In the smart home, the environment uses a robot named Cyborg to assist elderly people by switching off unnecessary lights, watering plants, gas control, monitoring for intruders, providing alerts during emergency situations, etc. Using the ABC algorithm, it detects the nearest safe place for residents to move to during an emergency situation. Similarly, the collected sensor signals from the electronic home appliances are stored in the dataset. to obtain more accurate and efficient detection of the ON/OFF state, the Artificial Bee Colony algorithm (ABC) is implemented. The ABC algorithm functions by connecting a socket system with the camera sensor and reading the sensor signals from the various electronic home appliances, gas sensor, camera, and PoseNet human positional sensor. It collects all real time information, including the position of human beings in the smart home, at regular intervals of time and stores it in the cloud storage platform in a dataset using the communication module. The locations of human beings can then be retrieved from cloud storage and compared with the location of electronic appliances to check the distance between the human being and the electronic appliances. If the human being is far away from electronic appliances, then the system receives instructions to turn off the unnecessary smart electronic appliances; otherwise, it can use the information to operate the smart electronic appliances in safety mode. The ABC procedure is explained below.

	- **–** ABC 2.1: The spatial dimension space of the current nectar source is split into regular intervals based on the following formula:

$$R\_{k,l}^{l} = Q\_k^l + \frac{(2h - H)}{H} (Q\_k^l - Q\_n^l)\_{\prime} h \in [0, H], \tag{3}$$

where *R* denotes the *h*-th interval of point from division of the current nectar source, *Q* denotes *k*-th current honey source generated in the *l*-th dimension space, and *Q* denotes the *n*-th current honey source generated in the *l*-th dimension space.

**–** ABC 2.2: In each interval of *R*, the interval is divided into several sub-intervals *Y* based on the formula

$$R\_{k,l}^{h,z} = R\_{k,l}^h + \sin\left(\frac{y - rand(0,1)}{2y}\pi\right) \left(R\_{k,l}^h - R\_{k,l}^{h+1}\right), y \in [1, \chi] \tag{4}$$

where *R* denotes the *y*-th sub-interval of the current nectar source, *rand*(0, 1) denotes the random distribution of values between 0 and 1 at a uniform rate, and *R* + 1 denotes the *R* + 1-th interval point produced by division of the next current nectar source.


$$F\_k^l = \min\{fit(F\_{k,l}^h) - fit(R\_k^l)\}, \\ fit(F\_{k,l}^h) - fit(R\_k^l) > 0, h \in [1, H] \tag{5}$$

where *Fk* denotes the difference between *Q* and the fitness value of the nectar source, *fit*(*v*) represents the fitness value of thee nectar source in the regular interval of *R*, and *fit*(*q*) denotes the fitness value of *R*.


The ABC algorithm can achieve the an effective search process in terms of locating the target node; it has good accuracy for determining the position of human beings in a smart home environment and can provide power savings for electronic home appliances in the smart home control system. Despite these advantages, it is inefficient in remote control of smart electronic home appliances. Therefore, the ABC algorithm is modified by implementing the following steps.

• KNN-ABC 1: Randomly generate the initial nectar source from the values of *M* based on the target nectar source of the bees. Based on the target nectar source with the maximum fitness value, randomly generate the initial nectar source values *N* using

$$Q\_l^{l0} = Q\_{min}^{l0} + rand(0, 1)(Q\_{max}^{l0} - Q\_{min}^{l0}) \, \tag{6}$$

where *Ql* is the *l*-th initial honey nectar source generated in the *k*-th dimension spatial space, *Qmin* is the minimum nectar source value of the *k*-th source of honey, *Qmax* represents the *k*-th source of honey generated in the spatial dimensional space, and *rand*(0, 1) generates random numbers between 0 and 1 and is uniformly distributed in the system.

• KNN-ABC 2: For every nectar source of honey, compute the reverse honey nectar source using

$$Q\_l^{l0'} = rand(0,1)(Q\_{\text{max}}^{l0} - Q\_{\text{min}}^{l0}) - Q\_l^{l0} \,. \tag{7}$$

where *Ql* is the the reverse nectar source of honey for the *l*-th initial generation of honey in the *k*-th spatial dimensional space.


$$fit(F) = \min\left(\sqrt{\left((a - q\_l)^2 + (b - q\_l)^2 - D\lambda\_{pi}\right)}\right), k = 1, 2, \dots, \phi\tag{8}$$

where *fit*(*F*) denotes the fitness value of the nectar honey source F at the position of the *l*-th beacon node, *D* denotes the average hop distance which is sent by the first beacon node of nectar *Q*, *ql* denotes the total number of hops between the *l*-th beacon node and the source of honey, and *φ* is the number of beacon nodes.

Using Equation (8) and the modified artificial bee colony algorithm (ABC) improves the accuracy of finding the target node while minimizing the error rate, and is able to provide both effective remote control of smart home electronic appliances and position monitoring of the electronic home appliances via exact angle measurement.

## **4. Result and Discussion**

The proposed KNN-ABC system was implemented in Python 3.6, and was compared with Gaussian Naive Bayes (GNB) [36], Artificial Bee Colony algorithm (ABC) [17], and KNN [37]. Table 2 shows the measures of Precision, Recall and Sensitivity for the different algorithms used in the smart home system. Data were collected from the Kaggle website [38].

Precision: Precision quantifies the number of true positive predictions provided by a given technique. It is calculated as follows:

$$\text{Precision} = \frac{TP}{TP + FP} \times 100.\tag{9}$$

Recall: The percentage of correctly classified true positive predictions is evaluated by calculating the recall, as follows:

$$\text{Recall} = \frac{TP}{TP + FN}.\tag{10}$$

F1-Score: The F1-Score is a measure of accuracy based on precision and recall values. It is calculated as follows:

$$\text{F1-Score} = \frac{2 \times \text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}.\tag{11}$$

Specificity: Specificity is used to measure the proportion of actual negative cases that a technique rightly predicts. Specificity is calculated as follows:

$$\text{Specificity} = \frac{TN}{TN + FP} \times 100.\tag{12}$$

Accuracy:

$$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} \times 100. \tag{13}$$

MSE: The mean squared error (MSE) calculates the average of the squares of the differences between the predicted values and actual values.

$$\text{MSE} = \frac{1}{n} \sum\_{i=1}^{n} (y\_{pi} - y\_{ai})^2. \tag{14}$$

MAE: The mean absolute error (MAE) calculates the average of the squares of the differences between the predicted values and actual values.

$$\text{MAE} = \frac{1}{n} \sum\_{i=1}^{n} |y\_{pi} - y\_{ai}| \,\text{.}\tag{15}$$


**Table 2.** Metrics of Precision and Recall in Smart Home System.

Table 2 shows a performance comparison between the proposed KNN-ABC technique and existing algorithms. Here, GNB using Smart Home assistance for elderly people using the Cyborg robot reached a sensitivity of 68.76%, precision of 65.16%, and recall of 55.35%, the Artificial Bee Colony algorithm (ABC) for power saving in smart home electronic appliances reached a sensitivity of 70.37%, precision of 72.11%, and recall of 67.65%, and the KNN technique for detecting the a nearest safer place in an emergency situation reached a sensitivity of 71.11%, precision of 66.78%, and recall of 68.46%. The proposed KNN-ABC technique for detecting intruders, finding the nearest safe place in an emergency, and saving power on smart home electronic appliances attained a sensitivity of 83.65%, a precision of 88.32%, and a recall of 78.54%. Figure 3 shows the F1 scores of the different algorithms tested for smart home assistance for elderly people using the Cyborg system. The F1 score is the weighted harmonic mean of the precision and recall, with 0.0 being the worst and 1.0 being the best.

**Figure 3.** F1-Score.

Figure 3 shows the F1 scores of the techniques used in the comparative analysis. Our proposed work produced the best result at 0.91, while the GNB algorithm produced the worst result at 0.61. The error rate of the smart home assistance system with the different algorithms is shown in Table 3.



From Table 3, it can be seen that our proposed KNN-ABC approach had the lowest error rate and produced better outcomes than the other algorithms. Figure 4 shows the correlation matrix for predicting intruders in the smart home environment.

**Figure 4.** Confusion matrix.

In Figure 4, the diagonal values are not meaningful as they are self-correlated, i.e., with the variable itself. The values shown to the left and right of diagonal are considered mirror images of each other. The highly correlated variables are shown as darker boxes. Here, standing activities of intruders are highly correlated with one another. Therefore, detection of intruder with activity is predicted as sitting on the bed. Figure 5 shows the accuracy rate of the different tested techniques.

From Figure 5 shows the accuracy rates of the different techniques in the smart home environment system: for detection of intruders, GNB reached 88.12%; for power saving, Artificial Bee Colony algorithm (ABC) reached 90.12%; for determining the safest place to go in an emergency situation, the KNN technique reached an accuracy rate of 91.45%; finally, our proposed KNN-ABC approach reached 93.72%. Figure 6 shows the computation times for the various techniques tested in the smart home system.

Figure 6, shows that of the various techniques, our proposed KNN-ABC approach requires the lowest computation time.

Limitations and Future Work: This work considers a new hybrid approach, i.e., KNN-ABC, which combines the virtues of the KNN and ABC methods to improve on these methods as well as on the GNN method in terms of recall rate, precision, accuracy, F1 score, and computational complexity. However, the performance evaluation in this paper was

restricted to smart home environment applications, and warrants further investigation to determine its improvement over other machine learning methods. Such an investigation and comparison that considers more advanced machine learning classifiers and data from other applications is recommended as a future extension of this work.

#### **5. Conclusions**

This paper proposes the implementation of a smart home environment control system through various sensor modules, control modules, and a human intervention robot named Cyborg; the system is used for control of the automatic ON/OFF state of various electronic appliances, detection of intruders in the smart home, and sending various alert notifications to the user. This system is intended to assist elderly people in an effective and efficient way with a fast response time. The accuracy rate of the various techniques was tested; GNB for the detection of intruders in the smart home environment system using the humanintervention robot named Cyborg reached 88.12%, the Artificial Bee Colony algorithm (ABC) for power saving in smart home electronic appliances reached 90.12%, the KNN technique for predicting safe locations in an emergency situation reached an accuracy rate of 91.45%, and our proposed KNN-ABC algorithm reached 93.72%. In the future, this work could be extended by providing the Cyborg robot system with more security features, including biometric concepts such as facial recognition and fingerprint identification. In summary, the proposed KNN-ABC algorithm shows better accuracy, precision, and recall rate than the GNB, KNN, and ABC algorithms. Better performance means more accurate prediction of activities and can lead to user satisfaction, a greater sense of security and safety, and improved quality of life.

**Funding:** This research received no external funding.

**Data Availability Statement:** Not applicable.

**Conflicts of Interest:** The authors declare no conflict of interest.
