data(abr1)
dat <- preproc(abr1$pos[,110:500], method="log10")
cls <- factor(abr1$fact$class)
## tmp <- dat.sel(dat, cls, choices=c("1","2"))
## dat <- tmp[[1]]$dat
## cls <- tmp[[1]]$cls
idx <- sample(1:nrow(dat), round((2/3)*nrow(dat)), replace = FALSE)
## constrcuct train and test data
train.dat <- dat[idx,]
train.cl <- cls[idx]
test.dat <- dat[-idx,]
test.cl <- cls[-idx]
## estimates accuracy
res <- classifier(train.dat, train.cl, test.dat, test.cl,
method="randomForest")
res
## get confusion matrix
cl.rate(obs=res$cl, res$pred) ## same as: cl.rate(obs=test.cl, res$pred)
## Measurements of Forensic Glass Fragments
data(fgl, package = "MASS") # in MASS package
dat <- subset(fgl, grepl("WinF|WinNF",type))
## dat <- subset(fgl, type %in% c("WinF", "WinNF"))
x <- subset(dat, select = -type)
y <- factor(dat$type)
## construct train and test data
idx <- sample(1:nrow(x), round((2/3)*nrow(x)), replace = FALSE)
tr.x <- x[idx,]
tr.y <- y[idx]
te.x <- x[-idx,]
te.y <- y[-idx]
res.1 <- classifier(tr.x, tr.y, te.x, te.y, method="svm")
res.1
cl.rate(obs=res.1$cl, res.1$pred)
## classification performance for the two-class case.
pos <- "WinF" ## select positive level
cl.perf(obs=res.1$cl, pre=res.1$pred, pos=pos)
## ROC and AUC
cl.roc(stat=res.1$posterior[,pos],label=res.1$cl, pos=pos)
Run the code above in your browser using DataLab