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

  • 大小: 6KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-01-02
  • 語言: Python
  • 標簽: KNN??mnist??python??

資源簡介

python版KNN識別mnist手寫數據集

資源截圖

代碼片段和文件信息

from?numpy?import?*
import?operator
from?os?import?listdir
import?matplotlib
import?matplotlib.pyplot?as?plt
import?pdb

def?classify0(inX?dataSet?labels?k=3):
????#pdb.set_trace()
????dataSetSize?=?dataSet.shape[0]
????diffMat?=?tile(inX?(dataSetSize1))?-?dataSet
????sqDiffMat?=?diffMat**2
????sqDistances?=?sqDiffMat.sum(axis=1)
????distances?=?sqDistances**0.5
????sortedDistIndicies?=?distances.argsort()?#ascend?sorted
????#return?the?index?of?unsorted?that?is?to?choose?the?least?3?item????
????classCount={}??????????
????for?i?in?range(k):
????????voteIlabel?=?labels[sortedDistIndicies[i]]
????????classCount[voteIlabel]?=?classCount.get(voteIlabel0)?+?1#?a?dict?with?label?as?key?and?occurrence?number?as?value
????sortedClassCount?=?sorted(classCount.iteritems()?key=operator.ite

評論

共有 條評論