Orange Forum • View topic - Set class with python / scripting

Set class with python / scripting

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

Set class with python / scripting

Postby oleczek » Tue Feb 14, 2012 14:21

Could you provide an example how to set a class to a column from a file. I read a CSV file and it has no class defined (like .tab format).

Thank you in advance,
Oleczek

Re: Set class with python / scripting

Postby Ales » Wed Feb 15, 2012 10:45

You have to construct a new domain with the appropriate class variable. For instance:
Code: Select all
iris  = orange.ExampleTable("iris")
new_domain = orange.Domain([a for a in iris.domain.variables if a.name != 'petal width'], iris.domain['petal width'])
new_data = orange.ExampleTable(new_domain, iris)

This creates a new table with 'petal width' as the class variable.


Return to Questions & Support



cron