Next Article in Journal
Methodology for Analysis and Quantitative Evaluation of Teaching Quality in University Subjects
Next Article in Special Issue
RHOASo: An Early Stop Hyper-Parameter Optimization Algorithm
Previous Article in Journal
A Robust Version of the Empirical Likelihood Estimator
Previous Article in Special Issue
Deep Neural Network for Gender-Based Violence Detection on Twitter Messages
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

k-Nearest Neighbor Learning with Graph Neural Networks

Department of Industrial Engineering, Sungkyunkwan University, 2066 Seobu-ro, Jangan-gu, Suwon 16419, Korea
Mathematics 2021, 9(8), 830; https://doi.org/10.3390/math9080830
Submission received: 24 March 2021 / Revised: 7 April 2021 / Accepted: 9 April 2021 / Published: 10 April 2021

Abstract

:
k-nearest neighbor (kNN) is a widely used learning algorithm for supervised learning tasks. In practice, the main challenge when using kNN is its high sensitivity to its hyperparameter setting, including the number of nearest neighbors k, the distance function, and the weighting function. To improve the robustness to hyperparameters, this study presents a novel kNN learning method based on a graph neural network, named kNNGNN. Given training data, the method learns a task-specific kNN rule in an end-to-end fashion by means of a graph neural network that takes the kNN graph of an instance to predict the label of the instance. The distance and weighting functions are implicitly embedded within the graph neural network. For a query instance, the prediction is obtained by performing a kNN search from the training data to create a kNN graph and passing it through the graph neural network. The effectiveness of the proposed method is demonstrated using various benchmark datasets for classification and regression tasks.

1. Introduction

The k-nearest neighbor (kNN) algorithm is one of the most widely used learning algorithms in machine learning research [1,2]. The main concept of kNN is to predict the label of a query instance based on the labels of k closest instances in the stored data, assuming that the label of an instance is similar to that of its kNN instances. kNN is simple and easy to implement, but is very effective in terms of prediction performance. kNN makes no specific assumptions about the distribution of the data. Because it is an instance-based learning algorithm that requires no training before making predictions, incremental learning can be easily adopted. For these reasons, kNN has been actively applied to a variety of supervised learning tasks including both classification and regression tasks.
The procedure for kNN learning is as follows. Suppose a training dataset D = { ( x t , y t ) } t = 1 N is given for a supervised learning task, where x t and y t are the input vector and the corresponding label vector of the t-th instance. y t is assumed to be a one-hot vector in the case of a classification task and a scalar value in the case of a regression task. In the training phase, the dataset D is just stored without any explicit learning from the dataset. In the inference phase, for each query instance x , kNN search is performed to retrieve kNN instances N ( x t ) = { ( x t ( i ) , y t ( i ) ) } i = 1 k that are closest to x based on a distance function d. Then, the predicted label y ^ is obtained as a weighted combination of the labels y ( 1 ) , , y ( k ) based on a weighting function w along with the distance function d as follows:
y ^ = f ( x ; D ) = i = 1 k w ( d ( x , x ( i ) ) ) · y ( i ) i = 1 k w ( d ( x , x ( i ) ) )
The difficulty in using kNN is determining the hyperparameters. The three main hyperparameters are the number of neighbors k, the distance function d, and the weighting function w [3]. Firstly, in terms of k, a small k makes it capture a specific local structure in the data, and thus, the outcome can be sensitive to noise, whereas a large k makes it more concentrate on the global structure of the data and suppresses the effect of noise. Secondly, the distance function d determines how to calculate the distance between the input vectors of a pair of instances with nearby instances having high relevance. Popular examples of this function for kNN are the Manhattan, Euclidean, and Mahalanobis distances. Thirdly, the weighting function w determines how much each kNN instance contributes to the prediction. The standard kNN assigns the same weight to each kNN instance (i.e., w ( d ) = 1 / k ). It is known to be better to assign larger/smaller weights to closer/farther kNN instances based on their distances to the query instance x using a non-uniform weighting function (e.g., w ( d ) = 1 / d ). Thus, a kNN instance with a larger weight will contribute more to the prediction for the instance.
The performance of kNN is known to be highly sensitive to hyperparameters, the best setting of which depends on the characteristics of the data [3,4]. Thus, the hyperparameters must be chosen appropriately to improve the prediction performance. Since this is a challenging issue, considerable research efforts have been devoted to hyperparameter optimization for kNN, which are introduced briefly in Section 2. Compared to related work, the main aim of this study is end-to-end kNN learning toward improved robustness to the hyperparameter setting and to make predictions for new data without additional optimization procedures.
This study presents a novel end-to-end kNN learning method, named kNN graph neural network (kNNGNN), which learns a task-specific kNN rule from the training dataset in an end-to-end fashion based on a graph neural network. For each instance in the training dataset and its kNN instances, a kNN graph is constructed with nodes representing the label information of the instances and edges representing the distance information between the instances. Then, a graph neural network is built to consider the kNN graph of an instance to predict the label for the instance. The graph neural network can be regarded as a data-driven implementation of implicit weight and distance functions. By doing so, the prediction performance of kNN can be improved without careful consideration of its hyperparameter setting. The proposed method is applicable to any type of supervised learning task, including classification and regression. Furthermore, the proposed method does not require any additional optimization procedure when making predictions for new data, which is advantageous in terms of computational efficiency. To investigate the effectiveness of the proposed method, experiments are conducted using various benchmark datasets for classification and regression tasks.

