title: Elasticnet regression(glmnet) predicting the same value for all observations in test data
body: <p>I'm using the <a href="http://www4.stat.ncsu.edu/~post/josh/LASSO_Ridge_Elastic_Net_-_Examples.html" rel="nofollow noreferrer">following</a> tutorial to try out ridge,lasso and elastic net regression on my own data. However, I get the same value predicted for all rows which can't be true, as a result I also get the same fit and mse values.</p>
  
  <p>I would really appreciate it if someone more knowledgable in R than I'm will have a look at my code and maybe point out what i'm doing wrong. Here it is:</p>
  
  <pre><code>library (glmnet)
  require(caTools)
  set.seed(111) 
  
  new_flat &lt;- fread('RED_SAMPLED_DATA_WITH_HEADERS.csv', header=TRUE, sep = ',') 
  sample = sample.split(new_flat$SUBSCRIPTION_ID, SplitRatio = .80)
  train = subset(new_flat, sample == TRUE)
  test = subset(new_flat, sample == FALSE)
  
  x=model.matrix(c201512_TOTAL_MARGIN~.-SUBSCRIPTION_ID,data=train) 
  y=train$c201512_TOTAL_MARGIN
  
  x1=model.matrix(c201512_TOTAL_MARGIN~.-SUBSCRIPTION_ID,data=test) 
  y1=test$c201512_TOTAL_MARGIN
  
  
  
  # Fit models:
  fit.lasso &lt;- glmnet(x, y, family="gaussian", alpha=1)
  fit.ridge &lt;- glmnet(x, y, family="gaussian", alpha=0)
  fit.elnet &lt;- glmnet(x, y, family="gaussian", alpha=.5)
  
  
  # 10-fold Cross validation for each alpha = 0, 0.1, ... , 0.9, 1.0
  fit.lasso.cv &lt;- cv.glmnet(x, y, type.measure="mse", alpha=1, 
                            family="gaussian")
  fit.ridge.cv &lt;- cv.glmnet(x, y, type.measure="mse", alpha=0,
                            family="gaussian")
  fit.elnet.cv &lt;- cv.glmnet(x, y, type.measure="mse", alpha=.5,
                            family="gaussian")
  
  for (i in 0:10) {
    assign(paste("fit", i, sep=""), cv.glmnet(x, y, type.measure="mse", 
                                              alpha=i/10,family="gaussian"))
  }
  
  
  # Plot solution paths:
  par(mfrow=c(3,2))
  # For plotting options, type '?plot.glmnet' in R console
  plot(fit.lasso, xvar="lambda")
  plot(fit10, main="LASSO")
  
  plot(fit.ridge, xvar="lambda")
  plot(fit0, main="Ridge")
  
  plot(fit.elnet, xvar="lambda")
  plot(fit5, main="Elastic Net")
  
  
  yhat0 &lt;- predict(fit0, s=fit0$lambda.1se, newx=x1)
  yhat1 &lt;- predict(fit1, s=fit1$lambda.1se, newx=x1)
  yhat2 &lt;- predict(fit2, s=fit2$lambda.1se, newx=x1)
  yhat3 &lt;- predict(fit3, s=fit3$lambda.1se, newx=x1)
  yhat4 &lt;- predict(fit4, s=fit4$lambda.1se, newx=x1)
  yhat5 &lt;- predict(fit5, s=fit5$lambda.1se, newx=x1)
  yhat6 &lt;- predict(fit6, s=fit6$lambda.1se, newx=x1)
  yhat7 &lt;- predict(fit7, s=fit7$lambda.1se, newx=x1)
  yhat8 &lt;- predict(fit8, s=fit8$lambda.1se, newx=x1)
  yhat9 &lt;- predict(fit9, s=fit9$lambda.1se, newx=x1)
  yhat10 &lt;- predict(fit10, s=fit10$lambda.1se, newx=x1)
  
  mse0 &lt;- mean((y1 - yhat0)^2)
  mse1 &lt;- mean((y1 - yhat1)^2)
  mse2 &lt;- mean((y1 - yhat2)^2)
  mse3 &lt;- mean((y1 - yhat3)^2)
  mse4 &lt;- mean((y1 - yhat4)^2)
  mse5 &lt;- mean((y1 - yhat5)^2)
  mse6 &lt;- mean((y1 - yhat6)^2)
  mse7 &lt;- mean((y1 - yhat7)^2)
  mse8 &lt;- mean((y1 - yhat8)^2)
  mse9 &lt;- mean((y1 - yhat9)^2)
  mse10 &lt;- mean((y1 - yhat10)^2)
  </code></pre>
  
  <p>EDIT : The plot in the code looks like <a href="https://i.stack.imgur.com/9cMqB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9cMqB.jpg" alt="this"></a></p>