Large Matrix to run in cv.glmnet() for multinomial classification

I am working on a large matrix with number of samples N=40 and features, P=7130. I am trying to fit the cv.glmnet() for the ridge but i am getting error while doing this.
The dimensions of the dataset is (40,7130)
The code for the cv.glmnet() is as follows:

ridge2_cv <- cv.glmnet(x, y, ## type.measure: loss to use for cross-validation. type.measure = "deviance", ## K = 10 is the default. nfold = 10, ## Multinomial regression family = "multinomial", ## ‘alpha = 1’ is the lasso penalty, and ‘alpha = 0’ the ridge penalty. alpha = 0) 

Here x is large matrix with 285160 elements. y is the multi-class response variable of size 40
I keep getting this error when i run the above function.

Error in cbind2(1, newx) %*% (nbeta[[i]]) : invalid class 'NA' to dup_mMatrix_as_dgeMatrix In addition: Warning messages: 1: In lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : one multinomial or binomial class has fewer than 8 observations; dangerous ground 2: In lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : one multinomial or binomial class has fewer than 8 observations; dangerous ground

2

1 Answer

Can you try with data.matrix() for the matrix instead of as.matrix? I remember trying out something similar.

ridge2_cv <- cv.glmnet(data.matrix(x), y, ## type.measure: loss to use for cross-validation. type.measure = "deviance", ## K = 10 is the default. nfold = 10, ## Multinomial regression family = "multinomial", ## ‘alpha = 1’ is the lasso penalty, and ‘alpha = 0’ the ridge penalty. alpha = 0) 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like