endpoints = make_array(-2, 7)
p = plt.plot(endpoints, slope*endpoints + intercept,
color='orange', label='Proposed line')
plt.scatter(d.column('x'), d.column('y'), color='blue', label='Poin
interact(plot_line, slope=widgets.FloatSlider(min=-4, max=4, step=.1),
intercept=widgets.FloatSlider(min=-4, max=4, step=.1));
You can probably find a reasonable-looking line by just eyeballing it. But remember: the least-squares
regression line minimizes the mean of the squared errors made by the line for each point. Your eye might not
be able to judge squared errors very well.
A note on mean and total squared error
It is common to think of the least-squares line as the line with the least
squared error (or the square root
of the mean squared error), as the textbook does.
But it turns out that it doesn't matter whether you minimize the mean squared error or the
You'll get the same best line in either case.