This is the code for the "How to Do Linear Regression the Right Way" live session by Siraj Raval on Youtube
This is the code for this video on Youtube by Siraj Raval. I'm using a small dataset of student test scores and the amount of hours they studied. Intuitively, there must be a relationship right? The more you study, the better your test scores should be. We're going to use linear regression to prove this relationship.
Here are some helpful links:
Gradient descent visualization
Sum of squared distances formula (to calculate our error)
Partial derivative with respect to b and m (to perform gradient descent)
Python 2 and 3 both work for this. Use pip to install any dependencies.
python3 demo.py to see the results:
Starting gradient descent at b = 0, m = 0, error = 5565.107834483211 Running... After 1000 iterations b = 0.08893651993741346, m = 1.4777440851894448, error = 112.61481011613473
Credits for this code go to mattnedrich. I've merely created a wrapper to get people started.