Sunday, 1 September 2013

Can't normalize array. Sum is NaN. Weka

Can't normalize array. Sum is NaN. Weka

I got an error "Can't normalize array. Sum is NaN." when I use the trained
model to classify text. I am using stringToWordVector filter.
This is my arff file after I filter using the stringToWordVector
@relation
'emotion_class-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer
-delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'\n\n
@attribute class_list {Happy,Fear,Anger,Sad,Neutral}
@attribute #Bopha numeric
@attribute #PlanPhilippines numeric
@attribute Mindanao numeric
@attribute interviewing numeric
@attribute survivors numeric
@attribute team numeric
@data
{0 ?,1 1,2 1,3 1,4 1,5 1,6 1}
this my code:
//Reads arff file
StringBuilder buffer = new StringBuilder(sample);
BufferedReader reader = new BufferedReader(new
java.io.StringReader(buffer.ToString()));
weka.core.converters.ArffLoader.ArffReader arff = new
weka.core.converters.ArffLoader.ArffReader(reader);
Instances dataRaw = arff.getData();
//Use string to word vector
StringToWordVector filter = new StringToWordVector();
filter.setInputFormat(dataRaw);
Instances dataFiltered = Filter.useFilter(dataRaw, filter);
dataRaw.setClassIndex(dataRaw.numAttributes() - 1);
Instances labeled = new Instances(dataFiltered);
Classifier cls = null;
cls =
(Classifier)weka.core.SerializationHelper.read("SampleModel.model");
for (int i = 0; i < dataFiltered.numInstances(); i++)
{
double clsLabel = cls.classifyInstance(dataFiltered.instance(i));
labeled.instance(i).setClassValue(clsLabel);
MessageBox.Show(clsLabel.ToString());
}
The error is in double clsLabel =
cls.classifyInstance(dataFiltered.instance(i));
Do you have other solution? Thanks in advance

No comments:

Post a Comment