Multiclass Classification via Class-Weighted Nearest Neighbors

Justin Khim, Ziyu Xu, Shashank SingharXiv 2020 · OpenReview

TL;DR

This paper introduces and analyzes a class-weighted k-nearest neighbors (kNN) algorithm for multiclass classification, particularly addressing challenges posed by imbalanced datasets and a large number of classes. The authors provide theoretical bounds on classification accuracy and error, demonstrating how class weighting can be used to optimize performance metrics beyond simple accuracy, such as F1-score.

What Problem Does This Paper Address?

Traditional kNN classifiers often struggle with imbalanced datasets, where some classes have significantly fewer examples than others. This imbalance can lead to poor performance on minority classes. Furthermore, in real-world scenarios like online retail or image recognition, the number of classes can be very large, exacerbating the imbalance problem. Existing kNN theory primarily focuses on binary classification and balanced datasets, leaving a gap in understanding and addressing these complex multiclass, imbalanced scenarios. This paper aims to fill that gap by developing and analyzing a class-weighted kNN approach that can adapt to these challenging data distributions.

Methods

The core of this paper is the introduction and theoretical analysis of a class-weighted k-nearest neighbors (kNN) classifier. Unlike standard kNN, this variant assigns different weights to different classes when determining the majority vote among the k nearest neighbors. The authors derive upper and minimax lower bounds for various performance metrics, including accuracy, class-weighted risk, and uniform error. A key methodological contribution is showing how uniform error bounds can be used to bound the difference between empirical and population confusion matrix quantities. This allows for the adaptive adjustment of class weights to optimize specific metrics like F1-score, which are more informative than raw accuracy in imbalanced settings. The theoretical analysis involves extending existing results from binary classification to the multiclass case, incorporating concepts like margin conditions and smoothness assumptions for regression functions.

Datasets

The paper uses a synthetic dataset generated from a specific distribution on the unit interval with three classes to illustrate the theoretical concepts and evaluate the algorithms. For real-world experiments, they utilize the Covertype dataset from the UCI repository, which contains cartographic features and seven forest cover classes.

Key Insights and Ideas

  • Class weighting as a principled approach: The paper demonstrates that class weighting in kNN is not just a heuristic but a theoretically grounded method for handling imbalanced multiclass data.
  • Optimizing beyond accuracy: The work highlights that for imbalanced datasets, metrics like F1-score are more relevant, and class weights can be tuned to optimize these specific metrics.
  • Theoretical guarantees for complex scenarios: The paper provides rigorous theoretical bounds (both upper and lower) for class-weighted kNN, extending existing kNN theory to large and imbalanced multiclass problems.
  • Adaptive weight optimization: The framework allows for adapting class weights based on the data distribution to achieve better performance on desired metrics.

Key Results

The paper presents several key theoretical and empirical results:

  • Theoretical Bounds: Derivation of upper and minimax lower bounds for accuracy, class-weighted risk, and uniform error for class-weighted kNN in multiclass settings.
  • Confusion Matrix Convergence: Bounds are established for the difference between empirical and population confusion matrix entries, uniformly over a set of weights.
  • Metric Optimization: The theoretical framework enables adaptive optimization of performance metrics like F1-score by adjusting class weights.
  • Empirical Validation: Numerical experiments on a synthetic dataset and the Covertype dataset demonstrate that the proposed greedy coordinate-wise search algorithm for optimizing weights can achieve competitive or better performance compared to grid search and unweighted kNN, particularly in terms of F1-score. For instance, on the Covertype dataset, the greedy algorithm achieved a higher test F1 score than the unweighted kNN.

Limitations and Future Work

The authors acknowledge several directions for future work:

  • Optimality of Weighting: It remains an open question whether the proposed weighted plug-in approaches are truly optimal for certain metrics, or if other methods might achieve better results.
  • Scalability for Large Class Numbers: For a very large number of classes, grid search for weights becomes computationally infeasible. Developing efficient methods for finding optimal weights in such regimes is a key challenge.
  • Computationally Efficient Classifiers: The ultimate goal is to develop a computationally efficient classifier that achieves minimax optimal statistical risk with respect to a given metric, which is still an open problem for non-trivial settings.
  • Generalization of Bounds: The paper notes that while the uniform error bound is independent of the number of classes, the risk bounds can exhibit dependencies on the number of classes, which might be further investigated.

Summary updated

Abstract

We study statistical properties of the k-nearest neighbors algorithm for multiclass classification, with a focus on settings where the number of classes may be large and/or classes may be highly imbalanced. In particular, we consider a variant of the k-nearest neighbor classifier with non-uniform class-weightings, for which we derive upper and minimax lower bounds on accuracy, class-weighted risk, and uniform error. Additionally, we show that uniform error bounds lead to bounds on the difference between empirical confusion matrix quantities and their population counterparts across a set of weights. As a result, we may adjust the class weights to optimize classification metrics such as F1 score or Matthew's Correlation Coefficient that are commonly used in practice, particularly in settings with imbalanced classes. We additionally provide a simple example to instantiate our bounds and numerical experiments.
BibTeX
@misc{khim2020multiclass,
  author = {Justin Khim and Ziyu Xu and Shashank Singh},
  title = {{Multiclass Classification via Class-Weighted Nearest Neighbors}},
  year = {2020},
  eprint = {2004.04715},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.04715},
}
Figure