Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 945
Nijan Avatar asked Aug 09 '17 23:08

Nijan


1 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.

like image 115
dronevil2 Avatar answered Sep 23 '22 19:09

dronevil2