Hi Martin.

This might be solved by issue 565 
https://github.com/scikit-learn/scikit-learn/issues/565.
Maybe you should add there that keeping the estimators in memory also 
prevents pickling.

Cheers,
Andy


On 03/13/2012 03:11 PM, Martin Fergie wrote:
> Good Afternoon,
>
> I'm trying to pickle a class that contains a reference to a
> GridSearchCV object and it is failing due to an instancemethod type. I
> was under the impression that scikit-learn objects should be
> picklable, is this correct? If so, would it be appropriate for me to
> raise an issue?
>
> Information about the Exception is included below.
>
> Thanks,
> Martin
>
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> /tmp/<ipython-input-7-687becba8c7c>  in<module>()
> ---->  1 cPickle.dump(gs, te)
>
> /opt/epd-7.2/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
>
>
> print GridSearchCV:
>
> GridSearchCV(cv=sklearn.cross_validation.StratifiedKFold(labels=[ 1.
> 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
>    1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
>    0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
>    0.  0.  0.  0.  0.  0.], k=10),
>         estimator=LinearSVC(C=1.0, dual=True, fit_intercept=True,
> intercept_scaling=1,
>       loss='l2', multi_class=False, penalty='l2', tol=0.0001),
>         fit_params={}, iid=True, loss_func=None, n_jobs=4,
>         param_grid={'C': [1, 10, 100, 1000, 10000, 100000]},
>         pre_dispatch='2*n_jobs', refit=True, score_func=None, verbose=1)
>
>
> The method causing the problem is LinearSVC.predict:
>
>    
>> /opt/epd-7.2/lib/python2.7/copy_reg.py(70)_reduce_ex()
>>      
>       69         if base is self.__class__:
> --->  70             raise TypeError, "can't pickle %s objects" % 
> base.__name__
>       71         state = base(self)
>
> ipdb>  self
> <bound method LinearSVC.predict of LinearSVC(C=1, dual=True,
> fit_intercept=True, intercept_scaling=1, loss='l2',
>       multi_class=False, penalty='l2', tol=0.0001)>
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>    


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to