• Register
1 vote
1k 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  1  1 1.7661266 45  2 0.80298213  9120 13  0   6   1   2
2  2  0 1.9571510 40  0 0.12187620  2600  4  0   0   1   1
3  3  0 1.6581801 38  1 0.08511338  3042  2  1   0   1   0
4  4  0 1.2338098 30  0 0.03604968  3300  5  0   0   1   0
5  5  0 1.9072394 49  1 0.02492570 63588  7  0   1   1   0
6  6  0 1.2131787 74  0 0.37560697  3500  3  0   1   1   1
> cv1 <- cv.glmnet(as.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="binomial")
Error in as.matrix(cbind2(1, newx) %*% nbeta) : 
error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in t(.Call(Csparse_dense_crossprod, y, t(x))) : 
error in evaluating the argument 'x' in selecting a method for function 't': Error: invalid class 'NA' to dup_mMatrix_as_dgeMatrix
> cv1 <- cv.glmnet(as.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="multinomial")
Error in t(.Call(Csparse_dense_crossprod, y, t(x))) : 
error 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?

6 5 3
7,540 points

1 Answer

1 vote

Solution :

For some reason the glmnet prefers data.matrix() over as.matrix() so

cv1 <- cv.glmnet(data.matrix(t2[,-c(1,2,7,12)]), t2[,2], family="multinomial")

will solve your problem.

9 7 4
38,600 points

Related questions

0 votes
1 answer 934 views
934 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.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
1 vote
1 answer 365 views
365 views
Problem : Currently I am learning r. I have the data table "normal" which has the numeric as far as I know normalized values. If I try to execute the below command k <- kmeans(normal,center=3) Then I always face the below error: &ldquo;Error in do_one(nmeth) : NA/NaN/ ... call (arg 1)&rdquo; I am trying to fix it by researching on it but still unable to fix it. Can somebody help me in fixing it?
asked Mar 28 morrisBson 3.2k points