3

I performed a RF-classification. I have 6 bands, ~250 trainingpoints in a shapefile, OOB estimate of error rate: 1.56% Picture of take trainingpoints added. My code:

setwd("D:/BA-Workspace/sw_comp_ap_aug/")


library(sp)
library(rgdal)
library(raster)
library(randomForest)


# CREATE LIST OF RASTERS
rlist=list.files(getwd(), pattern="tif$", full.names=TRUE) 

# CREATE RASTER STACK
xvars <- stack(rlist)  

# CREATE RASTER STACK
xvars <- stack(rlist)  
x <- coordinates(xvars)[, 1]
y <- coordinates(xvars)[, 2]

x_rst <- y_rst <- xvars[[1]]
x_rst[] <- x
y_rst[] <- y

xvars <- stack(x_rst, y_rst, xvars)
names(xvars) <- c("x", "y", "fitzefa1_rot1", "fitzefa1_gr1", "fitzefa1_bl1",     "fitzefa2_rot1", "fitzefa2_gr1", "fitzefa2_bl1")
# READ Raster TRAINING DATA
sdata <- readOGR(dsn=getwd(), layer="sw_trainshape")

# ASSIGN RASTER VALUES TO TRAINING DATA
v <- as.data.frame(extract(xvars, sdata))
sdata@data = data.frame(sdata@data, v[match(rownames(sdata@data), rownames(v)),])

sdata@data  <- sdata@data[-c(5,6)] 

# RUN RF MODEL
rf.mdl <- randomForest(x=sdata@data[,3:ncol(sdata@data)],     y=as.factor(sdata@data[,"Class"]),
                   ntree=501, importance=TRUE)

# CHECK ERROR CONVERGENCE
#plot(rf.mdl)
#sdata@data 

# PLOT mean decrease in accuracy VARIABLE IMPORTANCE

#varImpPlot(rf.mdl, type=1)
#setOldClass(SpatialPointsDataFrame)
# PREDICT MODEL
predict(xvars, rf.mdl, filename="RfClassPred.img", type="response", 
    index=1, na.rm=TRUE, progress="window", overwrite=TRUE)

Here the classified .img enter image description here

The classes are obviously wrong. Could it be due to wrong training-points?

I have 7 classes. (No excluded class for shadows or so, because I'm just trying to devide some tree-species) enter image description here

enter image description here

enter image description here

enter image description here

9
  • 1
    How did you collect the training data? Are the samples randomly stratified across all of the classes? Are all of the classes represented equally? How accurate are the training data--were they collected in the field with a GPS with poor accuracy?
    – Aaron
    Aug 27, 2014 at 17:30
  • Continued...Remember, as this is a pixel-based classifier, if any of the training sites are off by even one pixel, you may be introducing error into your model. Try simplifying your model to a small subset of the imagery and only classify one type of class.
    – Aaron
    Aug 27, 2014 at 17:34
  • 2 vegetation-classes were collected with GPS. Meadow, fields, sealed surfaces were not marked with GPS, but I made them as recognizeable for the classifier as possible. My shadow-classes were not devided, so I took forest-shadow, shadow on sealed surfaces as one class, because I thought that they are not important.
    – steveomb
    Aug 27, 2014 at 17:37
  • the 2 vegetation-classes were collected in homogeneous areas. I found them in person and identified them with GPS-points.
    – steveomb
    Aug 27, 2014 at 17:39
  • What type of accuracy does your GPS device have?
    – Aaron
    Aug 27, 2014 at 17:41

1 Answer 1

1

I think that somewhere in the classification process you are including spatial coordinates or pixel row/column IDs of your training samples. For a purely spectral classification and classes distributed in a spatially homogeneous manner it is not required to include spatial coordinates.

From a random forest perspective, this would explain the linear artifacts parallel to x-y axes, as random forest thresholds them linearly (one separation per variable). It seems also to separate well the clusters of training samples, which further supports this observation.

4
  • Both of your assertions are quite incorrect. Where it is not necessary to include naive spatial process [x,y], if there is anisotropy in the data, it can help account for trend. In regard to random forests, I am completely unclear as to what you mean. Given a literal translation, this is just wrong. Not only can you get multiple splits of a variable through a given tree, the model represents a bootstrap and is predicted through plurality. Both of these things make it inherently nonlinear. I believe that the linear artifacts are being caused by contrast differences in an image mosaic. Nov 21, 2014 at 17:04
  • 1
    If the spectral classes you are trying to detect are not sampled in a spatially homogeneous manner but in a clustered way (as it seems from the pictures of the OP, though I cannot see to which class they belong) the RF will find a optimal split (e.g. the lowest entropy) along either the x or y axis, as splitting on spectral values will surely give a higher entropy. The out of bag error will also be very low in this case. Regarding the use of multiple trees they should reduce the problem of overfitting the spatial locations. But again if training samples are clustered spatially, they won't.
    – pixelmitch
    Nov 21, 2014 at 17:32
  • 1
    This I completely agree with. I would add, building on @morbidmitch evaluation, that it is a misnomer that RF does not overfit. If there is significant correlation in the ensemble, often caused by lack of independence in observations, you will have an overfit problem. Nov 21, 2014 at 17:44
  • 1
    Yes. Exactly. In this case maybe the information about spatial trends or to simply enforce some smoothness in label prediction, it may be useful to add features such as local multiscale statistics (e.g. local means, local std, etc) instead of spatial locations. I also agree that this can be further emphasized by a wrong normalization between images composing a mosaic.
    – pixelmitch
    Nov 21, 2014 at 17:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.