[R] neuralnet to discriminate a given outcome by giving cutoff outputs

Luigi Marongiu marongiu.luigi at gmail.com
Sun Dec 20 14:02:21 CET 2015


Dear all,
I am trying to use neural networks to discriminate positive and
negative outcomes from a test; this outcome is given in the z variable
of the example I am providing. Each outcome is associated with a pair
of variables x and y and I was planning to identify the cut-offs that
could separate the positive from the negative results by splitting the
x/y space into 4 quadrants, the positive results lying in the 2nd
quadrant (the top right). In the example, the two cut-offs for x and y
are indicated with green lines (the values are absolutely subjective),
positive results are in red.
I was thinking of using the neural networks (implemented with the
neuralnet package) to obtain the x and y cut-offs but the returned
weight are off-scale. I tried to increment the number of hidden
neurons, to use more replicates and a maximum number of iteractions
but the results are never optimal.
Since I am completely new in neural networks usage, could you tell me
if the implementation is fine, where could I improve the model and
whether the neural network is the right approach for the problem I
need to solve?
Thank you
L

>>>
x<-c(31.1,    32.07,    33.01,    36.05,    17.88,    26.91,    27.35,
   38.44,    35.92,    38.08,    26.14,    40.35,    36.12,    21.51,
  22.75,    37.2,    16.94,    25.61,    25.83,    34.73,    36.93,
36.02,    37.43,    36.09,    34.74,    35.85,    16.35,    35.25,
26.98,    4.74,    2.89,    40.39,    42.18,    37.76,    2.73,
2.76,    2.64,    41.94,    45,    3.78,    2.86,    45,    2.77,
4.61,    2.52,    42.31,    2.92,    2.94,    3.01,    2.61,    45,
45,    44.54,    44.37,    36.24,    2.11,    2,    3.97,    44.54)
y<-c(0.08,    0.054,    0.082,    0.095,    0.135,    0.129,    0.099,
   0.072,    0.091,    0.093,    0.104,    0.077,    0.107,    0.108,
  0.107,    0.088,    0.121,    0.111,    0.069,    0.106,    0.041,
 0.091,    0.054,    0.083,    0.089,    0.086,    0.073,    0.085,
0.091,    0.008,    0.018,    0,    0,    0.001,    0.002,    0.011,
 0.001,    0.002,    -0.001,    0.005,    0.011,    0.002,    0.008,
 0.006,    0.006,    0.001,    0.006,    0.003,    0.015,    0.003,
0.002,    0.001,    0,    0.001,    0.002,    0.001,    -0.001,
0.002,    -0.001)
z<-c(1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
 1,    1,    1,    1,    1,    1,    0,    0,    0,    0,    0,    0,
  0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
   0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
0)
m<-data.frame(x,y,z)
pos <- subset(m, z == 1)
neg <- subset(m, z == 0)
# show points
X <- max(m$x)
Y <- max(m$y)
plot(pos$x, pos$y, pch=1, col="red",
     xlim=c(1,X), ylim=c(0,Y),
     xlab="x", ylab="y", main ="Training dataset",
     sub="Red = positive outcome; Black = negative outcome")
points(neg$x, neg$y, pch=1, col="black")
abline(v=6, lty=2, col="green")
abline(h=0.03, lty=2, col="green")
library(neuralnet)
tnm <- neuralnet(z ~ x + y,
                 data=m,
                 hidden=1,
                 algorithm = "rprop+",
                 err.fct = "ce",
                 act.fct = "logistic",
                 linear.output = FALSE
)
tnm$result.matrix
co.x <- tnm$result.matrix[5]
co.y <- tnm$result.matrix[6]
abline(v=co.x, lty=2, col="blue")
abline(h=co.y, lty=2, col="blue")



More information about the R-help mailing list