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

《机器学习实战》第8章 预测数值型数据:回归 

函数regression1方法中出错

def regression1():
    xArr, yArr = loadDataSet("./ex0.txt")
    xMat = mat(xArr)
    yMat = mat(yArr)
    ws = standRegres(xArr, yArr)
    fig = plt.figure()
    ax = fig.add_subplot(111)               
    ax.scatter(xMat[:, 1].flatten().tolist(), yMat.T[:, 0].flatten().A[0].tolist()
    # 【原】ax.scatter(xMat[:, 1].flatten(), yMat.T[:, 0].flatten().A[0])

    xCopy = xMat.copy() 
    xCopy.sort(0)
    yHat = xCopy * ws
    ax.plot(xCopy[:, 1], yHat)
    plt.show()

修改后运行成功:

报错

猜你喜欢

转载自blog.csdn.net/qq_28770757/article/details/86352301