机器学习实战第九章ValueError: Masked arrays must be 1-D

机器学习实战第九章ValueError: Masked arrays must be 1-D

机器学习实战第九章ValueError: Masked arrays must be 1-D_第1张图片

主要错误出现在函数reDraw(tolS, tolN)中:

def reDraw(tolS, tolN):
    reDraw.f.clf() 
    reDraw.a = reDraw.f.add_subplot(111)
    if chkBtnVar.get():
        if tolN < 2: tolN = 2
        myTree = regTrees.createTree(reDraw.rawDat, regTrees.modelLeaf, \
                                     regTrees.modelErr, (tolS, tolN))
        yHat = regTrees.createForeCast(myTree, reDraw.testDat, \
                                       regTrees.modelTreeEval)
    else:
        myTree = regTrees.createTree(reDraw.rawDat, ops=(tolS, tolN))
        yHat = regTrees.createForeCast(myTree, reDraw.testDat)
    reDraw.a.scatter(reDraw.rawDat[:, 0], reDraw.rawDat[:, 1], s=5)  
    reDraw.a.plot(reDraw.testDat, yHat, linewidth=2.0)
    reDraw.canvas.show()

将其中的

reDraw.a.scatter(reDraw.rawDat[:, 0], reDraw.rawDat[:, 1], s=5)
替换为

reDraw.a.scatter(reDraw.rawDat[:, 0].tolist(), reDraw.rawDat[:, 1].tolist(), s=5)  
则运行成功。

机器学习实战第九章ValueError: Masked arrays must be 1-D_第2张图片


你可能感兴趣的:(python,机器学习)