learn: Learning models from data

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/m01-Model.R

Description

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

Usage

1
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:

1
2
3
  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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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)

Example output

Loading required package: ClassDiscovery
Loading required package: cluster
Loading required package: oompaBase
Loading required package: ClassComparison
   A B
1  1 0
2  1 0
3  1 0
4  1 0
5  1 0
6  1 0
7  1 0
8  1 0
9  1 0
10 1 0
11 0 1
12 0 1
13 0 1
14 0 1
15 0 1
16 0 1
17 0 1
18 0 1
19 0 1
20 0 1
 [1] A A A A A A A A B A B B A B B B B B B B
Levels: A B

Modeler documentation built on May 7, 2019, 1:03 a.m.