Info

This question is closed. Reopen it to edit or answer.

How can cluster users?

1 view (last 30 days)
Giuseppe
Giuseppe on 9 Dec 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi,
I have a matrix where the first column is the user's id, I have 5 columns that represent the presence o absence of a variable (0 or 1 value). The matrix is:
17 0 0 0 0 0
18 0 0 0 0 0
19 0 0 0 0 0
20 1 0 0 1 0
21 0 0 0 1 0
22 1 1 1 1 1
23 0 1 0 0 0
I want a technique, as classification or clusterization, to group users with the same values, for example: a class with all the users where all variables are not present, a class where all variables are present, etc. How can I perform this in Matlab? thanks.

Answers (2)

Walter Roberson
Walter Roberson on 9 Dec 2013
binvec = mat2cell( dec2bin(0:31, 5) - '0', ones(32,1), 5);
binary_form = YourMatrix(:,2:end) * [16; 8; 4; 2; 1]; %note: algebraic matrix multiplication
grouped = accumarray( binary_form(:) + 1, YourMatrix(:,1), [], @(L.') {L} );
group_table = [binvec, grouped];
Now, group_table will be a 32 x 2 cell array. group_table{K,1} will be a combination of variables, and group_table{K,2} will be the ID numbers that belong to that group. Note that group_table{K,2} might be empty.

giuseppe
giuseppe on 10 Dec 2013
Hi Walter,
thanks for your reply..but I have some questions. What is L? In the expression of grouped why there is @? Matlab don't recognizes this symbol and it gives an error. On L I received the error:
Undefined function or variable 'L'.
Error in bayesian (line 280) grouped = accumarray( binary_form(:) + 1, Z(:,1), [], (L.'), {L} );
Z is my matrix. thanks.
  2 Comments
Walter Roberson
Walter Roberson on 10 Dec 2013
Sorry made a typo, should be
grouped = accumarray( binary_form(:) + 1, YourMatrix(:,1), [], @(L) {L.'} );
The expression
@(L) {L.'}
is equivalent to "handle of function T343203" where
function result = T343203(L)
result = {L.'};
end
The syntax @(x) expression_involving_x is an "anonymous function"
giuseppe
giuseppe on 19 Dec 2013
Hi Walter, another question: how can I access to the elements of the cell array? If I try:
group_table{1}
ans =
0 0 0 0 0
how can I find the id of grouped users? Thanks.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!