机器学习实战第九章:树回归

Posted on 2017-02-26 11:59  壶壶龟  阅读(310)  评论(0)    收藏  举报

这章程序错误比较多,更加剧了对我这种菜鸡的难度,先介绍一些书中的错误,其它坑以后再填。

我用的python3,书上用python2,所以会有此错误,在书的P165

书上程序:

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

会报错

TypeError: unsupported operand type(s) for /: 'map' and 'int'

 

第13行改为

fltLine = list(map(float,curLine))

python3中map的返回值变了,所以要加list()

这问题困扰了我好久,网上也查不到解决办法,终于在学下一章的时候想通了。。。