0
$\begingroup$

Hello fellows and folks.

I have been looking to do this for 1 month and still cannot find the way to do it.

Here’s what’s going on:

I have a csv file called ratings.csv with the following structure:

userID, movieID, rating
3,  12, 5
2, 7,  4

The rating scale goes from 0 to 5 stars. I want to be able to plot the sparsity of the matrix like it’s done in the following picture:

pictiure

As you can see, ratings scale goes from 0 to 5 on the right. It is a very well thought plot.

I have Matlab, Python, R etc. Could you come up with something and help me? I’ve tried hard but I cannot find the way to do it.

$\endgroup$
  • 2
    $\begingroup$ I don't understand you question. Do you want to repeat the plot? $\endgroup$ – nicoguaro May 20 at 0:08
  • $\begingroup$ Yes, exactly! Thats the idea but I cannot find the way to do it. $\endgroup$ – NaveganTeX May 20 at 0:28
  • 3
    $\begingroup$ Anyway, your picture looks like it is simply the output of Matlab's imagesc(A), once you have converted the ratings to a sparse matrix A (which, I assume, you know how to do with spconvert or the three-argument version of sparse). $\endgroup$ – Federico Poloni May 20 at 12:23
  • 1
    $\begingroup$ Is your answer supposed to be an update to your post? $\endgroup$ – nicoguaro May 20 at 15:30
  • 1
    $\begingroup$ You just added code without any explanation, consider adding an explanation. Also, mentioning why @FedericoPoloni solution does not work. $\endgroup$ – nicoguaro May 20 at 15:51
2
$\begingroup$

I was able to do it this way though it may had been easier to plot it the way Federico has mentioned before: imagesc(A).

I declared an A matrix of zeros of mxn dimension and then loaded the ratings. I then applied HeatMap(A) which yields the image below.

A = importdata('u.data');
user_id = A(:, 1);
movie_id = A(:, 2);
rating = A(:, 3);

% Build matrix R 
R = zeros(943, 1682);

for i=1:100000
R(user_id(i), movie_id(i)) = rating(i);

end


m = HeatMap(R,’Xlabel’,’I did it!’)
ax = hm.plot; % 'ax' will be a handle to a standard MATLAB axes.
colorbar('Peer', ax); % Turn the colorbar on
caxis(ax, [0 5]); % Adjust the color limits

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.