I want to classify satellite image in R using RWeka classifier, J48. I have a CSV file with the classes required, and raster data loaded in R. I am able to make the tree, however, I am not able to use the same tree to classify my satellite image.

Here's how it goes.

m1 <- J48(Class~B1+B2+B3+B4+B5+B7, data = inputfile)
if(require("party", quietly = TRUE)) plot(m1)
raster<- brick("merge.tif")
plotRGB(raster, 4, 3, 2, stretch="hist")

And then I am attempting to use the tree generated to classify my satellite image, but I keep getting errors.

predict (raster, J48, filename=out_classify, progress='text',format='GTiff', datatype='FLT4S', type='response', overwrite=TRUE)
Error in trim(filename) : error in evaluating the argument 'x' in selecting a method for function 'trim': Error: object 'out_classify' not found

And if I change the arguments, this is what I get. I am not sure how to proceed from this point forward.

predict (J48, raster, filename=out_classify, progress='text',format='GTiff', datatype='FLT4S', type='response', overwrite=TRUE)
Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('R_Weka_classifier_interface', 'R_Weka_interface')"

I am new to R, so I might take a while to decipher your answers. Any help would be greatly appreciated!


  • 1
    Could you post a link to a sample of your data? – Matthew Plourde May 15 '14 at 15:42
  • I am basically trying to use Landsat data and I have training sets as sample points. I made few corrections, first error was because I hadn't defined my output object/output file. And second error was because apparently predict statement isn't available for RWeka classifier. I managed to do the classification with Rpart and RandomForest. But in order to use RWeka, I can probably write a function in rasterEngine (part of spatial.tools). However, I haven't been able to do that as of yet! Any advice? – Anusheema May 16 '14 at 16:45
  • You need to carefully read the documentation for RWeka. Based on the error it loks3 like there is not a predict function, that can be used as a generic, for this object class. Since this is an interface package, this is not surprising. However, there is likely a way to predict a model that is a function call to weka. I would imagine that you will need to write your own predict function that uses whatever method the package implements, making it compatible with the vector/matrix/array class object that the raster package reads in. – Jeffrey Evans Jul 15 '17 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.