How to prepare data for association rules in python-weka-wrapper?

Viewed 582

I'm trying to learn rules on a given data using weka in python. Weka gets errors of 'Cannot handle string & numeric attributes'

I'm using https://github.com/fracpete/python-weka-wrapper3

At first, I did:

loader = Loader(classname="weka.core.converters.CSVLoader")
    data = loader.load_file(path)
    data.class_is_last()

But got:

javabridge.jutil.JavaException: weka.associations.Apriori: Cannot handle numeric attributes!

When trying to learn the rules.

I understand the error, weka wants nominal attributes. OK! I've searched and found ways to do it: http://weka.sourceforge.net/doc.dev/weka/filters/unsupervised/attribute/NominalToString.html

So I've tried:


loader = Loader(classname="weka.core.converters.CSVLoader")
    data = loader.load_file(path)
    nominal = Filter(classname="weka.filters.unsupervised.attribute.NumericToNominal", options=["-R", "first-last"])
    nominal.inputformat(data)
    nominal_data = nominal.filter(data)
    nominal_data.class_is_last()

    return nominal_data

But got:

javabridge.jutil.JavaException: weka.associations.Apriori: Cannot handle string attributes!

What am I missing? thanks

1 Answers

In Weka there are both String and nominal types of data. The String data type is a textual type with unspecified number of values (e.g. tracking Id: R99432239US) while the Nominal type correspond to values from a closed set (e.g. state {walking, running, sitting}).

When parsing a csv file, the loader assigns the data type of the attribute according to the number of values that appear in the data.

If you want to use treat numeric values as nominal, I believe that you will want to look at the Discretize filter instead of using the NumericToNominal filter.

Related