-
Notifications
You must be signed in to change notification settings - Fork 0
/
logisticRegression_PredictingBugCovering_fromRanking.R
94 lines (75 loc) · 2.62 KB
/
logisticRegression_PredictingBugCovering_fromRanking.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
90
91
92
93
94
#Logistic regression using CARET Package
#Predict bug covering questions based on various values of
#the parameters in the aggregation methods
install.packages(ElemStatLearn)
library(ElemStatLearn)
library(klaR)
library(caret)
library(gmodels)
library(e1071)
library(caTools)
#Obtain the data
# Import data
source("C://Users//chris//OneDrive//Documentos//GitHub//ML_VotingAggregation//aggregateAnswerOptionsPerQuestion.R");
summaryTable <- runMain();
#summaryTable <- data.frame(summaryTable);
#I need to guarantee that some examples (i.e., failing methods)
#do not dominate the training or testing sets. To do that, I need to get a
#close to equal proportion of examples in both sets
#Scramble the dataset before extracting the training set.
set.seed(8850);
g<- runif((nrow(summaryTable))); #generates a random distribution
summaryTable <- summaryTable[order(g),];
############################################################################################
# Build model
sub = sample(nrow(summaryTable), floor(nrow(summaryTable) * 0.7))
train = summaryTable[sub,]
test = summaryTable[-sub,]
xTrain = train[,"rankingVote"]
yTrain = as.factor(train$bugCovering);
xTest = test[,"rankingVote"]
yTest = as.factor(test$bugCovering);
xS = summaryTable[,"rankingVote"]
yS = data.frame(summaryTable[,"bugCovering"]);
#To compute Area Under the Curve and
myControl <- trainControl(
method = "repeatcv",
number = 10,
repeats = 5,
summaryFunction = twoClassSummary,
classProbs = TRUE, # IMPORTANT!
verboseIter = TRUE
)
model<- train(bugCovering ~ rankingVote,Sonar, method="glm", trControl=myControl);
p <- predict(model, test, type = "response")
colAUC(p,test[["bugCovering"]],plotROC=TRUE)
summary(p)
p_class<- ifelse(p>0.8147059,TRUE, FALSE) #requires to choose a probability threshold
confusionMatrix(p_class,test[["bugCovering"]])
predictted.df <- data.frame(predictted);
CrossTable(predictted.df$class,yS$bugCovering);
confusionMatrix(predictted.df$class,yS$bugCovering);
# Reference
# Prediction FALSE TRUE
# FALSE 33 3
# TRUE 1 2
#
# Accuracy : 0.8974
# 95% CI : (0.7578, 0.9713)
# No Information Rate : 0.8718
# P-Value [Acc > NIR] : 0.4284
#
# Kappa : 0.4468
# Mcnemar's Test P-Value : 0.6171
#
# Sensitivity : 0.9706
# Specificity : 0.4000
# Pos Pred Value : 0.9167
# Neg Pred Value : 0.6667
# Prevalence : 0.8718
# Detection Rate : 0.8462
# Detection Prevalence : 0.9231
# Balanced Accuracy : 0.6853
#
# 'Positive' Class : FALSE
#########################################################