-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainStandards.R
161 lines (138 loc) · 5.5 KB
/
mainStandards.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#' @description This function check the actual directory has a subdir called src
#' if exists it's a new working directory
setWorkspace <- function() {
files <- c("classifiers.R", "crossValidation.R", "database.R", "flexconc.R",
"functions.R", "statistics.R", "utils.R", "write.R")
if ("src" %in% list.dirs(full.names = F)) {
setwd("src")
} else if (all(files %in% list.files())) {
print("All files exists!")
} else {
stop("The follow file(s) are missing!\n", files[!files %in% list.files()])
}
}
options(java.parameters = "-Xmx4g")
setWorkspace()
scripts <- list.files(pattern = "*.R")
for (scri in scripts) {
source(scri)
}
Naive <- make_Weka_classifier("weka/classifiers/bayes/NaiveBayes", c("NaiveBayes", "bayes"))
DT <- make_Weka_classifier("weka/classifiers/rules/DecisionTable", c("DecisionTable", "rules"))
rm(scripts, scri)
baseClassifiers <- learner("J48", list(control = Weka_control(C = 0.05)))
extention <- ".csv"
label <- "class"
form <- as.formula("class ~ .")
funcType <- "probability"
meansFlexConC1S <- c()
method <- "Co-Training Standard"
databases <- c("Abalone.arff", "Arrhythmia.arff", "Car.arff", "Ecoli.arff",
"Glass.arff", "HillValley.arff", "KrVsKp.arff", "Leukemia.arff",
"Madelon.arff", "MultipleFeaturesKarhunen.arff", "Seeds.arff",
"Semeion.arff", "SolarFlare.arff", "SpectfHeart.arff",
"TicTacToeEndgame.arff", "Twonorm.arff", "Waveform.arff",
"Wine.arff", "Yeast.arff", "Haberman.arff", "PlanningRelax.arff",
"Btsc.arff", "MammographicMass.arff", "Pima.arff", "Sonar.arff",
"SolarFlare1.arff", "Ilpd.arff", "Automobile.arff",
"GermanCredit.arff", "Flags.arff", "Wilt.arff", "Vehicle.arff",
"Dermatology.arff", "PhishingWebsite.arff",
"ImageSegmentation.arff", "Mushroom.arff",
"OzoneLevelDetection.arff", "Nursery.arff", "Adult.arff",
"PenDigits.arff", "Musk.arff", "Cnae.arff")
learner <- baseClassifiers
myFuncs <- funcType
## Versions Standard and DWC Standard
bd <- 1
script_name <- "_CT_Strandard"
fileName <- paste("labelrate_", ratio * 100, "_select_", selection_rate * 100,
script_name, ".txt", sep = "")
for (dataset in databases) {
set.seed(19)
dataName <- strsplit(dataset, ".", T)[[1]][1]
originalDB <- read.arff(paste("../datasets", dataset, sep = "/"))
originalDB$class <- droplevels(originalDB$class)
dataL <- holdout(originalDB$class, .9)
dataTrain <- originalDB[dataL$tr, ]
dataTest <- originalDB[dataL$ts, ]
folds <- stratifiedKFold(dataTrain, dataTrain$class)
msg <- paste("DataSet[", bd, "]:\t", dataName, "\nParams:\n\t% Label: ",
ratio * 100, "%\n\t% Selected: ", selection_rate * 100, '%\n',
sep="")
cat(msg)
visao <- criar_visao(dataTrain)
dat1 <- visao[[1]]
dat2 <- visao[[2]]
visao_test <- criar_visao(dataTest)
data_test1 <- visao_test[[1]]
data_test2 <- visao_test[[2]]
acc_co <- c()
acc_co_v1 <- c()
acc_co_v2 <- c()
fscore_co <- c()
fscore_co_v1 <- c()
fscore_co_v2 <- c()
preci_co <- c()
preci_co_v1 <- c()
preci_co_v2 <- c()
recall_co <- c()
recall_co_v1 <- c()
recall_co_v2 <- c()
ite <- 1
begin <- Sys.time()
for (fold in folds) {
cat("It:\t", ite, "\n")
ite <- ite + 1
train1 <- dat1[-fold, ]
test1 <- dat1[fold, ]
train2 <- dat2[-fold, ]
test2 <- dat2[fold, ]
trainIds <- holdout(train1$class, ratio, mode = "random")
labelIds <- trainIds$tr
data1 <- newBase(train1, labelIds)
data2 <- newBase(train2, labelIds)
classDist <- ddply(train1[, ], ~class, summarise,
samplesClass = length(class))
co_training <- coTrainingOriginal(learner, myFuncs, data1, data2)
cm1 <- confusionMatrix(co_training[[1]], data_test1)
cm2 <- confusionMatrix(co_training[[2]], data_test2)
# Acurácia
acc_model1 <- getAcc(cm1)
acc_model2 <- getAcc(cm2)
acc_model_mean <- mean(c(acc_model1, acc_model2))
acc_co <- c(acc_co, acc_model_mean)
acc_co_v1 <- c(acc_co_v1, acc_model1)
acc_co_v2 <- c(acc_co_v2, acc_model2)
# Fscore
fscore_model1 <- fmeasure(cm1)
fscore_model2 <- fmeasure(cm2)
fscore_model_mean <- mean(c(fscore_model1, fscore_model2))
fscore_co <- c(fscore_co, fscore_model_mean)
fscore_co_v1 <- c(fscore_co_v1, fscore_model1)
fscore_co_v2 <- c(fscore_co_v2, fscore_model2)
# Precision
preci_model1 <- precision(cm1)
preci_model2 <- precision(cm2)
preci_model_mean <- mean(c(preci_model1, preci_model2))
preci_co <- c(preci_co, preci_model_mean)
preci_co_v1 <- c(preci_co_v1, preci_model1)
preci_co_v2 <- c(preci_co_v2, preci_model2)
# recall
recall_model1 <- recall(cm1)
recall_model2 <- recall(cm2)
recall_model_mean <- mean(c(recall_model1, recall_model2))
recall_co <- c(recall_co, recall_model_mean)
recall_co_v1 <- c(recall_co_v1, recall_model1)
recall_co_v2 <- c(recall_co_v2, recall_model2)
}
end <- Sys.time()
writeArchive(fileName, "../", dataName, method, acc_co, fscore_co, preci_co,
recall_co, begin, end)
writeArchive(paste('V1_', fileName, sep=""), "../", dataName, method,
acc_co_v1, fscore_co_v1, preci_co_v1, recall_co_v1, begin, end)
writeArchive(paste('V2_', fileName, sep=""), "../", dataName, method,
acc_co_v2, fscore_co_v2, preci_co_v2, recall_co_v2, begin, end)
cat("Arquivos do método ", method, " foram salvos.\n\n")
bd <- bd + 1
}
setwd('../')