I am getting large amount of error

Please check why I am not able to solve this challenge. I have used the exact same code used by Prateek Bhaiya in the tutorial of Linear Regression Implementation.
Link to my code:

Also, I am getting drastically different answers of theta when I change max_itrations and learning factor.

Kindly help me get out of this confusion.
Thanks in advance.

I am getting this error plot:
image

But when I use the sklearn library to find the output, using the LinearRegression() model I am getting 97% accuracy.

Whats wrong with the implementation code above??

The observation that I can make out of this is that, when the y values are large, in this case they are in the range -300 to 300, and since we normalized the x values they are in the range -1 to 1 mostly. Thus the parameters are getting very large.
And we cannot compute these effectively.

The dataset used by Prateek Bhaiya in the Tutorial had y values in the range -1 to 1. That was very suitable for the algorithm…
Please comment on my observation…

I also gives overflow error on executing the algorithm…

Hey Sagnik,
This kind of error occurs only because of the learning rate value. It’s either too small or too large. From seeing the value you’ve taken in your code I think you should try and reduce it. Make it 0.0001 or somewhere around that. It should work well.

You’re right in your observation. It is because while updating gradient using the loss, the updations in your case are big ones due to high value of the y values. Thus, you must reduce the learning rate to compromise for that.

I hope this helps.

1 Like

Hey, It actually worked,
So is this the way to figure out the learning rate, by trying random learning rates?

No, not completely random, I explained the intuition behind it in the second part of my answer above.

And yes, we might have try out some values in a particular range of values that falls in our intuition well.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.