# NOT RUN {
# Create a method that predict always the first class
# The model must be of the class 'fooModel'
mlpredict.fooModel <- function (model, newdata, ...) {
# Predict the first class with a random confidence
data.frame(
prediction = rep(model$classes[1], nrow(newdata)),
probability = sapply(runif(nrow(newdata)), function (score) {
max(score, 1 - score)
}),
row.names = rownames(newdata)
)
}
# }
# NOT RUN {
# Create a SVM predict method using the e1071 package (the class of SVM model
# from e1071 package is 'svm')
library(e1071)
mlpredict.svm <- function (dataset, newdata, ...) {
result <- predict(model, newdata, probability = TRUE, ...)
attr(result, 'probabilities')
}
# }
Run the code above in your browser using DataLab