Orange Forum • View topic - How to construct a data Table in Orange?

How to construct a data Table in Orange?

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

How to construct a data Table in Orange?

Postby nawaf » Mon Jan 06, 2014 13:53

Using Orange in Python, how to build a data table given the following data, attribute names and the class for each instance in data:

Code: Select all
data = [[.1,.2,.3,.4,.5,.6,.7],[.0,.9,.8,.7,.6,.5,.4],[.2,.3,.4,.5,.6,.7,.8], [.1,.1,.1,.3,.3,.3,.3]]
attr_names = [a, b, c, d, e, f, g]
class = ["0","1","1","0"]


I've seen the post, http://stackoverflow.com/questions/8986719/how-do-i-create-a-new-data-table-in-orange; however, the table doesn't include the class for each instance. I'd like to have it in the table to send it to a feature selection/scoring method such as InfoGain or MDL through
Code: Select all
Orange.feature.scoring.score_all


Code: Select all
LCV = [Orange.feature.Continuous(x) for x in attr_names]
Domain = Orange.data.Domain(LCV)
table = Orange.data.Table(Domain, data)

Re: How to construct a data Table in Orange?

Postby Ales » Tue Jan 14, 2014 19:32

Try this:
Code: Select all
LCV = [Orange.feature.Continuous(x) for x in attr_names]
CLS = Orange.feature.Discrete("CLS", values=["0","1"])
Domain = Orange.data.Domain(LCV, CLS)
table = Orange.data.Table(Domain, [inst + [c] for inst, c in zip(data, class_)])

Re: How to construct a data Table in Orange?

Postby nawaf » Wed Jan 15, 2014 11:02

I did the following:

clsAt = ['0', '1']
val = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
LCV=[Discrete(x,values = val ) for x in attr_names]
c = Discrete("y", values= clsAt)
d2 = Domain(LCV + [c])
t2 = Table(d2, new3)
Is it correct?
Is there away to avoid explicitly defining the possible values (val) of the attribute?

Re: How to construct a data Table in Orange?

Postby Ales » Wed Jan 15, 2014 15:20

nawaf wrote:Is it correct?
It seems correct.
nawaf wrote:Is there away to avoid explicitly defining the possible values (val) of the attribute?
No. Discrete attributes must have all values defined, although you can extend the list of values at a later time (see Orange.feature.Discrete.add_value)


Return to Questions & Support



cron