Created
June 19, 2018 14:14
-
-
Save artemklevtsov/d3f915e32ddf2d0bee5a996882f76d69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(ROCR) | |
library(ggplot2) | |
f_plot <- function(predictions, labels) { | |
if (is.list(predictions) && is.atomic(labels)) | |
labels <- rep.int(list(labels), length(predictions)) | |
p <- prediction(predictions, labels) | |
# Labels | |
nm <- names(predictions) | |
if (is.null(nm)) | |
nm <- make.names(seq_along(predictions)) | |
vals <- performance(p, "f") | |
data <- data.table( | |
name = rep.int(nm, lengths([email protected])), | |
y = unlist([email protected]), | |
x = unlist([email protected]) | |
) | |
ggplot(data, aes(x = x, y = y, color = name)) + | |
geom_line() + | |
labs(y = [email protected], | |
x = [email protected], | |
color = "") + | |
facet_wrap(~ name, ncol = 1L, scales = "free") + | |
theme(legend.position = "bottom") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(ROCR) | |
library(ggplot2) | |
pr_plot <- function(predictions, labels) { | |
if (is.list(predictions) && is.atomic(labels)) | |
labels <- rep.int(list(labels), length(predictions)) | |
p <- prediction(predictions, labels) | |
# Labels | |
nm <- names(predictions) | |
if (is.null(nm)) | |
nm <- make.names(seq_along(predictions)) | |
vals <- performance(p, "prec", "rec") | |
data <- data.table( | |
name = rep.int(nm, lengths([email protected])), | |
y1 = unlist([email protected]), | |
y2 = unlist([email protected]), | |
x = unlist([email protected]) | |
) | |
setnames(data, c("y1", "y2"), c([email protected], [email protected])) | |
data <- melt(data, id.vars = c("x", "name")) | |
ggplot(data, aes(x = x, y = value, color = variable)) + | |
geom_line() + | |
labs(y = "Value", | |
x = [email protected], | |
color = "") + | |
facet_wrap(~ name, ncol = 1L, scales = "free") + | |
theme(legend.position = "bottom") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(ROCR) | |
library(ggplot2) | |
roc_plot <- function(predictions, labels) { | |
if (is.list(predictions) && is.atomic(labels)) | |
labels <- rep.int(list(labels), length(predictions)) | |
p <- prediction(predictions, labels) | |
# AUC | |
auc <- performance(p, "auc") | |
auc <- unlist([email protected]) | |
# Labels | |
nm <- names(predictions) | |
if (is.null(nm)) | |
nm <- make.names(seq_along(predictions)) | |
nm <- sprintf("%s: AUC = %.3f", nm, auc) | |
# ROC | |
vals <- performance(p, "tpr", "fpr") | |
data <- data.table( | |
name = rep.int(nm, lengths([email protected])), | |
x = unlist([email protected]), | |
y = unlist([email protected]) | |
) | |
# Plot | |
ggplot(data, aes(x = x, y = y, color = name)) + | |
geom_path() + | |
labs(x = [email protected], | |
y = [email protected], | |
color = "") + | |
theme(legend.position = "bottom", | |
legend.direction = "vertical") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment