-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic models only.R
68 lines (48 loc) · 1.91 KB
/
basic models only.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
#Load File, Load Packages
bank<-read.csv("bank-additional-full.csv",header=TRUE,sep=";")
install.packages(rminer)
library(rminer)
#Create artificial time-axis beforehand though. The website noted that the values were chronologi-
#cally sorted. Therefore a simple itemnumber identifies a chronology.
time_axis <- as.numeric(rownames(bank))
bank_time1 <- cbind(bank, time_axis)
bank_time <- bank_time1[1:1000,]
#Set modeling techniques, for more information see description in rminer documentation
models_name <- rbind("Decision Tree", "Support Vector Machine", "Neural Network", "LOGIT")
models_specs <-rbind("ctree","ksvm","mlp","lr")
models <- cbind(models_name, models_specs)
colnames(models) <- c("Name", "Model")
# Hold-out (train, test sets)
H=holdout(bank_time$y,ratio=2/3)
#----------------------Modeling----------------------------#
for (a in 1:100) {
for (i in seq_len(nrow(models))) {
# Setting seed
set.seed(a)
#Modeling
M=fit(y~.,bank_time[H$tr,], model = models[i,2], task="class")
M2=fit(y~.,bank_time[H$tr,], model = models[i,2], task="prob")
# Creating variables model
P=predict(M,bank_time[H$ts,])
P2=predict(M2,bank_time[H$ts,])
#Title
cat(paste("----- Results for model", models[i,1], "-----", "\n"))
# AUC of ROC
cat(paste("AUC for ROC for model", models[i,1], "= "))
cat(mmetric(bank_time$y[H$ts],P2,"AUC"), "\n")
# AUC ALIFT
cat(paste("AUC for ALIFT model", models[i,1], "= "))
cat(mmetric(bank_time$y[H$ts],P2,"ALIFT"), "\n")
# Accuracy
cat(paste("Accuracy Pred. model", models[i,1], "= "))
cat(mmetric(bank_time$y[H$ts],P,"ACC"), "\n")
#ROC
mgraph(bank_time$y[H$ts],P2,graph="ROC",TC=2,main=paste("ROC Curve for",models[i,1]),
baseline=TRUE,leg=models[i,1],Grid=10)
#LIFT
mgraph(bank_time$y[H$ts],P2,graph="LIFT",TC=2,main=paste("LIFT Curve for", models[i,1]),
baseline=TRUE,leg=models[i,1],Grid=10)
}
}
########Reset Memory
gc()