Skip to content

Instantly share code, notes, and snippets.

@Athospd
Created September 10, 2014 23:44
Show Gist options
  • Save Athospd/ac43a5d6feb21791023b to your computer and use it in GitHub Desktop.
Save Athospd/ac43a5d6feb21791023b to your computer and use it in GitHub Desktop.
Esboço tosqueira de Cross-validation
library(glmnet)
X = model.matrix(rchp ~ 1
+ jogo_do_brasil*(competicao
+ jogo_do_brasil
+ fase2
+ jogo_do_n1
+ jogo_da_italia
+ I(log(soma_ranking))
+ I(log(produto_ranking))
+ soma_ranking
+ soma_ranking:I(fase2%in%c("Final","Semi"))
+ produto_ranking
+ alcance_habitual
+ I(alcance_habitual^2)
+ alcance_habitual
+ alcance_habitual:jogo_da_italia
+ I(log(alcance_habitual))
+ I(alcance_habitual^3)
+ I(log(produto_ranking)*log(soma_ranking)))^4, dados)[,-1]
cv = cv.glmnet(x = X[treino & !outlier, ],
y = y[treino & !outlier],
alpha = 1,
family="gaussian",
nfolds = 10,
type.measure = "mse")
plot(cv)
bestLambda = cv$lambda.min
fit <- glmnet(x = X[treino & !outlier, ],
y = y[treino & !outlier],
alpha = 1,
lambda = bestLambda,
thresh = 1e-12,
family="gaussian")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment