# -*- coding: utf-8 -*-
"""
Created on Wed Jun 18 11:46:15 2014 @author: hp
""" import numpy as np
import operator def createDataSet():
group=np.random.rand(4,2)
labels=['a','b','c','d']
return group,labels def classify0(inX,dataSet,labels,k):
dataSetSize=dataSet.shape[0]
diffMat=np.tile(inX,(dataSetSize,1))-dataSet
sqDiffMat=diffMat**2
sqDistances=sqDiffMat.sum(axis=1)
distances=sqDistances**0.5
sortedDistIndicies=distances.argsort()
classCount={}
for i in range(k):
voteLabel=labels[sortedDistIndicies[i]]
classCount[voteLabel]=classCount.get(voteLabel,0)+1
sortedClassCount=sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True)
return sortedClassCount[0][0] group,labels=createDataSet()
result=classify0([0,1],group,labels,3)
print '对坐标0,0的分类为%s'%(result)

  

最新文章

  1. .NET面试题系列[7] - 委托与事件
  2. 相机标定:Matlab标定工具箱使用要点
  3. android 自定义alertdialog和取消dialog
  4. HDFS深入浅析
  5. eclipse启动问题
  6. Seek the Name, Seek the Fame - POJ 2752(next运用)
  7. Cannot instantiate the type List<Integer>
  8. 关于write()和fsync()
  9. python2.7 使用super关键词 报错 TypeError: must be type, not&n
  10. 线性表的顺序存储设计和实现 - API函数实现
  11. cocos2dx-lua中handler解析
  12. ExtJS5入门
  13. H5图片预览、压缩、上传
  14. 基于Vue实现图片在指定区域内移动
  15. PHP TS 和 NTS 版本选择
  16. 利用 Create React Native App 快速创建 React Native 应用
  17. angularjs ng-app="angular_app" ng-controller="angular_controller" ng-init="findAll()"
  18. mysql 处理日期格式
  19. WebApp之Meta标签总结
  20. Flash文件在asp页面无法播放,网页上面的Flash文件在火狐浏览器不播放

热门文章

  1. 我的Android进阶之旅------>Android字符串资源中的单引號问题error: Apostrophe not preceded by 的解决的方法
  2. Unity3D性能优化小tips——把this.transform缓存缓存起来
  3. IntelliJ IDEA15,PhpStorm10,WebStorm11激活破解
  4. OpenERP|ODOO高德地图应用
  5. [机器学习实战] 决策树ID3算法
  6. Linux常用指令总结
  7. 面试、笔试中常用的SQL语句(数据库知识必杀)一共50个!!!
  8. Spring Boot(三):logback打印日志
  9. 点滴积累【JS】---JS小功能(onmousemove鼠标移动坐标接龙DIV)
  10. Atitit .h5文件上传 v3