• Register
0 votes
964 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 5 3
6,930 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)
9 7 4
38,600 points

Related questions

1 vote
1 answer 1K views
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 ... 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.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 58 views
58 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 281 views
281 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 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