Description Usage Arguments Value Author(s) References See Also Examples
fuse
provides a platform to take existing predictive models and combine there predictions into a single outcome.
1 2 3 4 5 6 7 8 9 10 11 |
mods |
a named list of models |
classes |
a character string of possible classes |
probs |
a logical: will the model predict class probabilities (as opposed to the discrete class) |
predict |
an optional list the same length as |
weights |
a numeric vector the same length as |
method |
usually a single method for combining the classifiers. Possible values are 'vote' (for majority vote), 'meanProb' (for weighted and unweighted averages of the class probabilities), 'prod' (the product of the class probabilities across models). Alternatively, a function with minimum arguments |
methodArgs |
an optional named list of arguments if a custom function is used with the |
... |
not currently used |
a list of class "fuse"
Max Kuhn
insert
predict.fuse
, ~~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ## Not run:
library(QSARdata)
data(Mutagen)
## Split the data three times into training and testing sets
library(caret)
set.seed(1)
inTrain <- createDataPartition(Mutagen_Outcome, p = 3/4, list = FALSE)
trainData <- Mutagen_Dragon[ inTrain,]
testData <- Mutagen_Dragon[-inTrain,]
trainClass <- Mutagen_Outcome[ inTrain]
testClass <- Mutagen_Outcome[-inTrain]
## There are some predictors with degenerate distirbutions, so
## remvoe these
isNZV <- nearZeroVar(trainData)
trainData <- trainData[, -isNZV]
testData <- testData[, -isNZV]
calData <- calData[, -isNZV]
## Make a copy opf the data in a single data frame
training <- trainData
training$Class <- trainClass
## Fit a random forest model
library(randomForest)
rfModel <- randomForest(Class ~ ., data = training)
## Now an SVM model
library(kernlab)
svmModel <- ksvm(as.matrix(trainData), trainClass, C = 4, prob.model = TRUE)
## Create a list of the models and associated prediction functions:
models <- list(rf = rfModel,
svm = svmModel)
pred <- list(function(x, dat, ...) predict(x, dat, type = "prob")[,1],
function(x, dat, ...) predict(x, dat, type = "probabilities")[,1])
fusedMods <- fuse(list(rf = rfModel, svm = svmModel),
probs = TRUE,
predict = pred,
method = "meanProb",
classes = levels(testClass))
confusionMatrix(predict(fusedMods, testData), testClass)
confusionMatrix(predict(rfModel, testData), testClass)
confusionMatrix(predict(svmModel, testData), testClass)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.