learn: Learning models from data

View source: R/m01-Model.R

learnR Documentation

Learning models from data

Description

The learn function provides an abstraction that can be used to fit a binary classification model to a training data set.

Usage

learn(model, data, status, prune=keepAll)

Arguments

model

An object of the Modeler-class

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.

Details

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)
  }

Value

An object of the FittedModel-class.

Author(s)

Kevin R. Coombes <krc@silicovore.com>

See Also

See predict for how to make predictions on new test data from an object of the FittedModel-class.

Examples

# 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)

Modeler documentation built on Jan. 9, 2025, 3:01 a.m.