I have tried this piece of code for multi variable regression for finding the coefficients but couldn't find where I am making mistake or if I am on the right path?
The problem is the mse value not getting converged.
here x1 , x2 , x3 are the 3 feature variables i am having(i have sliced each feature column into these x1 , x2 ,x3 vars)
def gradientDescent(x,y):
mCurrent1=mCurrent2=mCurrent3=bCurrent=0
iteration=1000
learningRate=0.0000001
n=len(x)
for i in range(0,iteration):
y_predict=mCurrent1*x1+mCurrent2*x2+mCurrent3*x3+bCurrent
mse=(1/n)*np.sum([val**2 for val in (y-y_predict)])
mPartDerivative1=-(2/n)*np.sum(x1*(y-y_predict))
mPartDerivative2=-(2/n)*np.sum(x2*(y-y_predict))
mPartDerivative3=-(2/n)*np.sum(x3*(y-y_predict))
bPartDerivative=-(2/n)*np.sum(y-y_predict)
mCurrent1=mCurrent1-(learningRate*mPartDerivative1)
mCurrent2=mCurrent2-(learningRate*mPartDerivative2)
mCurrent3=mCurrent3-(learningRate*mPartDerivative3)
bCurrent=bCurrent-(learningRate*bPartDerivative)
print('m1:{} m2:{} m3:{} b:{} iter:{} mse:{}'.format(mCurrent1,mCurrent2,mCurrent3,bCurrent,i,mse))
return(round(mCurrent1,3),round(mCurrent2,3),round(mCurrent3,3),round(bCurrent,3))

