[机器学习实战-ch09]TypeError: unsupported operand type(s) for /: ‘map’ and ‘int’
>>>reload(regTrees)
<module 'regTrees' from 'regTrees.pyc'>
>>> from numpy import *
The data from figure 9.1 is stored in a file called ex00.txt.
>>> myDat=regTrees.loadDataSet('ex00.txt')
>>> myMat = mat(myDat)
>>> regTrees.createTree(myMat)
查了一下网上的方法,发现loadDataSet()函数里面的map方法和int不兼容,网上解决方法是在map外面加一个list,像这样:
结果试了下,还是不行!!!
然后自己改了下代码,发现运行OK了!!!,如下:
def loadDataSet(fileName):
dataMat = []
fr = open(fileName)
for line in fr.readlines():
curLine = line.strip().split('\t')
fltLine = []
for i in curLine:
fltLine.append(float(i))
dataMat.append(fltLine)
return dataMat
转自:https://blog.csdn.net/qq_36337089/article/details/81328834
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)