Search code examples
pythonpython-3.xorange

Deploying Orange 3 models


Yes, I've read https://datascience.stackexchange.com/questions/23100/is-there-an-orange-server-to-deploy-the-models-developed-in-orange-3 .

What I mean I do not have to have Orange server (though obviously it would be nice to have it), but rather I would like to deploy the model developed in Orane somehow, e.g. replace an input data file and rerun the model built in Orange from command line to get some predictions out (or import Orange in Python code, load the model and tell it to use new set of data and get prediction out of it, which would be even better).


Solution

  • Use the Save Model widget to save the model into a pickle file, which you can then load into Python and use it to classify new data.

    Assuming that the model is save to "my_model.pkcls" and your (new) data is in "my_data.tab", do this in Python:

    import Orange
    import pickle
    
    model = pickle.load(open("my_model.pkcls", "rb"))
    data = Orange.data.Table("my_data.tab")
    print(model(data))
    

    For other ways to call the model, see the documentation, e.g. here: https://orange-data-mining-library.readthedocs.io/en/latest/tutorial/classification.html#learners-and-classifiers.