Orange Forum • View topic - build Orange.data.table from NumPy array with class info

build Orange.data.table from NumPy array with class info

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

build Orange.data.table from NumPy array with class info

Postby kernc » Tue Feb 28, 2012 21:05

I have multi-class training data.

If I load it with:
Code: Select all
domain = Orange.data.Domain(list_of_continuous_columns, False, class_vars=list_of_T/F_accepting_colums)
features = np.array(...) # N x M array of attributes
classes = np.array(...) # N x L array of T/F values for each class
data = Orange.data.Table(domain, features)
I still have to do:
Code: Select all
for i, instance in enumerate(data):
    instance.set_classes(classes[i])
to add known class info.

Is there a way I could populate data table without a loop?

I already tried concatenating features and classes arrays column-wise
Code: Select all
feats_and_classes = np.concatenate((features, classes), axis=1)
data = Orange.data.Table(domain, feats_and_classes)
but in this case, the error is:
AttributeError: the number of columns in the array doesn't match the number of attributes

Is there, or will (should) there be, a way (i.e. another Table constructor) ?

Thanks!

Re: build Orange.data.table from NumPy array with class info

Postby lanz » Fri Mar 02, 2012 0:13

Maybe someone will correct me, but I think there isn't a nice way to do this (yet). It could be added in the near future (multitarget support is still pretty fresh).

Until then, if you want to avoid a loop, you can just make a Table with all variables as features and then tranform it into a new domain with desired class_vars.

Code: Select all
tmpdom = Orange.data.Domain(list_of_continuous_columns + list_of_T/F_accepting_colums, False)
features = np.array(...) # N x M array of attributes
classes = np.array(...) # N x L array of T/F values for each class
data = Orange.data.Table(tmpdom, np.concatenate((features, classes), axis=1))
domain = Orange.data.Domain(list_of_continuous_columns, False, class_vars=list_of_T/F_accepting_colums)
data = Orange.data.Table(domain, data)


Return to Questions & Support



cron