I'd like to do large-scale regression (linear/logistic) in R with many (e.g. 100k) features, where each example is relatively sparse in the feature space---e.g., ~1k non-zero features per example.
It seems like the SparseM package slm
should do this, but I'm having difficulty converting from the sparseMatrix
format to a slm
-friendly format.
I have a numeric vector of labels y
and a sparseMatrix
of features X
in {0,1}. When I try
model <- slm(y ~ X)
I get the following error:
Error in model.frame.default(formula = y ~ X) :
invalid type (S4) for variable 'X'
presumably because slm
wants a SparseM
object instead of a sparseMatrix
.
Is there an easy way to either a) populate a SparseM
object directly or b) convert a sparseMatrix
to a SparseM
object? Or perhaps there's a better/simpler way to do this?
(I suppose I could explicitly code the solutions for linear regression using X
and y
, but it would be nice to have slm
working.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…