【目的】针对K最近邻(K-Nearest Neighbor,KNN)算法中k值的选取通常是人为设定,而且通常是固定的缺点,研究如何更好地选取k值。【方法】引入k的可信度的概念,提出一种基于局部密度和纯度的自适应选取k值的方法,并将其引入到传统的KNN分类算法中。【结果】该算法合理的考虑了样本的局部密度、纯度与选取k值的关系,不仅解决了k值的选取问题,并且避免了固定k值对分类的影响。【结论】该算法是有效的,可以得到较高的准确率,但算法的时效性有待提高。
【Objective】Aiming at the selection of parameter kvalue(usually fixed)in KNN algorithm is usually set by users,we should study how to better select kvalues.【Methods】This paper introduces the concept of the credibility of k,and proposes an improved adaptive selection of kvalues based on the local density and purity,and introduces into the traditional KNN classification algorithm.【Results】The algorithm is reasonable to consider the relationship between the local density and purity and the selection of k values,which not only solves the problems of choosing kvalues,but also avoids the influence of fixed kvalue on classification.【Conclusion】The algorithm is effective and can get higher accuracy,and the timeliness is also enhanced.