The k-Nearest Neighbors (kNN) algorithm has long been widely used in Machine Learning (ML) applications. However, the main concern when using it is the computational cost required for neighborhood search, which can make it unfeasible for large-scale applications. Optimization algorithms, such as the K-d tree, become an option in such scenarios. Under data streams, it can be challenging to maintain the properties of the K-d tree, as it requires inserting and deleting nodes on the fly. These operations can make maintaining the tree's balance and invariants difficult. Additionally, traditional K-d trees were initially designed for Minkowski-based distance functions. In this work, we describe an Online K-d tree and its adaptation to the Canberra distance that supports dynamic updates over data streams while preserving the structural invariants required for efficient traversal. Experimental analysis demonstrates that the Online K-d tree algorithm achieves faster processing time under data streams, and that adapting to the Canberra distance enabled effective subtree pruning, as evidenced by a minor loss in average accuracy and a substantial gain in instances processed per second. Our implementation can be found in our GitHub repository
翻译:k-最近邻(kNN)算法长期以来被广泛应用于机器学习(ML)应用中。然而,使用该算法时的主要问题在于邻域搜索所需的计算成本,这可能导致其不适用于大规模应用。在这种情况下,诸如K-d树之类的优化算法成为一种选择。在数据流环境下,维护K-d树的属性可能具有挑战性,因为它需要实时插入和删除节点。这些操作可能使得维护树的平衡性和不变量变得困难。此外,传统K-d树最初是为基于闵可夫斯基距离的函数设计的。在本工作中,我们描述了一种在线K-d树及其对堪培拉距离的适配,该树支持数据流上的动态更新,同时保留了高效遍历所需的结构不变量。实验分析表明,在线K-d树算法在数据流下实现了更快的处理时间,并且适配堪培拉距离使得有效的子树剪枝成为可能,这一点体现在平均准确率的微小损失和每秒处理实例数量的显著提升上。我们的实现可以在GitHub仓库中找到。