Orange Forum • View topic - Adding new attributes, and setting them as classes

Adding new attributes, and setting them as classes

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

Adding new attributes, and setting them as classes

Postby Sachiel » Sat Apr 17, 2010 17:09

After digging in the documentation, I would like to ask if it is the correct way of add a new meta attribute to an existing ExampleTable, and setting it as the class attribute:

Code: Select all
# First, load the data
data = orange.ExampleTable(filename) # A CSV file, with orange-formatted headers

# data has several attributes, and a single meta attribute, which is automatically set as class attribute. This is not true, so it is changed:
data.domain.classVar = None

# Create the new class attribute, a EnumVariable:
classvalues = ["YES", "MAYBE", "NO"]
newattr = orange.EnumVariable("bloom", values=classvalues)
newattr.baseValue = newattr.values.index("NO")

# Add the attribute as meta
data.domain.addmeta(orange.newmetaid(), newattr)

#Set it as class attribute
olddom = self.raw_data[mp].domain
newdom = orange.Domain(olddom, "bloom")
data.domain = newdom


It works with no errors, but I amb no 100% I am doing it well...

Postby Ales » Fri Apr 23, 2010 9:31

Code: Select all
newdom = orange.Domain(olddom, "bloom")
data.domain = newdom


I think this is safer:

Code: Select all
newdom = orange.Domain(olddom, "bloom")
data = orange.ExampleTable(newdom, data)

Postby Sachiel » Tue Apr 27, 2010 16:53

Thank you Ales.

I've just realized that, with this process, the meta-attributes are lost. How can they be maintaned?

Postby marko » Tue Apr 27, 2010 18:10

Add
Code: Select all
newdom.addmetas(olddom.getmetas())

after
Code: Select all
newdom = orange.Domain(olddom, "bloom")


Return to Questions & Support



cron