KNN实现手写数字识别.docx
《KNN实现手写数字识别.docx》由会员分享,可在线阅读,更多相关《KNN实现手写数字识别.docx(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、KNN实现手写数字识别博客上显示这个没有Jupyter的好看,想看Jupyter Notebook的请戳KNN实现手写数字识别.ipynb1-导入模块import numpy as npimport matplotlib. pyplot as pitfrom PIL import Imagefrom Idmnist import loaddigits%matplotlib inline2 -导入数据及数据预处理import tensorflow as tfit Import MN I ST datafrom tensorflow, examples, tutorials, mnist impo
2、rt input datadef load digitsO :mnist = input data, read data sets(path/, one hot=True)return mnistmnist = loaddigits ()Extracting C:/Users/marsggbo/Documents/Code/ML/TF Tutorial/data/MNIST datatrain-images-i dx3-ubyte. gzExtracting C:/Users/marsggbo/Documents/Code/ML/TF Tutorial/data/MNIST datatrain
3、 -labels-idxl-ubyte. gzExtracting C:/Users/marsggbo/Documents/Code/ML/TF Tutorial/data/MNIST datatlOk- images-idx3-ubyte. gzExtracting C:/Users/marsggbo/Documents/Code/ML/TF Tutorial/data/MNIST datatlOk labels-idxl-ubyte. gz数据维度print (,zTrain: + str(mnist. train, images, shape)print (,zTrain: + str(
4、mnist. train, labels, shape)print(Test: + str(mnist. test, images, shape)print(Test: + str(mnist. test, labels, shape)Train: (55000, 784)Train: (55000, 10)Test: (10000, 784)Test: (10000, 10)mnist数据采用的是TensorFlow的一个函数进行读取的,由上面的结果可以 知道训练集数据X.train有55000个,每个X的数据长度是784 ( 28*28 )。x_train, y_train, x_test
5、, y_test = mnist. train, images, mnist. train, labels, innis t. test, images, mnist. test, labels展示手写数字3 -构建模型class Knn():def init (self, k):self, k = kself, distance = def topKDistance(self, x train, x test): ,计算距离,这里采用欧氏距离 ,print (计算距离.”)distance = for i in range(x test, shapeLOJ): disl = x_train
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- KNN 实现 手写 数字 识别
限制150内