Learn R Programming

JOUSBoost (version 2.1.0)

predict.jous: Create predictions

Description

Makes a prediction on new data for a given fitted jous model.

Usage

# S3 method for jous
predict(object, X, type = c("response", "prob"), ...)

Arguments

object

An object of class jous returned by the jous function.

X

A design matrix of predictors.

type

The type of prediction to return. If type="response", a class label of -1 or 1 is returned. If type="prob", the probability \(p(y=1|x)\) is returned.

...

Value

Returns a vector of class predictions if type="response", or a vector of class probabilities \(p(y=1|x)\) if type="prob".

Examples

Run this code
# NOT RUN {
# Generate data from Friedman model #
set.seed(111)
dat = friedman_data(n = 500, gamma = 0.5)
train_index = sample(1:500, 400)

# Apply jous to adaboost classifier
class_func = function(X, y) adaboost(X, y, tree_depth = 2, n_rounds = 100)
pred_func = function(fit_obj, X_test) predict(fit_obj, X_test)

jous_fit = jous(dat$X[train_index,], dat$y[train_index], class_func,
                pred_func, keep_models=TRUE)
# get class prediction
yhat = predict(jous_fit, dat$X[-train_index, ])
# get probability estimate
phat = predict(jous_fit, dat$X[-train_index, ], type="prob")
# }

Run the code above in your browser using DataLab