# Edge AI for Real-Time Anomaly Detection in Smart Homes
## 4 Experimental Setup
### Model Implementation  
The proposed system employs two complementary machine learning models for anomaly detection:  
* **Isolation Forest (unsupervised anomaly detection)**: Identifies outliers based on data point separation. * **LSTM Autoencoder (deep learning for sequential anomaly detection)**: Detects long-term deviations in sensor data patterns. The dataset was split into an 80/20 train-test ratio, ensuring that anomalies were proportionally distributed in both sets. Model training was conducted on a PC with an Intel i7 processor (16 GB RAM), while inference testing was performed on an Edge AI device (Raspberry Pi 4, 4 GB RAM) to evaluate the feasibility of on-device anomaly monitoring. Table 4 presents the hyperparameters used for training the Isolation Forest and LSTM Autoencoder models, ensuring consistency in model configuration. Hyperparameter tuning was performed using a grid search approach, optimizing for low latency and high detection accuracy. For the LSTM Autoencoder, the number of layers and units was chosen to balance model complexity with inference efficiency on edge devices. This hyperparameter tuning approach resulted in a 13% improvement in anomaly detection accuracy and a 3% reduction in false positives, aligning with previous studies that demonstrated reductions in false positive rates from 53.6% to 27.8% through optimized parameter selection [27; 28]. These improvements highlight the importance of tuning key parameters to optimize edge inference reliability, ensuring a balance between detection accuracy and computational efficiency in resource-constrained environments. To implement real-time anomaly detection at the edge, we employed Isolation Forest (IF), an unsupervised machine learning algorithm widely used for detecting anomalies in high-dimensional data. Unlike traditional classification models, Isolation Forest does not require labelled training data. Instead, it isolates anomalies by iteratively partitioning the dataset, identifying instances that appear isolated from the majority. This method is particularly well suited for IoT environments due to its low computational cost and ability to detect outliers in complex sensor data. The algorithm was applied to temperature, motion, and energy usage readings, with the contamination parameter set to 0.03, meaning that approximately 3% of the dataset was identified as anomalous. The Python 3.10.0 implementation in code 1 details how to use Isolation Forest to detect anomalies in smart home sensor data. The code snippet in code 1 begins by generating synthetic IoT sensor data, simulating real-world conditions in a smart home environment. It then normalizes the data to ensure consistency in feature scaling before applying the Isolation Forest model. The algorithm assigns an Anomaly Score to each data point, classifying observations as either normal (0) or anomalous (1). These results were subsequently analyzed using time-series visualizations (the full code available in Appendix A.1. : Isolation Forest Implementation) to illustrate how anomalies correspond to unexpected fluctuations in sensor readings. To effectively detect anomalies in time-series IoT sensor data, we implemented an LSTM Autoencoder model. Unlike traditional anomaly detection methods, the LSTM Autoencoder learns normal behavioral patterns over time and identifies deviations based on reconstruction errors. The code snippet available in Appendix A.2. : LSTM Autoencoder Implementation illustrates the implementation of the model, including data pre-processing, training, and anomaly score computation. Although the proposed models were validated using synthetic smart home data, their real-world applicability must be assessed on actual smart home deployments. Future experiments will utilize publicly available datasets such as the following: