Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(recipes)
- library(tidyverse)
- library(AppliedPredictiveModeling)
- data(AlzheimerDisease)
- predictors %>%
- cbind(diagnosis) ->
- alzheimers
- alzheimers %>%
- mutate(male = factor(male),
- Genotype = fct_infreq(fct_lump(Genotype, n=3))) ->
- alzheimers
- # split data
- alzheimers %>%
- initial_split(prop=.9) ->
- alz_split
- alz_split %>%
- training() ->
- alz_train
- alz_split %>%
- testing() ->
- alz_test
- # scaling / basics process
- alz_train %>%
- recipe(diagnosis ~ ., .) %>%
- step_center(all_numeric()) %>%
- step_scale(all_numeric()) %>%
- prep(training=alz_train) ->
- alz_preprocess
- # feature reduction
- alz_preprocess %>%
- step_corr(all_numeric()) %>%
- step_nzv(all_predictors()) %>%
- step_zv(all_predictors()) %>%
- step_pca(all_numeric()) %>%
- step_upsample(diagnosis) %>%
- prep(training=alz_train, retain=TRUE) ->
- alz_preprocess
- # prep training
- alz_preprocess %>%
- juice(all_outcomes(), all_predictors()) ->
- alz_train_p
- # prep test
- alz_preprocess %>%
- bake(alz_test) ->
- alz_test_p
Add Comment
Please, Sign In to add comment