在 Weka Java API 中创建字符串属性
我正在尝试使用 Weka 的 Java API 创建一个新的字符串属性...
阅读 API javadocs,似乎这样做的方法是使用这个构造函数:
Attribute
public Attribute(java.lang.String attributeName,
FastVector attributeValues)
Constructor for nominal attributes and string attributes. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.
Parameters:
attributeName - the name for the attribute
attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
但我对应该传递给attributeValues 参数...
当我输入 null 时,Java 会抱怨受保护的对象
当我输入 Null 时,这是语法错误
当我放入 new FastVector()
时,它变成一个空的名义属性而不是字符串属性...
当我创建一个新对象:
FastVector fv = new FastVector();
fv.addElement(null);
然后将 fv 传递到参数中时,它返回一个空指针异常...
我到底应该在 attributeValues 参数中放入什么,以便它成为字符串属性?
I'm trying to create a new string Attribute using Weka's Java API...
Reading through the API javadocs, it appears that the way to do so is to use this constructor:
Attribute
public Attribute(java.lang.String attributeName,
FastVector attributeValues)
Constructor for nominal attributes and string attributes. If a null vector of attribute values is passed to the method, the attribute is assumed to be a string.
Parameters:
attributeName - the name for the attribute
attributeValues - a vector of strings denoting the attribute values. Null if the attribute is a string attribute.
but I'm stuck as to what I should pass into the attributeValues parameter...
when I put in null, Java complains about protected objects
when I put in Null, it's syntax error
when I put in new FastVector()
, it becomes a nominal attribute that is empty rather than a string attribute...
when I create a new object:
FastVector fv = new FastVector();
fv.addElement(null);
and then pass fv into the argument, it returns a null pointer exception...
what exactly should I put into the attributeValues argument so that it becomes a string attribute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将 null 转换为 FastVector。否则,将有更多方法应用于方法签名:
这里是动态创建实例的好资源:https://waikato.github.io/weka-wiki/formats_and_processing/creating_arff_file/
You have to cast the null to FastVector. Otherwise more methods would apply to the method signature:
Here is a good resource for creating Instances on the fly: https://waikato.github.io/weka-wiki/formats_and_processing/creating_arff_file/
在 WEKA 中构建 STRING 属性的简单方法是这样的:
主要问题是 WEKA 对 NULL 值的定义,或导入 weka.jar 并抛出异常模式的新型 Java 编辑器中的 NULL 向量。
Easy way to build STRING Attribute in WEKA is this:
Main problem is WEKA's definition of NULL value, or NULL vector in new type of Java editors with imported weka.jar and throw exceptions mode.