书2.2.1 解析txt文件 读取其中的数据
1.记录
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
<

本文档主要介绍了在机器学习实战中遇到的2txt文件读取问题,包括'reload()'函数的使用错误及datingTestSet2.txt文件的使用。在Python环境中,不再需要'reload()'函数,直接导入即可。同时指出了书中datingTestSet.txt文件名的错误,应更正为datingTestSet2.txt。
最低0.47元/天 解锁文章
1362

被折叠的 条评论
为什么被折叠?



