错误代码:
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(' ')
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(' ')
fltLine = list(map(float,curLine)) #map all elements to float()//将map对象转为list列表
dataMat.append(fltLine)
return dataMat
shape(dataset)
(80, 2)