mikexcohen / LinAlg4DataScience

Code that accompanies the book "Linear Algebra for Data Science"
298 stars 150 forks source link

Chapter 11, Exercise 4, mistake in code #4

Closed LysanetsAndriy closed 1 year ago

LysanetsAndriy commented 1 year ago

Wrong iterating variable in the nested for loop. y is used as an iterator as well as an iterated sequence. So after this loop, y is just a scalar(the last element of the initial array y) and not a vector. After that, SSE is computed by subtracting a scalar from a vector: np.sum((pred_happiness-y)**2. After changing the iterating variable name SSE is computed correctly, so the original y vector is subtracted from the pred_happiness vector.

mikexcohen commented 1 year ago

Oh yeah, great catch! And thanks for letting me know. It doesn't change the pattern or the conclusion, although it does mean the SSE's were wrong. Code is now fixed.