Neuralnet on R
1
0
Entering edit mode
8.7 years ago
brunaz ▴ 20

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!

R Neuralnetworks machinelearning • 5.2k views
ADD COMMENT
1
Entering edit mode
8.7 years ago
russhh 5.7k

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

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

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

Hi Russhh, How to descript the network structure and parameter tuning in your script. Thanks.

ADD REPLY
0
Entering edit mode

First you look at the function calls, then the function definitions. See https://cran.r-project.org/web/packages/neuralnet/neuralnet.pdf . neuralnet(fo, data = iris, linear.output=FALSE) implies the following arguments: hidden = 1, threshold = 0.01, stepmax = 1e+05, rep = 1, startweights = NULL, learningrate.limit = NULL, learningrate.factor = list(minus = 0.5, plus = 1.2), learningrate = NULL, lifesign = "none", lifesign.step = 1000, algorithm = "rprop+", err.fct = "sse", act.fct = "logistic", exclude = NULL, constant.weights = NULL, likelihood = FALSE . 4 years have made a huge difference in neural network applications. There may be better tools for doing this in R (I'm no expert, I was simply trying to get someones code to work)

ADD REPLY
0
Entering edit mode

Thanks. I submit a mauscript in which this package was used while the reviewer ask for all kinds details and ask for comprenhsive description to the neural network include strucutre and paramter tuning.

ADD REPLY

Login before adding your answer.

Traffic: 1962 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6