|
a |
|
b/bin/oner_class.r |
|
|
1 |
setwd(".") |
|
|
2 |
options(stringsAsFactors = FALSE) |
|
|
3 |
# library("clusterSim") |
|
|
4 |
|
|
|
5 |
library("OneR"); |
|
|
6 |
library(class) |
|
|
7 |
library(gmodels) |
|
|
8 |
source("./confusion_matrix_rates.r") |
|
|
9 |
|
|
|
10 |
threshold <- 0.5 |
|
|
11 |
|
|
|
12 |
fileName <- "../data/LungCancerDataset_AllRecords_NORM_27reduced_features.csv" |
|
|
13 |
prc_data_norm <- read.csv(file=fileName, head=TRUE,sep=",",stringsAsFactors=FALSE) |
|
|
14 |
|
|
|
15 |
cat("fileName: ", fileName, sep="") |
|
|
16 |
|
|
|
17 |
prc_data_norm <- prc_data_norm[sample(nrow(prc_data_norm)),] # shuffle the rows |
|
|
18 |
|
|
|
19 |
target_index <- dim(prc_data_norm)[2] |
|
|
20 |
|
|
|
21 |
training_set_perce = 80 |
|
|
22 |
cat("training_set_perce = ", training_set_perce, "\n", sep="") |
|
|
23 |
|
|
|
24 |
# the training set is the first 60% of the whole dataset |
|
|
25 |
training_set_first_index <- 1 # NEW |
|
|
26 |
training_set_last_index <- round(dim(prc_data_norm)[1]*training_set_perce/100) # NEW |
|
|
27 |
|
|
|
28 |
# the test set is the last 40% of the whole dataset |
|
|
29 |
test_set_first_index <- training_set_last_index+1 # NEW |
|
|
30 |
test_set_last_index <- dim(prc_data_norm)[1] # NEW |
|
|
31 |
|
|
|
32 |
cat("[Creating the subsets for the values]\n") |
|
|
33 |
prc_data_train <- prc_data_norm[training_set_first_index:training_set_last_index, 1:(target_index)] # NEW |
|
|
34 |
prc_data_test <- prc_data_norm[test_set_first_index:test_set_last_index, 1:(target_index)] # NEW |
|
|
35 |
|
|
|
36 |
prc_data_test_labels <- prc_data_norm[test_set_first_index:test_set_last_index, target_index] # NEW |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
print("dim(prc_data_train)") |
|
|
40 |
print(dim(prc_data_train)) |
|
|
41 |
|
|
|
42 |
print("dim(prc_data_test)") |
|
|
43 |
print(dim(prc_data_test)) |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
# #rf_new <- randomForest(Metastasis ~ ., data=prc_data_train, importance=TRUE, proximity=TRUE) |
|
|
47 |
|
|
|
48 |
|
|
|
49 |
# Original application of One Rule with all the dataset |
|
|
50 |
prc_model_train <- OneR(prc_data_train, verbose = TRUE) |
|
|
51 |
|
|
|
52 |
# Generation of the CART model |
|
|
53 |
# prc_model_train <- OneR(Metastasis ~ keep.side + platelet.count..PLT., method="class", data=prc_data_train); |
|
|
54 |
|
|
|
55 |
summary(prc_model_train) |
|
|
56 |
prediction <- predict(prc_model_train, prc_data_test) |
|
|
57 |
# eval_model(prediction, prc_data_test) |
|
|
58 |
|
|
|
59 |
prediction_binary <- as.numeric(prediction) -1 |
|
|
60 |
prc_data_test_PRED_binary <- data.frame(prediction) |
|
|
61 |
|
|
|
62 |
confusion_matrix_rates(prc_data_test_labels, prediction_binary, "@@@ Test set @@@") |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|