0

I am building a ridge and lasso regression on the same dataset, however lasso model's prediction's shape seems different than ridge. I'd appreciate if someone can explain what I'm doing wrong...

###Ridge Regression
model3 = Ridge(alpha=5)
model3.fit(x_train2, y_train)

y_pred3=model3.predict(x_test2)
y_pred3.shape
#result is: (1542, 1)

###Lasso Regression
from sklearn.linear_model import Lasso

model4 = Lasso(alpha=0.1)
model4.fit(x_train2, y_train)

y_pred4=model4.predict(x_test2)
y_pred4.shape
#result is: (1542,)
Georgy
  • 12,464
  • 7
  • 65
  • 73
Cagdas Kanar
  • 713
  • 4
  • 13
  • 23
  • Consider changing the title to something like "Lasso and Ridge models return different shapes for column vectors" or similar as I find your current one misleading. – Marcus V. Jan 08 '18 at 08:14

1 Answers1

0

I still don't know why Lasso model's prediction is in a different shape but I solved my problem by reshaping the array as :

B = np.reshape(y_pred4, (-1, 1))
B
B.shape
##result: (1542,1)
Cagdas Kanar
  • 713
  • 4
  • 13
  • 23
  • Could also just guess, why Lasso returns a column vector and Ridge not. Don't know if that qualifies as a bug. Just want to add that it is slightly shorter to write B = y_pred4.reshape(-1, 1). Also if you want to achieve the opposite use ravel: C = y_pred3.ravel() – Marcus V. Jan 08 '18 at 08:12