Preparing for CRAN upload
[agghoo.git] / example / example.R
... / ...
CommitLineData
1library(agghoo)
2
3data(iris) #already there
4library(mlbench)
5data(PimaIndiansDiabetes)
6
7# Run only agghoo on iris dataset (split into train/test, etc).
8# Default parameters: see ?agghoo and ?AgghooCV
9compareTo(iris[,-5], iris[,5], agghoo_run)
10
11# Run both agghoo and standard CV, specifiying some parameters.
12compareTo(iris[,-5], iris[,5], list(agghoo_run, standardCV_run), gmodel="tree")
13compareTo(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...).
19compareMulti(PimaIndiansDiabetes[,-9], PimaIndiansDiabetes[,9],
20 list(agghoo_run, standardCV_run), N=10, gmodel="rf")
21
22# Compare several values of V
23compareRange(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))".
28loss2 <- function(y1, y2) mean((y1 - y2)^2)
29
30# In regression on artificial datasets (TODO: real data?)
31data <- mlbench.twonorm(300, 3)$x
32target <- rowSums(data)
33compareMulti(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
37compareMulti(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
41M <- matrix(rnorm(200), ncol=2)
42compareTo(as.matrix(M[,-2]), M[,2], list(agghoo_run, standardCV_run), gmodel="knn")
43compareTo(as.matrix(M[,-2]), M[,2], list(agghoo_run, standardCV_run), gmodel="tree")