Guest User

Untitled

a guest
Mar 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. library(recipes)
  2. library(tidyverse)
  3. library(AppliedPredictiveModeling)
  4.  
  5. data(AlzheimerDisease)
  6. predictors %>%
  7. cbind(diagnosis) ->
  8. alzheimers
  9.  
  10. alzheimers %>%
  11. mutate(male = factor(male),
  12. Genotype = fct_infreq(fct_lump(Genotype, n=3))) ->
  13. alzheimers
  14.  
  15. # split data
  16. alzheimers %>%
  17. initial_split(prop=.9) ->
  18. alz_split
  19.  
  20. alz_split %>%
  21. training() ->
  22. alz_train
  23.  
  24. alz_split %>%
  25. testing() ->
  26. alz_test
  27.  
  28. # scaling / basics process
  29. alz_train %>%
  30. recipe(diagnosis ~ ., .) %>%
  31. step_center(all_numeric()) %>%
  32. step_scale(all_numeric()) %>%
  33. prep(training=alz_train) ->
  34. alz_preprocess
  35.  
  36. # feature reduction
  37. alz_preprocess %>%
  38. step_corr(all_numeric()) %>%
  39. step_nzv(all_predictors()) %>%
  40. step_zv(all_predictors()) %>%
  41. step_pca(all_numeric()) %>%
  42. step_upsample(diagnosis) %>%
  43. prep(training=alz_train, retain=TRUE) ->
  44. alz_preprocess
  45.  
  46. # prep training
  47. alz_preprocess %>%
  48. juice(all_outcomes(), all_predictors()) ->
  49. alz_train_p
  50.  
  51. # prep test
  52. alz_preprocess %>%
  53. bake(alz_test) ->
  54. alz_test_p
Add Comment
Please, Sign In to add comment