An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090527/7789ac9c/attachment-0001.pl>
Neural Network resource
4 messages · Indrajit Sengupta, Tony, Max Kuhn
I haven't used the AMORE package before, but it sounds like you haven't set linear output units or something. Here's an example using the nnet package of what you're doing i think: ### R START###
# set random seed to a cool number set.seed(42) # set up data x1<-rnorm(100); x2<-rnorm(100); x3<-rnorm(100) x4<-rnorm(100); x5<-rnorm(100); x6<-rnorm(100) b1<-1; b2<-2; b3<-3 b4<-4; b5<-5; b6<-6 y<-b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 my.df <- data.frame(cbind(y, x1, x2, x3, x4, x5, x6)) # 1. linear regression my.lm <- lm(y~., data=my.df) # look at correlation my.lm.predictions<-predict(my.lm) cor(my.df["y"], my.lm.predictions)
[,1] y 1
# 2. nnet library(nnet) my.nnet<-nnet(y~., data=my.df, size=3,
linout=TRUE, skip=TRUE,
trace=FALSE, maxit=1000)
my.nnet.predictions<-predict(my.nnet, my.df) # look at correlation cor(my.df["y"], my.nnet.predictions)
[,1] y 1
# to look at the values side by side cbind(my.df["y"], my.nnet.predictions)
y my.nnet.predictions 1 10.60102566 10.59958907 2 6.70939465 6.70956529 3 2.28934732 2.28928930 4 14.51012458 14.51043732 5 -12.85845371 -12.85849345 [..etc] ### R END ### Hope that helps a wee bit mate, Tony Breyal
On 27 May, 15:36, Indrajit Sengupta <indra_cali... at yahoo.com> wrote:
You are right there is a pdf file which describes the function. But let tell you where I am coming from. Just to test if a neural network will work better than a ordinary least square regression, I created a dataset with one dependent variable and 6 other independent variables. Now I had deliberately created the dataset in such manner that we have an excellent regression model. Eg: Y = b0 + b1*x1 + b2*x2 + b3*x3.. + b6*x6 + e where e is normal random variable. Naturally any statistical analysis system running regression would easily predict the values of b1, b2, b3, ..., b6 with around 30-40 observations. I fed this data into a Neural network (3 hidden layers with 6 neurons in each layer) and trained the network. When I passed the input dataset and tried to get the predictions, all the predicted values were identical! This confused me a bit and was wondering whether my understanding of the Neural Network was wrong. Have you ever faced anything like it? Regards, Indrajit
________________________________ From: "markle... at verizon.net" <markle... at verizon.net> Sent: Wednesday, May 27, 2009 7:54:59 PM Subject: Re: [R] Neural Network resource Hi: I've never used that package but most likely there is a? AMORE vignette that shows examples and describes the functions. it should be on the same cran? web page where the package resides, in pdf form. Hi All, I am trying to learn Neural Networks. I found that R has packages which can help build Neural Nets - the popular one being AMORE package. Is there any book / resource available which guides us in this subject using the AMORE package? Any help will be much appreciated. Thanks, Indrajit ______________________________________________ R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ? ? ? ? [[alternative HTML version deleted]] ______________________________________________ R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I fed this data into a Neural network (3 hidden layers with 6 neurons in each layer) and trained the network. When I passed the input dataset and tried to get the predictions, all the predicted values were identical! This confused me a bit and was wondering whether my understanding of the Neural Network was wrong. Have you ever faced anything like it?
You should really provide code for us to help. I would initially suspect that you didn't use a linear function between your hidden units and the outcomes. Also, using 3 hidden layers and 6 units per layer is a bit much for your data set (30-40 samples). You will probably end up overfitting.
Max
Here is the code that i had used:
#########################################
## Read in the raw data
fitness <- c(44,89.47,44.609,11.37,62,178,182,
40,75.07,45.313,10.07,62,185,185,
44,85.84,54.297,8.65,45,156,168,
42,68.15,59.571,8.17,40,166,172,
38,89.02,49.874,9.22,55,178,180,
47,77.45,44.811,11.63,58,176,176,
40,75.98,45.681,11.95,70,176,180,
43,81.19,49.091,10.85,64,162,170,
44,81.42,39.442,13.08,63,174,176,
38,81.87,60.055,8.63,48,170,186,
44,73.03,50.541,10.13,45,168,168,
45,87.66,37.388,14.03,56,186,192,
45,66.45,44.754,11.12,51,176,176,
47,79.15,47.273,10.6,47,162,164,
54,83.12,51.855,10.33,50,166,170,
49,81.42,49.156,8.95,44,180,185,
51,69.63,40.836,10.95,57,168,172,
51,77.91,46.672,10,48,162,168,
48,91.63,46.774,10.25,48,162,164,
49,73.37,50.388,10.08,67,168,168,
57,73.37,39.407,12.63,58,174,176,
54,79.38,46.08,11.17,62,156,165,
52,76.32,45.441,9.63,48,164,166,
50,70.87,54.625,8.92,48,146,155,
51,67.25,45.118,11.08,48,172,172,
54,91.63,39.203,12.88,44,168,172,
51,73.71,45.79,10.47,59,186,188,
57,59.08,50.545,9.93,49,148,155,
49,76.32,48.673,9.4,56,186,188,
48,61.24,47.92,11.5,52,170,176,
52,82.78,47.467,10.5,53,170,172
)
fitness2 <- data.frame(matrix(fitness,nrow = 31, byrow = TRUE))
colnames(fitness2) <- c("Age","Weight","Oxygen","RunTime","RestPulse","RunPulse","MaxPulse")
attach(fitness2)
## Create the input dataset
indep <- fitness2[,-3]
## Create the neural network structure
net.start <- newff(n.neurons=c(6,6,6,1),?????
???????????? learning.rate.global=1e-2,???????
???????????? momentum.global=0.5,?????????????
???????????? error.criterium="LMS",??????????
???????????? Stao=NA, hidden.layer="tansig",??
???????????? output.layer="purelin",??????????
???????????? method="ADAPTgdwm")
## Train the net
result <- train(net.start, indep, Oxygen, error.criterium="LMS", report=TRUE, show.step=100, n.shows=5 )
## Predict
pred <- sim(result$net, indep)
pred????????????
###########################################????????????
Here?I am trying to predict Oxygen levels using the 6 independent variables.?But whenever I am trying to run a prediction - I am getting constant values throughout (In the above example - the values of pred).
Thanks & Regards,
Indrajit
?
----- Original Message ----
From: Max Kuhn <mxkuhn at gmail.com>
To: Indrajit Sengupta <indra_calisto at yahoo.com>
Cc: markleeds at verizon.net; R Help <r-help at r-project.org>
Sent: Wednesday, May 27, 2009 9:19:47 PM
Subject: Re: [R] Neural Network resource
I fed this data into a Neural network (3 hidden layers with 6 neurons in each layer) and trained the network. When I passed the input dataset and tried to get the predictions, all the predicted values were identical! This confused me a bit and was wondering whether my understanding of the Neural Network was wrong. Have you ever faced anything like it?
You should really provide code for us to help. I would initially suspect that you didn't use a linear function between your hidden units and the outcomes. Also, using 3 hidden layers and 6 units per layer is a bit much for your data set (30-40 samples). You will probably end up overfitting.
Max