Skip to content

Commit

Permalink
Fixes #207
Browse files Browse the repository at this point in the history
  • Loading branch information
spsanderson committed Apr 28, 2022
1 parent a650516 commit 7b67476
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export(hai_kmeans_scree_data_tbl)
export(hai_kmeans_scree_plt)
export(hai_kmeans_tidy_tbl)
export(hai_kmeans_user_item_tbl)
export(hai_knn_data_prepper)
export(hai_kurtosis_vec)
export(hai_polynomial_augment)
export(hai_range_statistic)
Expand Down
46 changes: 46 additions & 0 deletions R/data-prep-knn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#' Prep Data for k-NN - Recipe
#'
#' @family Preprocessor
#' @family knn
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details This function will automatically prep your data.frame/tibble for
#' use in the k-NN algorithm. The k-NN algorithm is a lazy learning classification
#' algorithm. It expects data to be presented in a certain fashion.
#'
#' This function will output a recipe specification.
#'
#' @description Automatically prep a data.frame/tibble for use in the k-NN algorithm.
#'
#' @param .data The data that you are passing to the function. Can be any type
#' of data that is accepted by the `data` parameter of the `recipes::reciep()`
#' function.
#' @param .recipe_formula The formula that is going to be passed. For example
#' if you are using the `iris` data then the formula would most likely be something
#' like `Species ~ .`
#'
#' @examples
#' hai_knn_data_prepper(.data = Titanic, .recipe_formula = Survived ~ .)
#' rec_obj <- hai_knn_data_prepper(iris, Species ~ .)
#' get_juiced_data(rec_obj)
#'
#' @return
#' A recipe object
#'
#' @export
#'

hai_knn_data_prepper <- function(.data, .recipe_formula){

# Recipe ---
rec_obj <- recipes::recipe(.recipe_formula, data = .data) %>%
recipes::step_novel(recipes::all_nominal_predictors()) %>%
recipes::step_dummy(recipes::all_nominal_predictors(), one_hot = TRUE) %>%
recipes::step_zv(recipes::all_predictors()) %>%
recipes::step_normalize(recipes::all_numeric())

# Return ----
return(rec_obj)

}
3 changes: 2 additions & 1 deletion man/hai_data_impute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/hai_data_poly.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/hai_data_scale.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/hai_data_transform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/hai_data_trig.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions man/hai_knn_data_prepper.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b67476

Please sign in to comment.