Learn R Programming

literanger (version 0.2.0)

write_literanger: Serialize random forest

Description

Write a random forest to a file or connection using light-weight serialization for C++ objects.

Usage

write_literanger(object, file, verbose = FALSE, ...)

Arguments

object

A trained random forest literanger object.

file

A connection or the name of the file where the literanger object will be saved.

verbose

Show additional serialization information (not implemented).

...

Further arguments passed to saveRDS().

Author

stephematician stephematician@gmail.com

Details

This function uses 'cereal' light-weight serialization to write a literanger object (random forest) to a file or connection. The file can be read in via read_literanger() and used for prediction with no requirement for the original training data.

See Also

read_literanger() saveRDS

Examples

Run this code
## Classification forest
train_idx <- sample(nrow(iris), 2/3 * nrow(iris))
iris_train <- iris[ train_idx, ]
iris_test  <- iris[-train_idx, ]
lr_iris <- train(data=iris_train, response_name="Species")
file <- tempfile()
write_literanger(lr_iris, file)
lr_copy <- read_literanger(file)
pred_bagged <- predict(lr_copy, newdata=iris_test, prediction_type="bagged")

Run the code above in your browser using DataLab