【问题标题】:NameError when trying to run linear regression尝试运行线性回归时出现 NameError
【发布时间】:2020-05-15 13:18:26
【问题描述】:

我在尝试运行此程序时遇到错误:

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

请解决我的问题

【问题讨论】:

  • 如错误消息所述,您尚未定义 mc_values_anim 变量。

标签: python machine-learning linear-regression


【解决方案1】:

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

【讨论】:

    最近更新 更多