python - Cannot pickle Scikit learn NearestNeighbor classifier - can't pickle instancemethod objects -


i'm trying pickle nearestneighbor model says can't pickle instancemethod objects.

the code:

import cpickle pickle sklearn.neighbors import nearestneighbors  nbrs = nearestneighbors(n_neighbors=50, algorithm='ball_tree', metric=self.distancecie2000_classifier) nbrs.fit(allvalues) open('/home/ubuntu/nbrs.p','wb') f:        pickle.dump(nbrs, f) 

the full traceback:

  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 

somewhere within nearestneighbors instance attribute refers instance method passed in metric argument. pickle won't pickle instance methods, hence error.

one way around move method distancecie2000_classifier() out of class regular standalone function, if possible.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -