[R-sig-Geo] Multiple variables and Raster predict function
jfprieur at gmail.com
Wed Sep 4 18:02:36 CEST 2013
Hello, new to R, have been spending the summer learning how to use the e1071
SVM functions. I am working on classification of multispectral (IR,R,G,B)
aerial imagery using SVM. I have been getting good preliminary results
working with e1071 and using small subsets of these images that I
transformed into data frames (eg, not working on the actual raster but
rather numerical representations) to get the hang of things.
I use multiple band ratios to build my SVM models so, for example, when I am
training for WATER or GROUND classification, I use 4 ratios from my training
area (these are just for example): Green/IR, NDVI, GNDVI,
Blue/Sum(IR+R+G+B). The data frame I send to the model is:
V1 V2 V3 V4 V5
Water x x x x
Ground x x x x
I then run
svm.model.<-svm(V1 ~ .,data=trainset,cost=100,gamma=1), I ran the tuning
function to get some idea of the proper parameters to use.
My small test image is loaded into a data frame (using values function from
raster package). I calculate the same ratios for the test image so that the
data frame looks like:
V2 V3 V4 V5
x x x x
I then use
svm.pred<-predict(svm.model,<small image data frame>,decision.values=TRUE)
and output a raster manually (convert the data frame using setvalues) with
the results. This works well and gives us some interesting results.
In order to be able to process entire images (1.2Gb, 12500*12500)at once, I
have started using the predict function in the raster package (along with
ClusterR) and working directly on raster objects. I have made an initial
classification using the raster predict function and got a raster (r1) with
two values (1,2) output which matched very well with the above method. The
command used was:
r1<-predict(<test image with proper ratios
The process was very fast (5 minutes) so I am very interested in using this
method. Just wanted to doublecheck my understanding.
My basic questions:
a) Instead of the classified result (1,2) is there any way to get the
decision values with raster predict. I saw some discussion with
'fun=predprob' but not quite sure.
b)I believe it works this way: my input raster contains 4 layers
(V2,V3,V4,V5) that are the ratios calculated from the original test image.
Is the raster predict method sending them to the SVM model in the same way
as my initial method above, eg. are all my variables being used by the
raster predict function? I think that it is clever enough to figure out that
each layer in the stack is a variable but want to be sure. If not, how would
I duplicate my initial method (using the vanilla predict function) with
I hope this is clear enough, thanks for any help!
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Multiple-variables-and-Raster-predict-function-tp7584547.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo