-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable_selection_RFE.R
46 lines (34 loc) · 1.24 KB
/
variable_selection_RFE.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
############################################################
# Variable selection: By Recursive Feature Elimination (RFE)
###########################################################
str(nbFuncs)
func<- nbFuncs
index <- createMultiFolds(dataset$diagnosis,times=5)
varsize <- seq(1,30,by=2)
func$summary <- function(...) c(twoClassSummary(...),
defaultSummary(...))
varctrl <- rfeControl(method = "repeatedcv",
repeats = 5,
verbose = TRUE,
functions = func,
index = index)
set.seed(12345)
nbrfe <- rfe(x=dataset[,-1],
y=dataset$diagnosis,
sizes = varsize,
metric = "ROC",
rfeControl = varctrl)
opt_var <- predictors(nbrfe) # gives the variables with optimum effect
nbrfe$fit
nbrfe$resample
summary(nbrfe$resample)
#Plotting the result
trellis.par.set(caretTheme())
plot(nbrfe, type = c("g", "o"),
main= "Number of Variables Vs ROC",
xlab="Number of Variables",
col="green")
densityplot(nbrfe)
histogram(nbrfe)
# Taking the subset of variables that gives the optimum ROC with RFE
dataset_rfe <- dataset[,c("diagnosis",opt_var)]