KNNImpute.

## Abstract

This chapter discusses missing-value problems from the perspective of machine learning. Missing values frequently occur during data acquisition. When a dataset contains missing values, nonvectorial data are generated. This subsequently causes a serious problem in pattern recognition models because nonvectorial data need further data wrangling before models are built. In view of such, this chapter reviews the methodologies of related works and examines their empirical effectiveness. At present, a great deal of effort has been devoted in this field, and those works can be roughly divided into two types — Multiple imputation and single imputation, where the latter can be further classified into subcategories. They include deletion, fixed-value replacement, K-Nearest Neighbors, regression, tree-based algorithms, and latent component-based approaches. In this chapter, those approaches are introduced and commented. Finally, numerical examples are provided along with recommendations on future development.

### Keywords

- data imputation
- missing value analysis
- missing data
- data wrangling
- data analytics

## 1. Introduction

With recent development of the Internet of Things (IoT), communication technology, and wireless sensor networks, a huge amount of data is generated every day [1, 2]. It becomes easier to collect data in quantities than before, but new challenges subsequently arise. For example, in manufacturing industries, manufacturers often utilize and deploy thousands of sensors in production lines to monitor the quality of products and to detect possible anomaly or abnormal events. Those sensing data are stored in databases for further analysis. Nonetheless, the collected data are not always perfect. Missing-value entries may appear in databases. When a dataset contains missing values, it is referred to as an incomplete dataset. Missing values in manufacturing industries frequently occur due to sensor failure, particle occlusion, and physical/chemical interferences [3, 4, 5]. Unfortunately, most of them happen due to unknown causes and unforeseen circumstances. In addition to manufacturing industries, missing value problems also frequently occur in biomedical areas, for instance, microarray profiling — One of the commonly used tools in genomics [6]. Microarrays are well known for rapidly automated measurement at massive scale — High-throughput biotechnologies [7], but microarrays suffered from missing-value problems [8]. During microarray profiling, missing values might occur as a result of different reasons, such as human errors, dust or scratches on the slide [9], spotting problems, poor/failed hybridization [10], insufficient image resolutions, and fabrication errors [11]. Those unpredictable factors thereby increase the opportunity of defect microarrays. In fact, missing-value problems almost challenge every part of our daily applications ranging from manufacturing/biotechnology industries that rely on sensors to typical service industries that involve questionnaire-based surveys. Questionnaires are used to collect information from respondents. Nonetheless, respondents occasionally fail to provide answers that match the format to fit the response categories [12], subsequently generating unanswered questions or invalid formats/responses (e.g., out-of-range values). There are many reasons for such problems, e.g., respondents refused to answer, respondents chose wrong formats [13, 14], respondents intentionally/unintentionally left blanks, testers addressed unclear/confusing choices, designs involved sensitive/private questions, and interviews were interrupted. These factors could result in missing values in questionnaires.

The difficulty of processing incomplete data is that when a dataset contains missing values, the corresponding entries are marked with invalid values. Accordingly, such a dataset becomes nonvectorial because invalid values are present (which are constantly represented as Not-a-Number (NaN)). To tackle those entries with NaN, mathematical operations (e.g., pairwise distance) need further revision under such circumstances because nonvectorial arithmetic is not well defined.

To handle missing-value problems, data imputation is generally used. Data imputation is a statistical term that describes the process of substituting estimated values for missing ones. Related approaches for data imputation [15] can be classified into two types: Multiple imputation and single imputation. The former is aimed at generating two distributions. One is a distribution for selecting hyperparameters, and the other is a distribution for generating data. Multiple imputation uses a function for generating distributional hyperparameters and takes samples from such a function to obtain an averaged distributional hyperparameter set. Multiple imputation then utilizes this averaged distributional hyperparameter set to create a statistical distribution for describing the data distribution. Finally, data samples are drawn to replace missing values. Popular methods for multiple imputation include Expectation Maximization (EM) algorithms or Monte Carlo Markov Chain (MCMC) strategies [16, 17]. Regarding single imputation, it does not involve drawing data samples from an uncertain function to substitute for missing data as multiple imputation does. In brief, single imputation relies on neither sample drawing nor uncertain functions. At present, a great deal of effort has been devoted to single imputation, for example, hot-deck/cold-deck, deletion, fixed-value replacement (e.g., zeros, means, and medians), *K*-Nearest Neighbors (KNNs) [18], regression [10, 19, 20], tree-based algorithms [21, 22], and latent component-based approaches (including matrix completion) [15, 23, 24]. This chapter focuses on *K*-Nearest Neighbors, regression, tree-based algorithms, and latent component-based approaches because the imputation errors of deck/cold-deck and fixed-value replacement are not satisfactory. Moreover, deletion could result in loss of discriminant features or samples. Therefore, the subsequent sections lay emphasis on the other methods.

