Learn R Programming

bbl (version 0.1.5)

predict,bbl-method: Predict Response Group Using bbl Model

Description

Make prediction of response group identity based on trained model

Usage

# S4 method for bbl
predict(object, newdata = NULL, logit = TRUE,
  useC = TRUE, verbose = 1, naive = FALSE, progress.bar = FALSE)

Arguments

object

Object of class bbl containing trained model

newdata

Data frame of new data for which prediction is to be made. Columns must contain all of those in model@data. If column names are present, the columns will be matched based on them. Extra columns will be ignored. If column names are not provided, the columns should exactly match model@data predictor parts. If NULL, replaced by model@data (self-prediction).

logit

Return predictors whose logistic function gives probability; otherwise return probability itself.

useC

Use C++ version for posterior probability computation.

verbose

Verbosity level

naive

Naive Bayes. Skip all interaction terms.

progress.bar

Display progress of response group probability. Useful for large samples.

Value

Matrix of predictors/posterior proabilities with samples in rows and response groups in columns.

Details

Will use new data set for predictors and trained bbl model parameters and compute posterior probabilities of response group identity.

Examples

Run this code
# NOT RUN {
set.seed(154)

m <- 5
L <- 3
n <- 1000

predictors <- list()
for(i in 1:m) predictors[[i]] <- seq(0,L-1)
par0 <- randompar(predictors=predictors, h0=0, J0=0, dJ=0.5)
xi0 <- sample_xi(nsample=n, predictors=predictors, h=par0$h, J=par0$J) 

par1 <- randompar(predictors=predictors, h0=0.1, J0=0.1, dJ=0.5)
xi1 <- sample_xi(nsample=n, predictors=predictors, h=par1$h, J=par1$J) 

xi <- rbind(xi0,xi1)
y <- c(rep(0,n),rep(1,n))
dat <- cbind(data.frame(y=y),xi)
dat <- dat[sample(2*n),]
dtrain <- dat[seq(n),]
dtest <- dat[seq(n+1,2*n),]
ytest <- dtest[,'y']

model <- bbl(data=dtrain)
model <- train(model)

pred <- predict(object=model, newdata=dtest)
yhat <- apply(pred,1,which.max)-1
score <- mean(ytest==yhat)
score

auc <- pROC::roc(response=ytest, predictor=pred[,2], direction='<')$auc
auc
# }

Run the code above in your browser using DataLab