Some fixes + refactoring
[agghoo.git] / example / example.R
1 library(agghoo)
2
3 data(iris) #already there
4 library(mlbench)
5 data(PimaIndiansDiabetes)
6
7 # Run only agghoo on iris dataset (split into train/test, etc).
8 # Default parameters: see ?agghoo and ?AgghooCV
9 compareTo(iris[,-5], iris[,5], agghoo_run)
10
11 # Run both agghoo and standard CV, specifiying some parameters.
12 compareTo(iris[,-5], iris[,5], list(agghoo_run, standardCV_run), gmodel="tree")
13 compareTo(iris[,-5], iris[,5], list(agghoo_run, standardCV_run),
14 gmodel="knn", params=c(3, 7, 13, 17, 23, 31),
15 CV = list(type="vfold", V=5, shuffle=T))
16
17 # Run both agghoo and standard CV, averaging errors over N=10 runs
18 # (possible for a single method but wouldn't make much sense...).
19 compareMulti(PimaIndiansDiabetes[,-9], PimaIndiansDiabetes[,9],
20 list(agghoo_run, standardCV_run), N=10, gmodel="rf")
21
22 # Compare several values of V
23 compareRange(PimaIndiansDiabetes[,-9], PimaIndiansDiabetes[,9],
24 list(agghoo_run, standardCV_run), N=10, V_range=c(10, 20, 30))
25
26 # For example to use average of squared differences.
27 # Default is "mean(abs(y1 - y2))".
28 loss2 <- function(y1, y2) mean((y1 - y2)^2)
29
30 # In regression on artificial datasets (TODO: real data?)
31 data <- mlbench.twonorm(300, 3)$x
32 target <- rowSums(data)
33 compareMulti(data, target, list(agghoo_run, standardCV_run),
34 N=10, gmodel="tree", params=c(1, 3, 5, 7, 9), loss=loss2,
35 CV = list(type="MC", V=12, test_size=0.3))
36
37 compareMulti(data, target, list(agghoo_run, standardCV_run),
38 N=10, floss=loss2, CV = list(type="vfold", V=10, shuffle=F))
39
40 # Random tests to check that method doesn't fail in 1D case
41 M <- matrix(rnorm(200), ncol=2)
42 compareTo(as.matrix(M[,-2]), M[,2], list(agghoo_run, standardCV_run), gmodel="knn")
43 compareTo(as.matrix(M[,-2]), M[,2], list(agghoo_run, standardCV_run), gmodel="tree")