How to deal with a sparse matrix when using a perceptron based recommender system? I'm constrained to use a perceptron based method. I have a user-item matrix filled with rating data on scale of 1 to 5 like this, with around 50% of the matrix with no data:

r&lt;- matrix(c(2,4, NA,5,NA,3, NA,5,NA,1,NA,3,NA,5,NA,4,4,NA,NA,NA,1,1,2,NA,1,1,1,1,NA,NA,NA,NA,2,3,4,2,NA,NA,NA,NA,3,4,5,1,NA,NA,2,3,NA), nrow=7).
#one row represents one user, hile one column represents one item
r
    [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    2    5   NA    1   NA    2    5
[2,]    4   NA    4    2   NA   NA    1
[3,]   NA    1    4   NA   NA   NA   NA
[4,]    5   NA   NA    1   NA   NA   NA
[5,]   NA    3   NA    1    2   NA    2
[6,]    3   NA   NA    1    3    3    3
[7,]   NA    5    1    1    4    4   NA


I'm recoding the NA's to 0's, which makes the perceptron give out only 2 classes (one containing all the 1's and 0's , and the other containing all the 2,3,4 and 5. Which is understandable I guess.) How do I deal with this? I tried mean imputation but the results are not good (20% accuracy)

(I can't give exact code due to this being a proprietary code of my company, but any perceptron based method should work for this example)
Recoding the NAs to 0's is not what you want. Think of what this means: a missing value on an item for a particular user means that said user hasn't seen or listened to or bought (depending on what kind of data you have) that item, while a zero value means that the user disliked that item; so they have completely different meanings.

The goal of a recommender system is basically to fill those NA values in a way that "makes sense". It is very common to have sparse matrices in recommender systems. I don't know exactly what kind of approach you're using or why you're using a perceptron, but I would recommend you to check how matrix factorization for recommender systems works ("Matrix factorization for recommender systems" by Robert Bell, Chris Volinsky and Yehuda Koren is a good paper) and see if this approach works for your problem.

You can also try first a simple baseline model that takes into account the biases of the users and the biases of the items; Bell, Volinsky and Koren's paper is a good start.