Need Help in understanding the Code

r

#1

I was trying to solve Big Mart Sales problem and found below in one of the blog.I am unable to understand if below is the syntax for Lasso Regression

my_control = trainControl(method=“cv”, number=5)
Grid = expand.grid(alpha = 0, lambda = seq(0.001,0.1,by = 0.0002))

lasso_linear_reg_mod3 = train(x = Train[, -c(1,2)], y = Train$Item_Outlet_Sales,
method=‘glmnet’, trControl= my_control, tuneGrid = Grid)


#2

This is Ridge Regression because the parameter alpha = 0. For Lasso alpha is kept as 1.


#3

Thanks pjoshi in helping me by segregating two syntax using alpha value but I guess I need to be more clear with my question.
if I have to use the lasso regression then train(c,y,method,trcontrol,tunegrid) is the syntax ?
as I read at most places that this train function is for training and syntax is something else.


#4

@v.vicky000 this train() function is from the caret package. I’d suggest you to go through the below course as it has implementation of both Ridge and Lasso Regression in R.


#5

Thank you So Much… Though I had already gone through this case but your mention of Caret package helped me lot.