Day 5 - Linear Regression Numpy Code and Python

Python


 In the course today we learned about the following concepts:
  1. Lists 
  2. Dictionaries
  3. Tuples
  4. Sets
  5. Booleans
  6. Dealing with Files in Python
  7. 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

Popular posts from this blog

Day 1 - Numpy Revision

Week 18 (29/10/2018 - 02/11/2018)

Week 22 (26/11/18 - 30/11/18)