# Forecast of Medical Costs in Health Companies Using Models Based on Advanced Analytics
## 3 Materials and Methods
### Model Implementation
#### 3.3.1 LSTM Networks  
This neural network, over time, can connect three pieces of information: current input data; the short-term memory received from the preceding cell (the so-called hidden state); and the long-term memory of more remote cells (the so-called cell state)--from which the RNN cell produces a new hidden state [12]. Figure 3 shows an LSTM memory cell. Machine learning algorithms work best when numerical inputs are scaled to a standard range. Normalization and standardization are the two most popular techniques for scaling numerical data before modeling. Normalization scales each input variable separately to the range of 0-1, which is the range for floating-point values where we have the highest accuracy. Standardization scales each input variable separately by subtracting the mean (called centering) and dividing by the standard deviation to change the distribution to have a mean of zero and a standard deviation of one. \begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline
**Variable** & **CKD** & **COPD** & **AHT** & **Diabetes** & **Cancer** & **HIV** & **Tuber** & **Asma** & **Obesity** & **Transplant** \\ \hline Gender & 0.017622 & 0.000404 & 0.004497 & 0.004986 & \(-\)0.009991 & \(-\)0.002089 & 0.270194 & 0.046490 & \(-\)0.023649 & 0.028032 \\ Principal\_Group\_id & 0.079713 & 0.212875 & 0.082054 & 0.095878 & \(-\)0.009113 & \(-\)0.416173 & 0.257335 & 0.161863 & 0.068553 & \(-\)0.450470 \\ Stratum & 0.028784 & 0.049269 & 0.043887 & 0.052435 & \(-\)0.022120 & \(-\)0.037370 & \(-\)0.112660 & 0.068190 & 0.043283 & \(-\)0.029483 \\ City & 0.07663 & -0.018058 & 0.027033 & 0.020959 & 0.003335 & 0.212705 & 0.228476 & \(-\)0.027337 & 0.036065 & 0.065647 \\ Senior\_AddProfile\_id & 0.025530 & 0.029828 & 0.009477 & -0.005390 & 0.044711 & 0.017209 & 0.080920 & 0.006746 & \(-\)0.008737 & 0.061342 \\ FrailInterpretation\_id & \(-\)0.018983 & 0.017184 & \(-\)0.002330 & \(-\)0.018542 & 0.038993 & 0.030642 & 0.063878 & \(-\)0.001963 & \(-\)0.013096 & 0.028646 \\ AllocatedProvider\_id & 0.006603 & 0.084994 & 0.007397 & 0.083724 & 0.055718 & 0.108541 & 0.272037 & 0.107602 & 0.070681 & 0.055575 \\ Age\_Provision & 0.046911 & 0.054943 & 0.079575 & 0.086535 & \(-\)0.034936 & \(-\)0.006842 & \(-\)0.261186 & 0.120718 & 0.24812 & \(-\)0.040887 \\ WeeksContributed- LastFear & 0.019178 & 0.016896 & 0.020329 & 0.020762 & \(-\)0.004686 & 0.00072 & 0.202423 & 0.060753 & 0.018878 & 0.039546 \\ ContinuousContr- & 0.031204 & 0.039401 & 0.041397 & 0.051791 & \(-\)0.018609 & \(-\)0.045660 & \(-\)0.072248 & 0.088931 & 0.038706 & \(-\)0.046542 \\ hintedWeeks & 0.469864 & 0.541773 & 0.456648 & 0.480466 & 0.425494 & 0.251777 & 0.706559 & 0.485456 & 0.439157 & 0.304911 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Correlation with the InvoicedValue field. Figure 3: LSTM memory cell illustration [35; 36]. To normalize the data and feed the LSTM, we used _MinMaxScaler_ from _sklam:preprocessing_ to scale our data between -1 and 1. The feature range parameter was used to specify the range of the scaled data. Then, we converted the training and test data into a time series problem; we must predict a value in time T based on the month data. To train the LSTM network with our data, we needed to convert the data into a 3D format in the form accepted by LSTM. This means that the input layer expects a 3D data matrix when fitting the model and making predictions, even if the specific dimensions of the matrix contain only one value, for example, a sample or a feature. When defining the input layer of your LSTM network, the network assumes that you have one or more samples and requires that you specify the number of time steps and the number of features. There is not a general rule as to how many nodes or how hidden layers must be elected, and very often a trial-and-error approach may yield the best results for each problem [37]. As this is a simple network, we started trying with four neurons, then with eight, and finally, a test was performed with sixteen neurons, which was the first parameter of the LSTM layer.