2. Related Work

This section discusses related work on hyperparameter optimization for the kNN algorithm, which has been actively studied by many researchers. As previously mentioned, kNN learning involves three main hyperparameters: the number of neighbors k, the distance function d, and the weighting function w. A different dataset requires a different hyperparameter setting, and no specific setting can universally be the best for every application, as indicted by the no-free-lunch theorem [5]. Thus, the proper choice of these hyperparameters is critical for obtaining a high prediction performance. In practice, the best hyperparameter setting for a given dataset is usually determined by performing a cross-validation procedure that searches over possible hyperparameter candidates. Various search strategies are applicable, such as grid search, random search [6], and Bayesian optimization [7]. They are time consuming and costly, especially for large-scale datasets. Previous research efforts have focused on choosing the hyperparameters of kNN in more intelligent ways based on heuristics or extra optimization procedures for each query instance.
There are two main research approaches regarding the number of neighbors k. The first approach is to assign different k values to different query instances based on their local neighborhood information instead of a fixed k value [8,9,10,11,12]. The second approach is to employ non-uniform weighting functions to reduce the effect of k on the prediction performance.
For the distance function d, one research approach is to learn task-specific distance functions directly from data to improve the prediction performance, which is referred to as distance metric learning [13,14]. Many methods for this approach were developed for use in the classification settings [15,16,17,18,19], while some were developed for use in the regression settings [20,21,22]. Another approach is to adjust the distance function in an adaptive manner for each query instance [23,24,25,26,27]. This requires an extra optimization procedure, as well as a kNN search when making a prediction for each query instance.
For the weighting function w, existing methods have focused on designing non-uniform weighting functions that decay smoothly as the distance increases [4]. One main research approach is to assign adaptive weights to the kNN instances of each query instance by performing an extra optimization procedure [23,25,26,27,28], which also helps to reduce the effect of k. Another approach is to develop fuzzy versions of the kNN algorithm [29,30,31].
The three hyperparameters affect each other, which means that the optimal choice of one hyperparameter is dependent on the other hyperparameters. Therefore, they must be considered simultaneously rather than independently. Moreover, the methods involving costly extra optimization procedures when making predictions for query instances are computationally expensive, which is undesirable in practice. In addition, the majority of existing methods focus on specific settings, primarily classification tasks. Developing a universal method that is efficient and applicable to various tasks is beneficial. To address these concerns, this study proposes to jointly learn a distance function and a weighting function using a graph neural network in an end-to-end manner, which aims to make it robust to the choice of k in the prediction performance and is applicable to both classification and regression tasks.

3. Method

3.1. Graph Representation of Data

Suppose that a training set D = { ( x t , y t ) } t = 1 N is given, where x t R p is the t-th input vector for the input variables and y t is the corresponding label vector for the output variable. For a classification task with regard to c classes, y t is a c-dimensional one-hot vector where the element corresponding to the target class is set to 1 and all the remaining elements are set to 0. For a regression task with a single output, y t is a scalar representing the target value.
The proposed method uses a transformation function g that transforms each input vector x t into a graph G t such that G t = g ( x t ; D ) . Two hyperparameters need to be determined: the number of nearest neighbors k and the distance function d. They are used only to operate the transformation function g for kNN search from D ; however, they are not used explicitly in the learning procedure in Section 3.2. For each x t , its kNN instances are searched from D \ { ( x t , y t ) } based on the distance function d, denoted by N ( x t ) = { ( x t ( i ) , y t ( i ) ) } i = 1 k . Then, the kNN graph G t = ( V t , E t ) is constructed as a fully connected undirected graph with k + 1 nodes and k ( k + 1 ) / 2 edges as follows:
V t = { v t i | i { 0 , , k } } ; E t = { e t i , j | i { 0 , , k } , j { 0 , , k } , i j } ,
where each node feature vector v t i R c + 1 and edge feature vector e t i , j R p are represented as:
v t i = ( 0 , 1 ) , if i = 0 ( y t ( i ) , 0 ) , otherwise ; e t i , j = | x t ( i ) x t ( j ) | ,
where the t-th input vector x t is denoted by x t ( 0 ) for the simplicity of description. The number c is set to the number of classes in the case of classification and is 1 in the case of regression.
In the graph G t , the 0-th node corresponds to x t , and the other nodes correspond to the kNN instances of x t . Each node feature vector v t i represents the label information with the last element set to zero, except that v t 0 does not contain the label information and has the last element set to one. Each edge feature vector e t i , j consists of the absolute difference between each of the input variables x t ( i ) and x t ( j ) . Thus, G t represents the labels of the kNN instances and pairwise distances between the instances. It should be noted that G t does not contain y t because it needs to be unknown when making a prediction in a supervised learning setting.

