-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path22.07 - Logistic Regresyon - Logistic Regresyon 7 - Optimum Eşik Değeri.R
executable file
·93 lines (57 loc) · 2.06 KB
/
22.07 - Logistic Regresyon - Logistic Regresyon 7 - Optimum Eşik Değeri.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
### Logistic Regresyon #########################
library(caret)
library(glmnet)
library(tidyverse)
placement["sl_no"] <- NULL
placement["salary"] <- NULL
table(placement$status)
dataPlaced <- placement %>% filter(status == "Placed")
dataNotPlaced <- placement %>% filter(status == "Not Placed")
nrow(dataPlaced)
nrow(dataNotPlaced)
set.seed(155)
dataPlacedIndex <- sample(1:nrow(dataPlaced) , size = 0.75*nrow(dataNotPlaced) )
set.seed(155)
dataNotPlacedIndex <- sample(1:nrow(dataNotPlaced) , size = 0.75*nrow(dataNotPlaced) )
trainPlaced <- dataPlaced[ dataPlacedIndex , ]
trainNotPlaced <- dataNotPlaced[ dataNotPlacedIndex , ]
trainSet <- rbind(trainPlaced , trainNotPlaced)
table(trainSet$status)
testPlaced <- dataPlaced[ -dataPlacedIndex , ]
testNotPlaced <- dataNotPlaced[ -dataNotPlacedIndex , ]
testSet <- rbind(testPlaced , testNotPlaced)
table(testSet$status)
?glm
## GLM ile Logistic Regresyon Modeli Oluşturma
# modelLogit <- glm(status ~ . , data = trainSet , family = binomial(link = "logit"))
modelLogit <- glm(status ~ . , data = trainSet , family = "binomial")
modelLogit
summary(modelLogit)
### ANOVA Değişken Deviance Değerleri
anova(modelLogit)
summary(modelLogit)
## variable Importance
varImp(modelLogit)
### Model Üzerinden Tahminler
# install.packages("InformationValue")
library(InformationValue)
predictions1 <- predict(modelLogit , testSet , type = "response")
predictions2 <- plogis(predict(modelLogit , testSet))
cm <- InformationValue::confusionMatrix(testSet$status , predictedScores = predictions1)
accur <- (cm[1,1] + cm[2,2]) /sum(cm)
accur
errorRate <- (cm[1,2] + cm[2,1]) / sum(cm)
errorRate
### Optimal Cutoff value
summary(predictions1)
optCutoff <- InformationValue::optimalCutoff(testSet$status , predictedScores = predictions1)
optCutoff
cmOpt <- InformationValue::confusionMatrix(testSet$status ,
predictedScores = predictions1 ,
threshold = optCutoff )
cmOpt
accurOpt <- (cmOpt[1,1] + cmOpt[2,2]) /sum(cmOpt)
accurOpt
accur
cm
cmOpt