我正在尝试pickle NearestNeighbor模型,但它说无法pickle instancemethod对象。
代码:
import cPickle as pickle
from sklearn.neighbors import NearestNeighbors
nbrs = NearestNeighbors(n_neighbors=50, algorithm='ball_tree', metric=self.distanceCIE2000_classifier)
nbrs.fit(allValues)
with open('/home/ubuntu/nbrs.p','wb') as f:
pickle.dump(nbrs, f)
完整的回溯:
File "/home/ubuntu/colorSetter.py", line 82, in createClassifier
pickle.dump(nbrs, f)
File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle instancemethod objects