3.2. k-Nearest Neighbor Graph Neural Network

Here, the proposed method named kNNGNN is introduced, which implements kNN learning in an end-to-end manner. It adapts the message-passing neural network architecture [32], which can handle general node and edge features with isomorphic invariance, to build a graph neural network for kNN learning. To learn a kNN rule from the training dataset D , it builds a graph neural network that operates on the graph representation G = g ( x ; D ) for an input vector x given the training dataset D to predict the corresponding label vector y as y ^ = f ( G ) = f ( g ( x ; D ) ) .
The model architecture used in this study is as follows. It first embeds each v i into a p-dimensional initial node representation vector using an embedding function ϕ as h ( 0 ) , i = ϕ ( v i ) , i = 0 , , k . A message-passing step for the graph G is then performed using two main functions: message function M and update function U. The node representation vectors h ( l ) , i are updated as below:
m ( l ) , i = j | v j V \ v i M ( e i , j ) h ( l 1 ) , j , i , h ( l ) , i = U ( h ( l 1 ) , i , m ( l ) , i ) , i .
After L time steps of message passing, a set of node representation vectors { h ( l ) , i } l = 0 L per node is obtained. The set for the 0-th node { h ( l ) , 0 } l = 0 L is then processed with the readout function r to obtain the final prediction of the label y as:
y ^ = r ( { h ( l ) , 0 } l = 0 L ) .
The component functions ϕ , M, U, and r are parameterized as neural networks, mostly based on the idea presented in Gilmer et al. [32]. The function ϕ is a two-layer fully connected neural network with p tanh units in each layer. The function M is a two-layer fully connected neural network where the first layer consists of 2 m tanh units and the second layer outputs a m × m matrix. The function U is modeled as a recurrent neural network with gated recurrent units (GRUs) [33], which pass the previous hidden state h ( l 1 ) , i and the current input m ( l ) , i to derive the current hidden state h ( l ) , i at each time step l. The function r is a two-layer fully connected neural network where the first layer consists of p tanh units and the second layer outputs y ^ by softmax and linear units in the case of classification and regression tasks, respectively. Different types of supervised learning tasks can be addressed using different types of units in the last layer of r.
The model defined above is denoted as the function f. The model makes a prediction from the input vector x and its kNN instances in D , i.e., y ^ = f ( g ( x ; D ) ) . The model differs from conventional neural networks in that it does not directly learn the relationship between input and output variables. In terms of kNN learning, the weight and distance functions are embedded implicitly into the function f. Therefore, the function f can be regarded as an implicit representation of a kNN rule, in which the functions M and U work as implicit distance and weighting functions, respectively.

3.3. Learning from Training Data

Given the training dataset D = { ( x t , y t ) } t = 1 N , the proposed method learns a task-specific kNN rule from D in the form of y ^ = f ( g ( x ; D ) ) . The prediction model f is trained based on the graph representation g using the following objective function J :
J = 1 N ( x t , y t ) D L ( y t , y ^ t ) = 1 N ( x t , y t ) D L ( y t , f ( g ( x t ; D ) ) ) ,
where L is the loss function, the choice of which depends on the target task. The typical choices of the loss function are cross-entropy and squared error for the classification and regression tasks, respectively.

3.4. Prediction for New Data

Once the prediction model f is trained, it can be used to predict unknown labels for new data. The prediction procedure is illustrated in Figure 1. Given a query instance x * whose label y * is unknown, its kNN instances N ( x * ) = { ( x * ( i ) , y * ( i ) ) } i = 1 k are searched from the training dataset D based on the distance function d. Then, the corresponding graph G * = g ( x * ; D ) is generated. The prediction of y * , which is denoted by y ^ * , is computed using the model f as:
y ^ * = f ( G * ) = f ( g ( x * ; D ) ) .
The proposed method does not require additional optimization procedures when making predictions. The prediction for a query instance is simply conducted by performing a kNN search to identify the kNN instances and then processing these instances with the model. This is advantageous in terms of computational efficiency.
As the proposed method learns the kNN rule, incremental learning can be implemented efficiently. This is the main advantage of the kNN algorithm compared to other learning algorithms, especially when additional training data are collected over time after the model is trained. When new labeled data are added to the training dataset D , the prediction performance will be improved without updating the model.

