machinelearninginaction icon indicating copy to clipboard operation
machinelearninginaction copied to clipboard

ch02

Open timbersea opened this issue 4 years ago • 1 comments

line 53, in file2matrix classLabelVector.append(int(listFromLine[-1])) ValueError: invalid literal for int() with base 10: 'largeDoses'

the data in datingTestSet.txt like this 40920 8.326976 0.953952 largeDoses the error is in kNN line 53 for the sorce code : classLabelVector.append(int(listFromLine[-1])) ; that largeDoses can't cast to int

timbersea avatar Jul 20 '20 17:07 timbersea

hello @kgdngitfk , use: "data/2.KNN/datingTestSet2.txt" plz, do not use datingTestSet;

the reason why you encount : ValueError: invalid literal for int() with base 10: 'largeDoses' is because the last column of datingTestSet.txt is String, not Integer;

so use data/2.KNN/datingTestSet2.txt" plz

anonymity12 avatar Aug 07 '20 04:08 anonymity12