Orange Forum • View topic - Creation of a new classifier.

Creation of a new classifier.

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

Creation of a new classifier.

Postby manisha » Thu Dec 01, 2011 17:22

Hello,

I have been trying to create my own classifier since a few days. I followed the instruction given in the documentation of "Classifiers in python" and subtyping a python class. My main purpose is to create my own classifier but be able to use orngTest and orngStat modules for validation and evaluation. Is it really possible to do it?

I tried to have a look at the available orange modules and do something similar. As a result now, my classifier works but I cannot use it with orngTest in order to validate the model with test examples. It gives me an error
Code: Select all
 File "/Library/Python/2.6/site-packages/orange/Orange/evaluation/testing.py", line 971, in test_on_data
    te.add_result(cr[0], cr[1])
TypeError: 'NoneType' object is unsubscriptable

I am unableto figure out the real cause of the problem and kind of blocked now. Can anyone help me please????


Thanking you in advance.

Re: Creation of a new classifier.

Postby Ales » Thu Dec 01, 2011 17:37

You need to return both the predicted value and a probability distribution from the classifiers __call__ method when requested (i.e. passed a 'orange.GetBoth' flag as the second argument).
See http://orange.biolab.si/doc/ofb-rst/learners_in_python.html for examples.

Re: Creation of a new classifier.

Postby manisha » Fri Dec 02, 2011 10:49

Thanks Ales,

I tried with that. Now it's giving another error.
Code: Select all
 File "/Library/Python/2.6/site-packages/orange/Orange/evaluation/testing.py", line 971, in test_on_data
    te.add_result(cr[0], cr[1])
  File "/Library/Python/2.6/site-packages/orange/Orange/evaluation/testing.py", line 259, in add_result
    if type(aclass.value)==float:
AttributeError: 'str' object has no attribute 'value'

I am unable to figure out these errors. :(

Re: Creation of a new classifier.

Postby Ales » Fri Dec 02, 2011 11:12

Wrap the returned predicted value in an instance of orange.Value, for the classifiers 'classVar' e.g. if you have the values string (for iris dataset)
Code: Select all
value = self.domain.classVar("Iris-setosa")
or equivalently
Code: Select all
value = orange.Value(self.domain.classVar, "Iris-setosa")
Both examples also work if you pass intiger indices to the constructors as demonstrated in the beginners tutorial.

Re: Creation of a new classifier.

Postby manisha » Fri Dec 02, 2011 11:58

It works now. Thanks a lot Ales.
One last question, just to know. While computing accuracy, we have an option of knowing the standard errors by setting resultSE=True. But when I do this for my classifier, it always returns only the accuracy. This is what I am doing

Code: Select all
  accuracy = orngStat.CA(res1, resultSE=True)
    print "Computation accuracy =", accuracy

and this is what I am getting:
Code: Select all
  Computation accuracy = [0.97777777777777775]

Is there anything I might be doing wrong?

Re: Creation of a new classifier.

Postby Ales » Fri Dec 02, 2011 12:14

I think the argument name is 'reportSE' not 'resultSE'. Try
Code: Select all
orngStat.CA(res1, reportSE=True)

Re: Creation of a new classifier.

Postby manisha » Fri Dec 02, 2011 13:28

Ah ok ok... It was very stupid of me.
Thanks for the help :)

Re: Creation of a new classifier.

Postby jcress410 » Thu Jan 26, 2012 3:57

Ales wrote:You need to return both the predicted value and a probability distribution from the classifiers __call__ method when requested (i.e. passed a 'orange.GetBoth' flag as the second argument).
See http://orange.biolab.si/doc/ofb-rst/learners_in_python.html for examples.



This link seems broken, and I can't find this file in the source....

can someone direct me to examples of implementing new classifiers?

Re: Creation of a new classifier.

Postby Ales » Thu Jan 26, 2012 11:05

jcress410 wrote:This link seems broken, and I can't find this file in the source....

can someone direct me to examples of implementing new classifiers?


Try this link http://orange.biolab.si/doc/tutorial/learners-in-python/

Re: Creation of a new classifier.

Postby jcress410 » Thu Jan 26, 2012 21:27

Thanks for the pointer, though I'm not entirely sure this is the documentation I'm looking for.

I need to set up a tree with a custom splitting criterion, are there documented examples of this?

Re: Creation of a new classifier.

Postby Ales » Fri Jan 27, 2012 12:07

jcress410 wrote:I need to set up a tree with a custom splitting criterion, are there documented examples of this?

Two examples I can find in the code base are: http://orange.biolab.si/trac/browser/orange/orange/Orange/multitarget/tree.py and http://orange.biolab.si/trac/browser/orange/orange/Orange/ensemble/forest.py#L480 (the last one is no longer actually used in random forests, it was replaced by SimpleTreeLearner).

Make sure to also read the documentation on trees (http://orange.biolab.si/doc/reference/Orange.classification.tree/) and attribute scoring measures (http://orange.biolab.si/doc/reference/Orange.feature.scoring/#base-classes)


Return to Questions & Support



cron