91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 10.26MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-10-26
  • 語言: Python
  • 標簽: mlknnmnist??

資源簡介

knn算法識別mnist圖片,python3版本,詳細解析文章:https://blog.csdn.net/eleclike/article/details/79994846

資源截圖

代碼片段和文件信息

‘‘‘
author:?eleclike
date:?2018-4-15
environment:?python3.6win7-32bit
description:?二維特征樣本的knn算法演示
comment:?https://blog.csdn.net/eleclike
‘‘‘
import?numpy
from?matplotlib?import?pyplot?as?plt
print(‘\n\n\n‘)
###################?樣本數(shù)據(jù)初始化
#A類數(shù)據(jù)
xcord_a=[2.22.41.1]#x軸坐標
ycord_a=[1.42.33.4]#y軸坐標
#B類數(shù)據(jù)
xcord_b=[8.39.210.211.2]
ycord_b=[7.38.311.19.3]
#待測試樣本
xcord_x=[4.6]
ycord_x=[3.4]

####################?顯示數(shù)據(jù)
fig?=?plt.figure()
ax?=?fig.add_subplot(111)
#ax.scatter(xcordycord?c=colors?s=markers)
type1?=?ax.scatter(xcord_a?ycord_a?s=20?c=‘red‘)#s=后面的數(shù)值是這個點的大小,c=表示顏色
type2?=?ax.scatter(xcord_b?ycord_b?s=20?c=‘green‘)
type3?=?ax.scatter(xcord_x?ycord_x?s=20?c=‘blue‘)
ax.legend([type1?type2?type3]?[“A“?“B“?“x“]?loc=2)?#loc是從右上角開始數(shù)值為1的逆時針4個角的位置,范圍1~4
ax.axis([112112])#坐標范圍,前2個數(shù)值是x坐標的范圍,后2個是y軸坐標范圍
plt.xlabel(‘x?cord‘)
plt.ylabel(‘y?cord‘)
plt.show()

print(‘\n\n\n‘)
####################?計算待測試對象和樣本數(shù)據(jù)間的差值
#取待測試數(shù)據(jù)的坐標值
x?=?xcord_x[0]
y?=?ycord_x[0]
print(‘待測試對象坐標x=%f,y=%f‘%(xy))
#計算和A類樣本的距離值
dista?=?[]#保存和A類樣本的距離值
ind?=?0
for?xa?in?xcord_a:
ya?=?ycord_a[ind]#取對應(yīng)y點坐標
dist?=?((x-xa)**2?+?(y-ya)**2)**0.5#計算待測試數(shù)據(jù)與當前樣本坐標的距離
print(‘A:ind=%dcord:(%f%f)dist=%f‘%(indxayadist))
dista.append(dist)
ind?+=?1
#計算和B類樣本的距離值
distb?=?[]#保存和B類樣本的距離值
ind?=?0
for?xb?in?xcord_b:
yb?=?ycord_b[ind]#取對應(yīng)y點坐標
dist?=?((x-xb)**2?+?(y-yb)**2)**0.5#計算待測試數(shù)據(jù)與當前樣本坐標的距離
print(‘B:ind=%dcord:(%f%f)dist=%f‘%(indxbybdist))
distb.append(dist)
ind?+=?1


print(‘\n\n\n‘)

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-23?22:57??A01-knn_2d\
?????文件????????2006??2018-04-23?00:19??A01-knn_2d\kNN_2d.py
?????目錄???????????0??2018-04-23?23:01??A02-knn-mnist\
?????文件????????9238??2018-04-23?23:35??A02-knn-mnist\createmat.py
?????文件????????2196??2018-04-23?23:02??A02-knn-mnist\knn.py
?????文件????????3405??2018-04-23?23:34??A02-knn-mnist\main.py
?????目錄???????????0??2018-04-09?23:57??data\
?????目錄???????????0??2018-04-23?22:51??data\mnist\
?????文件?????7840016??1998-01-26?23:07??data\mnist\t10k-images.idx3-ubyte
?????文件???????10008??1998-01-26?23:07??data\mnist\t10k-labels.idx1-ubyte
?????文件????47040016??1996-11-18?23:36??data\mnist\train-images.idx3-ubyte
?????文件???????60008??1996-11-18?23:36??data\mnist\train-labels.idx1-ubyte

評論

共有 條評論

相關(guān)資源