Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How can cluster users?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (2)
Walter Roberson
am 9 Dez. 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.
0 Kommentare
giuseppe
am 10 Dez. 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 Kommentare
Walter Roberson
am 10 Dez. 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
am 19 Dez. 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.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!