【udacity】机器学习-knn最近邻算法

Evernote Export

1.基于实例的学习介绍

不同级别的学习,去除所有的数据点(xi,yi),然后放入一个数据库中,下次直接提取数据
但是这样的实现方法将不能进行泛化,这种方式只能简单的进行数据提取,它也会存储很多的噪音

3.最近邻算法

KNN算法原理就是查找未知点的最近已知点,然后进行归类,但是当遇到最近邻都相差不多的时候,就需要更大的背景去识别
k的意思是邻居的数量

4.KNN算法(伪代码)

Training Data--> D={xi,yi} #训练数据(输入的集合)
Diastance Metric--> d(q,x) #距离度量的方式
Number of Neighbors--> K #邻居的数量(已知)
Query Point--> q (未知点)
-NN = {i:d(qi,xi) k smallest} (由距离查询点最近的所有元素组成的)
-return
    -classification
    -regression

5.KNN算法的时间统计

  Running Time Space
1-NN learning 1 n
1-NN query logn 1
k-NN learning 1 n
k-NN query logn+k 1
linear regression learning n 1
linear regression query 1 1

我们提出了k近邻算法,算法的核心思想是,即是给定一个训练数据集,对新的输入实例,在训练数据集中找到与该实例最邻近的K个实例,这K个实例的多数属于某个类,就把该输入实例分类到这个类中。更通俗说一遍算法的过程,来了一个新的输入实例,我们算出该实例与每一个训练点的距离(这里的复杂度为0(n)比较大,所以引出了下文的kd树等结构),然后找到前k个,这k个哪个类别数最多,我们就判断新的输入实例就是哪类!knn算法是一种懒惰算法

6.KNN偏差

KNN概述

k-近邻算法(K-Nearest Neighbour alorithm),又称为KNN算法,是数据挖掘技术中原理最简单的算法。
**KNN的工作原理:**给定一个已知标签类别的训练数据集,输入没有标签的新数据后,在训练数据集中找到与新数据最近邻的K个实例,如果这K个实例的多数属于某个类别,那么新数据就属于这个类别。
**可以简单理解为:**由哪些离X最近的k个点来投票决定x归为哪个类
K近邻算法就是用两点之间的距离来计算

AB=(x1x2)2+(y1y2)2

当多个特征扩展到N维空间的时候,一般采用欧式距离来计算

dist(x,y)=(x1y1)2+(x2y2)2+...+(xnyn)2=i=1n(xiyi)2

K近邻算法的计算步骤
1.计算已知类别数据集中的点与当前点之间的距离
2.按照距离递增次序排序
3.选取与当前点距离最小的k个点
4.确定前k个点在类别的出现频率
5.返回前k个点出现频率最高的类别作为当前点的预测类别

KNN分类器
分类器并不会百分百的得到正确的结果,我们使用很多种方法来验证分类器的准确率,此外,分类器的性能野兽很多因素的影响,比如k的取值就在很大程度上影响了分类器的预测结果,还有分类器的设置、原始数据集等。为了测试分类器的效果,我们把原始的数据集分为两个部分,一部分用来训练算法(称为训练集),一部分用来测试算法的准确率(称为测试集)。同时,k-近邻算法没有进行数据的训练,直接使用的是未知的数据和已知数据进行比较。
也就是说knn分类器是懒惰算法

小结

