1. 程式人生 > >機器學習——k鄰近演算法的資料解析

機器學習——k鄰近演算法的資料解析

def file2matrix(filename):
    #?????
    fr = open(filename)
    #??????????
    arrayOLines = fr.readlines()
    #??????????
    numberofLines = len(arrayOLines)
    #????numberofLines?????��??????
    returnMat = zeros((numberofLines,3))
    classLabelVector = []
    index = 0
    #for??????????????��?????
    for line in arrayOLines:
        #??line?????????
        line = line.strip()
        #?????????\t???
        listFormLine = line.split('\t')
        #??????? ?????��??????????
        returnMat [index,:] = listFormLine[0:3]
        #??listFormLine???????�՛�??classLabelVector?????  ???????int
        classLabelVector.append(int(listFormLine[-1]))
        index+=1
        #???????????????????????
    return returnMat,classLabelVector