-
Notifications
You must be signed in to change notification settings - Fork 3
/
ROC.R
46 lines (35 loc) · 1.39 KB
/
ROC.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
library(ggplot2)
library(RColorBrewer)
mydata <- read.table("senSpecTable.txt",header = TRUE)
p <- qplot(FPR, TPR, data = mydata, geom = "blank", main = "ROC curve",
xlab = "False Positive Rate (1-Specificity)",
ylab = "True Positive Rate (Sensitivity)" )
ggplot(df,aes(FPR,TPR))+geom_line(size = 1, alpha = )+
labs(title= "ROC curve",
x = "False Positive Rate (1-Specificity)",
y = "True Positive Rate (Sensitivity)")
basicplot <- ggplot(mydata, aes(d = D, m = M1))
library(ggplot2)
diamonds$is_expensive <- diamonds$price > 2400
is_test <- runif(nrow(diamonds)) > 0.75
train <- diamonds[is_test==FALSE,]
test <- diamonds[is_test==TRUE,]
summary(fit <- glm(is_expensive ~ carat + cut + clarity, data=train))
library(ROCR)
prob <- predict(fit, newdata=test, type="response")
pred <- prediction(prob, test$is_expensive)
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
# I know, the following code is bizarre. Just go with it.
auc <- performance(pred, measure = "auc")
auc <- [email protected][[1]]
roc.data <- data.frame(fpr=unlist([email protected]),
tpr=unlist([email protected]),
model="GLM")
ggplot(roc.data, aes(x=fpr, ymin=0, ymax=tpr)) +
geom_ribbon(alpha=0.2) +
geom_line(aes(y=tpr)) +
ggtitle(paste0("ROC Curve w/ AUC=", auc))
system.file()
setwd(pwd)
this.dir <- dirname(parent.frame(2)$ofile)
setwd(this.dir)