we need to add a dummy variable ‘ones’ whose value is always 1 to X so we use np.hstack() method but if i use the method as X = np.hstack((ones, X)) then after prediction i am getting a linear prediction curve for all value of tau…but if I use X = np.hstack((X, ones )) then the prediction curve is changing accordingly as change in tau …Why?
Delimma in using np.hstack() method
hey @maitraanirban25 ,
you know that a general linear equation is like y = a0*1 + a1x1 + a2x2 + a3x3 +…
where x1,x2,x3… are our features of data , a1,a2,a3… are there respective coefficients and a0 is the intercept.
so to get that intercept term we use np.hstack((ones,X))
to explain this , lets assume a from X as [ 2,5,6,8 ]
so after np.hstack((ones,X))
we get X=[ 1,2,5,6,8]
agree?
lets say we have our coefficient as C = [ 0.2, 0.1, 0.3, 0.2,0.4 ]
So now if we calculate our y as by multiplying each feature with respective coefficient and then summing them up
we get y = 0.2 + 0.2 +1.5 +1.2+3.2 = 6.3
but if we would have taken np.hstack((X,ones)) and keeping the coefficients as same
we would be getting
X = [ 2,5,6,8 ,1] and C = [ 0.2, 0.1, 0.3, 0.2,0.4 ]
y = 0.4 + 0.5 + 1.8 + 1.6 + 0.4 = 4.7
So as you see, the algorithm has a defined manner to calculate it , which your intercept to be at first , so when you change the position of intercept value , coefficients of all other feature changes , along with intercept one. Hence , when you plot it , it result in a linear curve depending upon the tau value.
I hope this would have helped you to understand the reason behind it.
Thank You and Happy Learning .
Thanks Bhaiya … nice explanation
If your doubt is resolved , then i would request to kindly mark this as resolved in your doubt section and also to provide your valuable feedback as it will help us to improve this platform and provide you with better learning experience.
Thank You and Enjoy Learning .