I'm using PYML to construct a multiclass linear support vector machine (SVM). After training the SVM, I would like to be able to save the classifier, so that on subsequent runs I can use the classifier right away without retraining. Unfortunately, the .save() function is not implemented for that classifier, and attempting to pickle it (both with standard pickle and cPickle) yield the following error message:
pickle.PicklingError: Can't pickle : it's not found as __builtin__.PySwigObject
Does anyone know of a way around this or of an alternative library without this problem? Thanks.
Edit/Update
I am now training and attempting to save the classifier with the following code:
mc = multi.OneAgainstRest(SVM());
mc.train(dataset_pyml,saveSpace=False);
for i, classifier in enumerate(mc.classifiers):
filename=os.path.join(prefix,labels[i]+".svm");
classifier.save(filename);
Notice that I am now saving with the PyML save mechanism rather than with pickling, and that I have passed "saveSpace=False" to the training function. However, I am still gettting an error:
ValueError: in order to save a dataset you need to train as: s.train(data, saveSpace = False)
However, I am passing saveSpace=False... so, how do I save the classifier(s)?
P.S.
The project I am using this in is pyimgattr, in case you would like a complete testable example... the program is run with "./pyimgattr.py train"... that will get you this error. Also, a note on version information:
[michaelsafyan@codemage /Volumes/Storage/classes/cse559/pyimgattr]$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import PyML
print PyML.__version__
0.7.0