The rest of this chapter is organized as follows. Section 2 introduces related works, and their methods are subsequently introduced. Sections 3 shows the numerical results, and finally the conclusions are drawn in Section 4.

## 2. Imputation methods

The following subsections introduce data imputation using KNNs, regression, tree-based algorithms, and latent component-based approaches, respectively. For clarity, the description on the dataset uses the following definitions and notations. A nonmissing-value dataset is represented as **X** = {**x***n* |*n* **=** 1_{,} 2_{,…,}*N*}, where **X** is max-min normalized.

If supervised learning is required, the label information and the response variable corresponding to each sample **x***n* are respectively defined as *cn* and *yn*. The former belongs to categorical variables **c** = {*cn*| *n* **=** 1_{,} 2_{,…,}*N*}. The latter belongs to numerical variables **y** = {*yn*| *n* **=** 1_{,} 2_{,…,}*N*}. Moreover, the sizes of **X**, **c**, and **y** are *M*-by-*N*, 1-by-*N*, and 1-by-*N*. For **X**, **c**, and **y** that contain missing values,

### 2.1 Imputation based on *K*-nearest neighbors

KNNImpute [9] is a popular imputation tool that leverages KNN algorithms to find the *K*-nearest neighbors nearby a given sample *K*-nearest neighbors. Notably, there is a limitation for the selected *K*-nearest neighbors when KNNImpute is executed. That is, the dimensions of those *K*-nearest neighbors corresponding to missing-value entries should contain nonmissing-value data. In the plain version, label information was not used while the *K*-nearest neighbors were searched (Table 1).

Algorithm: KNNImpute | |
---|---|

Input: | |

Output: | |

1 | Select M′ dimensions |

2 | Store the indices of the selected dimensions in an M′-by-1 vector s |

3 | Apply KNN algorithm to |

4 | Store the K-nearest samples in an M′-by-K matrix |

5 | Compute a K-by-1 weight vector |

6 |

In the above-mentioned algorithm, “:” means selecting the entire rows or columns based on the position, and the operator *M* independent variables and the number of nearest neighbors. Iterative *K*-Nearest Neighbor imputation (IKNNimpute) [25] improved one of such drawbacks by using a loop that iteratively produced substituted values, chose the subset of *M* independent variables, and reselected near neighbors. Table 2 lists a simple version of IKNNimpute, where *j*-th iteration, and *J* denotes the number of iterations. Besides,

Algorithm: IKNNImpute | |
---|---|

Input: | |

Output: | |

1 | Form |

2 | Form |

3 | Forj = 1:J |

4 | Forn = 1:(N + 1) |

5 | Apply KNN algorithm to |

6 | Store the K-nearest samples in an M-by-K matrix |

7 | Compare a K-by-1 weight vector |

8 | |

9 | End |

10 | End |

### 2.2 Imputation based on regression

The underlying model of this category is primarily based on well-known Ordinary Least Squares (OLS), which focuses on minimizing least squares errors

Herein, **w** = (**XX**^{⊤})^{−1}**Xy**^{⊤} is the closed form for finding the weight vector. Given a nonmissing-value sample **x**_{t}, of which the response variable **w**^{⊤}**x**_{t} can generate estimated results. Such methods included Least Squares Imputation (LSImpute) [10], Local LSImpute (LLSImpute) [19], Sequential LLSimpute (SLLSimpute) [27], Iterated LLSImpute (ILLSImpute) [20], Weighted ILLSImpute [28], Regularized LLSImpute (RLLSImpute) [29], and so on.

