I was wondering whether it would be possible for Spark Cosine Similarity to work with Sparse input data? I have seen examples wherein the input consists of lines of space-separated features of the form:
id feat1 feat2 feat3 ...
but I have an inherently sparse, implicit feedback setting and would like to have input in the form:
id1 feat1:1 feat5:1 feat10:1
id2 feat3:1 feat5:1 ..
...
I would like to make use of the sparsity to improve the calculation. Also ultimately I wish to use the DIMSUM algorithm for calculating all-pairs-similarity that has been recently incorporated into Spark. Could someone suggest a sparse-input format that would work with DIMSUM on spark? I checked the example code and in the comments it says "The input must be a dense matrix" but this code was in examples so I don't know whether it was referring only to one particular case.
spark/examples/src/main/scala/org/apache/spark/examples/mllib/CosineSimilarity.scala
That's the path to the example code that I'm referring to.
Just a couple of lines representing how the sparse-input format should look (from a recommendation system perspective, user_id feat1:1 feat2:1 ...), to work with cosine similarity, would be extremely helpful.
Also would it be okay if I left the user_ids as strings?
I am aware that libsvm format is similar but there is no notion of a user id in this case, only input instances with features so I was wondering how the libsvm format would translate into a recommendation system domain?
My apologies for the extremely simplistic questions, I am extremely new to Spark and am just getting my feet wet.
Any help would be much appreciated. Thanks in advance!