title: R - nnet with a simple example of 2 classes with 2 variables
body: <p>I am using nnet for the first time, played with the basic examples found on the web, but cannot make out its output with a dummy toy data set. That a simple discrimination of two classes (signal and background) using 2 variables normally distributed.</p>
  
  <p>The following code can be copy&amp;paste in R (version 3.0):</p>
  
  <pre><code>library(nnet)
  
  ## Signal
  xs = rnorm( mean=0, sd=1, n=10000)
  ys = rnorm( mean=1, sd=1, n=10000)
  typs = rep( x=1, n=10000 )
  sig = data.frame( typs, xs, ys )
  colnames(sig) = c("z","x","y")
  sig_train = sig[c(1:5000),]
  sig_test = sig[c(5001:10000),]
  
  ## Background
  xb = rnorm( mean=1, sd=1, n=10000)
  yb = rnorm( mean=0, sd=1, n=10000)
  typb = rep( x=-1, n=10000 )
  bkg = data.frame( typb, xb, yb )
  colnames(bkg) = c("z","x","y")
  bkg_train = bkg[c(1:5000),]
  bkg_test = bkg[c(5001:10000),]
  
  ## Training
  trainData = rbind( sig_train, bkg_train )
  nnRes = nnet( z ~ ., trainData, size = 2, rang = 0.5, maxit = 100)
  print(nnRes)
  
  ## Testing
  sigNNPred = predict(nnRes, sig_test )
  bkgNNPred = predict(nnRes, bkg_test )
  </code></pre>
  
  <p>When looking at sigNNPred I have only zero's! </p>
  
  <p>So either the configuration of my NN is not performant, or I am looking at the wrong thing.</p>
  
  <p>Any hint is welcome.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Xavier</p>