IndexError: tuple index out of range
错误代码:
def loadDataSet(fileName): #general function to parse tab -delimited floats
dataMat = [] #assume last column is target value
fr = open(fileName)
for line in fr.readlines():
curLine = line.strip().split('\t')
fltLine = map(float,curLine) #map all elements to float()
dataMat.append(fltLine)
return dataMat
打印出dataset
[<map object at 0x0000022920841B70>, <map object at 0x0000022920841C50>, <map object at 0x0000022920841D68>, 。。。。。。
发现是一个个map对象
shape(dataset)
(80,)
只有行数没有列数
代码修正:
def loadDataSet(fileName): #general function to parse tab -delimited floats
dataMat = [] #assume last column is target value
fr = open(fileName)
for line in fr.readlines():
curLine = line.strip().split('\t')
fltLine = list(map(float,curLine)) #map all elements to float()//将map对象转为list列表
dataMat.append(fltLine)
return dataMat
shape(dataset)
(80, 2)
欢迎关注我的公众号:小秋的博客
CSDN博客:https://blog.csdn.net/xiaoqiu_cr
github:https://github.com/crr121
联系邮箱:rongchen633@gmail.com
有什么问题可以给我留言噢~