1. 程式人生 > >python數據集處理,加載成list

python數據集處理,加載成list

[] light clas num file line 處理 lena label

def loadDataSet(filename):
    f = open(filename)
    numFeatures = len(f.readline().split(‘\t‘)) - 1
    dataMat = []
    labelMat = []
    for line in f.readlines():
        lineArr=[]
        curLine=line.strip().split(‘\t‘)
        for i in range(0,numFeatures):
            lineArr.append(float(curLine[i]))
        dataMat.append(lineArr)
        labelMat.append(float(curLine[-1]))
    return dataMat,labelMat

python數據集處理,加載成list