Skip to content

Commit

Permalink
Merge pull request #1060 from OldLipe/feature/sits_accuracy
Browse files Browse the repository at this point in the history
Fix sits_accuracy NA bug (Related to #1042)
  • Loading branch information
gilbertocamara authored Jan 9, 2024
2 parents 6c08c1a + f71a8e1 commit adadf4f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions R/sits_accuracy.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sits_accuracy.class_cube <- function(data, ..., validation) {

# Convert the tibble to a matrix
xy <- matrix(c(points_tile$X, points_tile$Y),
nrow = nrow(points_tile), ncol = 2
nrow = nrow(points_tile), ncol = 2
)
colnames(xy) <- c("X", "Y")

Expand All @@ -206,10 +206,16 @@ sits_accuracy.class_cube <- function(data, ..., validation) {
band = labelled_band,
xy = xy
)
# Transform to vector
values <- unlist(values)
# Indexes of NA values
idx_na <- !is.na(values)
# Remove NAs from values
values <- values[idx_na]
# Get the predicted values
predicted <- labels_cube[.as_chr(unlist(values))]
# Get reference classes
reference <- points_tile$label
predicted <- labels_cube[.as_chr(values)]
# Get reference classes and remove NAs
reference <- points_tile$label[idx_na]
# Does the number of predicted and reference values match?
.check_pred_ref_match(reference, predicted)
# Create a tibble to store the results
Expand Down

0 comments on commit adadf4f

Please sign in to comment.