Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weka only changing numeric to nominal

Tags:

weka

I have a CSV file that I am importing into Weka. All variables are importing as numeric. I need to change 3 of them to nominal. However when I place numerictonominal filter on it- all variables change. I only want to change 3.

1) Is there a way to just change a few via the filter 2) Or can you set it during the import. If so, I can't figure that out either.

like image 301
mpg Avatar asked Nov 16 '13 03:11

mpg


People also ask

What is numeric to nominal?

A filter for turning numeric attributes into nominal ones. Unlike discretization, it just takes all numeric values and adds them to the list of nominal values of that attribute. Useful after CSV imports, to force certain attributes to become nominal, e.g., the class attribute, containing values from 1 to 5.

What is nominal in Weka?

nominal: This type of attribute represents a fixed set of nominal values. string: This type of attribute represents a dynamically expanding set of nominal values. String attributes are not used by the learning schemes in Weka.


Video Answer


2 Answers

I assume you are using the Weka Explorer (GUI). To apply the filter to specific attributes do the following.

Step 1: Select your filter in the preprocess tab
Step 2: Click on the box to the right of the "Choose" button (a new window opens)
Step 3: In the attributeIndices box enter your custom ranges

If you select the "More" button in the filter window you will get an explanation of the different options and the values you can supply.

In your particular case, the filter is by default applied to the first through last attributes. You should change the range to reflect your personal needs.

====Edit====
If you are using the Java API, the following code will point you in the right direction.

 
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.NumericToNominal;

public class Main {

    public static void main(String[] args) throws Exception
    {

        //load training instances
        Instances originalTrain= //...load data with numeric attributes 

        NumericToNominal convert= new NumericToNominal();
        String[] options= new String[2];
        options[0]="-R";
        options[1]="1-2";  //range of variables to make numeric

        convert.setOptions(options);
        convert.setInputFormat(originalTrain);

        Instances newData=Filter.useFilter(originalTrain, convert);

        System.out.println("Before");
        for(int i=0; i<2; i=i+1)
        {
            System.out.println("Nominal? "+originalTrain.attribute(i).isNominal());
        }

        System.out.println("After");
        for(int i=0; i<2; i=i+1)
        {
            System.out.println("Nominal? "+newData.attribute(i).isNominal());
        }

    }

} 
like image 114
Walter Avatar answered Sep 22 '22 10:09

Walter


first open the arff file. under filter click "choose" . under filter tree , navigate to unsupervised and search for "NumerictoNomial" .Click once and press Apply. Save the File and reload it. Note: Make sure you have checked the checkbox of your desired field that you want to change.

like image 27
jijo nair Avatar answered Sep 25 '22 10:09

jijo nair