joelgrus / data-science-from-scratch

code for Data Science From Scratch book
MIT License
8.63k stars 4.5k forks source link

Simple Linear Regression / Stochastic Gradient Descent #65

Closed paulaceccon closed 5 years ago

paulaceccon commented 5 years ago

SimpleLinearRegression.ipynb.zip I'm trying the example provided in the chapter containing Simple Linear Regression using SGD, and the result does not converge. The value of the function keeps getting bigger, and the gradient direction is not changed. So, the first theta, randomly generated, is returned.

joelgrus commented 5 years ago

the error function in your notebook is the opposite of the one in the code:

https://github.com/joelgrus/data-science-from-scratch/blob/master/first-edition/code/simple_linear_regression.py#L11

which makes the gradient have the wrong sign