尝试运行线性回归时出现NameError

时间:2020-05-15 13:18:26

标签: python machine-learning linear-regression

尝试运行此程序时出现错误:

fig, ax = plt.subplots()
ln, = plt.plot([], [], 'ro-' , animated=True)


def init():
    plt.scatter(xtest, ytest, color='g')
    ax.set_xlim(0, 1.0)
    ax.set_ylim(0, 1.0)
    return ln,

def update_frame(frame):
    m , c = mc_values_anim[frame]
    x1, y1 = -0.5, m * -.5 + c
    x2, y2 = 1.5, m * 1.5 + c
    ln.set_data([x1, x2], [y1, y2])
    return ln,


anim = FuncAnimation(fig, update_frame, frames=range(len(mc_values_anim)), 
                                init_func=init, blit=True)
HTML(anim.to_html5_video())

错误是:

NameError                                 Traceback (most recent call last)
<ipython-input-43-a04b9e0d4368> in <module>
     17 
     18 
---> 19 anim = FuncAnimation(fig, update_frame, frames=range(len(mc_values_anim)), 
     20                                 init_func=init, blit=True)
     21 HTML(anim.to_html5_video())

NameError: name 'mc_values_anim' is not defined

请解决我的查询

1 个答案:

答案 0 :(得分:0)

在上方创建一个新单元格并输入以下内容: mc_values_anim = mc_values [0:250:5]

相关问题