###################################################
### chunk number 1: 
###################################################
#line 109 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
library(MLInterfaces)
library(golubEsets)


###################################################
### chunk number 2: redu
###################################################
#line 112 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
data(Golub_Merge)
smallG <- Golub_Merge[200:259,]
smallG


###################################################
### chunk number 3: doknnB
###################################################
#line 120 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
#krun <- knnB( smallG, "ALL.AML", trainInd=1:40 )
krun = MLearn(ALL.AML~., smallG, knnI(k=1), 1:40)
krun


###################################################
### chunk number 4: lkco
###################################################
#line 128 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
confuMat(krun)


###################################################
### chunk number 5: lkco2
###################################################
#line 135 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
set.seed(1234)
#nns <- nnetB( smallG[1:10,], "ALL.AML", trainInd=1:40, size=2, decay=.01, maxit=250 )
nns <- MLearn( ALL.AML~., smallG[1:10,], nnetI, trainInd=1:40, size=2, decay=.01, maxit=250 )
nns
confuMat(nns)


###################################################
### chunk number 6:  eval=FALSE
###################################################
## #line 179 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
## summary(RObject(nns))


###################################################
### chunk number 7:  eval=FALSE
###################################################
## #line 184 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
## ags <- agnesB(smallG, k=4, height=0, stand=FALSE)


###################################################
### chunk number 8:  eval=FALSE
###################################################
## #line 186 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
## plot(RObject(ags), which.plot=2)


###################################################
### chunk number 9: lkci
###################################################
#line 194 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
getClass("learnerSchema")
getClass("xvalSpec")


###################################################
### chunk number 10: lkcc
###################################################
#line 200 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
getClass("classifierOutput")


###################################################
### chunk number 11: lkcl eval=FALSE
###################################################
## #line 207 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
## getClass("clustOutput")


###################################################
### chunk number 12: dox
###################################################
#line 233 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
library(golubEsets)
data(Golub_Merge)
smallG <- Golub_Merge[200:250,]
lk1 <- MLearn(ALL.AML~., smallG, knnI(k=1,l=0), xvalSpec("LOO"))
confuMat(lk1)


###################################################
### chunk number 13: doxr
###################################################
#line 241 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
ranpart = function(K, data) {
 N = nrow(data)
 cu = as.numeric(cut(1:N, K))
 sample(cu, size=N, replace=FALSE)
}
ranPartition = function(K) function(data, clab, iternum) {
 p = ranpart(K, data)
 which(p == iternum)
}
lkran <- MLearn(ALL.AML~., smallG, knnI(k=1,l=0), xvalSpec("LOG", 8, partitionFunc=ranPartition(8)))
confuMat(lkran)


###################################################
### chunk number 14: dox2
###################################################
#line 257 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
lk3 <- MLearn(ALL.AML~., smallG, knnI(k=1,l=0), xvalSpec("LOG", 8, partitionFunc=balKfold.xvspec(8)))
confuMat(lk3)


###################################################
### chunk number 15: dofs
###################################################
#line 270 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
data(iris)
iris2 = iris[ iris$Species %in% levels(iris$Species)[1:2], ]
iris2$Species = factor(iris2$Species) # drop unused levels
x1 = MLearn(Species~., iris2, ldaI, xvalSpec("LOG", 3,
   balKfold.xvspec(3), fs.absT(3)))
fsHistory(x1)


###################################################
### chunk number 16: getpp
###################################################
#line 292 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
predProb <- round(testScores(nns),3)


###################################################
### chunk number 17: gettrue
###################################################
#line 296 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
truth <- as.character(smallG$ALL.AML[-c(1:40)]) 
simpPred <- as.character(testPredictions(nns))


###################################################
### chunk number 18: mkclo
###################################################
#line 302 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
douClo <- function(pprob)  function(lo,hi) pprob>lo & pprob<hi


###################################################
### chunk number 19: evclo
###################################################
#line 307 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
smallDou <- douClo(predProb)


###################################################
### chunk number 20: repla
###################################################
#line 312 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
douPred <- simpPred
douPred[smallDou(.35,.65)] <- "doubt"


###################################################
### chunk number 21: lkpr
###################################################
#line 317 "vignettes/MLInterfaces/inst/doc/MLInterfaces.Rnw"
mm <- cbind(predProb,truth,simpPred,douPred)
mm
table(mm[,"truth"], mm[,"simpPred"])
table(mm[,"truth"], mm[,"douPred"])