SPARSE KERNEL PCA FOR OUTLIER DETECTION
Abstract
In this paper, we propose a new method to perform Sparse Kernel Principal Component Analysis (SKPCA) and also mathematically analyze the validity of SKPCA. We formulate SKPCA as a constrained optimization problem with elastic net regularization (Hastie et al.) in kernel feature space and solve it. We consider outlier detection (where KPCA is employed) as an application for SKPCA, using the RBF kernel. We test it on 5 real world datasets and show that by using just 4% (or even less) of the principal components (PCs), where each PC has on average less than 12% non-zero elements in the worst case among all 5 datasets, we are able to nearly match and in 3 datasets even outperform KPCA. We also compare the performance of our method with a recently proposed method for SKPCA by Wang et al., and show that our method performs better in terms of both accuracy and sparsity. We also provide a novel probabilistic proof to justify the existence of sparse solutions for KPCA using the RBF kernel. To the best of our knowledge, this is the first attempt at theoretically analyzing the validity of SKPCA.
Index Terms:
KPCA, Sparse KPCA, Elastic Net, Outlier DetectionI INTRODUCTION
Kernel PCA (KPCA) is a non-linear version of PCA proposed in [7]. A major limitation of KPCA is that the eigen vectors of the covariance matrix in the kernel space are linear combinations of all the training data points, which becomes cumbersome for storage as well as querying a new test point. Obtaining sparse coefficients in KPCA is of paramount importance for real world applications. This problem was first addressed in [8], where sparse kernel feature analysis method was proposed to obtain sparse coefficients, by imposing a penalty on the coefficients. Tipping in [9] proposed a Probabilistic PCA([10]) based method for SKPCA. However, such a method is data dependent as it does not ensure sparse solutions for all types of data. Achlioptas et al. in [11] propose a sparse unbiased and low variance estimator for the eigenvectors using concentration inequalities. Recently, Wang et al. in [3] formulated SKPCA as a regression problem and solved it using Alternating Direction Method of Multipliers (ADMM).
Outlier detection is a one class classification problem with possible multiple sub classes within the outlier class. The trained model for this task should be able to distinguish the learned inlier class from an outlier or novel class. One class SVM based approach in [5] and SVDD approach in [6] have previously been used for outlier detection. Another approach for outlier detection has been presented in [2], in which KPCA has been utilized for modeling the training set.
The main contributions of this paper are two fold. Firstly, we extend the work done in [1] to the case of SKPCA. We apply their technique in the kernel space to obtain a generalized version of the problem in Theorem 4 of [1] and also present a method to solve it. To the best of our knowledge, this method for SKPCA has not been employed before. To validate our method, we consider the problem of outlier detection for which KPCA has been used before in [2]. By performing extensive experimentation on 5 real world datasets, we show that it performs nearly as well as KPCA (even better than KPCA for 3 datasets) and better than the recently proposed sparse KPCA approach in [3] as well as naive thresholding (simply picking the largest magnitude coefficients). It must be emphasized here that we are not claiming that our SKPCA method performs better than normal KPCA, instead we are merely claiming that it works almost as well as normal KPCA even under high sparsity. Secondly, we provide a novel probabilistic proof to justify the existence of sparse solutions to the KPCA problem using the RBF kernel. To the best of our knowledge, this is the first attempt at mathematically justifying the validity of sparsifying the KPCA problem.
The paper is organized as follows - Section II gives a brief overview of the outlier detection algorithm in [2] using KPCA. Section III describes our method of Sparse KPCA for outlier detection. Section IV presents our theoretical justification of sparse KPCA for the RBF kernel. Section V discusses and shows the results of our experiments. Section VI concludes the paper.
II KPCA for Outlier Detection
Hoffmann in [2] presented an outlier detection approach using KPCA. In [2], spherical potential of a point (mapped to in feature space) is defined with respect to a data distribution as , where is the mean of the data in feature space. The reconstruction error is defined as , where and contains the top eigen vectors of the data in kernel space, arranged along the rows. We seek to get a sparse representation of using our SKPCA approach. Specifically, if the reconstruction error of a point is less than a certain threshold, then it is classified as an inlier otherwise as an outlier. When we use an RBF kernel, inliers lie inside a sphere whereas outliers lie outside it.
III Sparse KPCA For Outlier Detection
In this section, we explain our method of obtaining sparse coefficients for the PCs in kernel space and its application in the outlier detection problem.
III-A Sparse KPCA (SKPCA) Algorithm
We have data points which get mapped to in the kernel space. We assume that the data in the kernel space is centered. Similar to [1], we first propose the following regression problem to obtain the coefficients of the first PC ():
| (1) |
Here, is the Gram matrix of the centered data [7]. Also, and are x vectors with and as their elements respectively. So, we must minimize equation (1) (denote it by ) subject to . Substituting the values of and in , we get:
| (2) |
Rewriting (2) in matrix form and using , , i.e. the Gram matrix is symmetric, we get:
| (3) |
Observe that this is the same as the PCA problem in [1] with the data matrix replace by the Gram matrix . Even though the optimization problem is exactly the same, the constraint is different, namely instead of . This is quite intuitive.
Partially differentiating with respect to and setting it to :
| (4) |
Substituting from (4) in , we get:
| (5) |
Now, minimizing with respect to subject to is equivalent to the following problem:
| (6) |
Let denote the Lagrangian cost function obtained by imposing the equality constraint and be the Lagrange multiplier.
| (7) |
| (8) |
Now, let be the eigen decomposition of .
| (9) |
For the sparse PCA problem in [1], we had in the numerator above and not . However, is also monotonically increasing and so the value of the objective function will be maximum when is proportional to the eigen vector corresponding to the largest eigen value (as was the case for the sparse PCA problem in [1]), i.e. where is the maximum eigen value and is the corresponding eigen vector and .
This was only for the first PC. Now, we will deal with the case of the first PCs and introduce the Lasso term as done in [1] so as to obtain sparse solutions. For this, we must minimize the following objective function with respect to and which are x matrices:
| (10) |
Here, denotes the column in and denotes the x identity matrix.
Note that this is a convex problem with respect to and individually and so we shall follow an alternating optimization scheme, i.e. keeping fixed, find the optimal , then keeping fixed, find the optimal and repeat this process until convergence.
The solution for the first step of this iterative approach for sparse KPCA, i.e. keeping fixed and finding the optimal is the same as that for sparse PCA in [1]. Specifically, is obtained by solving the following objective function:
| (11) |
Note that here refers to the column of which was obtained in the previous iteration. This is the familiar naive elastic net problem [4] in , which can be solved using the LARS-EN algorithm [4].
The solution for the second step of this iterative approach for sparse KPCA, i.e. keeping fixed and finding the optimal is different as compared to that for sparse PCA in [1]. Specifically, we must solve the following problem:
| (12) |
Note that in sparse PCA, the objective function for finding the optimal was the same but the constraint was different, namely .
We present a corollary to Theorem 4 of [1] which enables us to solve the aforementioned problem in (12). We first restate Theorem 4 of [1] (renamed as Theorem 1 here) for ready reference of the reader followed by the corollary (Corollary 1).
Theorem 1
Consider the following problem where , are x matrices ( ):
The solution to this problem is given by .
Corollary 1
Consider the following problem where , are x matrices ( ) and is a x symmetric positive definite matrix:
The solution to this problem is given by where the SVD of and the SVD of .
Note that Corollary 1 can be interpreted as an extension of Theorem 1 to a generalized inner product space (defined by the matrix ).
We now present a proof for Corollary 1. Let the SVD decomposition of be . Thus, , where is a diagonal matrix with diagonal entries equal to square roots of the corresponding entries of . Now, denote and from the constraint, we must have . Also, and so , where . Thus, we have reduced the generalized problem to the following equivalent problem:
This is exactly the problem whose solution has been given in Theorem 4 of [1] (Theorem 1 in this paper). We directly use that result to get:
For our algorithm, we put , and in Corollary 1. This completes the solution for the second stage of the iterative algorithm.
SKPCA ALGORITHM:
1. Initialize with the eigen vectors of corresponding to the largest eigen values.
2. First for fixed , solve the elastic net problem in (11) for .
3. Then with the obtained in the previous step, update as
where and .
4. Repeat steps 2-3 till convergence.
III-B Outlier Detection Algorithm using Sparse KPCA
We employ the same strategy presented in [2] for distinguishing outliers from inliers as explained earlier, except that here we use the obtained from the algorithm above (i.e. the sparse solutions) to construct the matrix in the reconstruction error term.
IV Theoretical Justification of Sparse KPCA With RBF Kernel
Assume that we have a set of data points, drawn in i.i.d. fashion from a continuous probability distribution . Consider the subset of points. The elements of obey a particular condition, the details of which shall be presented later. We shall prove that the eigenvectors of the covariance matrix (henceforth referred to as ) in the kernel space constructed out of all points in can be expressed as a linear combination of just with high probability for sufficiently large and .
Once again, we assume that the data in the kernel space is centered. An eigenvector, of can be expressed as . Consider a random point sampled from . The projection of on in the kernel space is given as , where is the chosen kernel function. For our case, we choose the RBF kernel and thus . Without loss of generality, assume for simplicity. Thus, we have . For , define . We shall show that for holds with high probability. For , define . Then, for : .
The third term in the above factorization can further be written as: .
Finally, we get : .
We will now show that the second, third and fourth terms in the above factorization are individually close to 1, due to which their product is also close to 1 and as a result with high probability. First we shall show that the second term is close to 1 with high probability. Let where & are sampled in i.i.d. fashion from the distribution . Here, we assume that for . From elementary probability, which tends to for large enough . Thus, holds with high probability, for sufficiently large . For , . Hence, the second term is close to 1 with high probability.
We shall deal with the fourth term before we analyze the third term. By the Cauchy-Schwarz inequality, . We showed in the analysis of the second term that with high probability. We employ the same analysis for instead of (and instead of ) to conclude that with high probability. Thus, with , . Thus, the fourth term is also close to with high probability.
Finally, we come to the analysis of the third term. Here, from the analysis of the second term. Let denote a subset of any distinct points out of the points in . There are such subsets. Define . With this definition, . Let . Here again, we have for as for . Thus, which also tends to for . Without loss of generality, assume that satisfies the condition . This is the exact condition on the elements of which was mentioned in the beginning of this section. Taking , . Thus, even the third term is also close to with high probability.
Thus, holds with high probability. So, we have with high probability. This can be rewritten as , where ). Therefore, with high probability, where ’s are as defined before. This finishes our proof.
Note that one can design a naive algorithm based on the above proof, but its combinatorial nature would render it highly inefficient. We conjecture that our algorithm (or any other sparse KPCA algorithm) does this subset selection task efficiently and perhaps approximately by solving a convex problem instead.
V Experiments
We have compared the performance of our SKPCA algorithm with standard KPCA, naive thresholding of the largest magnitude components of the KPCA coefficients (with = average number of non-zero components per PC obtained through SKPCA) as well the algorithm given in [3]. We have compared our method with naive thresholding because it has been noted in [1] that naive thresholding works almost as well as their sparse PCA method. We have tested these methods on 5 real world datasets - MNIST (Fig. 1), Fashion MNIST[12] (Fig. 2), Satimage2[13] (Fig. 3), ETH-80 dataset (Fig. 4) and Internet Advertisements dataset[14] (Fig. 5). Our experiments reveal that our SKPCA algorithm provides high sparsity without compromising on accuracy. The accuracy using our SKPCA algorithm is nearly the same as KPCA, which is not possible with naive thresholding at low sparsity and the sparsity obtained is in general much more than that obtained from the algorithm in [3], for the same accuracy. Also, our algorithm has just 1 sparsity controlling parameter which is the L1-ratio = , whereas the algorithm in [3] has 5 parameters - . The metric used to measure accuracy in our experiments is F1-score (standard for outlier detection tasks). We obtained 3 plots in our simulations. The first one is a box plot to show the variability of F1-score over different training and test data subsets (we performed the same experiment 10 times on randomly chosen training and test data subsets out of the entire dataset). However, we did not show the variability of the algorithm in [3] for reasons explained later. The second one is a F1-score vs. sparsity (measured as the percentage of non-zero coefficients in the kernel space PCs) curve for all the aforementioned methods. The F1-score vs. sparsity curves were constructed by trying out the various methods on a range of sparsity controlling parameters for a randomly chosen subset of training and test data. The KPCA horizontal line in the F1-score vs. sparsity curves is provided just for reference and it has all non-zero coefficients. The third one contains ROC curves for all the aforementioned methods. The number of PCs used for MNIST, Fashion MNIST, ETH-80, Satimage2 and Internet Ads were 15, 15, 15, 7 and 24 respectively. We took in the RBF kernel to be the average of for all pairs such that . \justifyMNIST: Similar to the experiment performed in [2], we chose 0 as the inlier class and all digits from 1-9 as the outlier class. We used a training set of 3000 inliers and a test set consisting of 3000 inliers and 3000 outliers. The variability plot is for L1-ratio=0.7. The mean and standard deviation of sparsity for the 10 trials were 3.35% and 0.13% respectively. The ROC curve of our algorithm is also for L1-ratio=0.7, while the ROC curve of the algorithm in [3] is for . The area under ROC curve (AUROC) values for our SKPCA algorithm, standard KPCA, the algorithm in [3] and naive thresholding were 0.974, 0.986, 0.962 and 0.957 respectively.
Fashion MNIST: This is a recent dataset which is very similar to MNIST but much more challenging. Here, we took item 0 (t-shirts and some other tops) as the inlier class and item 1 (pants) as the outlier class. Training and test dataset size was the same as in MNIST. The variability plot is for L1-ratio=0.3. The mean and standard deviation of sparsity for the 10 trials were 8.43% and 0.24% respectively. The ROC curve of our algorithm is also for L1-ratio=0.3, while the ROC curve of the algorithm in [3] is for . The AUROC values for our SKPCA algorithm, standard KPCA, the algorithm in [3] and naive thresholding were 0.919, 0.898, 0.872 and 0.877 respectively.
Satimage2: The data was already presented as inliers and outliers. Training set size was 400 inliers and test set consisted of 500 inliers and 71 outliers (only that many were available). The variability plot is for L1-ratio=0.6. The mean and standard deviation of sparsity for the 10 trials were 5.55% and 0.33% respectively. The ROC curve of our algorithm is also for L1-ratio=0.6, while the ROC curve of the algorithm in [3] is for . The AUROC values for our SKPCA algorithm, standard KPCA, the algorithm in [3] and naive thresholding were 0.963, 0.958, 0.942 and 0.935 respectively.
ETH-80: We used the apples in this data set as inliers and tomatoes as outliers (they have nearly the same color and shape making it more challenging). Training set size was 300 inliers and test set consisted of 111 inliers and 111 outliers. The variability plot and is for L1-ratio=0.3. The mean and standard deviation of sparsity for the 10 trials were 11.07% and 0.70% respectively. The ROC curve of our algorithm is also for L1-ratio=0.3, while the ROC curve of the algorithm in [3] is for . The AUROC values for our SKPCA algorithm, standard KPCA, the algorithm in [3] and naive thresholding were 0.859, 0.853, 0.841 and 0.836 respectively.
Internet Ads:
The data was already presented as inliers and outliers. Training set size was 600 inliers and test set consisted of 380 inliers and 380 outliers. The variability plot and is for L1-ratio=0.4. The mean and standard deviation of sparsity for the 10 trials were 2.60% and 0.29% respectively. The ROC curve of our algorithm is also for L1-ratio=0.4, while the ROC curve of the algorithm in [3] is for .
The AUROC values for our SKPCA algorithm, standard KPCA, the algorithm in [3] and naive thresholding were 0.783, 0.785, 0.744 and 0.739 respectively.
It can be seen from the variability plots that the variance of F1-score is lower for SKPCA as compared to naive thresholding for all 5 datasets, which was also mentioned in [1] for sparse PCA. The F1-score vs. sparsity plots show that the F1-score of our SKPCA method is the closest to ordinary KPCA for all 5 datasets (and even better than it for 3 datasets), in comparison to the other 2 methods, over the entire sparsity range in consideration. Also, the AUROC value of our method is more than that of the other 2 methods for all 5 datasets and even more than that of ordinary KPCA for 3 datasets-Fashion MNIST, Satimage2 and ETH-80.
We have not added the variability of the method in [3] because we found out in our experiments that the parameters involved in their algorithm are very sensitive to the chosen data subset (resulting in large differences in F1-score and sparsity for different data subsets). This is not the case with our algorithm, i.e. our algorithm does not require much tuning of parameters over randomly chosen data subsets (for the same problem) as compared to [3], for near optimal performance. Table I lists the F1-score and sparsity (i.e. the % of non-zero coefficients per PC) obtained using our SKPCA algorithm and the method in [3] for the MNIST case over 10 randomly chosen training and test data subsets with fixed parameters for both algorithms - L1-ratio=0.7 for our algorithm and for the algorithm in [3].
VI CONCLUSION
In this paper, we presented a novel algorithm for sparse KPCA which outperforms the method in [3] and is comparable to KPCA in terms of accuracy, while providing high sparsity. We also mathematically showed the validity of sparsifying KPCA with the RBF kernel, which is the first attempt in this direction, to the best of our knowledge. We showed its successful application for outlier detection on 5 real world data sets. The next step would be to explore the performance of this sparse KPCA algorithm on other applications where KPCA is employed.
References
- [1] Zou, Hui, Trevor Hastie, and Robert Tibshirani. ”Sparse principal component analysis.” Journal of computational and graphical statistics 15.2 (2006): 265-286.
- [2] Hoffmann, Heiko. ”Kernel PCA for novelty detection.” Pattern Recognition 40.3 (2007): 863-874.
- [3] Wang, Duo, and Toshihisa Tanaka. ”Sparse kernel principal component analysis based on elastic net regularization.” Neural Networks (IJCNN), 2016 International Joint Conference on. IEEE, 2016.
- [4] Zou, Hui, and Trevor Hastie. ”Regularization and variable selection via the elastic net.” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 67.2 (2005): 301-320.
- [5] Schölkopf, Bernhard, et al. ”Support vector method for novelty detection.” Advances in neural information processing systems. 2000.
- [6] Tax, David MJ, and Robert PW Duin. ”Support vector domain description.” Pattern recognition letters 20.11 (1999): 1191-1199.
- [7] Schölkopf, Bernhard, Alexander Smola, and Klaus-Robert Müller. ”Kernel principal component analysis.” International Conference on Artificial Neural Networks. Springer, Berlin, Heidelberg, 1997.
- [8] Alexander Smola, O. Mangasarian and Schölkopf, Bernhardand Klaus-Robert Müller. ”Sparse kernel feature analysis,” Tech. Rep.,1999
- [9] M. E. Tipping, ”Sparse kernel principal component analysis,” in Advances in Neural Information Processing Systems 13. MIT Press,2001, pp. 633–539.
- [10] M. E. Tipping and C. M. Bishop, ”Probabilistic principal component analysis,” Journal of the Royal Statistical Society, Series B, vol. 61,pp. 611-522,1999.
- [11] Achlioptas, Dimitris, Frank McSherry, and Bernhard Schölkopf. ”Sampling techniques for kernel methods.” Advances in neural information processing systems. 2002.
- [12] Xiao, Han, Kashif Rasul, and Roland Vollgraf. ”Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms.” arXiv preprint arXiv:1708.07747 (2017).
- [13] http://odds.cs.stonybrook.edu/satimage-2-dataset/
- [14] Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.