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

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 921 views
921 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 421 views
421 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.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 1.3K views
1.3K 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 236 views
236 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 Martin K 6.6k points