-
Notifications
You must be signed in to change notification settings - Fork 92
Add argument for one hot encoding to parsnip #332
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
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
8a3b4b7
Add one hot option to encoding options
juliasilge 3a3743e
one_hot = FALSE for almost all models, one_hot = TRUE for glmnet models
juliasilge 1f4c40b
changed one_hot to logical; less confusing
topepo 4c6641c
revert glmnet encodings to one_hot
topepo e169f8f
Switch from logical to none/traditional/one_hot
juliasilge 51c18ad
Update predictor_indicators in model infrastructure
juliasilge 3420156
change objective function name for xgboost regression
topepo 2430518
more encoding updates related to intercepts
topepo 00e3180
set defaults for parsnip objects with no encoding information
topepo 91cc98d
"one-hot" not "one_hot"
topepo cb68875
apply encoding changes to form_xy and xy_form paths
topepo 3ebd066
fully export contrast function
topepo c30a50a
"one_hot" not "one-hot"
topepo 9c7df98
fixed a few bugs
topepo 164c4d3
revert xgboost change (in another PR)
topepo ac2aa17
updated news
topepo 856c829
two more global variable false positives
topepo 8503ae1
updates for how many engines handle dummy variables (if at all)
topepo c76ec17
details on encoding options
topepo d7eee45
one_hot documentation
topepo a2308d9
Update R/aaa_models.R
topepo 7318d7f
Update R/aaa_models.R
topepo 334f01c
Update R/aaa_models.R
topepo 110ca67
Update R/aaa_models.R
topepo d70e414
Update R/aaa_models.R
topepo ea3ec8c
Update R/contr_one_hot.R
topepo fc4f165
Update man/rmd/one-hot.Rmd
topepo 9a11306
Update man/rmd/one-hot.Rmd
topepo ccd52bb
documentation updates for one-hot
topepo d04b892
Update man/rmd/one-hot.Rmd
topepo f164247
Update man/rmd/one-hot.Rmd
topepo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#' Contrast function for one-hot encodings | ||
#' | ||
#' This contrast function produces a model matrix that has indicator columns for | ||
topepo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' each level of each factor. | ||
#' | ||
#' @param n A vector of character factor levels or the number of unique levels. | ||
#' @param contrasts This argument is for backwards compatibility and only the | ||
#' default of `TRUE` is supported. | ||
#' @param sparse This argument is for backwards compatibility and only the | ||
#' default of `FALSE` is supported. | ||
#' | ||
#' @includeRmd man/rmd/one-hot.Rmd details | ||
#' | ||
#' @return A diagonal matrix that is `n`-by-`n`. | ||
#' | ||
#' @export | ||
contr_one_hot <- function(n, contrasts = TRUE, sparse = FALSE) { | ||
if (sparse) { | ||
rlang::warn("`sparse = TRUE` not implemented for `contr_one_hot()`.") | ||
} | ||
|
||
if (!contrasts) { | ||
rlang::warn("`contrasts = FALSE` not implemented for `contr_one_hot()`.") | ||
} | ||
|
||
if (is.character(n)) { | ||
names <- n | ||
n <- length(names) | ||
} else if (is.numeric(n)) { | ||
n <- as.integer(n) | ||
|
||
if (length(n) != 1L) { | ||
rlang::abort("`n` must have length 1 when an integer is provided.") | ||
} | ||
|
||
names <- as.character(seq_len(n)) | ||
} else { | ||
rlang::abort("`n` must be a character vector or an integer of size 1.") | ||
} | ||
|
||
out <- diag(n) | ||
|
||
rownames(out) <- names | ||
colnames(out) <- names | ||
|
||
out | ||
} |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.