美文网首页
MLA CH2 kNN theory part

MLA CH2 kNN theory part

作者: Mandy今天也沉迷学习 | 来源:发表于2020-03-08 00:28 被阅读0次

在这一部分书中的例子是电影的分类

  • kNN理论,如何用距离来分类
  • python导入数据
  • 陷阱/隐患

2.1 以距离度量分类

*kNN优点:高准确性,对异常值不敏感,对数据没有假定
*kNN缺点:计算消耗大,存储要求大
*处理:标称值(nominal value),数值

  • We have labels for every data in training set.
  • When we 're given a new piece of data without a label, we compare that new piece of data to the existing data, every piece of existing data.
  • We then take the most similar pieces of data (the nearest neighbors) and look at their labels.
  • We look at the top k most similar pieces of data from our known dataset; this is where k comes from (which is a integer and usually less than 20).
  • Lastly, we take a majority vote from the k most similar pieces of data, and the majority is the new class we assign to the data we were asked to classify.

  • 我们将训练集中的所有数据打上标签(知道如何分类)。
  • 当我们得到一个没有打上标签数据时,我们将新数据与每一条已知数据进行比较。
  • 我们得到最相似的数据,然后观察他们的标签。
  • 我们从我们一直到的数据集中得到最相似的k个数据;这就是k的由来(k为一个一般小于20的整数)。
  • 我们从k个最相似的数据中得到的大多数投票就是是我们分配给要求分类的新数据的新类别(class)。

例子——>电影分类

  • 分类动作电影和爱情电影。
  • 观察6部电影的亲吻和打架的次数。
    *一部没有看过的电影,决定种类?
  1. 计算每一个电影到“?”的距离(距离的计算会在之后的内容中提到)。
  2. 将电影按照距离降序排列找到k-nearest的电影。假设k=3。得到三部电影HNRD,BW和CM。
  3. kNN算法认为这三部的大多数分类就是电影“?”的分类。我们知道这三部电影都是爱情片,所以我们也认为“?”是爱情片。

kNN的基本步骤

  1. 收集
  2. 准备:距离计算要求数值,数据格式的结构化要求。
  3. 分析
  4. 训练:不适用于kNN
  5. 测试:计算错误率
  6. 使用

相关文章

网友评论

      本文标题:MLA CH2 kNN theory part

      本文链接:https://www.haomeiwen.com/subject/zykldhtx.html