In LSImpute [10], the authors examined two types of correlations — those among independent variables (i.e., estimating **X** and **y**) and those among samples (i.e., estimating **y**). In the latter, **y** should be highly correlated during OLS modeling [30]. A combined model was also derived by taking the weighted average from the estimated **Y** = {*Yn*| *n* **=** 1_{,} 2_{,…,}*N*}, where **Y** was an *L*-by-*N* matrix. The fitting weight was converted from **w** to an *M*-by-*L* matrix **W**. For ILLSImpute, different subsets of independent variables in **X** were drawn and examined during iterations to estimate an optimal

### 2.3 Imputation based on tree-based algorithms

Since Random Forests (RFs) [32] were proposed, the performance of tree-structured classification and regression algorithms were significantly enhanced. Random Forests adopted Bagging (i.e., Bootstrap Aggregating) techniques to perform data sampling and perceptron learning. Multiple trees were created based on randomly selected features several times (where the numbers of features should be smaller than *M*), and each set of sampled data after Bootstrapping was used to train only one tree. A distinct structure used in Random Forests was called proximity matrix, which recorded the concurrence of pairwise samples in a leaf node, namely, the frequencies when two samples coexist in the same leaf node. Such a proximity matrix was symmetric, of which the size was *N*-by-*N*, and it was used as imputation weighting during data recovery.

Based on [22], two basic principles for handling incomplete data can be derived by summarizing the strategies mentioned in [22] — Preimputation [33] and on-the-fly imputation [21]. The former filled in missing-value entries with fixed replacement at the beginning. Replacement was iteratively updated using proximity matrices. RF growing process repeated until convergence. For the latter method, on-the-fly imputation did not fill in missing-value entries with initial substituted values, and it skipped using missing-value samples for computing splitting nodes. When missing-value samples reached leaves, imputation started. As assignment of missing-value samples to leaves involved randomness, iterations until convergence improved imputation.

### 2.4 Imputation based on latent component-based approaches

This type of method has a general procedure for reconstructing an incomplete data matrix. Firstly, the missing-value entries of a data matrix

Popular methods included SVDImpute (i.e., imputation based on Singular Value Decomposition) [34], Nonlinear Iterative Partial Least Squares-Principal Component Analysis (NIPALS-PCA) [35], matrix completion/approximation, and so forth. The common place of SVDImpute and NIPALS-PCA was that projection matrices (or eigenvectors) were computed, whereas plain NMF did not.

#### 2.4.1 SVDImpute

For SVDImpute, let *ι*-th iteration. Subsequently, SVD is perform on

where **U** is an *M*-by-*M* unitary matrix, **Σ** represents an *M*-by-*N* diagonal matrix, of which the diagonal terms are nonnegative real numbers sorted in descending order, and **V** denotes an *N*-by-*N* matrix. By selecting the top *D* largest diagonal values from **Σ**, the following two corresponding matrices **P** and **T** are formed

where “:,1:*D*” means selecting columns ranging from the first one to the *D*-th one, and “1:*D*,:” extracts rows. The process of (3) is the same as Truncated SVD. Subsequently, the reconstructed data matrix becomes

Herein, the operator **P**[*ι*]**T**[*ι*]. Eqs. (2)–(4) iterate until convergence.

#### 2.4.2 NIPALS-PCA

As for NIPALS-PCA (abbreviated as NP below), it minimizes the reconstruction error of

where **H** denotes an *M*-by-*N* index matrix of the nonmissing-value entries in **H**_{m,n} is one. Otherwise, it shows a zero. Let *n* = 1,2,…,*N*, and *m* = 1,2,…,*M*. Eq. (5) becomes convex if either **P** or **T** is fixed. Then, a solution can be achieved based on Alternating Least Squares (ALS). Taking the derivative form of (5) with respect to **T**_{:,n} and zeroing the result yield

Likewise, taking the derivative form of (5) with respect to **P**_{m,:} and arranging the result generate

At the beginning, NIPALS-PCA utilizes the SVD result in the first iteration (see (2)) and extracts the top *D* components from **U** and **V** as **P** and **T** (see (3)). Subsequently, alternating computation between **P**, **T**, and

