Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can cluster users?

2 次查看(过去 30 天)
Giuseppe
Giuseppe 2013-12-9
关闭: MATLAB Answer Bot 2021-8-20
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.

回答(2 个)

Walter Roberson
Walter Roberson 2013-12-9
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 2013-12-10
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 个评论
Walter Roberson
Walter Roberson 2013-12-10
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 2013-12-19
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!

Translated by