I am trying to create training instances with one date attribute and one numeric attribute. I get error because of my date value. The error is: java.lang.IllegalArgumentException: Attribute neither nominal nor string!
I guess I do not understand how to deal with this format. I have searched for it a lot but all of the examples are about using it in arff file and I couldn't find any example for java code. I will be so thankful if you could tell where I am going wrong or send me some links which could guide me through this problem.
Here is the code:
    Attribute dateTimeAttribute = new Attribute("dateTime","yyyy-MM-dd HH:mm:ss");
    Attribute valueAttribute = new Attribute("value");
    FastVector fvWekaAttributesLinear = new FastVector(2);  
    fvWekaAttributesLinear.addElement(dateTimeAttribute);
    fvWekaAttributesLinear.addElement(valueAttribute); 
    Instances isTrainingSet = new Instances("Relation", fvWekaAttributesLinear, 100000); 
    isTrainingSet.setClassIndex(1);
    Instance ins = new Instance(2);
    ins.setValue((Attribute)fvWekaAttributesLinear.elementAt(0), "2009-07-15 10:00:00");
    ins.setValue((Attribute)fvWekaAttributesLinear.elementAt(1), 0.5); 
This is how I solved the problem:
    Attribute dateTimeAttribute = new Attribute("dateTime","yyyy-MM-dd HH:mm");
    Attribute valueAttribute = new Attribute("value");
    FastVector fvWekaAttributesLinear = new FastVector(2);          
    fvWekaAttributesLinear.addElement(dateTimeAttribute);
    fvWekaAttributesLinear.addElement(valueAttribute); 
    Instances isTrainingSet = new Instances("Relation", fvWekaAttributesLinear, 100000);
    double[] attValues = new double[isTrainingSet.numAttributes()];
    attValues[0] = isTrainingSet.attribute("dateTime").parseDate("2009-07-15 10:00");
    attValues[1] = 0.5;
Here is a link that I found useful: http://zitnik.si/wordpress/2011/09/25/quick-intro-to-weka/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With