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)




posted @ 2018-01-03 16:12  crr121  阅读(7048)  评论(0编辑  收藏  举报