I would like to be able to use a sparse matrix as x
in caret::train
and it looks like many of them expect a data frame. I've been able to use sparse matrix with XGboost
with caret
but nnet
and ELM
both seem to require a data frame. I noticed in the code, caret tries to convert x
to data frame for nnet
and ELM
models.
Is there a list of models that support sparse matrix?
You can use this piece of code to find which models are using as.matrix in the fit function.
Beware that as.matrix turns a sparse matrix into a full blown matrix. You might run into memory issues. I have not tested if the individual underlying 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With