#### 2.4.3 NMFImpute

Alternating Least Squares has been widely applied to many models, especially matrix completion/approximation. Nonnegative matrix factorization (NMF) is an important topic in matrix completion/approximation, and it became a highlight when it was applied to recommendation systems in a Netflix contest [36, 37, 38]. At present, NMF has developed multiple variants, including (i) regularization based on

where **P**_{m,d} and **T**_{d,n} (where *d* = 1,2,…,*D*), respectively, yields

The multiplicative update rules for (9) are, respectively,

and

where *ε* is an extremely small positive number, and division is elementwise. Eqs. (10), (11), and (4) iterate until convergence.

## 3. Experimental results

To show the imputation performance of the above-mentioned methods, experiments on open datasets were conducted. The datasets included Abalone (Aba), Scene (SCN), White Wine (WW), and Indian Pines (IP). The number of samples were 4177, 2407, 4898, and 21025, respectively. Furthermore, the dimensionality was, respectively, 561, 294, 11, and 200. Imputation approaches included KNN Regression Imputation (KNRImpute), KNNImpute with *K* = 5, Regression Tree Imputation (RTImpute), Random Forest Imputation (RFImpute), and NIPALS-PCA Imputation (PCAImpute) with only one component. All of them were found in open sources.

To generate missing values for each dataset, this study used a random generator to decide missing-values entries. For KNRImpute, KNNImpute, RTImpute, and RFImpute, they required that missing values should not be uniformly distributed in data. Otherwise, imputation could not be performed. Thus, not every of the independent variables were chosen. Missing-value rates ranged from 3.00% to 9.00%, with a separation of 2.00%. When a dataset was recovered, the difference between the substituted values and the ground truth was compared. The criteria for examining the quality of imputation included root-mean-squared errors (RMSEs) and coefficients of determination (R^{2}). For coefficients of determination, this study reshaped (i.e., vectorized) a dataset into a vector and then used the following definition to compute R^{2}. Assume that *xg* represents an element of a ground-truth dataset (*g* = 1,…,*MN*),

When *R* was close to one, substituted values approached the ground truth. This implied that the difference between the substituted values and the ground truth was smaller.

Figures 1–4 display the average and the standard deviation of the RMSEs and R^{2}, where the horizontal axis denotes the missing rates, and the vertical axis is the evaluation result. The left subplots are line plots, and the right ones show bar charts with standard variation. As shown in the figures, standard variation was quite small. Besides, RMSEs became higher when missing rates were increased. Observations showed that KNRImpute, RTImpute, and RFImpute generated similar RMSEs. Overall, KNNImpute and PCAImpute were affected by the hyperparameters.

## 4. Conclusions

This chapter introduces recent methods for processing missing values. Besides, four types of commonly used algorithms, namely, *K*-Nearest Neighbors, regression, tree-based algorithms, and latent component-based approaches, were examined. Their advantages and disadvantages were also discussed in each subsection. It is worth noting that data imputation usually does not require training data. It becomes impractical when data imputation needs supervisory information or the ground truth (notably, the ground truth is unobservable). This is because when missing values occur in training data and even when the ground truth is missing, the supervised methods even cannot work to learn the ground truth. Therefore, those selected four types of commonly used algorithms in this chapter did not rely on and require any supervisory information.

To evaluate those commonly used algorithms, this chapter conducted experiments on open datasets. Criteria including root-mean-squared errors and coefficients of determination were adopted. Numerical results were also displayed in the experimental section for reference.

In more recent years, surveys showed that a deep learning model “Generative Adversarial Network (GAN)” has attracted much attention, and several novel imputation methods based on GANs have been proposed, e.g., MisGAN [49], MIWAE [50], and GAIN [51]. For future studies, deep learning architectures such as Deep PCA, PCANet, and Deep NMF, can be integrated into those four types of commonly used algorithms, namely, *K*-Nearest Neighbors, regression, tree-based algorithms, and latent component-based approaches and subsequently enhance data imputation.

## Acknowledgments

The authors would like to appreciate Guan-Yu Huang for conducting experiments to collect results. This work is supported in part by Pervasive Artificial Intelligence Research (PAIR) Labs, Taiwan.