[R] what is 'class.ind' here?
onyourmark
william108 at gmail.com
Sat May 30 11:51:06 CEST 2009
Hi. The there is an example in nnet help which is pasted in below.
I am not sure how they are generating 'targets'. What is the 'class.ind()
function doing?
In the help docs for it they say "Generates a class indicator function from
a given factor."
I tried putting a simple vector of the "classes" into test.cl (below) but I
get an error of
"(list) object cannot be coerced to type 'double'"
my 'targets' vector was the last column of a matrix:
targets=crs$dataset[,922]
and so I tried to use
targets=class.ind(targets)
but still after: > test.cl(targets[-samp], predict(crsNNET1,
crsNNET1[-samp]))
I get:
Error in as.vector(data) :
(list) object cannot be coerced to type 'double'
By the way, my samp vector is:
samp <- c(sample(1:250,125), sample(251:500,125), sample(500:920,300))
Here is the example from nnet:
data(iris3)
# use half the iris data
ir <- rbind(iris3[,,1],iris3[,,2],iris3[,,3])
targets <- class.ind( c(rep("s", 50), rep("c", 50), rep("v", 50)) )
samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
ir1 <- nnet(ir[samp,], targets[samp,], size = 2, rang = 0.1,
decay = 5e-4, maxit = 200)
test.cl <- function(true, pred) {
true <- max.col(true)
cres <- max.col(pred)
table(true, cres)
}
test.cl(targets[-samp,], predict(ir1, ir[-samp,]))
--
View this message in context: http://www.nabble.com/what-is-%27class.ind%27-here--tp23791900p23791900.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list