Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model size on disk way bigger than in memory

Tags:

r

r-caret

I created bagged tree model method = "treebag"using the caret package in R and the resulting model size is 12 Mb when viewing in R-Studio. But when I save to disk for later use with save() the size on disk increases to 151 Mb! Using different compression schemes brings the size down a bit but all are still way larger than in memory. Anyone successfully dealt with this problem?

like image 418
jtdoud Avatar asked Sep 19 '25 16:09

jtdoud


1 Answers

The likely reason is that the enclosing environment associated with objects is not considered in the results of object.size(), but is written to disk when saved. Use the pryr::object_size() function to see the object size with environment included. More explanation can be found at: http://adv-r.had.co.nz/memory.html#object-size

> object.size(m1)
16200200 bytes
> pryr::object_size(m1)
215 MB
> save(m1, file="m1.rda")
> file.info("m1.rda")$size
[1] 219475772

There also has been some discussion of this issue in another question: object.size() reports smaller size than .Rdata file

like image 125
LmW. Avatar answered Sep 22 '25 07:09

LmW.