# Missing Data Imputation in the Internet of Things Sensor Networks
## 4 Experiments
### Our Approach
#### 4.3.3 Step 3: Selecting the Best Fit Estimation  
After computing the missing values, the next stage is the selection of the most suitable imputation method within each group. For each data matrix \(C_{i}\), we make our selection by estimating the error between the previous imputation \(y_{pre,i}\) and current imputation \(y_{cur,i}\) based on the equation below;  
\[err=\sqrt{\frac{1}{n}\sum_{i=1}^{n}y_{pre,i}-y_{cur,i}} \tag{4}\]  
we set the result of the RF imputation as our threshold \(\gamma\) and place \(y_{pre,i}\equiv\gamma\) as the initial value of the previous estimate as described in Algorithm 1.  
Lastly, we use a reverse error score function RES(r) to obtain the final imputation sequence. This is based on two RMSE calculations between the previous imputation estimate with the lowest error and our given threshold \(\gamma\). A sequence that gives the lowest error score is chosen as the optimal imputation estimate for the given distribution.  
**Definition 3**.: _A reverse error score function RES(r) representing the error between \(\gamma\) and the final sequence \(\beta_{Ci}\) in each group \(C_{i}\) is expressed as:_  
\[M_{\gamma}=\frac{\partial(\gamma)}{\partial_{n}}=\sqrt{\frac{\sum_{i=1}^{N}(X_{ \gamma}-\hat{\beta}_{\beta_{ci}})^{2}}{n}} \tag{5}\]  
\[M_{\beta_{ci}}=\frac{\partial(\beta_{ci})}{\partial_{n}}=\sqrt{\frac{\sum_{l=1 }^{N}(\hat{\beta}_{\beta_{ci}}-X_{\gamma})^{2}}{n}} \tag{6}\]  
\[RES(r)=M(\gamma,\beta_{ci})=\left[\frac{\partial(\gamma)}{\partial_{n}}\frac{ \partial(\beta_{ci})}{\partial_{n}}\right] \tag{7}\]  
_where \(\gamma\) is the imputation threshold for \(C_{i}\) and \(\beta_{Ci}\) is the best estimate from the previously chosen imputation techniques._  
```
0: Incomplete matrix \(X\) (n x p). Parameter: \(\gamma\), missing value: vs.
0: Dataset with Imputed values \(X_{s}\).
1: Pre-impute missing values in matrix \(X\) (n x p) with distinct single imputation values
2: Select initial centers \(k\) at random \(C=\{c_{1}\),...,\(c_{k}\}\)
3:whileconvergence criteria is not metdo
4: assignment step:
5:for\(i=1\),...,\(N\)do
6: locate nearest centroid \(c_{k}\in C\) to points \(\{p_{i},...,p_{n}\}\)
7: append points \(\{p_{i},...,p_{n}\}\) to the set \(C_{k}\) centroid
8: Update:
9:for\(i=1\),...,\(k\)do
10:\(c_{i}\rightarrow\) center of all points in \(C_{i}\)
11:endfor
12:endfor
13:endwhile
14: Assign cluster label (\(C_{ik}\)) to points \(\{p_{1},...,p_{n}\}\in X\)
15:while\(1\)do
16:for each\(v\in C_{i}\)do
17:\(RF_{i}^{1}\) = missForest (\(p_{i}\in C_{i}\))
18:\(RI_{i}^{1}\) = regression (\(p_{i}\in C_{i}\))
19:\(kNN_{i}^{1}\) = k-Nearest Neighbour (\(p_{i}\in C_{i}\))
20:endfor
21:\(err_{ci}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}\gamma_{pre,i}-\alpha_{cur,i}}\)
22:if\(RI_{err}\leq kNN_{err}\)then
23:\(RI_{i}^{1}\rightarrow\beta_{Ci}\) / \(\bar{Y}\) Store imputed value in a temporary array
24:endif
25: Get the imputation sequence (\(M^{{}^{\prime}}\)) and compute a reverse error score function RES(r):
26:for\(v=1:k\)do
27: Get the reverse error score RES(r) using Equation (7)
28:if\(\beta_{Ci,err}\leq\gamma_{err}\)then
29:\(\beta_{Ci}\mapsto C_{i}\)
30:else\(\gamma\mapsto C_{i}\)
31:endif
32:endfor
33:endwhile
34: Return imputed dataset \(X_{s}\);
```  
**Algorithm 1**\(k\)-Best Fit Estimation Model.