Orange Forum • View topic - Predictions using script

Predictions using script

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

Predictions using script

Postby vnams » Thu Jul 05, 2007 18:02

This is from a newbie. I am trying random forests. Since they are not in a widget I am using scripts. How can I get predictions for another data set? I can do this using one of the other classifiers that have widgets. I tried the code to create a random forest widget, posted at
"Random Forest on Canvas(as a widget)", but it doesn't seem to give predictions. I've looked in the documentation but haven't found any info. Or even better would be a random forests widget that worked correctly.
Thanks, Vilis Nams

Postby marko » Sun Jul 08, 2007 21:32

We have already implemented the widget. As it is still quite new, we haven't tested it thoroughly yet. Therefore you can find it in "Prototypes" tag. It is hidden behind one of those "question mark" icons.

If you can't find the widget in your Orange Canvas, try with a new snapshot.

Predicting new examples in scripts is not that hard. A short example follows.

First you need to build a classifier:
Code: Select all
import orange, orngEnsemble
data = orange.ExampleTable("")
learner = orngEnsemble.RandomForestLearner(trees=100)
classifier = learner(data)

You can now load new data and use already built classifier for prediction. A bit of caution is needed: domains need to be the same.
Code: Select all
data2 = orange.ExampleTable("")
print classifier(data2[0])    #predict first example from data2

You can also create a new example on the fly (domain has to stay the same):
Code: Select all
example = orange.Example(data.domain, ["first","adult","female","?"])
print classifier(example)

If you need any further clarification, don't hesitate to ask.


Return to Questions & Support