• Register
0 votes
716 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>
6.9k points

1 Answer

0 votes

Solution :

It seems your original data frame has a factor variable among the predictor variables. So when ever you use model.matrix it does something sensible with this variable; if you pass it directly to predict, it will not know what to do.

newX <- model.matrix(~.-y,data=x_test)
fit_test<-predict(fit, newx=newX,s=lambda_min)

You could also have replicated this example with a minimal example, with just a few lines of data ... for example, this setup gives the same error 

set.seed(101)
dd <- data.frame(y=rnorm(5),
            a=1:5,b=2:6,c=3:7,d=letters[1:5])
model <- model.matrix(y~., data=dd)
n <- nrow(dd)
train <- sample(1:n, size=round(0.8*n))
test <- setdiff(1:n,train)
36.1k points

Related questions

1 vote
1 answer 779 views
779 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 50 views
50 views
Problem : Getting following error related to r error in `row.names<-.data.frame`(`*tmp*`, value = value) : duplicate 'row.names' are not allowed
asked Nov 11, 2019 peterlaw 6.9k points
0 votes
1 answer 200 views
200 views
Problem : I want to select some columns from my data frame by the use of below code: library(dplyr) dv %>% select(LGA) select(dv, LGA) Both of them are failing with below error : Unable to find an inherited method for function select' for signature ... (leaflet) library(mapview) library(RColorBrewer) library(scales) I' am very new to R, so need guidance in resolving the problems like this?
asked Dec 7, 2019 alecxe 7.5k points
0 votes
1 answer 1K views
1K 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 850 views
850 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