0

I use model.matrix() method in R to generate dummy variables as:

dd <- data.frame(a = gl(2,2))
model.matrix(~ a - 1,dd)

Instead of 0 and 1 output labels, what parameter we need to set in model.matrix() so that output labels are -1 and 1?

Haroon Lone
  • 2,837
  • 5
  • 29
  • 65
  • Please read section: "Why not code binary inputs as 0 and 1" at link http://www.faqs.org/faqs/ai-faq/neural-nets/part2/ – Haroon Lone Oct 25 '16 at 14:38

1 Answers1

0

Although I did not get it properly, but I followed these steps

dd <- data.frame(a = gl(2,2))
temp <- model.matrix(~ a - 1,dd)
temp <- apply(temp, 2, function(x) ifelse(x == 0, -1, 1))
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65