• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

I am using glmnet function and am getting following error:

error in cbind2(1, newx) %*% nbeta : not-yet-implemented method for <data.frame> %*% <dgcmatrix>

by (4k points)  
edited by

1 Answer

0 votes


Error in as.matrix(cbind2(1, newx) %% nbeta) : error in evaluating the argument 'x' in selecting a method for function 'as.matrix': Error in cbind2(1, newx) %% nbeta : not-yet-implemented method for %*%

The Code creating Issue:


demo <- read.csv("demo.csv", header=TRUE)

test <- read.csv("test.csv", header=TRUE)

for (i in seq(dim(test)[2])){

test[[i]] <- as.factor(test[[i]])


for (i in seq(dim(demo)[2])){

demo[[i]] <- as.factor(demo[[i]])


X = sparse.model.matrix(as.formula(paste("ACTION ~",  


     sep = "", collapse=" +"))), data = test)

  model = cv.glmnet(X, test[,1], family = "arial")

print("glmnet model completed")

predict(model,newx=demo[,2:10], s="lambda.min")


Your unique information casing has a factor (clear cut) variable among the indicator factors. When you use model.matrix it accomplishes something reasonable with this variable; in the event that you simply pass it straightforwardly to foresee, it doesn't have a clue what to do.

You could have repeated this model with an insignificant/made-up model, with only a couple of lines of information ... for instance, this arrangement gives a similar mistake 

newX <- model.matrix(~.-y,data=x_test)

fit_test<-predict(fit, newx=newX,s=lambda_min)


dd <- data.frame(y=rnorm(5),


model <- model.matrix(y~., data=dd)

n <- nrow(dd)

train <- sample(1:n, size=round(0.8*n))

test <- setdiff(1:n,train)

by (1.4k points)