Skip to content

Instantly share code, notes, and snippets.

@monogenea
Last active April 6, 2020 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monogenea/cc76296dbeb488880929bd7d29d81d32 to your computer and use it in GitHub Desktop.
Save monogenea/cc76296dbeb488880929bd7d29d81d32 to your computer and use it in GitHub Desktop.
# Grep species, set colors for heatmap
speciesClass <- gsub(colnames(train$Y), pat = "species", rep = "")
cols <- colorRampPalette(rev(brewer.pal(n = 7, name = "RdGy")))
# Validation predictions
predProb <- predict(model, val$X)
predClass <- speciesClass[apply(predProb, 1, which.max)]
trueClass <- speciesClass[apply(val$Y, 1, which.max)]
# Plot confusion matrix
confMat <- confusionMatrix(data = factor(predClass, levels = speciesClass),
reference = factor(trueClass, levels = speciesClass))
pheatmap(confMat$table, cluster_rows = F, cluster_cols = F,
border_color = NA, show_colnames = F,
labels_row = speciesClass,
color = cols(max(confMat$table)+1))
# Accuracy in validation set
mean(predClass == trueClass) # 0.7541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment