How to calculate the actual size of a .fit()-trained model in sklearn?

Viewed 5083

Is it possible to calculate the size of a model ( let's say a Random Forest classifier ) in scikit-learn?

For example:

  from sklearn.ensemble import RandomForestClassifier
  clf = RandomForestClassifier(n_jobs=-1, n_estimators=10000, min_samples_leaf=50)
  clf.fit(self.X_train, self.y_train)

Can I determine the size of clf?

2 Answers

Along the same lines as Nijan's answer, you can also do it without having to save the model, using pickle:

import pickle
import sys

p = pickle.dumps(clf)
print(sys.getsizeof(p))

It will return the size in bytes.

Related