我正在尝试使用InputMappedClassifier运行分类器,因为我知道测试Arff缺少训练Arff中的某些属性。但是,当我运行时:

java -cp ./weka.jar weka.classifiers.misc.InputMappedClassifier -t aa/lang-train.arff \
-T aa/lang-test.arff -W weka.classifiers.trees.J48 -classifications \
weka.classifiers.evaluation.output.prediction.PlainText


它生成异常:

java.lang.IllegalArgumentException: Invalid class index: 2466
    at weka.core.Instances.setClassIndex(Instances.java:1293)
    at weka.core.converters.ConverterUtils$DataSource.getStructure(ConverterUtils.java:346)
    at weka.classifiers.evaluation.output.prediction.AbstractOutput.printClassifications(AbstractOutput.java:625)
    at weka.classifiers.evaluation.output.prediction.AbstractOutput.print(AbstractOutput.java:702)
    at weka.classifiers.evaluation.Evaluation.evaluateModel(Evaluation.java:1572)
    at weka.classifiers.Evaluation.evaluateModel(Evaluation.java:649)
    at weka.classifiers.AbstractClassifier.runClassifier(AbstractClassifier.java:297)
    at weka.classifiers.misc.InputMappedClassifier.main(InputMappedClassifier.java:943)


如果我在没有-classifications的情况下运行它,那么它将起作用。如何获得分类?

最佳答案

您为InputMappedClassifier提供了错误的选项。抱怨您正在给它训练(-t)和测试(-T)数据。它支持以下内容:

Options specific to weka.classifiers.misc.InputMappedClassifier:

-I
    Ignore case when matching attribute names and nominal values.
-M
    Suppress the output of the mapping report.
-trim
    Trim white space from either end of names before matching.
-L <path to model to load>
    Path to a model to load. If set, this model
    will be used for prediction and any base classifier
    specification will be ignored. Environment variables
    may be used in the path (e.g. ${HOME}/myModel.model)
-W
    Full name of base classifier.
    (default: weka.classifiers.rules.ZeroR)
-output-debug-info
    If set, classifier is run in debug mode and
    may output additional info to the console
-do-not-check-capabilities
    If set, classifier capabilities are not checked before classifier is built
    (use with caution).


因此,您的命令应如下所示:

java -cp ./weka.jar weka.classifiers.misc.InputMappedClassifier -W weka.classifiers.trees.J48 \
-t aa/lang-train.arff \
-T aa/lang-test.arff \
-classifications weka.classifiers.evaluation.output.prediction.PlainText

关于java - 从命令行使用InputMappedClassifier,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28247240/

10-09 13:28