saveRF: the internal structure of given random forests model is saved to file. loadRF: the internal structure of random forests model is loaded from given file and a model is created and returned.
saveRF(model, fileName)loadRF(fileName)
Arguments
model: The model structure as returned by CoreModel.
fileName: Name of the file to save/load the model to/from.
Details
The function saveRF saves the internal structure of given random forests model to file. The structures from C++ code are stored to the file with specified file, while internal structures from R are stored to file named fileName.Rda. The model must be a valid structure returned by CoreModel.
The function loadRF loads the internal structure of random forests saved in a specified files and returns access to it.
Returns
saveRF invisibly returns some debugging information, while loadRF
returns a loaded model as a list, similarly to CoreModel.
Author(s)
Marko Robnik-Sikonja
See Also
CORElearn, CoreModel.
Examples
# use iris data set# build random forests model with certain parametersmodelRF <- CoreModel(Species ~ ., iris, model="rf", selectionEstimator="MDL",minNodeWeightRF=5, rfNoTrees=100, maxThreads=1)print(modelRF)# prediction with node distributionpred <- predict(modelRF, iris, rfPredictClass=FALSE, type="both")# print(pred)# saves the random forests model to filesaveRF(modelRF,"tempRF.txt")# restore the model to another modelloadedRF = loadRF("tempRF.txt")# prediction should be the samepredLoaded <- predict(loadedRF, iris, rfPredictClass=FALSE, type="both")# print(predLoaded)# sum of differences should be zero subject to numeric imprecision sum(pred$probabilities - predLoaded$probabilities)cat("Are predicted classes of original and retrieved models equal? ", all(pred$class == predLoaded$class),"\n")# cat("Are predicted probabilities of original and retrieved model equal? ", # all(pred$probabilities == predLoaded$probabilities), "\n" ) # clean up the models when no longer neededdestroyModels(modelRF)destroyModels(loadedRF)# clean up for the sake of R package checksfile.remove("tempRF.txt")file.remove("tempRF.txt.Rda")