Question: Neuralnet on R
0
gravatar for brunaz
3.2 years ago by
brunaz0
brunaz0 wrote:

Dear all,

That is my first experience with neural networks so I appreciate any possible help or tips.

I have a datset with 332 columns providing integer infomation, such as 0 or 1 (binary).

The last column classifies each example (row) in a superfamily. For example,

row 1:  0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 Superfamily1
row 2:  0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 Superfamily2

What I am trying to do is, based on the binary information (all columns except the last one), predict the Superfamily. I have a train dataset and a test one.

I have tried doing that:

*attach(train)
creditnet <- neuralnet(Superfamily~., train, hidden = 4, lifesign = "minimal", linear.output = FALSE, threshold = 0.1)*

But I get an error message:

*Error in terms.formula(formula) : 

  '.' in formula and no argument 'data'*

What should I do? What am I doing wrong?

Thank you in advance!

ADD COMMENTlink modified 3.2 years ago by russhh4.4k • written 3.2 years ago by brunaz0
0
gravatar for russhh
3.2 years ago by
russhh4.4k
UK, U. Glasgow
russhh4.4k wrote:

Neuralnet doesn't appear to like that formula shorthand

As an example:

library(neuralnet)
data(iris)
iris$Species <- with(iris, Species == 'setosa') # making some binary variable
neuralnet(Species ~ ., data = iris)
# Error in terms.formula(formula) : '.' in formula and no 'data' argument
cn <- paste(colnames(iris)[1:4], collapse = ' + ')
cn
# [1] "Sepal.Length + Sepal.Width + Petal.Length + Petal.Width"
fo <- as.formula(paste('Species', '~', cn)) # define the formula
fo
# Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
neuralnet(fo, data = iris, linear.output=FALSE)
# Call: neuralnet(formula = fo, data = iris, linear.output = FALSE) # needs tweaking but works
# 
# 1 repetition was calculated.
#
#          Error Reached Threshold Steps
# 1 0.01298571046    0.009784036357    90
ADD COMMENTlink written 3.2 years ago by russhh4.4k

and on a separate note, please don't use 'attach'

ADD REPLYlink written 3.2 years ago by russhh4.4k

First of all, Thank you very much! I appreciate your help! I've tried to follow your tips, however now I get another error message:

Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments

Would you mind helping me with that too? Thank you again!

ADD REPLYlink written 3.2 years ago by brunaz0

Does the same thing happen if you type

iris$Species <- as.character(with(iris, Species == 'setosa'))

instead of

iris$Species <- with(iris, Species == 'setosa')

in the example I gave you?

ADD REPLYlink written 3.2 years ago by russhh4.4k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 670 users visited in the last hour