# use iris data set
# build random forests model with certain parameters
modelRF <- CoreModel(Species ~ ., iris, model="rf",
selectionEstimator="MDL",minNodeWeight=5,rfNoTrees=100)
print(modelRF)
# build decision tree with naive Bayes in the leaves
modelDT <- CoreModel(Species ~ ., iris, model="tree", modelType=4)
print(modelDT)
# build regression tree similar to CART
instReg <- regDataGen(200)
modelRT <- CoreModel(response~., instReg, model="regTree", modelTypeReg=1)
print(modelRT)
# build kNN kernel regressor by preventing tree splitting
modelKernel <- CoreModel(response~., instReg, model="regTree",
modelTypeReg=7, minNodeWeight=Inf)
print(modelKernel)
# A more complex example demonstrating also destroyModels() follows.
# Test accuracy of random forest predictor with 20 trees on iris data
# using 10-fold cross-validation.
ncases <- nrow(iris)
ind <- ceiling(10*(1:ncases)/ncases)
ind <- sample(ind,length(ind))
pred <- rep(NA,ncases)
fit <- NULL
for (i in unique(ind)) {
# Delete the previous model, if there is one.
if (!is.null(fit)) destroyModels(fit)
fit <- CoreModel(Species ~ ., iris[ind!=i,], model="rf", rfNoTrees=20)
pred[ind==i] <- predict.CoreModel(fit, iris[ind==i,], type="class")
}
table(pred,iris$Species)
Run the code above in your browser using DataLab