Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(1)
- cv.out = cv.glmnet(X.train,y.train, alpha = 0, nfolds = 10, lambda = seq(0, .1, length = 15)) #cv.glmnet will create it's own lambda sequency by default
- plot(cv.out)
- best.lambda = cv.out$lambda.min
- best.lambda
- log(best.lambda)
- ridge.model = glmnet(X.train, y.train, alpha = 0, nlambda = 100)
- ridge.pred = predict(ridge.model, s = best.lambda, newx = X.test)
- ridge.testmse = mean((y.test - ridge.pred)^2)
- predict(ridge.model, type = "coefficients", s = best.lambda)
- ridge.testmse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement