Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Glmnet varimp fix 2 #190
Closed
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce86233
take absolute value of glmnet coefficients
strongh ea87e11
typo in some glmnet error messages
strongh 73bc343
add varImp testthat file, with assertions for non-negative glmnet values
strongh cd25b26
skip test if glmnet is not installed
strongh 0d4c677
update models.RData
strongh 8cd351b
removed RData file
strongh
Jump to file or symbol
Failed to load files and symbols.
Binary file not shown.
| @@ -0,0 +1,25 @@ | ||
| +library(caret) | ||
| + | ||
| +context('Testing varImp') | ||
| + | ||
| +test_that('glmnet varImp returns non-negative values', { | ||
| + skip_on_cran() | ||
| + skip_if_not_installed('glmnet') | ||
| + set.seed(1) | ||
| + dat <- SLC14_1(200) | ||
| + | ||
| + reg <- train(y ~ ., data = dat, | ||
| + method = "glmnet", | ||
| + tuneGrid = data.frame(lambda = .1, alpha = .5), | ||
| + trControl = trainControl(method = "none")) | ||
| + | ||
| + # this checks that some coefficients are negative | ||
| + coefs <- predict(reg$finalModel, s=0.1, type="coef") | ||
| + expect_less_than(0, sum(0 > coefs)) | ||
| + # now check that all elements of varImp are nonnegative, | ||
| + # in spite of negative coefficients | ||
| + vis <- varImp(reg, s=0.1, scale=F)$importance | ||
| + expect_equal(0, sum(0 > vis)) | ||
| +}) | ||
| + | ||
| + |