predict.CoreModel {CORElearn} | R Documentation |
Using a previously built model and new data, predicts the class value and probabilities for classification problem and function value for regression problem.
## S3 method for class 'CoreModel': predict(object, newdata, ..., costMatrix=NULL, dataFromFiles=FALSE, type=c("both","class","probability"))
object |
The model structure as returned by CoreModel . |
newdata |
Data frame with fresh data. |
costMatrix |
Optional cost matrix can provide nonuniform costs for classification problems. |
dataFromFiles |
Value TRUE specifies that the data for prediction shall be read directly from files. |
type |
Controls what will be return value in case of classification. |
... |
Other model dependent options for prediction. See optionCore . |
The function uses the object
structure as returned by CoreModel
and
applies it on the data frame newdata
. The newdata
must be transformable
using the formula specified for building the model (with dependent variable removed). If the dependent
variable is present in newdata
, it is ignored. In case of dataFromFiles=TRUE
the passed structure must be
matrix(nrow=numberOfPredicted,ncol=numberOfClasses)
for classification and
matrix(nrow=numberOfPredicted,ncol=1)
for regression problems.
Optional cost matrix can provide nonuniform costs for classification problems. For regression
problem this parameter is ignored. The costs can be different from the ones used for building the model
in CoreModel
.
If the data for the prediction is read read directly from files with dataFromFiles=TRUE
it has
to conform to data format of C4.5 (M5) or native format of CORElearn. Its
description is available at http://lkm.fri.uni-lj.si/rmarko/software/.
For regression model a vector of predicted values for given input instances. For classification
problem the parameter type
controls what is returned. With default value "both"
function returns a list with two components class
and probabilities
containing predicted class values and probabilities for all class values, respectively.
With type
set to "class"
or "probability"
the function returns only the selected component
as vector or matrix.
Marko Robnik-Sikonja, Petr Savicky
CORElearn
,
CoreModel
,
modelEval
,
optionCore
,
paramCoreIO
.
# use iris data set # build random forests model with certain parameters modelRF <- CoreModel(Species ~ ., iris, model="rf", selectionEstimator="MDL",minNodeWeight=5,rfNoTrees=100) print(modelRF) # prediction with node distribution pred <- predict(modelRF, iris, rfPredictClass=FALSE, type="both") print(pred)