class LR:
def __init__(self, x, y):
self.x = x
self.y = y
self.xmean = np.mean(x)
self.ymean = np.mean(y)
self.x_xmean = self.x - self.xmean
self.y_ymean = self.y - self.ymean
self.covariance = sum(self.x_xmean * self.y_ymean)
self.variance = sum(self.x_xmean * self.x_xmean)
def getYhat(self, input_x):
input_x = np.array(input_x)
return self.intercept + self.slope * input_x
def getCoefficients(self):
self.slope = self.covariance/self.variance
self.intercept = self.ymean - (self.xmean * self.slope)
return self.intercept, self.slope
I am using the above class to calculate intercept and slope for a Simple Linear Regression. However, I would like to tweak it to make it work for Multiple Linear Regression as well, but WITHOUT using matrix formula $(XX^T)^{-1}X^TY$.
Please suggest.