跳到主要内容

资源 · 指南或文章

k-Nearest Neighbors Algorithm

讲解 k 近邻分类:由最近的若干点多数投票决定类别,这是机器学习基础面试中的常见主题。

审核日期

打开原站: k-Nearest Neighbors Algorithm (在新标签页中打开原网站)

添加到路线图

把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。

来源内容语言:英语

The k-nearest neighbors algorithm (k-NN) is a supervised Machine Learning algorithm. It's a classification algorithm, determining the class of a sample vector using a sample data. In k-NN classification, the output is a class membership. An object is classified by a plurality vote of its neighbors, with the object being assigned to the class most common among its k nearest neighbors (k is a positive integer, typically small). If k = 1, then the object is simply assigned to the class of that single nearest neighbor. The idea is to calculate the similarity between two data points on the basis of a distance metric. Euclidean distance is used mostly for this task.

PrepKit 概览

本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。

适合人群
来源未说明适用级别
形式
参考资料

涵盖内容

  • 五步流程:计算距离、排序、取前 K 个标签、输出众数。
  • 一张演示图:对同一个点,k = 3 和 k = 5 会给出不同的类别。
  • 建议选用奇数 K(通常为 3 或 5)以避免平票。

使用建议

这是 PrepKit 的学习建议,并非来源的说法。

在手绘的二维网格上,分别用 k = 1、3 和 5 对几个点分类,然后编写代码,并解释答案为什么会变化。

范围与局限

内容简短,示例是来自维基百科和 GeeksForGeeks 的图片;没有复杂度、特征缩放或练习。附有葡萄牙文译本的链接。

获取方式与形式

GitHub 上的英文 README,免费,出自采用 MIT 许可的 trekhleb/javascript-algorithms 仓库。

PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88

本概览的依据
  • src/algorithms/ml/knn/README.md

收录此条目的页面

订阅 PrepKit 通讯

可选。使用 PrepKit 并不需要订阅。

我们如何处理你的邮箱