-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogisticregression.R
More file actions
26 lines (22 loc) · 1.03 KB
/
logisticregression.R
File metadata and controls
26 lines (22 loc) · 1.03 KB
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
logisticregression <- function(table, labelcolumn, label1 , label2, featurecolumn){
library(pROC)
library(randomForest)
table[,labelcolumn] <- gsub(label1,0,table[,labelcolumn])
table[,labelcolumn] <- gsub(label2,1,table[,labelcolumn])
plot(table[,featurecolumn],table[,labelcolumn])
print(unique(table[,labelcolumn]))
plot.new()
glm_fit=glm(as.numeric(table[,labelcolumn]) ~ table[,featurecolumn], family=binomial, data = table)
lines(table[,featurecolumn], glm_fit$fitted.values)
test = predict(glm_fit,type = "response") >= 0.5
test2 <- gsub(TRUE,1,as.vector(test))
test2 <- gsub(FALSE,0,as.vector(test2))
par(pty="s")
roc.info <- roc(as.numeric(table[,labelcolumn]),glm_fit$fitted.values,plot = TRUE)
roc.info <- roc(as.numeric(table[,labelcolumn]),glm_fit$fitted.values,plot = TRUE, legacy.axes=TRUE,
percent=TRUE, xlab="FALSE Positive Percentage", ylab="True Positive Percentage",
lwd=4)
print(coords(roc.info, "best", ret = "threshold"))
fit_values <- data.frame(glm_fit$data[,labelcolumn],glm_fit$fitted.values)
print(fit_values)
}