Search code examples
filterattributespreprocessorweka

USing AddExpression / MathExpression in Weka


I am working on a very basic WEKA assignment, and I'm trying to use WEKA to preprocess data from the GUI (most current version). I am trying to do very basic if statements and mathematical statements in the expression box when double clicking on MathExpression and I haven't had any success. For example I want to do

if (a5 == 2 || a5 == 0) then y = 1; else y = 0

Many different variations of this haven't worked for me and I'm also unclear on how to refer to "y" or if it needs a reference within the line.

Another example is -abs(log(a7)–3) which I wasn't able to work out either. Any ideas about how to make these statements work?


Solution

  • From javadoc of MathExpression

    The 'A' letter refers to the value of the attribute being processed. Other attribute values (numeric only) can be accessed through the variables A1, A2, A3, ...

    Your filter applies to all attributes of your dataset. If I load iris dataset and apply following filter.

    weka.filters.unsupervised.attribute.MathExpression -E log(A).

    your attribute ,sepallength values change as following.

    Before Filter      After Filter           
    Minimum 4.3    Minimum  1.459
    Maximum 7.9    Maximum  2.067
    Mean    5.843  Mean 1.755
    StdDev  0.828  StdDev   0.141
    

    Also if you look to javadoc, there is no if else function but ifelse function. Therefore you should write something like

    ifelse ( (A == 2 || A == 0), 1,0 ) 
    

    Also this filter applies to all attributes. If you want to change only one attribute and according to other attribute values ; then you need to use "Ignore range option" and use A1,A2 to refer to other attribute values.

    if you need to add new attribute use AddExpression.

    An instance filter that creates a new attribute by applying a mathematical expression to existing attributes.