brif {brif}R Documentation

Build a model (and make predictions)


Depending on the arguments supplied, the function brif.formula, brif.default or brif.trainpredict will be called.


brif(x, ...)



a data frame or a formula object.


arguments passed on to brif.formula, brif.default or brif.trainpredict.


a data frame, a vector or a list. If newdata is supplied, prediction results for newdata will be returned in a data frame or a vector, depending on the problem type (classification or regression) and the type argument; otherwise, an object of class "brif" is returned, which is to be used in the function predict.brif for making predictions. See brif.default for components of the "brif" object.


trainset <- sample(1:nrow(iris), 0.5*nrow(iris))
validset <- setdiff(1:nrow(iris), trainset)

# Train and predict at once 
pred_scores <- brif(Species~., data = iris, subset = trainset, 
                    newdata = iris[validset, 1:4], type = 'score')
pred_labels <- brif(Species~., data = iris, subset = trainset, 
                    newdata = iris[validset, 1:4], type = 'class')

# Confusion matrix
table(pred_labels, iris[validset, 5])

# Accuracy
sum(pred_labels == iris[validset, 5])/length(validset)

# Train using the formula format
bf <- brif(Species~., data = iris, subset = trainset)

# Or equivalently, train using the data.frame format
bf <- brif(iris[trainset, c(5,1:4)])

# Make a prediction 
pred_scores <- predict(bf, iris[validset, 1:4], type = 'score')
pred_labels <- predict(bf, iris[validset, 1:4], type = 'class')

# Regression
bf <- brif(mpg ~., data = mtcars)
pred <- predict(bf, mtcars[2:11])
plot(pred, mtcars$mpg)
abline(0, 1)

# Optionally, delete the model object to release memory
rm(list = c("bf"))

[Package brif version 1.4.1 Index]