1
$\begingroup$

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

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

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$

You're looking for a heatmap. Check out e.g. https://stackoverflow.com/q/33282368/3924118 (if you like Python more than the others). See also this documentation.

$\endgroup$
1
$\begingroup$

I did it!

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

% Build matrix R and w (weights matrix)
R = zeros(943, 1682);
w = zeros(943, 1682);
for i=1:100000
    R(user_id(i), movie_id(i)) = rating(i);
    w(user_id(i), movie_id(i)) = 1;
end


m = HeatMap(R)
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

Output:

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.