-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCFS.R
More file actions
42 lines (26 loc) · 954 Bytes
/
Copy pathCFS.R
File metadata and controls
42 lines (26 loc) · 954 Bytes
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
runCFS <- function(data){
starttime <- Sys.time()
subset <- cfs(class~., data)
endtime <- Sys.time()
print("total time of execution")
print(endtime - starttime)
print("Number of subset fields")
print(length(subset))
#print(ncol(data))
classfld <- data[ncol(data)]
colindices <- grep(subset, colnames(data))
mydata <- cbind(data[colindices], classfld)
idx <- sample(1:nrow(data),trunc(.7*nrow(data)))
data_train <- mydata[idx,]
data_test <- mydata[-idx,]
accuracy <- 0
data_train$class <- as.factor(data_train$class)
data_test$class <- as.factor(data_test$class)
# train a model here
model <- train(class ~ ., method = "rpart", data = data_train) # Code for decision tree model
predictions <- predict(model, data_test, na.action = na.pass)
cm <- confusionMatrix(predictions, data_test$class)
accuracy <- cm$overall['Accuracy']
print(accuracy)
return (accuracy)
}