title: Inspect object attribute pickling sizes
body: <p>My object pickle dump is unexpectedly huge. I'd like to investigate which attribute causes that. How do I do that?</p>
  
  <p>I've tried both <code>sys.getsizeof</code> and <code>pympler.asizeof</code>, they didn't give me the answer.</p>
  
  <p>This question is more of the general approach, but if you really want to know, my object is a sklearn trained logicstic regression model. My pickle dump is 500MB, but none of the individual attributes from <code>dir(model)</code> reflects it:</p>
  
  <pre><code>import sys
  from pympler.asizeof import asizeof
  for a in dir(clf):
      print('%25s\t%10d\t%10d' %(a, sys.getsizeof(getattr(clf, a)), asizeof(getattr(clf, a))))
  
                      C           28          32
              __class__         1464           0
            __delattr__           56          56
               __dict__          648        8944
                __dir__           72           0
                __doc__         8359        8360
                 __eq__           56          56
             __format__           72           0
                 __ge__           56          56
       __getattribute__           56          56
           __getstate__           64           0
                 __gt__           56          56
               __hash__           56          56
               __init__           64           0
      __init_subclass__           72           0
                 __le__           56          56
                 __lt__           56          56
             __module__           78          80
                 __ne__           56          56
                __new__           72           0
             __reduce__           72           0
          __reduce_ex__           72           0
               __repr__           64           0
            __setattr__           56          56
           __setstate__           64           0
             __sizeof__           72           0
                __str__           56          56
       __subclasshook__           72           0
            __weakref__           16          16
        _estimator_type           59          64
       _get_param_names           64           0
      _predict_proba_lr           64           0
           class_weight           16          16
               classes_         6536        6536
                  coef_          112         112
      decision_function           64           0
                densify           64           0
                   dual           24          24
                    fit           64           0
          fit_intercept           28          32
             get_params           64           0
             intercept_           96          96
      intercept_scaling           28          32
               max_iter           28          32
            multi_class           52          56
                n_iter_          100         104
                 n_jobs           28          32
                penalty           51          56
                predict           64           0
      predict_log_proba           64           0
          predict_proba           64           0
           random_state           16          16
                  score           64           0
             set_params           64           0
                 solver           58          64
               sparsify           64           0
                    tol           24          24
                verbose           24          24
             warm_start           24          24
  </code></pre>
  
  <p>My training data is around the 500MB scale, so I guess it was captured unnecessarily somewhere and I want to remove that when saving to file. Note that it's not that obvious because I do have some preprocessing sklearn pipeline before feeding the result into the classifier (not part of the pipe)</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>Some code, simplified from my actual company code:</p>
  
  <pre><code>clf = LogisticRegression(penalty="l2", C=100)
  clf.fit(X, target)
  with open(filepath, 'wb') as f:
      pickle.dump(clf, f)
  </code></pre>
  
  <p>Let me know what other information you think might be helpful.</p>