Java How to convert a String attribute to Nominal to classify in Weka?

0

Hello, I have a program written in java that performs the classification process using the library of weka 3.6 and predicts which class a new record belongs to when I add the data. The problem is that it only works when they are numeric data because when I try to add data string I get the error:

java.lang.IllegalArgumentException: Value not defined for given nominal attribute!

I would like to know how can I translate the string attributes into nominal ones?

Instance instance = new Instance(8);

Attribute atributo = train.attribute("NumPalabras");
Attribute atributo2 = train.attribute("Texto");
Attribute atributo3 = train.attribute("valor1");
Attribute atributo4 = train.attribute("valor2");
Attribute atributo5 = train.attribute("valor3");
Attribute atributo6 = train.attribute("valor4");
Attribute atributo7 = train.attribute("ValorMasAlto");

instance.setValue(atributo, NumPalabras);
instance.setValue(atributo2, Texto);///AQUI ES DONDE SE PRENSENTA EL ERROR
instance.setValue(atributo3, valor1);
instance.setValue(atributo4, valor2);
instance.setValue(atributo5, valor3);
instance.setValue(atributo6, valor4);
instance.setValue(atributo7, ValorMasAlto);

instance.setDataset(train);
return instance;
    
asked by Sanders3 22.04.2018 в 08:23
source

1 answer

0

I have never used that library so I have hardly any knowledge, but reading the official documentation it seems that for Numeric Attribute you should use a second parameter in the constructor:

Attribute(java.lang.String attributeName, boolean createStringAttribute) Constructor for a numeric or string attribute.

In yours you are using the simple one, without the boolean to false to say that it is NOT String. Try with that

    
answered by 22.04.2018 в 11:15