Commit f425b983 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

To be able to handle NAs we need to add the parameter: na.action = na.omit,...

To be able to handle NAs we need to add the parameter: na.action = na.omit, this is, omit pixels with NA value.
parent ec8c492e
......@@ -54,25 +54,23 @@ model_opt_r <- function(k,
if (sample_type == "regular") {
pbt <- raster::sampleRegular(raster, size = sample_size, sp = T)
}
f <- which(is.na(pbt@data[1]))
if (length(f) != 0) {
pbt <- pbt[-f,]
}
set.seed(seed2[k])
classes <-
as.factor(sample(c(1:2), size = nrow(pbt), replace = T))
if (length(levels(classes)) < 2) {
break
}
data <- as.data.frame(cbind(classes, pbt@data))
}
########################################################################
if (model == "rf") {
model1 <-
randomForest::randomForest(as.factor(classes) ~ .,
na.action = na.omit,
data = data,
mtry = mtry)
if (is.na(mean(model1$err.rate[, 1])) == TRUE) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment