Orange Forum • View topic - apply classifier to unknown data not possible?

apply classifier to unknown data not possible?

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

apply classifier to unknown data not possible?

Postby chappo » Tue Apr 13, 2010 16:46

Hey guys,

I am new to Orange as well as to Machine Learning in general.
I played around with some sample scripts about Bayes-Learning provided by orange.
In case classifier.py: "the script loads the data, uses it to constructs a classifier using naive Bayesian method, and then classifies first five instances of the data"

But isnt it often the aim to predict classes for unknown instances? I couldnt find any example.
I tried something like:

Code: Select all
import orange
data = orange.ExampleTable("../data/cartheft.tab")
classifier = orange.BayesLearner(data)

for i in range(10):
    c = classifier(['Red', 'SUV', 'Imported', '?'])
    print "original", data[i].getclass(), "classified as", c


But what I got was:
TypeError: attribute error; example (and, optionally, return type) expected


Instances of the data set look as follows:
Yellow, SUV, Domestic, No
Red, SUV, Imported, Yes

where Red, SUV, Imported not is included.
So I would like to classify this instances as yes or no.


Have I mixed something up in general or could you give me an example to predict unknown instances?


Cheers!

Postby marko » Tue Apr 13, 2010 18:25

Instead of a list you should pass an Example with the same domain as the learning data to the classifier. For example:
Code: Select all
test_example = orange.Example(data.domain, ['Red', 'SUV', 'Imported', '?'])
c = classifier(test_example)

Postby chappo » Wed Apr 14, 2010 10:52

marko wrote:Instead of a list you should pass an Example with the same domain as the learning data to the classifier. For example:
Code: Select all
test_example = orange.Example(data.domain, ['Red', 'SUV', 'Imported', '?'])
c = classifier(test_example)


That works. Thanks a lot!

Re: apply classifier to unknown data not possible?

Postby rakirk » Sat Apr 14, 2012 16:08

FYI- this can also happen if you attempt to cross-validate a learner that has already classified a data set. For instance:

Code: Select all
nbn=orange.BayesLearner(data)
learners=[nbn,]
orngTest.crossValidation(learners,trainingData,len(data))


will reproduce this error, while


Code: Select all
nbn=orange.BayesLearner()
learners=[nbn,]
orngTest.crossValidation(learners,trainingData,len(data))


will not


Return to Questions & Support



cron