[R-sig-Geo] how to export results of predict.randomForest
Anne Axel
axelanne at msu.edu
Wed Dec 24 21:58:36 CET 2008
Hi List,
I am requesting help with exporting results from the
predict.randomForest function. This is my first attempt at working
with spatial data in R--I was able to import the data and run the
randomForest model, but I cannot figure out how to export the data
for use in ArcGIS or ENVI.
I've pasted below the code I used for randomForest and exporting of
results. If anyone has suggestions, I would be eternally
grateful! Thanks, and Happy Holidays.
Anne Axel
Department of Fisheries and Wildlife
Michigan State University
20 Natural Resources Building
East Lansing, MI 48824 USA
517-930-2248
axelanne at msu.edu
####Read in *img file with 55 bands
bands=readGDAL("multibands3.img")
imgtabla <- as(bands, "data.frame")
######Read in training data and run randomForest
data=read.csv("bandnumsOutput_cond2.csv", header=TRUE)
data2=data[,1:58]
data.rf=randomForest(COVERTYPE~ ., data=data2, mtry=16, importance =
TRUE, do.trace=100)
print(data.rf)
output=predict(data.rf, imgtabla)
#### I've tried numerous ways of exporting the data, but I don't seem
to have the data in a format that's acceptable to the functions. In
addition, I've tried to coerce data into other formats, but nothing
has worked. Any suggestions?
> writeGDAL(bands, output, drivername = "GTiff", type = "Float32",
mvFlag = NA, options=NULL)
Error in .local(.Object, ...) :
STRING_ELT() can only be applied to a 'character vector', not a 'integer'
In addition: Warning messages:
1: In if (nchar(fname) == 0) stop("empty file name") :
the condition has length > 1 and only the first element will be used
2: In if (nchar(filename) == 0) stop("empty file name") :
the condition has length > 1 and only the first element will be used
> writeGDAL(output, bands, drivername = "GTiff", type = "Float32",
mvFlag = NA, options=NULL)
Error in nchar(fname) : cannot coerce type S4 to character vector
> write.ENVI(output)
Error in dim(X) = c(nRow, nCol, nBand) : length-0 dimension vector is invalid
> write.ascii.grid(output, "output", header = NULL, write.header = TRUE)
Error: is.matrix(data) is not TRUE
Anne C. Axel
Department of Fisheries and Wildlife
Michigan State University
20 Natural Resources Building
East Lansing, MI 48824 USA
517-930-2248
axelanne at msu.edu
More information about the R-sig-Geo
mailing list