452752 (2) [Avatar] Offline
#1
kNN.py
[ 1 KB ]
datingDatMat,datingLabels = kNN.file2matrix('datingTestSet.txt') spits 'ValueError: invalid literal for integer() with base 10: 'largeDoses'

Here is the code:

def file2matrix(filename):
fr = open(filename)
arrayOLines = fr.readlines()
numberOfLines = len(arrayOLines)
returnMat = zeros((numberOfLines,3))
classLabelVector = []
index = 0
for line in arrayOLines:
line = line.strip()
listFromLine = line.split('\t')
returnMat[index,:] = listFromLine[0:3]
classLabelVector.append(int(listFromLine[-1]))
index += 1
return returnMat,classLabelVector
452752 (2) [Avatar] Offline
#2
452752 wrote:datingDatMat,datingLabels = kNN.file2matrix('datingTestSet.txt') spits 'ValueError: invalid literal for integer() with base 10: 'largeDoses'

Here is the code:

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