4. Experimental Investigation

4.1. Datasets

The effectiveness of the proposed method was investigated through experiments on various benchmark datasets. They contained 20 classification datasets, and twenty regression datasets were collected from the UCI machine learning repository (http://archive.ics.uci.edu/ml/ (accessed on 10 January 2021) and the StatLib datasets archive (http://lib.stat.cmu.edu/datasets/(accessed on 10 January 2021)). The datasets used for classification tasks were annealing, balance, breastcancer, carevaluation, ecoli, glass, heart, ionosphere, iris, landcover, movement, parkinsons, seed, segment, sonar, vehicle, vowel, wine, yeast, and zoo. The datasets used for regression tasks were abalone, airfoil, appliances, autompg, bikesharing, bodyfat, cadata, concretecs, cpusmall, efficiency, housing, mg, motorcycle, newspopularity, skillcraft, spacega, superconductivity, telemonitoring, wine-red, and wine-white. Each dataset had a different number of instances with a different dimensionality. For each dataset, one-thousand instances were randomly sampled if the size of the dataset was greater than 1000. All numeric variables were normalized into the range of [ 1 , 1 ] . The details of the datasets used are listed in Table 1 and Table 2.

4.2. Compared Methods

Three kNN methods that use different weighting schemes w were compared in the experiments: uniform kNN, weighted kNN, and the proposed kNNGNN. The uniform kNN and weighted kNN respectively used the following weighting functions:
w U ( d ( x , x ) ) = 1 / k ; w W ( d ( x , x ) ) = 1 / d ( x , x ) .
For kNNGNN, the weighting function is embedded implicitly.
For each method, the hyperparameter settings were varied to examine their effects. The candidates for the distance function d were as follows:
Manhattan d L 1 ( x , x ) = | | x x | | 1 ; Euclidean d L 2 ( x , x ) = | | x x | | 2 = ( x x ) T ( x x ) ; Mahalanobis d M ( x , x ) = ( x x ) T S 1 ( x x ) ,
where S is the covariance matrix of the input variables calculated from the training dataset.
Accordingly, there were a total of nine combinations of distance and weighting functions compared in the experiments, as summarized in Table 3. None of the methods used any additional optimization procedures when making predictions. For kNNGNN, the distance function was only explicitly used for the kNN search to generate graph representations of the data. For each combination, the effect of k was investigated on the prediction performance by varying its value from 1, 3, 5, 7, 10, 15, 20, and 30.

4.3. Experimental Settings

In the experiments, the performance of each method was evaluated using a two-fold cross-validation procedure. In this procedure, the original dataset was divided into five disjoint subsets. Then, two iterations were conducted, each of which used one subset and the other subset as the training and test sets, respectively. As performance measures, the misclassification error rate and root mean squared error (RMSE) were used for the classification and regression tasks, respectively. Given a test set denoted by D = { ( x t , y t ) } t = 1 N , the performance measures are calculated as:
ErrorRate = 1 N ( x t , y t ) D I ( argmax ( y t ) argmax ( y ^ t ) ) ; RMSE = 1 N ( x t , y t ) D ( y t y ^ t ) 2 .
For the proposed method, each prediction model was built based on the following configurations. In the objective function J , the loss function L used for the classification and regression tasks was set to cross-entropy and squared error, respectively. For the model, the hyperparameter L was set to 3, as Gilmer et al. [32] demonstrated any L 3 would work. The hyperparameter p was explored on { 10 , 20 , 50 } by holdout validation. In the training phase, dropout was applied to the function r with a dropout rate of 0.1 for regularization [34]. During the training, eighty percent and 20% of the training set were used to train and validate the model, respectively. The model parameters were updated using the Adam optimizer with a batch size of 20. The learning rate was set to 10 3 at the first training epoch and was reduced by a factor of 0.1 if no improvement in the validation loss was observed for 10 consecutive epochs. The training was terminated when the learning rate was decreased to 10 7 or the number of epochs reached 500. In the inference phase, for each query instance, thirty different outputs were obtained by performing stochastic forward passes through the trained model with the dropout turned on [35]. The average of these outputs was then used to obtain the predicted label for the instance.
All baseline methods were implemented using the scikit-learn package in Python. The proposed method was implemented based on GPU-accelerated TensorFlow in Python. All experiments were performed 10 times independently with different random seeds. For the results, the average performance over the repetitions was compared. Then, for each of the three weighting functions w, the summary statistics of the performance over different settings of distance functions d and the number of neighbors k are reported.

4.4. Results and Discussion

Figure 2 shows the error rate comparison results of the baseline and proposed methods with varying the hyperparameter settings on 20 classification datasets. Compared to the baseline methods, kNNGNN overall yielded lower error rates at various values of k for most datasets. For the results with different hyperparameters, the average, standard deviation, and best error rate for each dataset are summarized in Table 1. kNNGNN yielded the lowest average and standard deviation of the error rate over different hyperparameters on most datasets, which indicated that the performance of kNNGNN was less sensitive to its hyperparameter settings. In particular, kNNGNN was superior to the baseline method when the hyperparameter k was larger.
Figure 3 compares the baseline and proposed methods in terms of the RMSE with varying hyperparameter settings on 20 regression datasets. As shown in this figure, the performance curves of kNNGNN flattened as k increased on most datasets, whereas the RMSE of the baseline methods tended to increase at large k for some datasets. Table 2 shows the average, standard deviation, and best RMSE for different hyperparameter settings for each dataset. The behavior of kNNGNN was similar to that of the classification tasks. kNNGNN showed stable performance against changes in the hyperparameter settings. kNNGNN yielded the lowest average and standard deviation of the RMSE for the majority of datasets.
In summary, the experimental results successfully demonstrated the effectiveness of kNNGNN in improving the prediction performance for both classification and regression tasks. Although kNNGNN failed to yield the lowest error for some datasets, kNNGNN yielded high robustness to its hyperparameters. This indicated that kNNGNN would provide comparable performance without carefully tuning its hyperparameters; thus, it can be preferred in practice considering the difficulty of choosing the optimal hyperparameter setting. Because the performance curve of kNNGNN flattened at large k values on most datasets, setting a moderate k value around 15∼20 would be reasonable considering the trade-off between the performance and computational cost.

5. Conclusions

This study presented kNNGNN, which learns a task-specific kNN rule from data in an end-to-end fashion. The proposed method constructed the kNN rule in the form of a graph neural network, in which the distance and weighting functions were embedded implicitly. The graph neural network considered the kNN graph of an instance as the input to predict the label of the instance. Owing to the flexibility of neural networks, the method can be applied to any form of supervised learning tasks including classification and regression. It does not require any extra optimization procedure when making predictions for new data, which is beneficial in terms of computational efficiency. Moreover, as the method learns the kNN rule instead of the explicit relationship between the input and output variables, incremental learning can be implemented efficiently.
The effectiveness of the proposed method was demonstrated through experiments on benchmark classification and regression datasets. The results showed that the proposed method can yield comparable prediction performance with less sensitivity to the choice of its hyperparameters. The proposed method allows more robust kNN learning without carefully tuning the hyperparameters. The use of a graph neural network for kNN learning may still have room for improvement and thus merits further investigation. One practical concern is the high complexity of a graph neural network in terms of time and space, which increases with k. A graph neural network cannot be trained in a reasonable amount of time without using a GPU. Alleviation of complexity to improve learning efficiency will be an avenue for future work.

Funding

This work was supported by the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT; Ministry of Science and ICT) (Nos. NRF-2019R1A4A1024732 and NRF-2020R1C1C1003232).

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Wu, X.; Kumar, V.; Quinlan, J.R.; Ghosh, J.; Yang, Q.; Motoda, H.; McLachlan, G.J.; Ng, A.; Liu, B.; Philip, S.Y.; et al. Top 10 algorithms in data mining. Knowl. Inf. Syst. 2008, 14, 1–37. [Google Scholar] [CrossRef] [Green Version]
  2. Cover, T.; Hart, P. Nearest neighbor pattern classification. IEEE Trans. Inf. Theory 1967, 13, 21–27. [Google Scholar] [CrossRef]
  3. Jiang, L.; Cai, Z.; Wang, D.; Jiang, S. Survey of improving k-nearest-neighbor for classification. In Proceedings of the International Conference on Fuzzy Systems and Knowledge Discovery, Haikou, China, 24–27 August 2007; pp. 679–683. [Google Scholar]
  4. Atkeson, C.G.; Moore, A.W.; Schaal, S. Locally Weighted Learning. Artif. Intell. Rev. 1997, 11, 11–73. [Google Scholar] [CrossRef]
  5. Wolpert, D.H. The lack of a priori distinctions between learning algorithms. Neural Comput. 1996, 8, 1341–1390. [Google Scholar] [CrossRef]
  6. Bergstra, J.; Bengio, Y. Random search for hyper-parameter optimization. J. Mach. Learn. Res. 2012, 13, 281–305. [Google Scholar]
  7. Snoek, J.; Larochelle, H.; Adams, R.P. Practical Bayesian optimization of machine learning algorithms. In Proceedings of the Advances in Neural Information Processing Systems, Lake Tahoe, NV, USA, 3–6 December 2012; pp. 2951–2959. [Google Scholar]
  8. Zhang, S.; Li, X.; Zong, M.; Zhu, X.; Wang, R. Efficient kNN classification with different numbers of nearest neighbors. IEEE Trans. Neural Netw. Learn. Syst. 2017, 29, 1774–1785. [Google Scholar] [CrossRef] [PubMed]
  9. Zhang, S.; Cheng, D.; Deng, Z.; Zong, M.; Deng, X. A novel kNN algorithm with data-driven k parameter computation. Pattern Recognit. Lett. 2018, 109, 44–54. [Google Scholar] [CrossRef]
  10. Wang, J.; Neskovic, P.; Cooper, L.N. Neighborhood size selection in the k-nearest-neighbor rule using statistical confidence. Pattern Recognit. 2006, 39, 417–423. [Google Scholar] [CrossRef]
  11. García-Pedrajas, N.; del Castillo, J.A.R.; Cerruela-García, G. A proposal for local k values for k-nearest neighbor rule. IEEE Trans. Neural Netw. Learn. Syst. 2015, 28, 470–475. [Google Scholar] [CrossRef]
  12. Zhang, S.; Li, X.; Zong, M.; Zhu, X.; Cheng, D. Learning k for kNN classification. ACM Trans. Intell. Syst. Technol. 2017, 8, 43. [Google Scholar] [CrossRef] [Green Version]
  13. Li, D.; Tian, Y. Survey and experimental study on metric learning methods. Neural Netw. 2018, 105, 447–462. [Google Scholar] [CrossRef]
  14. Kulis, B. Metric Learning: A Survey. Found. Trends Mach. Learn. 2013, 5, 287–364. [Google Scholar] [CrossRef]
  15. Weinberger, K.Q.; Saul, L.K. Distance metric learning for large margin nearest neighbor classification. J. Mach. Learn. Res. 2009, 10, 207–244. [Google Scholar]
  16. Goldberger, J.; Roweis, S.; Hinton, G.; Salakhutdinov, R. Neighbourhood components analysis. In Advances in Neural Information Processing Systems; MIT Press: Cambridge, MA, USA, 2004; pp. 513–520. [Google Scholar]
  17. Sugiyama, M. Dimensionality reduction of multimodal labeled data by local fisher discriminant analysis. J. Mach. Learn. Res. 2007, 8, 1027–1061. [Google Scholar]
  18. Davis, J.V.; Kulis, B.; Jain, P.; Sra, S.; Dhillon, I.S. Information-theoretic metric learning. In Proceedings of the International Conference on Machine Learning, Cincinnati, OH, USA, 13–15 December 2007; pp. 209–216. [Google Scholar]
  19. Wang, W.; Hu, B.G.; Wang, Z.F. Globality and locality incorporation in distance metric learning. Neurocomputing 2014, 129, 185–198. [Google Scholar] [CrossRef]
  20. Assi, K.C.; Labelle, H.; Cheriet, F. Modified large margin nearest neighbor metric learning for regression. IEEE Signal Process. Lett. 2014, 21, 292–296. [Google Scholar] [CrossRef] [Green Version]
  21. Weinberger, K.Q.; Tesauro, G. Metric Learning for Kernel Regression. In Proceedings of the International Conference on Artificial Intelligence and Statistics, San Juan, Puerto Rico, 21–24 March 2007; pp. 612–619. [Google Scholar]
  22. Nguyen, B.; Morell, C.; De Baets, B. Large-scale distance metric learning for k-nearest neighbors regression. Neurocomputing 2016, 214, 805–814. [Google Scholar] [CrossRef]
  23. Wang, J.; Neskovic, P.; Cooper, L.N. Improving nearest neighbor rule with a simple adaptive distance measure. Pattern Recognit. Lett. 2007, 28, 207–213. [Google Scholar] [CrossRef]
  24. Zhou, C.Y.; Chen, Y.Q. Improving nearest neighbor classification with cam weighted distance. Pattern Recognit. 2006, 39, 635–645. [Google Scholar] [CrossRef]
  25. Jahromi, M.Z.; Parvinnia, E.; John, R. A method of learning weighted similarity function to improve the performance of nearest neighbor. Inf. Sci. 2009, 179, 2964–2973. [Google Scholar] [CrossRef]
  26. Paredes, R.; Vidal, E. Learning weighted metrics to minimize nearest-neighbor classification error. IEEE Trans. Pattern Anal. Mach. Intell. 2006, 28, 1100–1110. [Google Scholar] [CrossRef] [PubMed]
  27. Domeniconi, C.; Peng, J.; Gunopulos, D. Locally adaptive metric nearest-neighbor classification. IEEE Trans. Pattern Anal. Mach. Intell. 2002, 24, 1281–1285. [Google Scholar] [CrossRef] [Green Version]
  28. Kang, P.; Cho, S. Locally linear reconstruction for instance-based learning. Pattern Recognit. 2008, 41, 3507–3518. [Google Scholar] [CrossRef]
  29. Keller, J.M.; Gray, M.R.; Givens, J.A. A fuzzy k-nearest neighbor algorithm. IEEE Trans. Syst. Man, Cybern. 1985, SMC-15, 580–585. [Google Scholar] [CrossRef]
  30. Biswas, N.; Chakraborty, S.; Mullick, S.S.; Das, S. A parameter independent fuzzy weighted k-nearest neighbor classifier. Pattern Recognit. Lett. 2018, 101, 80–87. [Google Scholar] [CrossRef]
  31. Maillo, J.; García, S.; Luengo, J.; Herrera, F.; Triguero, I. Fast and scalable approaches to accelerate the fuzzy k-Nearest neighbors classifier for big data. IEEE Trans. Fuzzy Syst. 2019, 28, 874–886. [Google Scholar] [CrossRef]
  32. Gilmer, J.; Schoenholz, S.S.; Riley, P.F.; Vinyals, O.; Dahl, G.E. Neural message passing for quantum chemistry. In Proceedings of the International Conference on Machine Learning, Sydney, Australia, 11–15 August 2017; pp. 1263–1272. [Google Scholar]
  33. Cho, K.; Van Merriënboer, B.; Gulcehre, C.; Bahdanau, D.; Bougares, F.; Schwenk, H.; Bengio, Y. Learning phrase representations using RNN encoder-decoder for statistical machine translation. In Proceedings of the Conference on Empirical Methods in Natural Language Processing, Doha, Qatar, 25–29 October 2014; pp. 1724–1734. [Google Scholar]
  34. Srivastava, N.; Hinton, G.; Krizhevsky, A.; Sutskever, I.; Salakhutdinov, R. Dropout: A simple way to prevent neural networks from overfitting. J. Mach. Learn. Res. 2014, 15, 1929–1958. [Google Scholar]
  35. Gal, Y.; Ghahramani, Z. Dropout as a Bayesian approximation: Representing model uncertainty in deep learning. In Proceedings of the International Conference on Machine Learning, New York, NY, USA, 19–24 June 2016; pp. 1050–1059. [Google Scholar]
