ML02: 机器学习KNN 算法

摘要: 一张图说清楚KNN算法

看下图,清楚了吗?

 
没清楚的话,也没关系,看完下面几句话,就清楚了。

 KNN算法是用来分类的。

这个算法是如何来分类的呢?

看下图,你可以想想下图中的

『绿色圆点』是一只刚生下来的 小鸭子,

『红三角』是成年的老母鸡,

『蓝方块』是成年的母鹅。

问题来了,小鸭子去找自己的妈妈,它觉得老母鸡是自己的妈妈呢,还是母鹅是自己的妈妈呢?

小鸭子(KNN算法)视力范围1米内(实线圆圈),发现了2只母鸡和1只鹅,小鸭子就认为母鸡是自己的妈妈。

如果小鸭子(KNN算法)视力范围2米内(虚线圈),发现了3只母鹅和2只母鸡,鹅比鸡多,小鸭子就认为鹅是自己的妈妈。

还没有清楚的话,看下面的原汁原味的解释吧。

Example of k-NN classification. The test sample (green circle) should be classified either to the first class of blue squares or to the second class of red triangles. If k = 3 (solid line circle) it is assigned to the second class because there are 2 triangles and only 1 square inside the inner circle. If k = 5 (dashed line circle) it is assigned to the first class (3 squares vs. 2 triangles inside the outer circle).

reference:

https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm

原文地址:https://www.cnblogs.com/zhixingheyi/p/8098075.html