/
nnComparison.R
103 lines (90 loc) · 2.8 KB
/
nnComparison.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
95
96
97
98
99
100
101
102
103
# standard backprop
library(RSNNS)
model <- mlp(trainInputs, trainOutputs,
size=5,
learnFunc="Std_Backpropagation", learnFuncParams=c(0.02, 0),
maxit=500,
linOut = FALSE,
inputsTest = testInputs,
targetsTest = testOutputs
)
model <- mlp(x = trainInputs,
y = as.numeric(trainOutputs),
size=c(5,3),
learnFunc="Quickprop",
learnFuncParams=c(0.01, 2.0, 0.0001, 0.1),
maxit=100,
inputsTest = testInputs,
targetsTest = testOutputs,
linOut = FALSE
)
model <- mlp(x = trainInputs,
y = as.numeric(trainOutputs),
#y = trainOutputs,
size=5,
learnFunc="BackpropWeightDecay",
learnFuncParams=c(0.1, .0005, 0, 0),
maxit=500,
inputsTest = testInputs,
targetsTest = testOutputs,
linOut = FALSE
)
#print(model)
summary(model)
# predict on test set
predict_test <- predict(model, testInputs)
# Initial model plots on cross-validation data
par(mfrow=c(2,2))
plotIterativeError(model, ylim = errlim) # SSE error vs. training iteration
plotRegressionError(testOutputs, predict_test) # regression quality
plotROC(fitted.values(model), trainOutputs) # ROC on training data
plotROC(predict_test, testOutputs)
detach(RSNNS)
## nnet vs neuralnet
library(neuralnet)
nn.bp <- neuralnet(fo, data = trainData,
hidden=2,
threshold = 0.01,
stepmax = 1e+5,
learningrate = 0.01,
lifesign = "full",
algorithm = "backprop",
err.fct = "ce",
act.fct = "logistic",
linear.output = FALSE
)
nn.bp
nn <- neuralnet(fo, data = trainData,
hidden=2,
threshold = 0.01,
stepmax = 1e+5,
learningrate = 0.01,
lifesign = "full",
algorithm = "rprop+",
err.fct = "ce",
act.fct = "logistic",
linear.output = FALSE
)
nn
detach(neuralnet)
library(nnet)
nn.nnet <- nnet(fo, data = trainData,
size = 5,
#entropy = T,
abstol = 0.01,
decay = 5e-4,
maxit = 5000,
linout = FALSE
)
nn.nnet <- nnet(x = trainInputs,
#y = trainOutputs,
y = as.numeric(trainOutputs),
size = 5,
entropy = T,
abstol = 0.01,
decay = 5e-4,
maxit = 5000,
linout = FALSE
)
nn.nnet
detach(nnet)