In this script, we will evaluate the performance of the WATG technique for region classification in PolSAR textures.
# Load some packages:
if(!require(caret)) install.packages("caret")
if(!require(MLmetrics)) install.packages("MLmetrics")
n.total = 160
regions = c(rep("Forest",40), rep("Sea",80), rep("Urban", 40))
Entropy.Complexity = data.frame("Entropy" = numeric(n.total),
"Complexity" = numeric(n.total),
"Region" = character(n.total),
stringsAsFactors=FALSE)
Entropy.Complexity.csv = read.csv(file="../../Data/EntropyComplexityFGPET1A1.csv",
header=TRUE, sep=",")
Entropy.Complexity$Entropy = Entropy.Complexity.csv[,1]
Entropy.Complexity$Complexity = Entropy.Complexity.csv[,2]
Entropy.Complexity$Region = regions
split = 0.85
trainIndex = createDataPartition(Entropy.Complexity$Region, p = split, list = FALSE)
x = data.frame(Entropy.Complexity$Entropy[trainIndex], Entropy.Complexity$Complexity[trainIndex])
y = factor(Entropy.Complexity$Region[trainIndex])
x_validation = data.frame("Entropy" = Entropy.Complexity$Entropy[-trainIndex], "Complexity" = Entropy.Complexity$Complexity[-trainIndex])
y_validation = factor(Entropy.Complexity$Region[-trainIndex])
Entropy.Complexity = data.frame("Entropy" = Entropy.Complexity$Entropy[trainIndex],
"Complexity" = Entropy.Complexity$Complexity[trainIndex],
"Region" = Entropy.Complexity$Region[trainIndex],
stringsAsFactors=FALSE)
set.seed(123)
ctrl = trainControl(method="repeatedcv", number = 10, repeats = 10)
knnFit = train(Region~., data = Entropy.Complexity, method = "knn",
trControl = ctrl,
preProcess = c("center","scale"),
tuneLength = 20)
pred = predict(knnFit, newdata = x_validation)
xtab = table(pred, y_validation)
confusionMatrix(xtab)
Confusion Matrix and Statistics
y_validation
pred Forest Sea Urban
Forest 5 2 0
Sea 1 10 0
Urban 0 0 6
Overall Statistics
Accuracy : 0.875
95% CI : (0.6764, 0.9734)
No Information Rate : 0.5
P-Value [Acc > NIR] : 0.0001386
Kappa : 0.8033
Mcnemar's Test P-Value : NA
Statistics by Class:
Class: Forest Class: Sea Class: Urban
Sensitivity 0.8333 0.8333 1.00
Specificity 0.8889 0.9167 1.00
Pos Pred Value 0.7143 0.9091 1.00
Neg Pred Value 0.9412 0.8462 1.00
Prevalence 0.2500 0.5000 0.25
Detection Rate 0.2083 0.4167 0.25
Detection Prevalence 0.2917 0.4583 0.25
Balanced Accuracy 0.8611 0.8750 1.00
cat("Accuracy: ", Accuracy(pred, y_validation), " Recall: ", Recall(pred, y_validation), " Precision: ", Precision(pred, y_validation), " F1-Score: ", F1_Score(pred, y_validation), "\n")
Accuracy: 0.875 Recall: 0.7142857 Precision: 0.8333333 F1-Score: 0.7692308
n.total = 160
regions = c(rep("Forest",40), rep("Sea",80), rep("Urban", 40))
Entropy.Complexity = data.frame("Entropy" = numeric(n.total),
"Complexity" = numeric(n.total),
"Region" = character(n.total),
stringsAsFactors=FALSE)
Entropy.Complexity.csv = read.csv(file="../../Data/EntropyComplexityFGPET1A05.csv",
header=TRUE, sep=",")
Entropy.Complexity$Entropy = Entropy.Complexity.csv[,1]
Entropy.Complexity$Complexity = Entropy.Complexity.csv[,2]
Entropy.Complexity$Region = regions
split = 0.85
trainIndex = createDataPartition(Entropy.Complexity$Region, p = split, list = FALSE)
x = data.frame(Entropy.Complexity$Entropy[trainIndex], Entropy.Complexity$Complexity[trainIndex])
y = factor(Entropy.Complexity$Region[trainIndex])
x_validation = data.frame("Entropy" = Entropy.Complexity$Entropy[-trainIndex], "Complexity" = Entropy.Complexity$Complexity[-trainIndex])
y_validation = factor(Entropy.Complexity$Region[-trainIndex])
Entropy.Complexity = data.frame("Entropy" = Entropy.Complexity$Entropy[trainIndex],
"Complexity" = Entropy.Complexity$Complexity[trainIndex],
"Region" = Entropy.Complexity$Region[trainIndex],
stringsAsFactors=FALSE)
set.seed(123)
ctrl = trainControl(method="repeatedcv", number = 10, repeats = 10)
knnFit = train(Region~., data = Entropy.Complexity, method = "knn",
trControl = ctrl,
preProcess = c("center","scale"),
tuneLength = 20)
pred = predict(knnFit, newdata = x_validation)
xtab = table(pred, y_validation)
confusionMatrix(xtab)
Confusion Matrix and Statistics
y_validation
pred Forest Sea Urban
Forest 5 0 0
Sea 1 12 0
Urban 0 0 6
Overall Statistics
Accuracy : 0.9583
95% CI : (0.7888, 0.9989)
No Information Rate : 0.5
P-Value [Acc > NIR] : 1.49e-06
Kappa : 0.9322
Mcnemar's Test P-Value : NA
Statistics by Class:
Class: Forest Class: Sea Class: Urban
Sensitivity 0.8333 1.0000 1.00
Specificity 1.0000 0.9167 1.00
Pos Pred Value 1.0000 0.9231 1.00
Neg Pred Value 0.9474 1.0000 1.00
Prevalence 0.2500 0.5000 0.25
Detection Rate 0.2083 0.5000 0.25
Detection Prevalence 0.2083 0.5417 0.25
Balanced Accuracy 0.9167 0.9583 1.00
cat("Accuracy: ", Accuracy(pred, y_validation), " Recall: ", Recall(pred, y_validation), " Precision: ", Precision(pred, y_validation), " F1-Score: ", F1_Score(pred, y_validation), "\n")
Accuracy: 0.9583333 Recall: 1 Precision: 0.8333333 F1-Score: 0.9090909
n.total = 160
regions = c(rep("Forest",40), rep("Sea",80), rep("Urban", 40))
Entropy.Complexity = data.frame("Entropy" = numeric(n.total),
"Complexity" = numeric(n.total),
"Region" = character(n.total),
stringsAsFactors=FALSE)
Entropy.Complexity.csv = read.csv(file="../../Data/EntropyComplexityAAPED3T1A1.csv",
header=TRUE, sep=",")
Entropy.Complexity$Entropy = Entropy.Complexity.csv[,1]
Entropy.Complexity$Complexity = Entropy.Complexity.csv[,2]
Entropy.Complexity$Region = regions
split = 0.85
trainIndex = createDataPartition(Entropy.Complexity$Region, p = split, list = FALSE)
x = data.frame(Entropy.Complexity$Entropy[trainIndex], Entropy.Complexity$Complexity[trainIndex])
y = factor(Entropy.Complexity$Region[trainIndex])
x_validation = data.frame("Entropy" = Entropy.Complexity$Entropy[-trainIndex], "Complexity" = Entropy.Complexity$Complexity[-trainIndex])
y_validation = factor(Entropy.Complexity$Region[-trainIndex])
Entropy.Complexity = data.frame("Entropy" = Entropy.Complexity$Entropy[trainIndex],
"Complexity" = Entropy.Complexity$Complexity[trainIndex],
"Region" = Entropy.Complexity$Region[trainIndex],
stringsAsFactors=FALSE)
set.seed(123)
ctrl = trainControl(method="repeatedcv", number = 10, repeats = 10)
knnFit = train(Region~., data = Entropy.Complexity, method = "knn",
trControl = ctrl,
preProcess = c("center","scale"),
tuneLength = 20)
pred = predict(knnFit, newdata = x_validation)
xtab = table(pred, y_validation)
confusionMatrix(xtab)
Confusion Matrix and Statistics
y_validation
pred Forest Sea Urban
Forest 3 3 0
Sea 3 9 0
Urban 0 0 6
Overall Statistics
Accuracy : 0.75
95% CI : (0.5329, 0.9023)
No Information Rate : 0.5
P-Value [Acc > NIR] : 0.01133
Kappa : 0.6
Mcnemar's Test P-Value : NA
Statistics by Class:
Class: Forest Class: Sea Class: Urban
Sensitivity 0.5000 0.750 1.00
Specificity 0.8333 0.750 1.00
Pos Pred Value 0.5000 0.750 1.00
Neg Pred Value 0.8333 0.750 1.00
Prevalence 0.2500 0.500 0.25
Detection Rate 0.1250 0.375 0.25
Detection Prevalence 0.2500 0.500 0.25
Balanced Accuracy 0.6667 0.750 1.00
cat("Accuracy: ", Accuracy(pred, y_validation), " Recall: ", Recall(pred, y_validation), " Precision: ", Precision(pred, y_validation), " F1-Score: ", F1_Score(pred, y_validation), "\n")
Accuracy: 0.75 Recall: 0.5 Precision: 0.5 F1-Score: 0.5
n.total = 160
regions = c(rep("Forest",40), rep("Sea",80), rep("Urban", 40))
Entropy.Complexity = data.frame("Entropy" = numeric(n.total),
"Complexity" = numeric(n.total),
"Region" = character(n.total),
stringsAsFactors=FALSE)
Entropy.Complexity.csv = read.csv(file="../../Data/EntropyComplexityAAPED3T1A05.csv",
header=TRUE, sep=",")
Entropy.Complexity$Entropy = Entropy.Complexity.csv[,1]
Entropy.Complexity$Complexity = Entropy.Complexity.csv[,2]
Entropy.Complexity$Region = regions
split = 0.85
trainIndex = createDataPartition(Entropy.Complexity$Region, p = split, list = FALSE)
x = data.frame(Entropy.Complexity$Entropy[trainIndex], Entropy.Complexity$Complexity[trainIndex])
y = factor(Entropy.Complexity$Region[trainIndex])
x_validation = data.frame("Entropy" = Entropy.Complexity$Entropy[-trainIndex], "Complexity" = Entropy.Complexity$Complexity[-trainIndex])
y_validation = factor(Entropy.Complexity$Region[-trainIndex])
Entropy.Complexity = data.frame("Entropy" = Entropy.Complexity$Entropy[trainIndex],
"Complexity" = Entropy.Complexity$Complexity[trainIndex],
"Region" = Entropy.Complexity$Region[trainIndex],
stringsAsFactors=FALSE)
set.seed(123)
ctrl = trainControl(method="repeatedcv", number = 10, repeats = 10)
knnFit = train(Region~., data = Entropy.Complexity, method = "knn",
trControl = ctrl,
preProcess = c("center","scale"),
tuneLength = 20)
pred = predict(knnFit, newdata = x_validation)
xtab = table(pred, y_validation)
confusionMatrix(xtab)
Confusion Matrix and Statistics
y_validation
pred Forest Sea Urban
Forest 2 2 0
Sea 4 10 0
Urban 0 0 6
Overall Statistics
Accuracy : 0.75
95% CI : (0.5329, 0.9023)
No Information Rate : 0.5
P-Value [Acc > NIR] : 0.01133
Kappa : 0.5862
Mcnemar's Test P-Value : NA
Statistics by Class:
Class: Forest Class: Sea Class: Urban
Sensitivity 0.33333 0.8333 1.00
Specificity 0.88889 0.6667 1.00
Pos Pred Value 0.50000 0.7143 1.00
Neg Pred Value 0.80000 0.8000 1.00
Prevalence 0.25000 0.5000 0.25
Detection Rate 0.08333 0.4167 0.25
Detection Prevalence 0.16667 0.5833 0.25
Balanced Accuracy 0.61111 0.7500 1.00
cat("Accuracy: ", Accuracy(pred, y_validation), " Recall: ", Recall(pred, y_validation), " Precision: ", Precision(pred, y_validation), " F1-Score: ", F1_Score(pred, y_validation), "\n")
Accuracy: 0.75 Recall: 0.5 Precision: 0.3333333 F1-Score: 0.4