Figure 1. Schematic of the kNN graph neural network (kNNGNN) prediction procedure.
Figure 1. Schematic of the kNN graph neural network (kNNGNN) prediction procedure.
Mathematics 09 00830 g001
Figure 2. Error rate comparison with varying hyperparameter settings on classification datasets.
Figure 2. Error rate comparison with varying hyperparameter settings on classification datasets.
Mathematics 09 00830 g002
Figure 3. RMSE comparison with varying hyperparameters on regression datasets.
Figure 3. RMSE comparison with varying hyperparameters on regression datasets.
Mathematics 09 00830 g003
Table 1. Summary statistics of the error rate over different hyperparameter settings on the classification datasets.
Table 1. Summary statistics of the error rate over different hyperparameter settings on the classification datasets.
Dataset [Size × Dim.]No. of ClassesUniform kNNWeighted kNNkNNGNN (Proposed)
AverageStd. Dev.BestAverageStd. Dev.BestAverageStd. Dev.Best
annealing [898 × 38]50.07240.03560.01750.03640.01460.01740.02540.00460.0189
balance [625 × 4]30.14530.03560.11300.14360.03770.10980.13270.02350.1046
breastcancer [683 × 9]20.03820.00510.03060.03810.00510.03050.03690.00510.0290
carevaluation [1000 × 6]40.20350.03060.16190.18580.03260.14610.11100.03540.0717
ecoli [336 × 7]80.18530.03500.14270.17030.02560.14220.18490.02380.1555
glass [214 × 9]60.38080.04250.31960.34410.02290.30740.37030.02590.3244
heart [298 × 13]20.20810.03110.17920.20930.03490.16840.21260.03660.1804
ionosphere [351 × 34]20.18080.04480.11200.17900.04280.11200.08380.01220.0681
iris [150 × 4]30.08860.05220.04070.07660.04170.04270.05730.01570.0413
landcover [675 × 147]90.35500.20500.19500.34500.20230.18470.21870.05130.1767
movement [360 × 90]150.48080.14360.21250.36790.11250.21250.33000.03750.2569
parkinsons [195 × 22]20.16340.04580.07750.13730.03680.07750.15360.02530.0918
seed [210 × 7]30.08090.01140.05900.07790.00900.06100.08400.00780.0619
segment [1000 × 19]70.10210.02810.05940.08400.01840.05860.07490.00790.0586
sonar [208 × 60]20.29290.06210.17060.26840.05560.17060.23870.03490.1837
vehicle [846 × 18]40.29510.04690.22760.28800.04320.22390.27750.03910.2191
vowel [990 × 10]110.28680.13670.05160.14500.05530.05160.15040.04040.0561
wine [178 × 13]30.10350.10100.03160.08610.07590.03040.05220.03290.0270
yeast [1000 × 8]100.44950.02180.43050.43690.02920.41160.45140.02840.4222
zoo [101 × 16]70.22690.16560.05050.11450.07760.04840.10120.04620.0709
The lowest values for each dataset are presented in bold.
Table 2. Summary statistics of the RMSE over different hyperparameter settings on the regression datasets.
Table 2. Summary statistics of the RMSE over different hyperparameter settings on the regression datasets.
Dataset [Size × Dim.]Uniform kNNWeighted kNNkNNGNN (Proposed)
AverageStd. Dev.BestAverageStd. Dev.BestAverageStd. Dev.Best
abalone [1000 × 8]0.20180.01830.18120.20060.01850.18040.19820.01030.1829
airfoil [1000 × 5]0.25730.01850.22090.22700.01150.20600.18840.01250.1698
appliances [1000 × 25]0.26630.01730.25330.26170.01900.24930.26010.00240.2563
autompg [392 × 7]0.18460.01370.16420.17680.01390.15760.18210.00920.1715
bikesharing [1000 × 14]0.18860.03150.13860.18130.02910.13480.07520.04810.0310
bodyfat [252 × 14]0.18870.03450.14340.18550.03500.14160.12960.04590.0830
cadata [1000 × 8]0.33840.02810.29990.33290.02850.29680.31530.02430.2848
concretecs [1000 × 8]0.25660.01970.22370.23610.01970.20650.20360.02360.1804
cpusmall [1000 × 12]0.13700.05030.08280.12470.04140.08100.08760.01430.0708
efficiency [768 × 8]0.14680.03260.10770.13920.03460.09800.07000.03260.0483
housing [506 × 13]0.25030.01970.21790.23330.01680.20380.21800.01990.1847
mg [1000 × 6]0.29470.02490.27820.28910.02750.26970.29230.01810.2802
motorcycle [133 × 1]0.28450.04730.24150.28620.01700.27300.26940.01950.2491
newspopularity [1000 × 58]0.12420.01170.11560.12440.01170.11580.12180.00140.1200
skillcraft [1000 × 18]0.37410.04350.33650.37340.04370.33540.36030.02410.3317
spacega [1000 × 6]0.15760.01240.14150.15520.01310.13920.15560.00970.1421
superconductivity [1000 × 81]0.29620.04490.25740.27900.03930.24540.26550.01050.2491
telemonitoring [1000 × 16]0.42740.03630.39430.42350.03770.39050.41210.01250.3914
wine-red [1000 × 11]0.28440.02340.26680.27510.02720.25470.28120.00880.2708
wine-white [1000 × 11]0.28950.02320.27560.28320.02590.26710.28540.00770.2758
The lowest values for each dataset are presented in bold.
Table 3. Methods compared in the experiments.
Table 3. Methods compared in the experiments.
kNN Method (Weighting Function w)
Uniform kNNWeighted kNNkNNGNN (Proposed)
distance function dManhattan (L1)kNN_L1WkNN_L1kNNGNN_L1
Euclidean (L2)kNN_L2WkNN_L2kNNGNN_L2
Mahalanobis (M)kNN_MWkNN_MkNNGNN_M
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Kang, S. k-Nearest Neighbor Learning with Graph Neural Networks. Mathematics 2021, 9, 830. https://doi.org/10.3390/math9080830

AMA Style

Kang S. k-Nearest Neighbor Learning with Graph Neural Networks. Mathematics. 2021; 9(8):830. https://doi.org/10.3390/math9080830

Chicago/Turabian Style

Kang, Seokho. 2021. "k-Nearest Neighbor Learning with Graph Neural Networks" Mathematics 9, no. 8: 830. https://doi.org/10.3390/math9080830

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop