Weka wrapper numeric to nominal filter

464 views
Skip to first unread message

Hamad Khan

unread,
Mar 18, 2017, 2:18:42 PM3/18/17
to python-weka-wrapper
can any one know how can i convert all my attributes from numeric types to nominal, so that i can run J48 classifier. Below is the code which i wrote but it doesn't work

loader = Loader(classname="weka.core.converters.CSVLoader")
data1 = loader.load_file("E:\python wrapper\Files\training.csv")

nominal = Filter(classname="weka.filters.unsupervised.attribute.NumericToNominal", options=["-R", "first-last"])
nominal.inputformat(data1)
nominaldata1 = nominal.filter(data1)
nominaldata1.class_is_last()

P.S i want to convert all the attributs of data from numeric to nominal.

Thanks in advance.

Hamad Khan

unread,
Mar 18, 2017, 2:32:39 PM3/18/17
to python-weka-wrapper

I have attached my testing and training data and also the classifier code
J48 classifier.py
testing.csv
training.csv

Peter Reutemann

unread,
Mar 18, 2017, 8:09:49 PM3/18/17
to python-weka-wrapper
>> can any one know how can i convert all my attributes from numeric types to
>> nominal, so that i can run J48 classifier. Below is the code which i wrote
>> but it doesn't work
>>
>> loader = Loader(classname="weka.core.converters.CSVLoader")
>> data1 = loader.load_file("E:\python wrapper\Files\training.csv")
>>
>> nominal =
>> Filter(classname="weka.filters.unsupervised.attribute.NumericToNominal",
>> options=["-R", "first-last"])
>> nominal.inputformat(data1)
>> nominaldata1 = nominal.filter(data1)
>> nominaldata1.class_is_last()
>>
>>
>> P.S i want to convert all the attributs of data from numeric to nominal.

The above is correct. However, your attached code showed that you
re-initialized the NumericToNominal filter again, resetting the
structure that it learned from the first dataset, resulting in
incompatible datasets.

Rule of thumb: always check whether your train and test set are compatible!

Also, if in doubt, simply output the dataset to stdout with a simple
print(...) call to check whether filtering worked as expected.
Finally, you can also use an IDE like PyCharm and debug your scripts.
Makes it so much easier what's going on.

I've attached a fixed version of your script - it also contains the
check of train/test that I mentioned.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
J48 classifier.py
Reply all
Reply to author
Forward
0 new messages