zoukankan      html  css  js  c++  java
  • 《机器学习实战》第7章的一处代码错误

    ---------------------------------------------------------------------------
    IndexError                                Traceback (most recent call last)
    <ipython-input-69-fab03f1fce4e> in <module>()
    ----> 1 adaboost.buildStump(dataArr, labelArr, D)
    
    /home/cavin/Documents/BookData/machinelearninginaction/Ch07/adaboost.py in buildStump(dataArr, classLabels, D)
         44                 predictedVals = stumpClassify(dataMatrix, i, threshVal, inequal)
         45                 errArr = np.mat(np.ones((m, 1)))
    ---> 46                 errArr[predictedVals == labelMat] = 0
         47                 weightedError = D.T * errArr
         48                 print("""split: dim %d, thresh %.2f, thresh inequal: 
    
    IndexError: index 1 is out of bounds for axis 1 with size 1
    

    P120 程序清单7-1 单层决策树生成函数

    def buildStump(dataArr, classLabels, D):
        ...
        errArr[predictedVals == labelMat] = 0
    

    在3.6版本的anaconda下执行会提示错误:

    解决方法:

    errArr[predictedVals == labelMat.T] = 0
    

    也就是把labelMat转置,出现这个错误原因是predictedValslabelMat的shape不同导致的

  • 相关阅读:
    maven配置
    redis测试
    智慧社区技术总结
    视频导航
    Delphi 任务栏中不显示窗口
    Delphi 设置程序图标为系统默认图标
    清除Windows系统图标缓存
    C/C++ 变量的本质分析
    005 C/C++ 数据类型_void
    004 C/C++ 数据类型_类型别名
  • 原文地址:https://www.cnblogs.com/wuzhiblog/p/8605532.html
Copyright © 2011-2022 走看看