Reputation: 989
I am trying to aggregate in a list multiple CART models built with rpart::rpart
.
I just realised that each model stores quite a lot of (meta?)data in $terms
and $where
(over 10MB of data per model in my case) which makes my final list un-manageable.
It seems to me that the summary given by print(my_rpart_object)
should be sufficient to describe the object and run predictions, so I wonder if there is a way to trim / compress rpart trees?
Upvotes: 2
Views: 456
Reputation: 113
I was struggling with this as well. I found setting the "where" element of the rpart tree to NULL significantly reduced the tree's memory footprint:
rpart_model <- rpart(...)
rpart_model$where <- NULL
Upvotes: 1
Reputation: 989
Found it: each rpart
object was carrying an environment with it. To remove it :
rpart_model <- rpart(...)
environment(rpart_model$terms) <- NULL
List of 21 part objects went from 1.2GB to 8MB.
Upvotes: 2