# NOT RUN {
#ksvm classification
library(kernlab)
#note we pass prob.model=TRUE as gensemble requires the probabilities for classification.
ksvm_model_args <- list(prob.model=TRUE, type="C-svc", C=1, epsilon=0.1)
#create the abstract model instance
abm <- ab.create(model.call="ksvm", model.args=ksvm_model_args, predict.args=list(type="probabilities"), xtrans=as.matrix)
#nnet classification
library(nnet)
#use the formula
abm <- ab.create(model.call="nnet", model.args=list(size=3), formula=TRUE)
#rpart classification
library(rpart)
abm <- ab.create(model.call="rpart", model.args=list(control=rpart.control(minsplit=0)), predict.args=list(type='prob'))
#classification test stub (try with the different abm's from above)
X <- iris[,1:4]
Y <- iris[,5]
#generate train/test samples
cnt <- nrow(iris)
samp <- sample(1:cnt, cnt * 0.7, rep=FALSE)
#train the model
mod <- ab.model(abm, X[samp,], Y[samp])
#get the predictions
preds <- ab.predict(abm, mod, X[-samp,])
#compare to actual classes
cbind(apply(preds, 1, which.max), Y[-samp])
#ksvm regression
library(kernlab)
abm <- ab.create(model.call="ksvm", xtrans=as.matrix)
#nnet regression
library(nnet)
abm <- ab.create(model.call="nnet", model.args=list(size=3, linout=TRUE, maxit=400, rang=0.001, decay=0.0001), xtrans=as.matrix)
#rpart regression
library(rpart)
abm <- ab.create(model.call="rpart", model.args=list(method='anova', control=rpart.control(minsplit=2, cp=1e-03)))
#regression test stub
X <- trees[,1:2]
Y <- trees[,3]
#generate train/test samples
cnt <- nrow(trees)
samp <- sample(1:cnt, cnt * 0.7, rep=FALSE)
#build the model
mod <- ab.model(abm, X[samp,], Y[samp])
#try some predictions
preds <- ab.predict(abm, mod, X[-samp,])
#compare vs actual values
cbind(preds, Y[-samp])
# }
Run the code above in your browser using DataLab