Search code examples
pythonmachine-learningdata-miningorange

Are we able to run Orange from Python program


Currently, I am using the Orange data mining software tool to experiment my data. Are we able to run Orange from Python script instead of using the software (can we write some python code to execute the program?). I have a Python script to generate data files.I want to write a Python script to use different functionalities from Orange. Is that possible. Do we have a tutorial for that? Thanks


Solution

  • Every component of Orange is run from Python, because Orange is written is Python. You can run individual components (say, for reading the data, data visualization and model inference) from Python as well. Documentation how to develop such components and run them is available in Widget Development Documentation. Besides unit tests for testing of GUI components, almost all widgets also include some test code which is executed just by runing the widgets directly from python (e.g., python OWRuleViewer.py).

    You can invoke one or a number of widgets from your own code as well. For example, the following code would run a rule viewer widget:

    import Orange
    from Orange.widgets.visualize.owruleviewer import OWRuleViewer
    from AnyQt.QtWidgets import QApplication
    from Orange.classification import CN2Learner
    
    data = Orange.data.Table("titanic")
    learner = Orange.classification.CN2Learner()
    model = learner(data)
    model.instances = data
    
    a = QApplication([])
    ow = OWRuleViewer()
    ow.set_classifier(model)
    
    ow.show()
    a.exec()
    

    This script first reads the data (on titanic passengers), then infers the classification rules using CN2, and passes this model to a rule viewer (OWRuleViewer). Rule viewer is an Orange widget that displays the rules, and for the above example could look like shown below. Notice that the interactive part of the widget (selection of rules and with that selection of examples from which the rules were developed) is not explored in the above script.

    titanic rules