0

I have a training and test ARFF file dataset as such. I had created the below dataset by extracting region-of-interest from a 6 band image and the labels pertaining to each coordinate.

@RELATION agricultural.data

@attribute band0 numeric
@attribute band1 numeric
@attribute band3 numeric
@attribute band4 numeric
@attribute band5 numeric
@attribute band6 numeric
@attribute class {1,2,3,4,5,6,7,8,9}

@data
-10.95659,-7.61896,-9.8674499,-9.118701,-8.620638,-12.699167,5
...
-9.172866,-9.814803,-10.693634,-13.313326,-8.568673,-12.355089,3

Using the above data I have trained the RandomForest and have gotten some results which seem in-line with what I expect.


I have an ARFF file dataset as such. It doesn't have any class attribute

@RELATION agricultural.data.fullimage

@attribute band0 numeric
@attribute band1 numeric
@attribute band3 numeric
@attribute band4 numeric
@attribute band5 numeric
@attribute band6 numeric

@data
-9.261405,-7.302625,-10.753542,-8.018068,-7.776727,-12.878252
...
-9.188496,-10.676176,-14.194083,-9.687324,-9.785445,-12.490084

This is actual image line-by-line generated ARFF file. I want to classify the whole image. It doesn't have any labels. How do I classify the image. (Segmentation?)

FilteredClassifier fc = new FilteredClassifier();
fc.setClassifier(myRandomForestTrainedModel);

for(int pixel=0;pixel < ncols;pixel++) {
    double prediction;
    /**Some edge case handling**/
    prediction = fc.classifyInstance(data.instance(pixel)); //Each data here is a row in the image which I create an ARFF file for
    byteLinePrediction[pixel] = (byte)Math.floor(prediction+0.5);
} 

There is an exception at the classifyInstance() function which reads as below:

weka.core.UnassignedClassException: weka.classifiers.meta.FilteredClassifier: Class attribute not set!

But, I don't have classes assigned to these pixels as I don't want to evaluate the performance of the classifier but use the classifier to generate an classified(segmented) image map.

Tarun Maganti
  • 3,076
  • 2
  • 35
  • 64

1 Answers1

1

The data that you use for making predictions needs to have the exact same format as the training data, including the class attribute (Weka may query at prediction time possible class values). That attribute must also be flagged as class attribute (setClassIndex(...)).

However, all actual values in the data section can be missing ('?').

You can use the Add filter to append the class attribute to your test data, including the required nominal labels.

fracpete
  • 2,448
  • 2
  • 12
  • 17
  • So I dump placeholder values? And use the prediction as used in evaluation of test dataset. I was exactly trying that after I posted this question. I did not get output. I'll let you know if I work it out. – Tarun Maganti Feb 02 '23 at 05:46
  • `classifyInstance` returns the **index** of the label. Use the [value(int)](https://weka.sourceforge.io/doc.dev/weka/core/Attribute.html#value-int-) method of your class attribute to determine the label string (casting the double to an int). – fracpete Feb 02 '23 at 06:16