我正在使用插入符号来训练脊回归:
...
@list_route(methods=['post'])
def register(self, request):
return Response({
'status': 'User registered'
})
所以,我找到了最佳的lambda和alpha。事实上,这对我的问题来说并不重要,它们是什么。
现在,我怎么能在整个数据集中运行alpha = 0和lambda = 242.0128的一次岭回归(使用插入符号)?
我发现我可以将trainControl方法指定为'none'。请参阅下面的代码。我是否正确指定了tuneGrid(只有一行)。这是怎么做的?
非常感谢!
library(ISLR)
Hitters = na.omit(Hitters)
x = model.matrix(Salary ~ ., Hitters)[, -1] #Dropping the intercept column.
y = Hitters$Salary
set.seed(0)
train = sample(1:nrow(x), 7*nrow(x)/10)
library(caret)
set.seed(0)
# Values of lambda over which to check:
grid = 10 ^ seq(5, -2, length = 100)
train_control = trainControl(method = 'cv', number = 10)
tune.grid = expand.grid(lambda = grid, alpha = 0)
ridge.caret = train(x[train, ], y[train],
method = 'glmnet',
trControl = train_control,
tuneGrid = tune.grid)
ridge.caret$bestTune
# alpha is 0 and best lambda is 242.0128