2013년 12월 28일 토요일

neural network

R script
--------------

library(datasets)

names(infert)

#  *------------------------------------------------------------------*
#  | train the network
#  *------------------------------------------------------------------*

library(neuralnet)

#input is age, parity, induced ...

nn <- neuralnet(
 case~age+parity+induced+spontaneous,
 data=infert, hidden=5, err.fct="ce",
 linear.output=FALSE)

#  *------------------------------------------------------------------*
#  | output training results
#  *------------------------------------------------------------------* 

# basic
nn

# reults options
names(nn)


# result matrix contains weights

nn$result.matrix

# The given data is saved in nn$covariate and
# nn$response as well as in nn$data for the whole data
# set inclusive non-used variables. The output of the
# neural network, i.e. the fitted values o(x), is provided
# by nn$net.result:

out <- cbind(nn$covariate,nn$net.result[[1]])

dimnames(out) <- list(NULL, c("age", "parity","induced","spontaneous","nn-output"))

head(out)


# visualization
plot(nn)


댓글 없음:

댓글 쓰기