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
# S3 method for WrappedModel
predict(object, task, newdata, subset = NULL, ...)
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 oftask
.- subset
(integer | logical |
NULL
)
Selected cases. Either a logical or an index vector. By defaultNULL
if all observations are used.- ...
(any)
Currently ignored.
Value
(Prediction).
See also
Other predict:
asROCRPrediction()
,
getPredictionProbabilities()
,
getPredictionResponse()
,
getPredictionTaskDesc()
,
setPredictThreshold()
,
setPredictType()
Examples
# train and predict
train.set = seq(1, 150, 2)
test.set = seq(2, 150, 2)
model = train("classif.lda", iris.task, subset = train.set)
#> Error: Please use column names for `x`
p = predict(model, newdata = iris, subset = test.set)
#> Error in predict(model, newdata = iris, subset = test.set): object 'model' not found
print(p)
#> Error in print(p): object 'p' not found
predict(model, task = iris.task, subset = test.set)
#> Error in predict(model, task = iris.task, subset = test.set): object 'model' not found
# predict now probabiliies instead of class labels
lrn = makeLearner("classif.lda", predict.type = "prob")
model = train(lrn, iris.task, subset = train.set)
#> Error in x[0, , drop = FALSE]: incorrect number of dimensions
p = predict(model, task = iris.task, subset = test.set)
#> Error in predict(model, task = iris.task, subset = test.set): object 'model' not found
print(p)
#> Error in print(p): object 'p' not found
getPredictionProbabilities(p)
#> Error in checkClass(x, classes, ordered, null.ok): object 'p' not found