-
Notifications
You must be signed in to change notification settings - Fork 0
/
bh_confwriteexcel_cluster.R
64 lines (49 loc) · 2.27 KB
/
bh_confwriteexcel_cluster.R
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
bh_confwriteexcel_cluster<-function(AccMatrix, fname,option)
{
library(xlsx)
classifier<-list("PerTurbo","SVM","DecTree","RandForst")
nfolds<-nrow(AccMatrix$OA)
sheetnames<-paste0(classifier[option],"Fold",seq(from=1,to=nfolds, by=1))
# create workbooks and styles
setwd("/share/home/damodara/DenmarkWork/RCodes/Results/ISPRS_7")
wp<-createWorkbook(type="xlsx")
# col and row styles
cs1 <- CellStyle(wp) + Font(wp, isBold = TRUE,color="blue") # rowcolumns
#cs2 <- CellStyle(wb) + Font(wb, iscolor="blue")
for (i in 1:nfolds)
{
sheet<-createSheet(wp, sheetName=sheetnames[i])
Title<-"ISPRS_7 NDVI_AP Classification"
xlsx.addTitle(wp,sheet, Title)
rows <- createRow(sheet, rowIndex=5);cells <- createCell(rows, colIndex=3)[[1,1]]
setCellValue(cells,"OA")
# write Overall accuarcy
addDataFrame(t(AccMatrix$OA[i,]), sheet, startRow=5, startColumn=4,row.names = FALSE, col.names = TRUE,colnamesStyle=cs1,
rownamesStyle=cs1,byrow=FALSE)
# write the confusion matrix
rows <- createRow(sheet, rowIndex=9);cells <- createCell(rows, colIndex=3)[[1,1]]
setCellValue(cells,"ConfusionMatrix")
#
addDataFrame(AccMatrix$conf[i], sheet, startRow=10, startColumn=4,row.names = TRUE, col.names = TRUE,colnamesStyle=cs1)
## write the Producer Accuarcy
rows <- createRow(sheet, rowIndex=22);cells <- createCell(rows, colIndex=3)[[1,1]]
setCellValue(cells,"ProducerAccuracy")
#
addDataFrame(AccMatrix$PA[i], sheet, startRow=23, startColumn=4,row.names = TRUE, col.names = TRUE,colnamesStyle=cs1)
## write the User Accuarcy
rows <- createRow(sheet, rowIndex=22);cells <- createCell(rows, colIndex=16)[[1,1]]
setCellValue(cells,"UserAccuracy")
#
addDataFrame(AccMatrix$UA[i], sheet, startRow=23, startColumn=17,row.names = TRUE, col.names = TRUE,colnamesStyle=cs1)
}
saveWorkbook(wp,fname)
}
# Function for the Title and Font
xlsx.addTitle<-function(wb, sheet, title){
rows <-createRow(sheet,rowIndex=3)
sheetTitle <-createCell(rows, colIndex=8)
TITLE_STYLE <- CellStyle(wb)+ Font(wb, heightInPoints=16,
color="red", isBold=TRUE, underline=1)
setCellValue(sheetTitle[[1,1]], title)
setCellStyle(sheetTitle[[1,1]], TITLE_STYLE)
}