These are chat archives for FreeCodeCamp/DataScience

15th
Mar 2018
Bigyan Karki
@bigyankarki
Mar 15 2018 23:22
from numpy.linalg import inv

def normal_equation(x, y, initial_thetta):
    final_thetta = inv(x.T * x) * (x.T * y)
    return final_thetta
can anyone point me whats wrong with this code? x is matrix with 678x9 attribute matrix, and y is a 768x1 target vector
operands could not be broadcast together with shapes (9,768) (768,9)
i get this error everytime i run it
Bigyan Karki
@bigyankarki
Mar 15 2018 23:44
from numpy.linalg import inv

def normal_equation(x, y):
    final_thetta = inv(x.T.dot(x)).dot(x.T).dot(y)
    return final_thetta
I tried using .dot() method but no avail.
oh wait.
from numpy.linalg import pinv

def normal_equation(x, y):
    final_thetta = pinv(x.T.dot(x)).dot(x.T).dot(y)
    return final_thetta
pinv worked though.