Linear Regression Numpy Code and Python
Python
 In the course today we learned about the following concepts:
- Lists
 - Dictionaries
 - Tuples
 - Sets
 - Booleans
 - Dealing with Files in Python
 - Iterating in a file
 
Linear Regression Numpy Code
The code was completed and it was:
import math
beta = beta_zero
cost_diff = 100
rmse =-1
for i in range(10000):
    old_rmse = rmse
    y_hatnew = x_data.dot(beta)
    y_diff =y_true.reshape(len(x_inputs),1) - y_hatnew
    rmse = math.sqrt(y_diff.T.dot(y_diff)/x_data.shape[0])
    print(i,":",rmse)
    if abs(rmse-old_rmse) < 0.000000000001:
        break
    derivative = 2*y_diff.T.dot(x_data)/x_data.shape[0]
    beta = beta+step*derivative.T
print(beta) 
The
 next task given to us was to implement the sklearn function of Linear 
Regression and to compare the results of our version and the sklearn 
function.
Comments
Post a Comment