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

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 (5.3k points)  
edited by

1 Answer

0 votes

Issue:

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:

library(glmnet)

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 ~",  

paste(colnames(test[,-1]),

     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")

Solution:

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)

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)

by (1.4k points)  
...