Learn R Programming

mlr (version 2.8)

predict.WrappedModel: Predict new data.

Description

Predict the target variable of new data using a fitted model. What is stored exactly in the [Prediction] object depends on the predict.type setting of the Learner. If predict.type was set to “prob” probability thresholding can be done calling the setThreshold function on the prediction object.

The row names of the input task or newdata are preserved in the output.

Usage

"predict"(object, task, newdata, subset, ...)

Arguments

object
[WrappedModel] Wrapped model, result of train.
task
[Task] The task. If this is passed, data from this task is predicted.
newdata
[data.frame] New observations which should be predicted. Pass this alternatively instead of task.
subset
[integer | integer] An index vector specifying the training cases to be used for fitting. By default the complete data set is used. Logical vectors will be transformed to integer with which.
...
[any] Currently ignored.

Value

[Prediction].

See Also

Other predict: asROCRPrediction, getPredictionProbabilities, getPredictionResponse, plotViperCharts, setPredictThreshold, setPredictType

Examples

Run this code
# train and predict
train.set = seq(1, 150, 2)
test.set = seq(2, 150, 2)
model = train("classif.lda", iris.task, subset = train.set)
p = predict(model, newdata = iris, subset = test.set)
print(p)
predict(model, task = iris.task, subset = test.set)

# predict now probabiliies instead of class labels
lrn = makeLearner("classif.lda", predict.type = "prob")
model = train(lrn, iris.task, subset = train.set)
p = predict(model, task = iris.task, subset = test.set)
print(p)
getPredictionProbabilities(p)

Run the code above in your browser using DataLab