# Integrating Environmental Data for Mental Health Monitoring: A Data-Driven IoT-Based Approach
## 3 Methodology
### Machine Learning and Big Data Integration  
Given the volume and complexity of the data from three different datasets mentioned in Section 3.1, we used big data tools for distributed data processing and machine learning. The following steps were undertaken:  
* **Data Processing**: The data were processed using standard machine learning and deep learning techniques in Python. The datasets were loaded using pandas and then  
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Stress Level** & **Temperature Range** & **Humidity Range** \\ \hline Very High & Below \(-20\)\({}^{\circ}\)C or above 30 \({}^{\circ}\)C & Above 80\% \\ High & Below \(-10\)\({}^{\circ}\)C or 31 \({}^{\circ}\)C to 35 \({}^{\circ}\)C & 70\% to 80\% \\ Medium & \(-10\)\({}^{\circ}\)C to \(-1\)\({}^{\circ}\)C or 26 \({}^{\circ}\)C to 30 \({}^{\circ}\)C & 50\% to 70\% \\ Low & \(0\)\({}^{\circ}\)C to 15 \({}^{\circ}\)C & 30\% to 50\% \\ Very Low & \(16\)\({}^{\circ}\)C to 25 \({}^{\circ}\)C & 40\% to 60\% \\ \hline \hline \end{tabular}
\end{table}
Table 1: Categorisation of Stress Levels Based on Temperature and Humidity.  
cleaned and preprocessed through normalisation and feature scaling. We applied z-score normalisation to temperature and humidity values and handled missing data through interpolation. The final dataset was then labelled based on predefined stress levels derived from temperature and humidity conditions. Models were trained and evaluated on a 70-30% split for training and testing data.
* **Feature Selection:** A combination of statistical analysis and domain knowledge was used to identify the most relevant features for predicting emotional states. The selected features included temperature (T), humidity (RH), and historical temperature and humidity values, which were used to classify stress levels into five categories: very low, low, medium, high, and very high.
* **Model Training:** Several machine learning algorithms were implemented, including:  
1. **Logistic Regression (LR):** LR was chosen as a baseline model due to its simplicity, interpretability, and efficiency for binary and multi-class classification tasks. It is particularly effective for datasets where the relationship between features (temperature and humidity) and the target (stress levels) is approximately linear, making it a natural choice for initial model comparison.
2. **Support Vector Machines (SVM):** SVM was selected for its ability to perform well in high-dimensional spaces and its robustness in handling both linear and non-linear decision boundaries. The Radial Basis Function (RBF) kernel was used to capture the complex relationships between temperature, humidity, and stress levels, especially when the data are not linearly separable. This makes SVM a powerful tool for classification problems where accuracy is critical.
3. **Long Short-Term Memory (LSTM) Networks:** LSTM was chosen to model the sequential dependencies between historical temperature and humidity values. As a type of Recurrent Neural Network (RNN), LSTM is designed to capture long-term dependencies, which is critical for predicting stress levels based on time-series data. This ability to account for temporal patterns makes LSTM ideal for scenarios where emotional states may evolve over time, driven by the continuous fluctuations in temperature and humidity. Each model was trained using a 70-30% split for training and testing data. We performed hyperparameter tuning for each algorithm using grid search and cross-validation to optimise model performance.
* **Model Evaluation:** The models were evaluated using various performance metrics, including accuracy, precision, recall, and F1 score. We also assessed the ability of each model to predict stress levels based on historical temperature and humidity values, simulating a 30 min prediction window to enable early intervention in real-world scenarios.