Orange Forum • View topic - status of object pickling (saving trained classifiers)

status of object pickling (saving trained classifiers)

A place to ask questions about methods in Orange and how they are used and other general support.

status of object pickling (saving trained classifiers)

Postby kettle » Wed Nov 12, 2008 15:46

I've read several posts about the status of pickling, and there seems to be considerable confusion as to whether or not this feature is currently working.

I decided to try out pickling with a simple naivebayes classifier in the console, but it didn't quite work out:
Code: Select all
>>> import orange, orngBayes, pickle
>>> data = orange.ExampleTable("")
>>> bayes = orngBayes.BayesLearner( data, m=1 )
>>> pickle.dump(bayes,open("mypickle","wb"))
>>> obj = pickle.load(open("mypickle","rb"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/sandbox/lib/python2.5/", line 1370, in load
    return Unpickler(file).load()
  File "/root/sandbox/lib/python2.5/", line 858, in load
  File "/root/sandbox/lib/python2.5/", line 1224, in load_build
AttributeError: attribute 'variable' of 'orange.ContingencyClass' objects is not writable

it would be very useful to know what state this functionality is in. Is it still being tested? What is the recommended way to do it? Is there any documentation covering this?
Alternatively, are there any plans to implement a text-based alternative? It seems it would be sufficient to record the statistics in a text file and use this as a means to reconstitute a learner.


re: pickling

Postby kettle » Wed Nov 12, 2008 15:51

Ok now I see the unpickling issue is acknowledged, but I guess it's going to be a while?

Postby Janez » Wed Nov 12, 2008 22:47


implementing pickling is a huge task. Last year I thought I solved this by some general code and specific code for some (well, for quite a few classes). But then it surfaced that there are many more classes requiring exceptions. I began working on it (and the first class I hit was the naive Bayesian classifier, which you were playing with, too), but at the moment I'm so overburdened with other stuff not related to Orange, that I don't think I'll be able to do it any time soon.

I don't believe we'll venture into any general text-based alternatives since pickling is something we will most definitely support some day. But for naive Bayes it is, as you say, just the matter of saving some simple statistical data. Maybe take a look at the PMML format - not implemented in Orange, but it's rather trivial to do it.


Postby kettle » Thu Nov 13, 2008 4:36

Thanks for the reply. I'm sure this won't be of help to everyone, but a possible alternative is to integrate the your learner into a webframework like pylons or django (or build your own server).
I did this today, and it works perfectly fine for what I'm trying to do.
In my setup, I load the learner once, when I boot my webserver, then it is available to process requests for the duration of the application.
I need to retrain whenever I reboot the webserver, but this is much preferable to batch mode, or booting up the learner every time I need to process another piece of test data.
This also has the advantage of making it very easy to automatically retrain the classifier on new data.

Return to Questions & Support