问题描述
限时送ChatGPT账号..我正在尝试使用一个日期属性和一个数字属性创建训练实例.由于我的日期值,我收到错误消息.错误是:java.lang.IllegalArgumentException: 属性既不是名义值也不是字符串!
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!
我想我不明白如何处理这种格式.我已经搜索了很多,但所有的例子都是关于在 arff 文件中使用它的,我找不到任何 java 代码的例子.如果您能告诉我哪里出错或给我发送一些可以指导我解决此问题的链接,我将不胜感激.
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.
代码如下:
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);
推荐答案
我是这样解决问题的:
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;
这是我发现有用的链接:http://zitnik.si/wordpress/2011/09/25/weka 快速介绍/
Here is a link that I found useful: http://zitnik.si/wordpress/2011/09/25/quick-intro-to-weka/
这篇关于如何在java代码中的weka中使用日期类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论