## 3 Methodology
### Sleep Quality Forecasting  
This module is executed on a daily basis. It is responsible for processing the feature vectors received during the day to forecast the sleep quality that the user will experience in the next night. The forecast is obtained by executing a random tree regressor model. As explained in Section 3.1, the model is trained thanks to a set of labeled data obtained from volunteers.  
The model of the random tree regressor corresponds to a decision tree, where the feature space is progressively split into subsets based on certain features. Each internal node of the tree, including the root, represents a decision based on the value of a particular feature, and each leaf node represents a possible forecast value. In order to provide context-aware tips to improve sleep, we are interested in understanding the reasons for which the ML algorithm predicts a given value. To this aim, we need to inspect the _decision path_ of the decision tree, i.e., the sequence of feature conditions evaluated along the branches from the root to the specific leaf node that led to the actual forecast. We derive the decision path by leveraging the machine learning library employed in the experimental evaluation of our work, namely scikit-learn [[https://scikit-learn.org/](https://scikit-learn.org/)]([https://scikit-learn.org/](https://scikit-learn.org/)) (accessed on 29 January 2024).  
Figure 2 shows a sample of the random tree model. As exemplified in the figure, the green nodes represent the decision path for a certain feature vector. In our case, the decision path provides insights into how the algorithm arrived at a specific sleep quality forecast based on a subset of the user's feature vector values, which encode information about the user's past behavior and contextual conditions. The listing reported in the box below the tree in Figure 2 shows the notation that we use to represent the decision path illustrated by the green nodes. Note that, in our notation, we represent the true conditions that determined the path from the root to the decision leaf. For instance, since the condition of the root node ('previous day sleep duration \(\leq 10.5^{\prime}\)) was evaluated as false in the example, in our notation, we report the corresponding true condition, 'previous day sleep duration \(>~{}10.5^{\prime}\). We use this notation to communicate the decision path to the LLM-based modules. Indeed, as explained in Section 3.5, we do not craft the prompt given to the LLM modules using the feature vector; instead, we use the decision path, since it precisely describes the reasons and conditions that determine the forecast for a given individual. Otherwise, the whole feature vector would contain several pieces of irrelevant information, i.e., features that did not contribute to the actual forecast.  
The random tree regressor predicts a real number \(r\) between negative infinity and positive infinity, while we are interested in providing the user with a qualitative forecast of his/her future sleep quality. For the sake of this work, we consider four levels of sleep quality, ranging from very good sleep quality (level 1) to very bad sleep quality (level 4). Hence, we approximate the predicted number \(r\) to the nearest integer in [1; 4] to compute the corresponding qualitative sleep quality level. In particular,  
* values of \(r\) in \((-\infty,1.5)\) are approximated to 1, which represents very good sleep quality;
* values of \(r\) in \([1.5,2.5)\) are approximated to 2, which represents fairly good sleep quality;
* values of \(r\) in \([2.5,3.5)\) are approximated to 3, which represents fairly bad sleep quality;
* values of \(r\) in \([3.5,\infty)\) are approximated to 4, which represents very bad sleep quality.  
The sleep quality forecasting module communicates its approximated forecast, together with the corresponding decision path, to the module for LLM-based behavior change tip generation and to the LLM-based context-aware explainer module.