Chris
Chris

Reputation:

How can you take a multi-class attribute and binarize it with weka?

I have an attribute, say numberOfChildren that can take on the values 0, 1, 2, 3. I want to preprocess the data in WEKA such that it becomes just 0 or 1, a hasChildren attribute, which is 0 of numberOfChildren is 0, and 1 if numberOfChildren is greater than 0.

How can you do this in Weka's preprocesser stage?

Upvotes: 3

Views: 1218

Answers (2)

Atilla Ozgur
Atilla Ozgur

Reputation: 14701

You use math expression filter.

Consider following arff file.

@relation NumberOfChildrenExample

@attribute A numeric
@attribute numberOfChildren numeric

@data
1,0
2,1
3,2
4,3
5,4
6,5

You use following command.

java  weka.filters.unsupervised.attribute.MathExpression -unset-class-temporarily \
-E "ifelse(A>0,1,0)" -V -R 2 -i datasets\NumberOfChildrenExample.arff
  • -V invert selection
  • -R choose 2 column, hasChildren

otherwise this filter convert all numeric columns

@attribute A numeric
@attribute numberOfChildren numeric

@data

1,0
2,1
3,1
4,1
5,1
6,1

Since you want hasChildren attribute, you need to also use Rename

Upvotes: 2

Daniel Widdis
Daniel Widdis

Reputation: 9091

Try going to weka.filters.unsupervised.attribute and scanning the list. Discretize might work but might also split your data in half. MergeTwoValues might work for you if you merge the 3 to 2, then the 2 to 1, leaving you with 0 and 1.

Upvotes: 1

Related Questions