prappleizer / prappleizer.github.io

This repo contains my introductory python textbook for astronomy students, which covers the basics of learning the language with an emphasis on astronomical applications.
http://prappleizer.github.io/textbook.pdf
55 stars 22 forks source link

Incorrect quadratic residuals calculation in "Linear Regression" tutorial #4

Open robert-horn opened 2 years ago

robert-horn commented 2 years ago

Your code for calculating the residuals for the quadratic regression contains this line:

    fit_line = x*a0**2 + x*a1 + a2

Which leads to the output that the sum of residuals is -584

In fact, the line should be

    fit_line = a0*x**2 + x*a1 + a2

as the coefficient is for the x^2 term, not the root of the coefficient for the x term

When corrected, this gives the output that the sum of the residuals is actually 1.4139800441625994e-12, which is actually much smaller than the residual for the linear fit!

This entirely invalidates the paragraph which follows it, which explains why the number is so large.