Orange Forum • View topic - TypeError in C45Learner()?

TypeError in C45Learner()?

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

TypeError in C45Learner()?

Postby npo » Wed Apr 17, 2013 6:56

I have built an application that uses the Orange.classification.tree.C45Learner(). In it, I construct an empty Orange data table to which I add instances one by one. Then I pass the data table to C45Learner() as an argument in the usual way, namely:

Code: Select all
tree = Orange.classification.tree.C45Learner(data)


I've ran my application on a number of different case studies now. 95% of the time it works, and the C45Learner() will return a tree and function as intended. But it just will not work on some case studies. In these cases, I get the following error:

Code: Select all
Traceback (most recent call last): File "K:\\Python\\app\\treeprocessor.py", line 53, in run
    tree = Orange.classification.tree.C45Learner(data) TypeError: __init__() takes exactly 1 argument (2 given)


(My file treeprocessor.py is a subclass of multiprocessing.Process)

The error seems to suggest that C45Learner() is not expecting an argument (other than self, I suppose, behind the scenes). But I am not sure why this error occurs when I run certain case study datasets and not others. My code that produces the Orange data table that is the argument to C45Learner() does not change between datasets, and I only ever pass one argument (the data object) to the learner.

I am perplexed by this error. I can only assume, on my end, that there is some unseen quirk in the case study data that I use to build the data object for the learner, which is causing the data object to corrupt somehow. But this is not what the error message seems to suggest.

Any thoughts on what might be happening here?

Re: TypeError in C45Learner()?

Postby Ales » Wed Apr 17, 2013 16:07

The problem (I am assuming) manifests when the data table has zero length. The overloaded __new__ method of C45Learner uses an incorrect test for the presence of the instances argument. It uses
Code: Select all
if instances:
when it should use
Code: Select all
if instances is not None

This is a bug, and a quick search through the code reveals it is quite common.

Re: TypeError in C45Learner()?

Postby npo » Wed Apr 17, 2013 23:46

Thanks, yes, I subsequently discovered that the data table didn't have any instances in it.

Re: TypeError in C45Learner()?

Postby Ales » Thu Apr 18, 2013 10:19

I fixed the test in the __new__ method of C45Learner (and other learners) in the latest development snapshot.
Your code would still raise an exception but at least now it would be a 'KernelException: 'orange.C45Learner': no examples'


Return to Questions & Support



cron