0

我正在尝试一些使用 weka API for Java 的简单代码。在尝试查找 numberofAttributes 时,它会为任何 .data 文件触发错误。虽然它适用于 .arff 文件。已从UCI存储库下载文件

---Registering Weka Editors---
Trying to add database driver (JDBC): RmiJdbc.RJDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): org.gjt.mm.mysql.Driver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): com.mckoi.JDBCDriver - Error, not in CLASSPATH?
Trying to add database driver (JDBC): org.hsqldb.jdbcDriver - Error, not in CLASSPATH?
java.io.IOException: premature end of line. Expected attribute type., read Token[EOL], line 5
    at weka.core.converters.ConverterUtils.errms(ConverterUtils.java:912)
    at weka.core.converters.C45Loader.readHeader(C45Loader.java:417)
    at weka.core.converters.C45Loader.getStructure(C45Loader.java:211)
    at weka.core.converters.C45Loader.getDataSet(C45Loader.java:234)
    at weka.core.converters.ConverterUtils$DataSource.getDataSet(ConverterUtils.java:268)
    at MetaFeatureStatistical.main(MetaFeatureStatistical.java:42)
Exception in thread "main" java.lang.NullPointerException
    at MetaFeatureStatistical.main(MetaFeatureStatistical.java:43)

第 42 和 43 行如下:

instances=source.getDataSet(); 
instances.setClassIndex(instances.numAttributes()-1);
4

1 回答 1

0

instances.numAttributes()由于实例为空,它会引发错误。source.getDataSet()无法完成,因此未为实例分配值,因为文件存在问题,可能在第 5 行。在我们知道您正在使用的文件之前,我们无法说出原因。

于 2013-02-19T06:30:19.640 回答