What carriage models can use a sparse matrix for X?

I would like to be able to use a sparse matrix like x in caret::train , and it looks like many of them are expecting a data frame. I managed to use a sparse matrix with XGboost with caret , but nnet and ELM both seem to need a data frame. I noticed in the code, the carriage is trying to convert x to a data frame for nnet and ELM models.

Is there a list of models that support a sparse matrix?

+5
source share
1 answer

You can use this code snippet to find which models use as.matrix in the fit function.

Beware that as.matrix turns a sparse matrix into a full-blown matrix. You may run into memory problems. I have not tested if individual base models accept a sparse matrix.

 library(caret) # run on version 6.0-71 model_list <- getModelInfo() df <- data.frame(models = names(model_list), fit = rep("", length(model_list)), stringsAsFactors = FALSE) for (i in 1:length(model_list)) { df$fit[i] <- as.expression(functionBody(model_list[[i]]$fit)) } # find xgboost matrix df$models[grep("xgb.DMatrix", df$fit)] [1] "xgbLinear" "xgbTree" # find all models where fit contains as.matrix(x) df$models[grep("as.matrix\\(x\\)", df$fit)] [1] "bdk" "binda" "blasso" "blassoAveraged" "bridge" "brnn" [7] "dnn" "dwdLinear" "dwdPoly" "dwdRadial" "enet" "enpls.fs" [13] "enpls" "foba" "gaussprLinear" "gaussprPoly" "gaussprRadial" "glmnet" [19] "knn" "lars" "lars2" "lasso" "logicBag" "LogitBoost" [25] "lssvmLinear" "lssvmPoly" "lssvmRadial" "mlpSGD" "nnls" "ordinalNet" [31] "ORFlog" "ORFpls" "ORFridge" "ORFsvm" "ownn" "PenalizedLDA" [37] "ppr" "qrnn" "randomGLM" "relaxo" "ridge" "rocc" [43] "rqlasso" "rqnc" "rvmLinear" "rvmPoly" "rvmRadial" "sda" [49] "sddaLDA" "sddaQDA" "sdwd" "snn" "spikeslab" "svmLinear" [55] "svmLinear2" "svmLinear3" "svmLinearWeights" "svmLinearWeights2" "svmPoly" "svmRadial" [61] "svmRadialCost" "svmRadialSigma" "svmRadialWeights" "xgbLinear" "xgbTree" "xyf" 
+2
source

All Articles