This is actually not related to sklearn at all, but I run into it often
enough that I'm replying here anyway: Pickle dumps an object (first
parameter) to a file (second parameter). I get those backwards all the time
and used to have a utility function to swap args if I got it backwards.
Also, it expects a file object, not a filename, so you actually want:
import cPickle as pickle # faster on Py2.x, default on Py3.
with open(filename, 'wb') as f:
pickle.dump(obj, f, -1)
The -1 at the end chooses the latest file format version, which is more
compact.
-Ken
On Wed, Oct 17, 2012 at 1:31 PM, Niall Twomey <[email protected]> wrote:
> Hi all.
>
> I want to save an array of models trained on lots of data to file. I have
> tried the following code (roughly speaking anyway)
>
>> models = []
>> # Populate the list of models with dict items containing one number and
>> PCA and GMM models
>> import pickle
>> pickle.dump( "models.pickle", models )
>
>
> but I get errors saying:
>
>> AttributeError: 'list' object has no attribute 'write'.
>
> which presumably referrs to the models list.
>
> Saving them to file is crucial for me, but I have no idea how to proceed
> from here. Any advice will be appreciated.
>
> Thanks.
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general