Search code examples
javamachine-learningweka

Using InputMappedClassifier From Command Line


I'm trying to run a classifier with the InputMappedClassifier, since I know the test arff is missing some attributes in the training arff. However, when I run:

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

It generates the exception:

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)

If I run it without -classifications, it works. How can I get the classifications?


Solution

  • You're giving the InputMappedClassifier the wrong options. It's complaining that you are giving it the training (-t) and test (-T) data. It supports the following:

    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).
    

    So your command should look like this:

    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