• Register
0 votes

Problem :

 I am learning to work with neural networks in R. As a learning tutorial I am using the following problem over at Kaggle:


This problem is specifically designed for people who want to learn and please note there is no reward tied to it.

I have started with a simple logistic regression, My training data looks like the following 

Column : Row

- survived: 1
- pclass:   3
- sex:      male
- age:      22.0
- sibsp:    1
- parch:    0
- ticket:   PC 17601
- fare:     7.25
- cabin:    C85
- embarked: S

And my starting R code looks like following code:

> net <- neuralnet(survived ~ pclass + sex + age + sibsp + parch + ticket + fare + cabin + embarked, train, hidden=10, threshold=0.01)

But whenever I try to run this line of code I get the following error:

Error in neurons[[i]] %*% weights[[i]] : 
requires numeric/complex matrix/vector arguments

Can anyone help in resolving my issue?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The Error Message "Requires numeric/complex matrix/vector arguments" occurs when you have either factor or character variables in your data.

There are three ways to solve your problem:

1. Try Deleting the variable

2.  If your variable is the ordered factor then use integer instead.

3.  If your variable is character, then transform it into factor and then into dummy variable.

You can use the model.matrix() mentioned above or class.ind() function from nnet package to transfer the factor into dummy variable.

9 7 4
38,600 points

Related questions

0 votes
1 answer 1.2K views
Problem : Suppose I have data.frame a And I am using following code m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude) Here the col2 has some NA values And col3,col4 have values less than 1. I am getting following error: Error in lm.fit ... because of the NAs. Problem with this warning is interpreted by every google results is pointing towards the NA values. Have I misinterpreted the error ?
asked Nov 22, 2019 peterlaw 6.9k points
0 votes
1 answer 700 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) ... =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?
asked Dec 11, 2019 alecxe 7.5k points
0 votes
1 answer 1.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.8K views
Problem : I have been facing below error message and traceback: Error in FUN(X[[i]], ...) : only defined on the data frame with all numeric variables 5 stop("only defined on the data frame with all numeric variables") 4 FUN(X[[i]], ...) 3 lapply(args, ... .numeric(data[good,]) But now I get the different error message back as below : "Error: (list) object cannot be coerced to type 'double'"
asked Dec 16, 2019 alecxe 7.5k points
1 vote
1 answer 484 views
Problem : I am learning R. I am trying to make the subset of my data frame in the R which is based on one or the other value available in my column of the factors but because of some unknown reason to me I am unable to use | operator with the factor values. If I try to ... != "c" as it will not work. I am stuck with above error from past two days. Please guide me in fixing above R error for me.
asked May 12, 2020 Martin K 6.6k points
1 vote
1 answer 1.3K views
Problem : I want to use the glmnet package on a dataset. I am trying to use cv.glmnet() to get the lambda value for the glmnet(). Please find below the dataset and error message: > head(t2) X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 1 ... in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix Any suggestions regarding the solution?
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 1.3K views
Problem : When ever i use the predict glmnet function i get the below mentioned error error in cbind2(1, newx) %*% nbeta : not-yet-implemented method for <data.frame> %*% <dgcmatrix>
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 1.1K views
Problem : I have about 25 dataframes which are essentially the frequency counts of my elements stored in the column called Elements. They all have some of the different and some of the the same elements in my Elements columns so they just look like below : dataframe called ... on them but facing below error: Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match .
asked Dec 24, 2019 alecxe 7.5k points
0 votes
2 answers 1.3K views
Problem : I am facing below error and I am unable to understand the meaning of the error. All my variable names are correct and there are no typing errors. Does anybody faced this issue before any solution on it? My erroneous code : datNewagg <- aggregate (dataNew, by = ... mean) It gives following error : Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Dec 6, 2019 alecxe 7.5k points
0 votes
1 answer 64 views