clear all
#install necessary packages
#install.packages(c("raster","sp","rgdal","randomForest","clusterGeneration","mnormt","party"),"D:\code\RF\R_library")
library(sp)
library(rgdal)
library(raster)
library(randomForest)
library(clusterGeneration)
library(mnormt)
library(party)
library(corrplot)
secretly<-read.csv("D:/software/random forest/170704 characteristics.csv", header=TRUE)
#train samples using random forest
rfdata <- randomForest(class~., data=secretly, importance=TRUE, proximity=TRUE)
#S=genPositiveDefMat("eigen",dim=30)
#S=genPositiveDefMat("unifcorrmat",dim=30)
#corrplot(cor(rfdata), order = "hclust")
importance(rfdata)
importance(rfdata,type=1)
varImpPlot(rfdata)
rfdata <- cforest(class~., data=secretly, control=cforest_unbiased(ntree=50))
varimp(rfdata)
#read the RS imagery
#2007
whole_bands=brick("D:/GF2/random forest/28stacking.tif")
#specify the band names
names(whole_bands)=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20","21", "22", "23", "24", "25", "26", "27", "28")
img_bio <- predict(whole_bands,rfdata, type="response")
writeRaster(img_bio, "output.img", format="HFA", datatype="FLT4S", overwrite=TRUE)
importance(secretly)
评论1