Learn R Programming

RSofia (version 1.1)

predict.sofia: Predict Method for Sofia-ml Model Fits

Description

Predicted values based on Sofia-ml model object.

Usage

"predict"(object, newdata, prediction_type, ... )

Arguments

object
sofia-ml object
newdata
If the model was fit with sofia.formula, a data frame; if it was fit with sofia.fit, a new set of X's
prediction_type
linear: use standard linear dot product for predictions; logistic: use prediction function of exp() / (1 + exp()) for prediction, in the manner of logistic regression
...
unused

Value

produces a numeric vector of predictions

See Also

sofia

Examples

Run this code

data(irismod)
i.TRAIN <- sample(1:nrow(irismod), 100)

model.logreg <- sofia(Is.Virginica ~ ., data=irismod[i.TRAIN,], learner_type="logreg-pegasos")
p <- predict(model.logreg, newdata=irismod[-1*i.TRAIN,], prediction_type = "logistic")
table(predicted=p>0.5, actual=irismod[-1*i.TRAIN,]$Is.Virginica)

model.pegasos <- sofia(Is.Virginica ~ ., data=irismod[i.TRAIN,], learner_type="pegasos")
d <- predict(model.pegasos, newdata=irismod[-1*i.TRAIN,], prediction_type = "linear")
table(predicted=d>0, actual=irismod[-1*i.TRAIN,]$Is.Virginica)

Run the code above in your browser using DataLab