learn {Modeler} | R Documentation |
The learn
function provides an abstraction that can be used to
fit a binary classification model to a training data set.
learn(model, data, status, prune=keepAll)
model |
An object of the |
data |
A matrix containing the training data, with rows as features and columns as samples to be classified. |
status |
A factor, with two levels, containing the known classification of the training data. |
prune |
A "pruning" funciton; that is, a funciton that takes two arguments (a data matrix and a class factor) and returns a logical vector indicating which features to retain. |
Objects of the Modeler-class
contain functions to learn
models from training data to make predictions on new test data. These
functions have to be prepared as pairs, since they have a shared
opinion about how to record and use specific details about the
parameters of the model. As a result, the learn function is
implemented by:
learn <- function(model, data, status) { model@learn(data, status, model@params, model@predict) }
An object of the FittedModel-class
.
Kevin R. Coombes <krc@silicovore.com>
See predict
for how to make predictions on new test data
from an object of the FittedModel-class
.
# set up a generic RPART model rpart.mod <- Modeler(learnRPART, predictRPART, minsplit=2, minbucket=1) # simulate fake data data <- matrix(rnorm(100*20), ncol=20) status <- factor(rep(c("A", "B"), each=10)) # learn the specific RPART model fm <- learn(rpart.mod, data, status) # show the predicted results from the model on the trianing data predict(fm) # set up a nearest neighbor model knn.mod <- Modeler(learnKNN, predictKNN, k=3) # fit the 3NN model on the same data fm3 <- learn(knn.mod, data, status) # show its performance predict(fm3)