-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompareModelStrats.R
89 lines (75 loc) · 2.28 KB
/
CompareModelStrats.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
library(caret)
library(class)
library(ggplot2)
source("modelpipe.R")
load("prepared_datasets.RData")
fitModelWithNFeat = function(fitter, n, setname,
fold=5, seed=123) {cat(class(fitter), '\n')
if (n > ncol(xnorms[[setname]])) {
return(NA)
}
fsFitter = SolderedPipeFitter(
FastTSelector(nFeat=n),
fitter
)
fit = train(
fsFitter,
xnorms[[setname]],
ys[[setname]],
trControl = trainControl(
method = "cv",
number = fold,
seeds = as.list(rep(seed, times=fold+1))
)
)
return(list(
fit = fit,
acc = fit$results$Accuracy
))
}
fitters = list(
knn5 = KnnFitter(k=5),
knn9 = KnnFitter(k=9),
logistic = GlmFitter(lambda=1e-10),
l1 = GlmFitter(alpha=1, lambda=NULL),
l2 = GlmFitter(alpha=0, lambda=NULL),
lda = LdaFitter(),
dlda = dldaFitter,
rf = RandomForestFitter(),
ada = AdaFitter()
)
xnames = names(xnorms)
names(xnames) = xnames
modelFits10 = lapply(X=xnames, FUN=function(setname) {
return(lapply(X=fitters, FUN=function(fitter) {
fitModelWithNFeat(fitter=fitter, n=10, setname=setname)
}))
})
modelFits10Accs = sapply(
X = modelFits10,
FUN = function(u) {sapply(u, function(v) {v$fit$results$Accuracy})}
)
write.table(data.frame(M=rownames(modelFits10Accs), modelFits10Accs),
file="modelFits10Accs.tsv", sep="\t", row.names=FALSE)
## modelFits20 = lapply(X=xnames, FUN=function(setname) {
## return(lapply(X=fitters, FUN=function(fitter) {
## fitModelWithNFeat(fitter=fitter, n=20, setname=setname)
## }))
## })
## modelFits20Accs = sapply(
## X = modelFits20,
## FUN = function(u) {sapply(u, function(v) {v$acc})}
## )
## write.table(data.frame(M=rownames(modelFits20Accs), modelFits20Accs),
## file="modelFits20Accs.tsv", sep="\t", row.names=FALSE)
modelFits50 = lapply(X=xnames, FUN=function(setname) {
return(lapply(X=fitters, FUN=function(fitter) {
fitModelWithNFeat(fitter=fitter, n=50, setname=setname)
}))
})
modelFits50Accs = sapply(
X = modelFits50,
FUN = function(u) {sapply(u, function(v) {v$acc})}
)
write.table(data.frame(M=rownames(modelFits50Accs), modelFits50Accs),
file="modelFits50Accs.tsv", sep="\t", row.names=FALSE)