## 2 Materials and Methods
### Prediction Models
#### 2.2.2 Variable Engineering  
Data preprocessing, also called variable engineering, involves various processes, including creating feature matrices to train the models, splitting the dataset into training and testing, preprocessing missing data, and variable scaling.  
1. Creation of feature matrices to train the models: For a health professional using an algorithm of this type, it is beneficial to obtain the result based on the evolution of the patients over time and not only their current state. Therefore, eight years of data were taken from the database and grouped into two matrices of different characteristics used to make the prediction.  
The first matrix grouped eight years of data, calculating the mode for each variable in all of those years, as shown in Figure 1, totaling 123 variables. The purpose of grouping is to obtain a value for each variable representing the results and the change in the variable itself over the eight years.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Variable** & **Variable** \\ \hline Heart rate & Complete heart block \\ Injury or ischemia & Age \\ LV mass (gm) & Gender \\ Ventricular tachycardia & Smoking amount (quantity of cigarettes smoked in a week) \\ Chest pain & Depression scale total \\ Cardiac injury score & Weight in lb \\ Atrial flutter & Taking Medication? H-2 blockers \\ Atrial fibrillation & Taking Medication? Fibrates \\ Angina & Taking Medication? Any diuretic \\ Stroke & Taking Medication? Nitrates \\ Diabetes & Taking Medication? Any calcium channel blocker \\ Hematocrit (\%) & Taking Medication? Progestins \\ Cholesterol & Taking Medication? Alpha-blockers \\ Systolic and diastolic pressure & Heparins \\ Myocardial infarction & Taking Medication? Insulins \\ \hline \hline \end{tabular}
\end{table}
Table 1: Some of the selected variables from the CHS database.  
Figure 1: Feature matrix created by calculating the mode per year for each variable.  
However, since the first matrix summarizes data from eight years in a particular value, a second matrix that maintained a more temporal character than the first was created. For this purpose, the eight years of data were grouped by calculating the mode every three years, as shown in Figure 2. In this way, each variable is divided into three sub-variables, and the models can better analyze the temporal change in the data. Note that both matrices have the same number of rows, but the second matrix has a more significant number of columns (349 variables in total).  
Splitting the dataset into training and testing: The 5125 patients were divided into training and test sets. The Pareto Principle (80/20 rule) specifies that 80% of the results are derived from 20% of the causes [24]. Thus, considering this rule and the number of patients in the database, theoretically, using 80% of the data for training purposes and 20% for testing purposes will help to avoid possible overfitting. On the other hand, if there are fewer training data, the machine learning model will show high variance in training. The model performance evaluation will have a higher variance with fewer test data. Essentially, the aim is to balance the partitioning so that the variance is minimal.  
Preprocessing of missing data: All selected CHS variables have a percentage of missing data. The mode of the respective column was used to replace those variables with missing values (nan) in the database.  
Variable scaling: Most of the variables selected are categorical (1 or 0), but other variables have higher values (such as weight, ECG times, and other tests). Therefore, the scaling of variables was performed so that all values would be between 0 and 1 [25].