Orange Forum • View topic - Changing the value of an attribute of an instance

Changing the value of an attribute of an instance

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

Changing the value of an attribute of an instance

Postby walruses » Sun Nov 10, 2013 10:21

I am confused about how I should change the value of an attribute of an instance.

I have tried:

data[i][j]=1

and

data[i][j]=Orange.data.Value(1)

but the result I get is '#RNGE'

Is this because the value I am trying to store is not in the domain of the attribute?

What is the correct way of doing this?

I am at the moment trying to use attribute weighting, so I want to multiply each attribute of an instance by a given weight but I am also interested in how in general I can change a particular instance's, particular attributes.

This is what I have so far:

#weightVector is actually a list of tuples where the first value in the tuple is the attribute name, and the second the weight

Code: Select all
def attributeWeighter(data, weightVector):
    for i,instance in enumerate(data):
        for j,attribute in enumerate(instance):
            data[i][j]=Orange.data.Value(data[i][j]*weightVector[j][1])
    return data

Re: Changing the value of an attribute of an instance

Postby Ales » Mon Nov 11, 2013 10:56

walruses wrote:but the result I get is '#RNGE'

Is this because the value I am trying to store is not in the domain of the attribute?
Yes.

walruses wrote:What is the correct way of doing this?

Code: Select all
data[i][j] = 1
#or better
data[i][j] = data.domain[j](1)
But you have to be careful with regards to the possible values a discrete variable can take on.

(I am not sure why
Code: Select all
data[i][j]=Orange.data.Value(1)
succeeds in setting the field to invalid, both the upper versions should raise an error)

walruses wrote:I am at the moment trying to use attribute weighting, so I want to multiply each attribute of an instance by a given weight
You can't really do that for discrete attributes. You should take special care to remove them or convert them to continuous attributes.

Re: Changing the value of an attribute of an instance

Postby walruses » Mon Nov 11, 2013 12:35

Okay thanks- and what is the correct procedure for changing a features domain to continuous or adding another value to a discrete domain?


Return to Questions & Support



cron