3

我在iPython中从下面运行了网格搜索分类器:

http://scikit-learn.org/dev/auto_examples/grid_search_digits.html

然后尝试通过酸洗对其进行序列化,但收到以下回溯:

In [6]: with open('clf.pkl', 'wb') as f:
    cPickle.dump(clf, f)
   ...:     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-577559be619c> in <module>()
      1 with open('clf.pkl', 'wb') as f:
----> 2     cPickle.dump(clf, f)
      3 

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/copy_reg.pyc in     _reduce_ex(self, proto)
     68     else:
     69         if base is self.__class__:
---> 70             raise TypeError, "can't pickle %s objects" % base.__name__
     71         state = base(self)
     72     args = (self.__class__, base, state)

TypeError: can't pickle instancemethod objects

有解决办法吗?

我正在使用 iPython 和 sklearn 的最新测试版。

谢谢 :)

4

1 回答 1

1

网格搜索分类器用于保留所有创建泡菜问题的估计器。这个问题之前已经注意到解决了。这个补丁注释告诉你可以通过 pickling 来腌制分类器best_estimator_。在你的情况下,这将是:

cPickle.dump(clf.best_estimator_, f)
于 2012-08-17T14:14:41.117 回答