标签:
版权声明:<—— 本文为作者呕心沥血打造,若要转载,请注明出处@http://blog.csdn.net/gamer_gyt <——
======================================================================
本系列博客主要参考 Scikit-Learn 官方网站上的每一个算法进行,并进行部分翻译,如有错误,请大家指正
======================================================================
决策树的算法分析与Python代码实现请参考之前的一篇博客:K最近邻Python实现 接下来我主要演示怎么使用Scikit-Learn完成决策树算法的调用
Scikit-Learn中 sklearn.neighbors的函数包括(点击查看来源URL)
The sklearn.neighbors
module
implements the k-nearest neighbors algorithm.
User guide: See the Nearest Neighbors section for further details.
neighbors.NearestNeighbors
([n_neighbors, ...])
Classifier implementing the k-nearest neighbors vote.
Classifier implementing a vote among neighbors within a given radius
neighbors.KNeighborsRegressor
([n_neighbors, ...])
neighbors.RadiusNeighborsRegressor
([radius, ...])
neighbors.NearestCentroid
([metric, ...])
BallTree for fast generalized N-point problems
KDTree for fast generalized N-point problems
neighbors.LSHForest
([n_estimators, radius, ...])
DistanceMetric class
neighbors.KernelDensity
([bandwidth, ...])
Unsupervised learner for implementing neighbor searches. |
Regression based on k-nearest neighbors. |
Regression based on neighbors within a fixed radius. |
Nearest centroid classifier. |
Performs approximate nearest neighbor search using LSH forest. |
Kernel Density Estimation |
neighbors.kneighbors_graph
(X, n_neighbors[, ...])neighbors.radius_neighbors_graph
(X, radius)
Computes the (weighted) graph of k-Neighbors for points in X |
Computes the (weighted) graph of Neighbors for points in X |
首先看一个简单的小例子:
执行
其输出结果均为:
这是在小数据集的情况下并不能看到他们的差别,当数据集变大时,这种差别便显而易见了
预测结果为:
[0] #第0类
[‘setosa‘] #第0类对应花的名字
转载: scikit-learn学习之K最近邻算法(KNN)
标签:
原文地址:http://www.cnblogs.com/harvey888/p/5852741.html