• Register
0 votes
1.2k 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?

7.5k points

Please log in or register to answer this question.

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
38.6k points

Related questions

0 votes
1 answer 11 views
11 views
Problem: Error in terms.formula(formula) : '.' in formula and no 'data' argument.
asked Jul 3 Shima 126k points
0 votes
1 answer 100 views
100 views
Problem: Hey everyone, any Help: cholmod error 'x and/or y have wrong dimensions' at file ../matrixops/cholmod_sdmult.c, line 90
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.8k views
2.8k 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 1.7k views
1.7k 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
1 answer 6 views
6 views
Problem: Invalid prediction for "rpart" object?
asked 6 days ago Mezbah 130k points
0 votes
1 answer 88 views
88 views
Problem: HELP: Error in terms.formula(formula, data = data) : invalid model formula in extractvars
asked Mar 14 Wafa Abu Yousef 6.1k points
1 vote
1 answer 2.7k views
2.7k 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 48 views
48 views
Problem: I am in trouble while solving it .. please help me .. difference between classification and prediction in data mining
asked Apr 20 Ifra 43.4k points
0 votes
1 answer 3 views
3 views
Problem: Excel formula count if cell contains any text.
asked Jul 7 Rada Gracelynn 104k points
0 votes
1 answer 11 views
11 views
Problem: Excel how to make a formula work for the whole column.
asked Jun 26 Rada Gracelynn 104k points