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?
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?
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))