Created
May 27, 2018 13:45
-
-
Save grohith327/6f3a733dc90fc3595bad43d4f5658a2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Linear Regression | |
import numpy as np | |
n = 700 | |
alpha = 0.0001 | |
a_0 = np.zeros((n,1)) | |
a_1 = np.zeros((n,1)) | |
epochs = 0 | |
while(epochs < 1000): | |
y = a_0 + a_1 * x_train | |
error = y - y_train | |
mean_sq_er = np.sum(error**2) | |
mean_sq_er = mean_sq_er/n | |
a_0 = a_0 - alpha * 2 * np.sum(error)/n | |
a_1 = a_1 - alpha * 2 * np.sum(error * x_train)/n | |
epochs += 1 | |
if(epochs%10 == 0): | |
print(mean_sq_er) |
I think your work is very good, but somehow i am messing it up. When I try to run the code the error goes toward infinity instead of toward zero. This leads to a runtime overflow error and all values in error and y becomes NaN.
Any ideas what could cause this?
Hi @OregonMortenson add these lines in respective locations
y_train = y_train.reshape(-1,1)
a_0 = a_0[0:300]
a_1= a_1[0:300]
it will work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think your work is very good, but somehow i am messing it up. When I try to run the code the error goes toward infinity instead of toward zero. This leads to a runtime overflow error and all values in error and y becomes NaN.
Any ideas what could cause this?