This project compares classical machine learning models and federated learning approaches for occupancy detection in a room.
The project uses a dataset with the following features:
- Temperature
- Humidity
- Light
- CO2
- HumidityRatio
- Occupancy (Target variable: 0 for not occupied, 1 for occupied)
The data is sourced from three files:
data/datatraining.txt(Used for training all models)data/datatest.txt(Used for validation of all models)data/datatest2.txt(Used for final testing of all models)
-
Classical Machine Learning Models (Centralized Training):
- Random Forest
- K-Nearest Neighbors (KNN)
- XGBoost
- Gaussian Naive Bayes
- Perceptron
- Support Vector Machine (SVM)
- Decision Tree (CART)
-
Federated Learning Algorithms (using Flower framework):
- FedAvg (Federated Averaging): Standard federated learning algorithm.
- FedProx: A variation of FedAvg designed to handle system and data heterogeneity among clients by adding a proximal term to the local loss function.
Federated learning simulations are run with varying numbers of clients (e.g., 2, 3, 5, 10) to observe the impact of client count on performance.
-
Evaluation Metrics:
- Accuracy
- Confusion Matrix
- Training Time
-
Outputs and Visualizations:
- Comparative Results Table: A summary table (logged to console and saved as
results/comparative_results_table.html) comparing all models based on validation accuracy, test accuracy, and training time. - Confusion Matrices: For the test set (
datatest2.txt), confusion matrices are generated for each classical model and the final global federated learning models (saved in theresultsdirectory). - Learning Curves (Federated Learning): For each federated learning strategy and client count, separate plots show:
- Validation accuracy and validation loss over federated rounds (client-side evaluation on
datatest.txt). - Test accuracy and test loss over federated rounds (server-side evaluation on
datatest2.txt). (Saved in theresultsdirectory, e.g.,lc_validation_FedAvg_2clients.png,lc_test_FedAvg_2clients.png).
- Validation accuracy and validation loss over federated rounds (client-side evaluation on
- Model Complexity/Convergence Curves (Classical Models): For several classical models, plots show training and validation accuracy as a key hyperparameter (related to model complexity or convergence) is varied. This helps visualize overfitting.
- Decision Tree:
max_depthvs. Accuracy - KNN:
n_neighborsvs. Accuracy - Random Forest:
max_depthvs. Accuracy - XGBoost:
max_depthvs. Accuracy - SVM:
Cparameter vs. Accuracy - Perceptron:
max_itervs. Accuracy (Saved in theresultsdirectory, e.g.,complexity_curve_decision_tree.png).
- Decision Tree:
- Comparative Results Table: A summary table (logged to console and saved as
