# Forecast of Medical Costs in Health Companies Using Models Based on Advanced Analytics
## 3 Materials and Methods
### Data Processing  
In this step, we transformed raw data into an adequate and understandable format. In the real world, datasets contain errors. Therefore, this step solves errors and the datasets  
Figure 1: Steps of the implemented methodology. Figure 2: Variables by source. become easy to manage [28]. Below, we briefly describe the most important data we followed in each dataset:  
The following transformations from the data:  
1. Dates are converted into DateTime Y%-M%-D% and thus dates are formatted;
2. Empty fields of dates are denoted by 1900-01-01;
3. Empty fields are mapped in 0 values;
4. The \"TotalComorbidities\" field is created, allowing to identify the number of diagnoses or cohorts of a patient;
5. Category values are encoded;
6. Mappings to a dictionary of types of documents;
7. Exceedingly small provision values of less than 1000 are disregarded;
8. DateTime Y%-M%-D% dates are formatted;
9. The \"Number\" and \"InvoicedValue\" fields are converted into int. format. After unifying and cleaning the dataset, we ended up with a total of 160,463,128 entries about the invoices for the provided medical services. Table 2 shows the variables selected to work in the simulators with a 5% sample corresponding to 3,202,610 services with 34 different attributes. The output variable in this study is \"InvoicedValue\". \begin{table}
\begin{tabular}{c c c c} \hline
**Id** & **Column** & **Entries** & **Description** \\ \hline
0 & ProvisionDate & 3,202,610 & Service provision date \\
1 & Identification & 3,202,610 & Affiliate identification \\
2 & ProvisionCode & 3,202,610 & Provision identification \\
3 & Number of services & 3,202,610 & Number of invoiced services \\
4 & InvoicedValue & 3,202,610 & Invoice value \\
5 & Principal\_Group\_id & 3,202,610 & Principal grouping, e.g., surgery \\
6 & Group\_1\_id & 3,202,610 & e.g., hospital surgery \\
7 & Group\_2\_id & 3,202,610 & e.g., abdominal/neck/neurosurgery \\
8 & Group\_3\_id & 3,202,610 & e.g., bariatric appendicectomy \\  & & 0—84,011 & Gender \\
9 & Gender & 1—1,965,111 & 0—no data \\  & & 2—1,153,488 & 1—men \\
10 & BirthDate & 3,202,610 & Date of birth of the affiliate \\
11 & DeathDate & 3,202,610 & Date of death of the affiliate \\
12 & MaritalStatus & 3,202,610 & Marital status (married/single/divorced) \\  & & & Socioeconomic stratum \\  & & 0—1,168,949 & 0—no data \\  & & 1—22,069 & 1—low–low \\  & & 2—19,375 & 2—low \\
13 & Stratum & 3—1,937,099 & 3—medium–low \\  & & 4—26,785 & 4 —medium \\  & & 5—7088 & 5—medium–high \\  & & 6—21,275 & 6-high \\
14 & Sisben & 3,202,610 & Marks if a beneficiary of social programs \\
15 & WeeksContributedLastYear & 3,202,610 & Weeks contributed to the last year \\
16 & ContinuousContributedWeeks & 3,202,610 & Weeks contributed since first affiliation \\
17 & Regime & 3,202,610 & Contributive or subsidized \\
18 & City & 3,202,610 & City where the service was provided \\
19 & Rural & 3,202,610 & People living in the countryside. not in cities \\  & & No—3,060,478 & If patient has a chronic kidney disease \\
20 & CKD & Yes—142,132 & If patient has a chronic kidney disease \\  & & No—3,058,721 & Gender \\
21 & COPD & Yes—143,889 & If patient has COPD \\ \hline \end{tabular}
\end{table} 
Table 2: Selected attributes. In Table 3, we show the Spearman correlation coefficients between the selected variables and the invoiced values for patients who are not marked with any morbidity: \"Without comorbidity\" means that it is not classified under any health cohort, as well as those marked with at least one morbidity \"With one morbidity\" designates patients belonging to at least one or more health cohorts. Similarly, in Table 4, we show the Pearson correlation coefficients between the listed variables and the invoiced value for patients within each cohort or pathology. This process allowed us to identify the most statistically significant variables that can be associated with the medical cost.