# Predicting the Risk of Chronic Kidney Disease (CKD) Using Machine Learning Algorithm
## 3 Proposed Methodology
### Cost-Sensitive MSE Loss Function  
Mean absolute error (MAE) and mean squared error (MSE) are the two basic evaluation methods for regression tasks. Their formulas are shown below,  
\[MAE=\frac{1}{N}\sum_{i=1}^{N}\left|y_{i}^{i}-y_{p}^{i}\right| \tag{2}\]  
Figure 5: Distribution of Creatinine.  
Figure 6: Impact of imbalance problem.  
\[MSE=\frac{1}{N}\sum_{i=1}^{N}(y^{i}_{t}-y^{i}_{p})^{2} \tag{3}\]  
where \(y^{i}_{t}\) is the target value of the \(ith\) labeled data, and \(y^{i}_{p}\) is the predicted value of the same from the regression algorithm. Errors in MSE are squared; it makes samples with small error less important (due to squaring) and creates a stronger incentive to train data with larger error. This happens for attribute values where the available data are rare. However, it does not mean that cost function with further higher-order on errors will achieve better results. Especially for data with noise which will be amplified too. In order to strike a balance, MSE is considered as a suitable loss function for this task.  
Although MSE makes less frequent data more important, due to the imbalance of data, the model is trained to reduce error for more abundant data. This causes the error of the rare data to be larger than the common data. To alleviate this problem, we split the data into \(k\) subsets. Then, calculate the mean error of each subset named as _average_error_\(\_\)\(\_\)\(\_\) and their average named as _average_error_\(\_\)\(\_\). The ratio between _average_error_\(\_\)\(\_\)\(\_\)\(\_\)\(\_\) and _average_error_\(\_\)\(\_\) is used as a weight for the error of each sample from different subset.  
\begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Creatinine** & **Original** & **Sampling-1** & **Sampling-2** & **Sampling-3** & **Sampling-4** & **Sampling-5** & **Sampling-6** \\ \hline
0.1 & 395 & 395 & 395 & 395 & 395 & 395 & 395 \\ \hline
0.2 & 93 & 93 & 93 & 93 & 93 & 93 & 93 \\ \hline
0.3 & 549 & 549 & 549 & 549  
As the weight of error is sensitive to the cost of each subset, we called the loss function as cost-sensitive MSE, and its formula is shown as below.  
\[Cost\_Sensitive\_MSE=\frac{1}{N}\sum_{i=1}^{N}\frac{average\_error\_o_{k}}{average \_error\_o}\times(y_{t}^{i}-y_{p}^{j})^{2} \tag{4}\]  
Compared to the original MSE cost, we added a weight to the squared error for each sample. The weight is the ratio of \(average\_error\_o_{k}\) and \(average\_error\_o\). This new loss function is implemented as follows.  
1. Calculate the range of target variable (Range) and minimum value of target variable (Min).
2. Split the data into 10 subsets depending on Range. For example, samples with target variable larger than (0.2 \(\times\) Range + Min) and smaller than (0.3 \(\times\) Range + Min) belong to subset_3.
3. After the first training epoch, calculate the mean error of each subset, which is named the \(average\_error\_o_{k}\).
4. Calculate the mean value of \(average\_error\_o_{k}\) for 10 subsets, which is the \(average\_error\_o\).  
For the subsets with fewer samples, \(average\_error\_o_{k}\) will be larger than \(average\_error\_o\) and weight coefficient will be larger than 1. For the subsets with more samples, \(average\_error\_o_{k}\) will be smaller than \(average\_error\_o\) and weight coefficient will be smaller. Unlike using higher order exponential on errors, which is applied on all samples, the method we proposed is tuned for samples in specific intervals. The advantage of this method is that it can not only increase the importance of rare data, but also avoids the negative effects from high-order exponential errors applied to all samples in the training data set.