Skip to content

Instantly share code, notes, and snippets.

@monogenea

monogenea/11-audioClass.R

Last active Apr 6, 2020
Embed
What would you like to do?
# 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
You can’t perform that action at this time.