predict.MOA_trainedmodel: Predict using a MOA classifier on a new dataset

Description Usage Arguments Value See Also Examples

View source: R/train.R

Description

Predict using a MOA classifier on a new dataset. Make sure the new dataset has the same structure and the same levels as get_points returns on the datastream which was used in trainMOA

Usage

1
2
3
## S3 method for class 'MOA_trainedmodel'
predict(object, newdata, type = "response",
  transFUN = object$transFUN, ...)

Arguments

object

an object of class MOA_trainedmodel, as returned by trainMOA

newdata

a data.frame with the same structure and the same levels as used in trainMOA

type

a character string, either 'response' or 'votes'

transFUN

a function which is used on newdata before applying model.frame. Useful if you want to change the results get_points on the datastream (e.g. for making sure the factor levels are the same in each chunk of processing, some data cleaning, ...). Defaults to transFUN available in object.

...

other arguments, currently not used yet

Value

A matrix of votes or a vector with the predicted class

See Also

trainMOA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Hoeffdingtree
hdt <- HoeffdingTree(numericEstimator = "GaussianNumericAttributeClassObserver")
data(iris)
## Make a training set
iris <- factorise(iris)
traintest <- list()
traintest$trainidx <- sample(nrow(iris), size=nrow(iris)/2)
traintest$trainingset <- iris[traintest$trainidx, ]
traintest$testset <- iris[-traintest$trainidx, ]
irisdatastream <- datastream_dataframe(data=traintest$trainingset)
## Train the model
hdtreetrained <- trainMOA(model = hdt,
 Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width,
 data = irisdatastream)

## Score the model on the holdoutset
scores <- predict(hdtreetrained,
   newdata=traintest$testset[, c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")],
   type="response")
str(scores)
table(scores, traintest$testset$Species)
scores <- predict(hdtreetrained, newdata=traintest$testset, type="votes")
head(scores)

RMOA documentation built on May 29, 2017, 8:58 p.m.