# A Study on ML-Based Sleep Score Model Using Lifelog Data
## 2 Materials and Methods
### Primary Habit Score: Good/Bad Sleep State
#### 2.2.1 Setting Description Variables (Features) and Result Variables (Target)  
The explanatory variables of the data set are divided into continuous variables and categorical variables as follows:  
* Continuous variables: total sleep variability, SRI (Sleep Regularity Index) (2 days, 3 days, 4 days, 5 days, 6 days, 7 days), number and time of naps, sleep midpoint variability, day-of-week information, daily sleep start and end information, information on sleep stages within the first 90 min of sleep, information on steps 2 h before the first start of sleep. * Categorical variables: 10-12 h sleep FLAG variable, sleep onset variability 1-h FLAG variable, total sleep time variability within 1 h FLAG variable. The categorization for continuous variables for scoring consists of two steps as follows:  
* The first step, fine classing ([PERSON], 2008; [PERSON], 2019) [30; 31], is carried out to improve consistency and explanatory power. Through this, a representative variable is selected in consideration of the correlation within the explanatory variable and the information value ([PERSON], 2019) [31] and a section for the variable is derived. * The second step is coarse classing ([PERSON], 2008; [PERSON], 2019) [30; 31]; based on the categorization in the first step, a new category is derived by checking the data state. Specifically, for a linear relationship with the occurrence of good sleep, adjacent categories with similar weight-of-evidence (WoE) values ([PERSON], 2010; [PERSON], 2011) [32; 33] are integrated so that the WoE value increases or decreases monotonically ([PERSON], 2018) [34]. In this way, the amount of data on the number of occurrences and nonoccurrence of good sleep for each category is adjusted and categories are integrated based on the WoE value. Features calculated based on WoE values for the target in this study are summarized in Table 3.  
2.2 Defining Good Sleep Habit Labels Using a Logistic Regression Model for the Primary Sleep Habit Score  
This study used a logistic regression model [35] to generate the primary sleep habit score. The reasons for this are: (1) ease of interpretation of regression coefficients; (2) since the model can estimate the probability of belonging to a class, it is often used for risk and credibility analysis required for probability calculation; (3) it can be used as a base model. For these reasons, this study uses the logistic regression model to score good and bad sleep habit status data. Good sleep habit level is expressed as the probability of developing a good sleep state that satisfies good sleep conditions. A model for the effect on the probability of good sleep occurrence has been created using logistic regression with various explanatory variables (Table 3). Logistic regression predicts the likelihood of an event using a linear combination of explanatory variables and is defined by Equation (4) [36]:  
\[ln(odds)=ln\frac{p}{1-p}=w_{1}\times x_{1}+w_{2}\times x_{2}+\ldots+w_{n} \times x_{n}. \tag{4}\]  
To evaluate the performance of the model, the training data and the verification data were first randomly extracted and divided, at a ratio of 7:3 and then three verification metrics commonly used in the credit evaluation model were used, specifically area under ROC (receiver-operating characteristic) curve [37], K-S (Kolmogorov-Smirnov) statistic [38], and Gini coefficient [39]. AUROC (area under ROC) means the area under the ROC curve: the closer the value is to 1, the higher the sensitivity and specificity, so the model can be called a good classification model. In the problem of generating scores, such as in the study of credit scoring, it is known that a model has good discriminating power when the value is 0.7 or more. The K-S statistic is an index that compares the difference in the cumulative distribution function between two groups (in our case, good sleep state and poor sleep state) and tests whether they come from the same distribution.