• Register
0 votes
443 views

Problem :

I want to use the neural net for predictions.

I am trying to create some X as follows :

x <- cbind(seq(1, 50, 1), seq(51, 100, 1))

I am trying to create some Y as follows :

y <- x[,1]*x[,2]

Give them the names as follows

colnames(x) <- c('x1', 'x2')

names(y) <- 'y'

Make the data.frame as below:

dt <- data.frame(x, y)

Finally I got, below error

model <- neuralnet(y~., dt, hidden=10, threshold=0.01)

error in terms.formula(formula) : '.' in formula and no 'data' argument

Does anybody have any idea regarding the error I am facing? Any solution?

6 5 3
7,540 points

1 Answer

0 votes

Solution :

As my comment states, this looks like a bug to me in the non-exported method neuralnet:::generate.initial.variables. As a work around, you can just build a long formula from the names of dt, excluding y, please find below the solution for your problem.

n <- names(dt)
f <- as.formula(paste("y ~", paste(n[!n %in% "y"], collapse = " + ")))
f
## gives
> f
y ~ x1 + x2
## fit model using `f`
model <- neuralnet(f, data = dt, hidden=10, threshold=0.01)
> model
Call: neuralnet(formula = f, data = dt, hidden = 10, threshold = 0.01)
1 repetition was calculated.
Error Reached Threshold Steps
1 53975276.25     0.00857558698  1967
9 7 4
38,600 points

Related questions

1 vote
1 answer 1.3K views
1.3K views
Problem : I am facing following error : formula(formula, data = data) : invalid model formula in ExtractVars I am using the below code: install.packages("rpart") library("rpart") # you must change the below from windows to work on your linux box: mydata <- read.csv(file="c ... file to commas. I guess it is unable to read the data correctly. I am very new to the R and also a very new programmer.
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 1.4K views
1.4K views
Problem : I am trying to predict probabilities in a dataset by using glmnet but facing following issue cholmod error 'x and/or y have wrong dimensions' at file ../matrixops/cholmod_sdmult.c, line 90
asked Nov 13, 2019 peterlaw 6.9k points
0 votes
1 answer 820 views
820 views
Problem : I am learning to work with neural networks in R. As a learning tutorial I am using the following problem over at Kaggle: https://www.kaggle.com/c/titanic This problem is specifically designed for people who want to learn and please note there is no reward ... Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments Can anyone help in resolving my issue?
asked Nov 27, 2019 alecxe 7.5k points
0 votes
2 answers 811 views
811 views
Problem : I am looking for the function with the parameters such as data name as (mydata), factor as (myfactor) and variable names such as (myvar) to dynamically generate the histograms as I have to use them in lattice. I tried to do as mentioned above but error appears ... of type 'character'. I think the program doesn't know where to look for this myf` string. How should I fix this issue?
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 14 views