k-近邻  
算法功能 分类(核心),回归
算法类型 有监督学习,惰性学习,距离类模型
数据输入 包含数据标签y,且特征空间中至少包含k个训练样本(k>=1);特征空间中各个特征的量纲需统一,若不统一则需要进行归一化处理;自定义的超参数k(k>=1)
模型输出 在KNN分类中,输出是标签中的某个类别;在KNN回归中,输出是对象的属性值,该值是距离输入的数据最近的k个训练样本标签的平均值
%23%23%23%23%201.%E5%9F%BA%E4%BA%8E%E5%AE%9E%E4%BE%8B%E7%9A%84%E5%AD%A6%E4%B9%A0%E4%BB%8B%E7%BB%8D%0A%E4%B8%8D%E5%90%8C%E7%BA%A7%E5%88%AB%E7%9A%84%E5%AD%A6%E4%B9%A0%EF%BC%8C%E5%8E%BB%E9%99%A4%E6%89%80%E6%9C%89%E7%9A%84%E6%95%B0%E6%8D%AE%E7%82%B9(%24x_i%2Cy_i%24)%EF%BC%8C%E7%84%B6%E5%90%8E%E6%94%BE%E5%85%A5%E4%B8%80%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%EF%BC%8C%E4%B8%8B%E6%AC%A1%E7%9B%B4%E6%8E%A5%E6%8F%90%E5%8F%96%E6%95%B0%E6%8D%AE%0A%E4%BD%86%E6%98%AF%E8%BF%99%E6%A0%B7%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%96%B9%E6%B3%95%E5%B0%86%E4%B8%8D%E8%83%BD%E8%BF%9B%E8%A1%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EF%BC%89%0ADiastance%20Metric--%3E%20d(q%2Cx)%20%23%E8%B7%9D%E7%A6%BB%E5%BA%A6%E9%87%8F%E7%9A%84%E6%96%B9%E5%BC%8F%0ANumber%20of%20Neighbors--%3E%20K%20%23%E9%82%BB%E5%B1%85%E7%9A%84%E6%95%B0%E9%87%8F(%E5%B7%B2%E7%9F%A5)%0AQuery%20Point--%3E%20q%20(%E6%9C%AA%E7%9F%A5%E7%82%B9)%0A-NN%20%3D%20%7Bi%3Ad(qi%2Cxi)%20k%20smallest%7D%20%EF%BC%88%E7%94%B1%E8%B7%9D%E7%A6%BB%E6%9F%A5%E8%AF%A2%E7%82%B9%E6%9C%80%E8%BF%91%E7%9A%84%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E7%BB%84%E6%88%90%E7%9A%84%EF%BC%89%0A-return%0A%20%20%20%20-classification%0A%20%20%20%20-regression%0A%60%60%60%0A%23%23%23%23%205.KNN%E7%AE%97%E6%B3%95%E7%9A%84%E6%97%B6%E9%97%B4%E7%BB%9F%E8%AE%A1%0A%0A%7C%20%20%7C%20Running%20Time%20%7C%20Space%20%7C%0A%7C%20---%20%7C%20---%20%7C%20---%20%7C%0A%7C%201-NN%20learning%7C%201%20%7C%20n%20%7C%0A%7C%201-NN%20query%20%7C%20logn%20%7C%201%20%7C%0A%7C%20k-NN%20learning%20%7C%201%20%7C%20n%20%7C%0A%7C%20k-NN%20query%20%7C%20logn%2Bk%20%7C%201%20%7C%0A%7C%20linear%20regression%20learning%20%7C%20n%20%7C%201%20%7C%0A%7C%20linear%20regression%20query%20%7C%201%20%7C%201%20%7C%0A%0A%3E%E6%88%91%E4%BB%AC%E6%8F%90%E5%87%BA%E4%BA%86k%E8%BF%91%E9%82%BB%E7%AE%97%E6%B3%95%EF%BC%8C%E7%AE%97%E6%B3%95%E7%9A%84%E6%A0%B8%E5%BF%83%E6%80%9D%E6%83%B3%E6%98%AF%EF%BC%8C%E5%8D%B3%E6%98%AF%E7%BB%99%E5%AE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BC%95%E5%87%BA%E4%BA%86%E4%B8%8B%E6%96%87%E7%9A%84kd%E6%A0%91%E7%AD%89%E7%BB%93%E6%9E%84%EF%BC%89%EF%BC%8C%E7%84%B6%E5%90%8E%E6%89%BE%E5%88%B0%E5%89%8Dk%E4%B8%AA%EF%BC%8C%E8%BF%99k%E4%B8%AA%E5%93%AA%E4%B8%AA%E7%B1%BB%E5%88%AB%E6%95%B0%E6%9C%80%E5%A4%9A%EF%BC%8C%E6%88%91%E4%BB%AC%E5%B0%B1%E5%88%A4%E6%96%AD%E6%96%B0%E7%9A%84%E8%BE%93%E5%85%A5%E5%AE%9E%E4%BE%8B%E5%B0%B1%E6%98%AF%E5%93%AA%E7%B1%BB%EF%BC%81**knn%E7%AE%97%E6%B3%95%E6%98%AF%E4%B8%80%E7%A7%8D%E6%87%92%E6%83%B0%E7%AE%97%E6%B3%95**%0A%0A%23%23%23%23%206.KNN%E5%81%8F%E5%B7%AE%0A%0A%23%23%23%20KNN%E6%A6%82%E8%BF%B0%0Ak-%E8%BF%91%E9%82%BB%E7%AE%97%E6%B3%95(K-Nearest%20Neighbour%20alorithm)%EF%BC%8C%E5%8F%88%E7%A7%B0%E4%B8%BAKNN%E7%AE%97%E6%B3%95%EF%BC%8C%E6%98%AF%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98%E6%8A%80%E6%9C%AF%E4%B8%AD%E5%8E%9F%E7%90%86%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%E7%AE%97%E6%B3%95%E3%80%82%0A**KNN%E7%9A%84%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%EF%BC%9A**%E7%BB%99%E5%AE%9A%E4%B8%80%E4%B8%AA%E5%B7%B2%E7%9F%A5%E6%A0%87%E7%AD%BE%E7%B1%BB%E5%88%AB%E7%9A%84%E8%AE%AD%E7%BB%83%E6%95%B0%E6%8D%AE%E9%9B%86%EF%BC%8C%E8%BE%93%E5%85%A5%E6%B2%A1%E6%9C%89%E6%A0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%B8%80%E8%88%AC%E6%95%B0%E5%80%BC%E5%BE%88%E5%A4%A7%E6%97%B6%E5%80%99%E4%B8%8D%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%8D%95%E4%B8%AA%E6%A0%B7%E6%9C%AC%E4%B9%9F%E4%B8%8D%E8%83%BD%E5%A4%AA%E5%B0%91%EF%BC%8C%E5%AE%B9%E6%98%93%E5%8F%91%E7%94%9F%E8%AF%AF%E5%88%86%0A*%20%E6%A0%B7%E6%9C%AC%E4%B8%8D%E5%B9%B3%E8%A1%A1%E9%97%AE%E9%A2%98(%E5%8D%B3%E6%9C%89%E4%BA%9B%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%A0%B7%E6%9C%AC%E6%95%B0%E9%87%8F%E5%BE%88%E5%A4%9A%EF%BC%8C%E8%80%8C%E5%85%B6%E4%BB%96%E6%A0%B7%E6%9C%AC%E7%9A%84%E6%95%B0%E9%87%8F%E5%BE%88%E5%B0%91)%0A*%20%E5%8F%AF%E7%90%86%E8%A7%A3%E6%80%A7%E6%AF%94%E8%BE%83%E5%B7%AE%EF%BC%8C%E6%97%A0%E6%B3%95%E7%BB%99%E5%87%BA%E6%95%B0%E6%8D%AE%E7%9A%84%E5%86%85%E5%9C%A8%E5%90%AB%E4%B9%89%0A%0A%0A%0A%0A%0A%0A%0A%0A

 

转载于:https://www.cnblogs.com/pandaboy1123/p/10254061.html

你可能感兴趣的:(【udacity】机器学习-knn最近邻算法)