Orange Forum • View topic - Train and Test on Separate Data

Train and Test on Separate Data

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

Train and Test on Separate Data

Postby trnichols » Wed Nov 07, 2012 5:00

Hello! I'm fairly new to Orange and had a question pertaining to training and testing on separate data. Consider the fact that I have two files (train) and (test). The (train) data has two class values (true and false), with 1000 line items classified as either true or false. The (test) data has a class but labeled as "unknown", which I want to be able to classify as either true or false. I'm able to use the:
res = Orange.evaluation.testing.learn_and_test_on_test_data(learners, train, test)
and get results to build my confusion matrix, but I really need to be able to see (print) each of the line item of the (test) data (after classification) to see how they were classified (true or false).

Is this possible? If someone is able to point me in the right direction, that would be great! I've been looking and trying many different approaches, but unable to find a solution. Your help is greatly appreciated!! THANKS!

~Tony

Re: Train and Test on Separate Data

Postby Ales » Wed Nov 07, 2012 11:33

The individual test instance results are stored in 'res.results' list (the class labels are stored as integer indices into the class_var.values)
Code: Select all
res = Orange.evaluation.testing.learn_and_test_on_test_data(learners, train, test)
for i, (result, instance) in enumerate(zip(res.results, test)):
    print "Test instance %i, (actual class: %i)" % (i, result.actual_class)
    print "\t", "\n\t".join("learner %r predicted %s" % (name, cls) for name, cls in
                            zip(res.classifier_names, result.classes))
    print


Also note that you need to provide correctly labeled test data for the 'learn_and_test_on_data' (the function itself makes sure the classifier does not see the correct class).

If you want to reuse the learned classifiers to classify new (unknown instances) pass store_classifiers=True to the 'learn_and_test_on_test_data function
Code: Select all
res = Orange.evaluation.testing.learn_and_test_on_test_data(learners, train, test, store_classifiers=True)
print res.classifiers

for i, new_instance in enumerate(new_data):
    print "Instance", i
    print "\t", "\n\t".join("%r predicted %s" % (classifier, classifier(new_instance)) \
                            for classifier in res.classifiers)

Re: Train and Test on Separate Data

Postby trnichols » Thu Nov 08, 2012 4:37

Ales,

Thank you!! Works great!

~ Tony


Return to Questions & Support