nnet.formula(formula, data=NULL, weights, ...,
subset, na.action=na.fail, contrasts=NULL)
nnet.default(x, y, weights, size, Wts, mask,
linout=F, entropy=F, softmax=F, censored=F,
skip=F, rang=0.7, decay=0, maxit=100,
Hess=F, trace=T, MaxNWts=1000, abstol=1.0e-4,
reltol=1.0e-8, ...)
class ~ x1 + x2 + ...
x values for examples.
formula are
preferentially to be taken.
NAs are found.
The default action is for the procedure to fail. An alternative is
na.omit, which leads to rejection of cases with missing values on
any required variable. (NOTE: If given, this argument must be named.)
linout,
entropy,
softmax and
censored are mutually
exclusive.
softmax, in which non-zero targets mean possible
classes. Thus for
softmax a row of
(0, 1, 1) means one example
each of classes 2 and 3, but for
censored it means one example whose
class is only known to be 2 or 3.
rang,
rang]. Value about 0.5 unless the
inputs are large, in which case it should be chosen so that
rang * max(
|x|) is about 1.
Hessian.
T.
MaxNWts will probably allow fits that
are very slow and time-consuming (and perhaps uninterruptable under
Windows).
abstol, indicating an
essentially perfect fit.
1 - reltol.
"nnet".
Mostly internal structure, but has slots
If the response in
formula is a factor,
an appropriate classification network is constructed; this has one
output and entropy fit if the number of levels is two, and a number of
outputs equal to the number of classes and a softmax output stage for
more levels. If the response is not a factor, it is passed on
unchanged to
nnet.default.
A quasi-Newton optimizer is used, written in
C.
# use half the iris data
ir <- rbind(iris[,,1],iris[,,2],iris[,,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,]))
# or
ird <- data.frame(rbind(iris[,,1], iris[,,2], iris[,,3]),
species=c(rep("s",50), rep("c", 50), rep("v", 50)))
ir.nn2 <- nnet(species ~ ., data=ird, subset=samp, size=2, rang=0.1,
decay=5e-4, maxit=200)
table(ird$species[-samp], predict(ir.nn2, ird[-samp,], type="class"))