0
$\begingroup$

I'm trying to automate a train/evaluate workflow from a Python script, so I need to be able to run Weka from the command line. I'm able to train my model successfully using this:

java weka.classifiers.meta.FilteredClassifier  ^
-t "2023-07-05 training.arff" -d "testmodel.model" ^
-F "weka.filters.unsupervised.attribute.Remove -R first" -S 1 -W `weka.classifiers.trees.J48 -- -C 0.25 -M 2`

But I'm having trouble generating predictions on a different set of data (i.e., performing the "Re-evaluate model on current test set" operation, which works successfully in the Weka Explorer GUI). I am using this command, as suggested here.

java ^
weka.filters.supervised.attribute.AddClassification ^
-serialized "testmodel.model" ^
-classification ^
-remove-old-class ^
-i "2023-07-05 testing.arff" ^
-o "2023-07-05 classified.arff" ^
-c last

This results in the following error:

weka.core.UnsupportedAttributeTypeException: weka.classifiers.meta.FilteredClassifier: Cannot handle unary class!
        at weka.core.Capabilities.test(Capabilities.java:1045)
        at weka.core.Capabilities.test(Capabilities.java:1256)
        at weka.core.Capabilities.test(Capabilities.java:1138)
        at weka.core.Capabilities.testWithFail(Capabilities.java:1468)
        at weka.filters.supervised.attribute.AddClassification.testInputFormat(AddClassification.java:409)
        at weka.filters.Filter.setInputFormat(Filter.java:492)
        at weka.filters.SimpleFilter.setInputFormat(SimpleFilter.java:115)
        at weka.filters.Filter.filterFile(Filter.java:1128)
        at weka.filters.Filter.runFilter(Filter.java:1415)
        at weka.filters.supervised.attribute.AddClassification.main(AddClassification.java:846)

My testing set just has '0' in the last column (since I don't know the actual values), so I guess technically it is unary, but that shouldn't matter since it's making predictions on the other values, right?

Can anyone tell me what I'm doing wrong? Is there something special that I need to do because I used a filtered classifier to train the model, perhaps?

EDIT: If I manually edit the ARFF file for the testing set such that the classification field description contains all the possible class values, then I am able to generate predictions, i.e.,

Change this line:

@attribute classification {0}

To this:

@attribute classification {0,2,3}

That still seems like a kludge, though.

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.