[R] neural net
arun
smartpink111 at yahoo.com
Fri Dec 14 02:39:58 CET 2012
Hi,
I tried your dataset. I couldn't reproduce the Error: message. Instead,
mydata<-read.table(text="
drug param1 param2 param3 param4 param5 class
A 111 15 125 40 0.5 1
B 347 13 280 55 3 2
C 335 9 119 89 -40 1
D 477 37 75 2 0 1
E 863 24 180 10 5 2
F 737 28 150 15 6 2
G 390 63 167 12 0 3
H 209 93 200 48 45 3
I 376 72 201 45 -60 3
J 262 16 205 49 25 3
K 273 39 267 53 11 1
L 192 33 164 19 15 2
M 282 2 213 86 30 1
N 111 11 198 68 -21 1
O 387 20 143 12 16 2
P 674 15 78 -20 -17 2
R 734 54 140 24 7 2
S 272 46 159 57 28 2
T 245 37 90 6 31 2
",sep="",header=TRUE,stringsAsFactors=TRUE)
library(neuralnet)
nn <- neuralnet(
class~param1+param2+param3+param4+param5+param5, #param5 is duplicated(typo?)
data=mydata, hidden=2, err.fct="ce",
linear.output=FALSE)
#Warning message:
#'err.fct' was automatically set to sum of squared error (sse), because the response is not binary
nn
#Call: neuralnet(formula = class ~ param1 + param2 + param3 + param4 + param5 + param5, data = mydata, hidden = 2, err.fct = "ce", linear.output = FALSE)
#
#1 repetition was calculated.
#
# Error Reached Threshold Steps
#1 12.50980687 0.009804371657 30
plot(nn)
sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] neuralnet_1.31 MASS_7.3-16 stringr_0.6 reshape_0.8.4 plyr_1.7.1
loaded via a namespace (and not attached):
[1] tools_2.15.0
A.K.
----- Original Message -----
From: Katarzyna Nurzynska <paxkn at nottingham.ac.uk>
To: PIKAL Petr <petr.pikal at precheza.cz>; "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Thursday, December 13, 2012 10:56 AM
Subject: Re: [R] neural net
Hi
Thanks for your reply. I have compared my data with some other which works and I cannot see the difference...
The structure of my data is shown below:
> str(data)
'data.frame': 19 obs. of 7 variables:
$ drug : Factor w/ 19 levels "A","B","C","D",..: 1 2 3 4 5 6 7 8 9 10 ...
$ param1 : int 111 347 335 477 863 737 390 209 376 262 ...
$ param2 : int 15 13 9 37 24 28 63 93 72 16 ...
$ param3 : int 125 280 119 75 180 150 167 200 201 205 ...
$ param4 : int 40 55 89 2 10 15 12 48 45 49 ...
$ param5 : num 0.5 3 -40 0 5 6 0 45 -60 25 ...
$ Class : int 1 2 1 1 2 2 3 3 3 3 ...
> summary(data)
drug param1 param2 param3 param4 param5 Class
A : 1 Min. :111.0 Min. : 2.0 Min. : 75.0 Min. :-20.00 Min. :-60.000 Min. :1.000
B : 1 1st Qu.:253.5 1st Qu.:15.0 1st Qu.:132.5 1st Qu.: 12.00 1st Qu.: 0.000 1st Qu.:1.000
C : 1 Median :335.0 Median :28.0 Median :164.0 Median : 40.00 Median : 6.000 Median :2.000
D : 1 Mean :383.0 Mean :33.0 Mean :166.0 Mean : 35.26 Mean : 4.447 Mean :1.895
E : 1 3rd Qu.:433.5 3rd Qu.:42.5 3rd Qu.:200.5 3rd Qu.: 54.00 3rd Qu.: 20.500 3rd Qu.:2.000
F : 1 Max. :863.0 Max. :93.0 Max. :280.0 Max. : 89.00 Max. : 45.000 Max. :3.000
(Other):13
The structure of the example data which worked is shown below:
> str(infert)
'data.frame': 248 obs. of 8 variables:
$ education : Factor w/ 3 levels "0-5yrs","6-11yrs",..: 1 1 1 1 2 2 2 2 2 2 ...
$ age : num 26 42 39 34 35 36 23 32 21 28 ...
$ parity : num 6 1 6 4 3 4 1 2 1 2 ...
$ induced : num 1 1 2 2 1 2 0 0 0 0 ...
$ case : num 1 1 1 1 1 1 1 1 1 1 ...
$ spontaneous : num 2 0 0 0 1 1 0 0 1 0 ...
$ stratum : int 1 2 3 4 5 6 7 8 9 10 ...
$ pooled.stratum: num 3 1 4 2 32 36 6 22 5 19 ...
> summary(infert)
education age parity induced case spontaneous stratum pooled.stratum
0-5yrs : 12 Min. :21.00 Min. :1.000 Min. :0.0000 Min. :0.0000 Min. :0.0000 Min. : 1.00 Min. : 1.00
6-11yrs:120 1st Qu.:28.00 1st Qu.:1.000 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:21.00 1st Qu.:19.00
12+ yrs:116 Median :31.00 Median :2.000 Median :0.0000 Median :0.0000 Median :0.0000 Median :42.00 Median :36.00
Mean :31.50 Mean :2.093 Mean :0.5726 Mean :0.3347 Mean :0.5766 Mean :41.87 Mean :33.58
3rd Qu.:35.25 3rd Qu.:3.000 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:62.25 3rd Qu.:48.25
Max. :44.00 Max. :6.000 Max. :2.0000 Max. :1.0000 Max. :2.0000 Max. :83.00 Max. :63.00
So still not sure how to solve the problem ....
_________
From: PIKAL Petr [petr.pikal at precheza.cz]
Sent: 13 December 2012 07:16
To: dada; r-help at r-project.org
Subject: RE: [R] neural net
Hi
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of dada
> Sent: Thursday, December 13, 2012 12:41 AM
> To: r-help at r-project.org
> Subject: [R] neural net
>
> Hi
> I would like to do neural netowrk analysis on my data. It look like
> this:
>
> drug param1 param2 param3 param4 param5 class
> A 111 15 125 40 0.5 1
> B 347 13 280 55 3 2
> C 335 9 119 89 -40 1
> D 477 37 75 2 0 1
> E 863 24 180 10 5 2
> F 737 28 150 15 6 2
> G 390 63 167 12 0 3
> H 209 93 200 48 45 3
> I 376 72 201 45 -60 3
> J 262 16 205 49 25 3
> K 273 39 267 53 11 1
> L 192 33 164 19 15 2
> M 282 2 213 86 30 1
> N 111 11 198 68 -21 1
> O 387 20 143 12 16 2
> P 674 15 78 -20 -17 2
> R 734 54 140 24 7 2
> S 272 46 159 57 28 2
> T 245 37 90 6 31 2
>
> I have entered the code below:
> > nn <- neuralnet(
> + class~param1+param2+param3+param4+param5+param5,
> + data=mydata, hidden=2, err.fct="ce",
> + linear.output=FALSE)
>
> However the error appeared:
> Error in model.frame.default(formula.reverse, data) :
> object is not a matrix
>
> I changed the data frame to matrix:
> mydata.mat=as.matrix(mydata)
This is not very wise. It changes all numeric values to character. From documentation and your data frame there is nothing obviously wrong. However you did not provide info about structure of your data something like
summary(mydata) or str(mydata).
Documentation does not say much about how neuralnet reacts e.g. on NA values. The best way how to proceed seems to try recommended data and compare them to your data to see where are the differences.
Or you can read sources to see where the error message originates.
Regards
Petr
>
> but still the same error appears...
>
> How can I fix this ? I would be very grateful for your help !
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/neural-net-
> tp4652927.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.
This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list