-
Notifications
You must be signed in to change notification settings - Fork 92
Add LiblineaR engine to logistic_reg()
#429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closes #419 |
We did some digging and ended up finding that
We believe these are the sources of any differences between glmnet and LiblineaR. library(tidyverse)
library(parsnip)
data(two_class_dat, package = "modeldata")
data_grid <- crossing(A = seq(0.4, 4, length = 200), B = seq(.14, 3.9, length = 200))
liblinear_pred <-
logistic_reg(penalty = 0.01, mixture = 1) %>%
set_engine("LiblineaR") %>%
set_mode("classification") %>%
fit(Class ~ ., two_class_dat) %>%
predict(data_grid, type = "prob") %>%
bind_cols(data_grid) %>%
mutate(engine = "LiblineaR")
glmnet_pred <-
logistic_reg(penalty = 0.01, mixture = 1) %>%
set_engine("glmnet") %>%
set_mode("classification") %>%
fit(Class ~ ., two_class_dat) %>%
predict(data_grid, type = "prob") %>%
bind_cols(data_grid) %>%
mutate(engine = "glmnet")
glm_pred <-
logistic_reg() %>%
set_engine("glm") %>%
set_mode("classification") %>%
fit(Class ~ ., two_class_dat) %>%
predict(data_grid, type = "prob") %>%
bind_cols(data_grid) %>%
mutate(engine = "glm")
bind_rows(liblinear_pred, glmnet_pred, glm_pred) %>%
ggplot(aes(x = A, y = B)) +
geom_point(data = two_class_dat, aes(col = Class), alpha = .5, show.legend = FALSE) +
geom_contour(aes( z = .pred_Class1, lty = engine), breaks = 0.5, col = "black") +
coord_equal() +
theme_minimal() Created on 2021-02-16 by the reprex package (v1.0.0) |
topepo
reviewed
Feb 23, 2021
Co-authored-by: Max Kuhn <mxkuhn@gmail.com>
Closed
This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the LiblineaR engine to
logistic_reg()
.We are currently having some real uncertainty about what is going on with the
cost
argument toLiblineaR::LiblineaR()
. The docs say:However, for both lasso and ridge regression, treating
1 / cost
like a regularization penalty gives very different results than glmnet. It seems like LIBLINEAR is using a different optimizer or maybe solving a different thing altogether??? 😮Here is ridge (similar for lasso):
Created on 2021-02-11 by the reprex package (v1.0.0)
You have to really bump up the regularization to get LiblineaR to do anything different than
glm()
.