Orange Forum • View topic - TypeError: attribute no. # is ordinal, string value expected

TypeError: attribute no. # is ordinal, string value expected

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

TypeError: attribute no. # is ordinal, string value expected

Postby jasonzutty » Tue Mar 05, 2013 17:04

I am getting a problem trying to pull apart and rebuild an Orange table. Maybe someone here can shed some light on this:

Code: Select all
import Orange
import numpy as np

# Load up the lenses data
myTable = Orange.data.Table('lenses')
# Convert data to numpy
f,c,w = myTable.toNumpy()
# Make class data in to a single column
c = np.reshape(c , (-1,1) )
# Combine features and class data in to single array
totalData = np.hstack( (f,c) )
# Create feature descriptors
features = [Orange.feature.Continuous(str(x)) for x in np.arange(f.shape[1])]
# Create class descriptor
class_var = Orange.feature.Discrete('class')
# Build domain
domain = Orange.data.Domain(features,class_var)
# Build table
newTable = Orange.data.Table(domain,totalData)


My issue is that I get my class variable as a bunch of #RNGE values

If I try to build a single instance
Code: Select all
inst = Orange.data.Instance(domain, totalData[0].tolist())


I get:
TypeError: attribute no. 5 (class) is ordinal, string value expected

Any ideas?

Thanks,
Jason

Re: TypeError: attribute no. # is ordinal, string value expe

Postby Ales » Tue Mar 05, 2013 17:41

You need to provide a list of values for the Discrete variable. For instance
Code: Select all
# Create class descriptor
class_var = Orange.feature.Discrete('class', values=["none', 'hard', 'soft'])


Return to Questions & Support