从命令行使用InputMappedClassifier

时间:2015-01-31 01:34:32

标签: java machine-learning weka

我正在尝试使用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的情况下运行它,它就可以了。我怎样才能获得分类?

1 个答案:

答案 0 :(得分:2)

您为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