Newer
Older
notebooks / ccn2019-featsel.R
library(tidyverse)
library(caret)
library(here)
library(inspectdf)
library(glmnet)
library(ROSE)

rm(seqs)
load(here("notebooks/data/nback_seqs.Rd"))
seqs <- seqs %>% drop_na(rt, correct, tl,sl)

f <- correct ~ n + t + s + v + l + vl + sl + tl + ul + ll

set.seed(654321)

train.indices <- createDataPartition(seqs[[toString(f[[2]])]], p = .8, list =FALSE)

seqs.train.balanced <- seqs[train.indices,]
seqs.train <- ROSE(f, data = seqs.train.balanced)$data

seqs.train.x <- model.matrix(f, seqs.train)[,-1]
seqs.train.y <- seqs.train[[toString(f[[2]])]]

seqs.test  <- seqs[-train.indices,]
seqs.test.x <-  model.matrix(f, seqs.test)[,-1]
seqs.test.observed_y <- seqs.test[[toString(f[[2]])]]


ctrl <- rfeControl(functions = lrFuncs,
                   method = "cv",
                   number = 10,
                   verbose = T)

rmProfile <- rfe(seqs.train.x, seqs.train.y,
                 preProcess = c("nzv"),
                 rfeControl = ctrl)

rmProfile