資源簡介
《機器學習實戰(zhàn)》源代碼
代碼片段和文件信息
‘‘‘
Created?on?Sep?16?2010
kNN:?k?Nearest?Neighbors
Input:??????inX:?vector?to?compare?to?existing?dataset?(1xN)
????????????dataSet:?size?m?data?set?of?known?vectors?(NxM)
????????????labels:?data?set?labels?(1xM?vector)
????????????k:?number?of?neighbors?to?use?for?comparison?(should?be?an?odd?number)
????????????
Output:?????the?most?popular?class?label
@author:?pbharrin
‘‘‘
from?numpy?import?*
import?operator
from?os?import?listdir
def?classify0(inX?dataSet?labels?k):
????dataSetSize?=?dataSet.shape[0]
????diffMat?=?tile(inX?(dataSetSize1))?-?dataSet
????sqDiffMat?=?diffMat**2
????sqDistances?=?sqDiffMat.sum(axis=1)
????distances?=?sqDistances**0.5
????sortedDistIndicies?=?distances.argsort()?????
????classCount={}??????????
????for?i?in?range(k):
????????voteIlabel?=?labels[s
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-07-14?05:41??machinelearninginaction\
?????目錄???????????0??2017-07-14?05:41??machinelearninginaction\.git\
?????文件??????????31??2012-03-01?15:44??machinelearninginaction\.git\COMMIT_EDITMSG
?????文件?????????341??2011-05-04?15:31??machinelearninginaction\.git\config
?????文件??????????73??2011-05-04?15:27??machinelearninginaction\.git\desc
?????文件??????????23??2011-05-04?15:27??machinelearninginaction\.git\HEAD
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\hooks\
?????文件?????????452??2011-05-04?15:27??machinelearninginaction\.git\hooks\applypatch-msg.sample
?????文件?????????896??2011-05-04?15:27??machinelearninginaction\.git\hooks\commit-msg.sample
?????文件?????????160??2011-05-04?15:27??machinelearninginaction\.git\hooks\post-commit.sample
?????文件?????????552??2011-05-04?15:27??machinelearninginaction\.git\hooks\post-receive.sample
?????文件?????????189??2011-05-04?15:27??machinelearninginaction\.git\hooks\post-update.sample
?????文件?????????398??2011-05-04?15:27??machinelearninginaction\.git\hooks\pre-applypatch.sample
?????文件????????1578??2011-05-04?15:27??machinelearninginaction\.git\hooks\pre-commit.sample
?????文件????????1239??2011-05-04?15:27??machinelearninginaction\.git\hooks\prepare-commit-msg.sample
?????文件????????3611??2011-05-04?15:27??machinelearninginaction\.git\hooks\update.sample
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\info\
?????文件?????????240??2011-05-04?15:27??machinelearninginaction\.git\info\exclude
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\logs\
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\logs\refs\
?????目錄???????????0??2016-10-26?08:59??machinelearninginaction\.git\logs\refs\heads\
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\logs\refs\remotes\
?????目錄???????????0??2016-10-26?08:59??machinelearninginaction\.git\logs\refs\remotes\origin\
?????目錄???????????0??2017-07-14?05:41??machinelearninginaction\.git\ob
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\ob
?????文件?????????933??2011-12-19?17:28??machinelearninginaction\.git\ob
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\ob
?????文件????????1526??2011-12-19?17:28??machinelearninginaction\.git\ob
?????目錄???????????0??2017-07-14?05:40??machinelearninginaction\.git\ob
?????文件?????????189??2011-06-15?15:17??machinelearninginaction\.git\ob
?????文件?????????839??2011-05-04?15:41??machinelearninginaction\.git\ob
............此處省略543個文件信息
評論
共有 條評論