Biostar Beta. Not for public use.
Neuralnet on R
0
Entering edit mode
16 months ago
brunaz • 0

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
0
Entering edit mode
14 months ago
russhh ♦ 4.4k
UK, U. Glasgow

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
0
Entering edit mode

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

ADD REPLYlink
0
Entering edit mode

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
0
Entering edit mode

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

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1