• Register
0 votes
726 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

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
9 7 4
38,600 points

Related questions

1 vote
1 answer 1.7K views
1.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 1.9K views
1.9K 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.1K views
1.1K 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 1.2K views
1.2K 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 53 views
1 vote
1 answer 1.1K views
1.1K views
Problem : Currently I am learning the r programming. I am unable to find the answer to below error but I am unable to do so. Currently I have one dataframe it has a column of strings. My task is to count the exact number of characters present in each entry of ... , with no default Error in match.fun(FUN): argument "FUN" is missing, with no default Can someone guide me in fixing above error?
asked Mar 30, 2020 morrisBson 3.2k points
1 vote
1 answer 1.1K views
1.1K views
Problem : I am beginner to Scatter Plot. I have recently joined new project and they gave task to plot the simple best fit line to a scatterplot. If I try to execute my below code with my data I always face the following error message: plot(log(datatest$MEAN_intact_for),log( ... plot my graph it works as expected but the problem comes up if I try to add a abline command to have a best fit line.
asked Apr 14, 2020 morrisBson 3.2k points
0 votes
1 answer 306 views
0 votes
1 answer 711 views
1 vote
2 answers 685 views
685 views
Problem : I am very new to R. I am facing a issue while entering CurrentDay. I had previously created it as below : Transaction <- function(PnL, Day)   results <- list(a = PnL, b = Day)  return(results) The above PnL and Day are both numeric values. Day ... /MA  return(MAValue) } Please guide me why am I receiving below error? Error in fun(left, right) : non-numeric argument to binary operator.
asked Apr 14, 2020 morrisBson 3.2k points