how to create pairwise label matrix ?
Afficher commentaires plus anciens
Hello,
I aim to create a label matrix that works as the following:
suppose I have the samples (1,2,3,4) as vectors and I want to say if any two are neighbors so the label is (1). if any two are not neighbors so the label is (-1). Note that neighbors means these two samples are of the same class. for example, the samples 1 and 3 belong to the same class and the samples 2 and 4 belong to the same class. Now, since the samples 1 and 3 of the same class so the label is (1). The samples 2 and 4 of the same class so the label is (1). The samples 1 and 4 is not of the same class so the label is (-1). The samples 3 and 2 is not of the same class so the label is (-1). In the matrix if the pair like (1,1) or (2,2).. so put zero. finally, the matrix should be:
[0 -1 1;-1 0 -1;1 -1 0 ]
So, any ideas to do that please.
Regards,
4 commentaires
Guillaume
le 26 Juil 2018
if any two are neighbors so the label is one. if any two are not neighbors so the label is -1 and use label 0 otherwise
Hum, as far as I can tell some things are either neighbours (1) or not (-1), there is no third option. So what would 0 denote?
As for answering your question, it's completely unclear what the definition of a neighbour is. Similarly, you're talking about 1, 3 being of the same class. We have no idea what 1, 3 mean, nor what same class mean.
Can you give an example of input(s) and desired output(s)?
Sarah A
le 26 Juil 2018
Guillaume
le 26 Juil 2018
yes, it's a lot clearer now. The only thing missing is how do you know the sample class?
Sarah A
le 31 Juil 2018
Réponse acceptée
Plus de réponses (1)
Guillaume
le 26 Juil 2018
Going with dpb's example (with slightly better variable names, don't use class it's too useful a function to shadow!), to generate the label matrix:
varclass = categorical({'A','B','A','B'});
labelmatrix = 2 * (varclass == varclass') - 1;
labelmatrix(logical(eye(numel(varclass)))) = 0
3 commentaires
dpb
le 26 Juil 2018
" class it's too useful a function..."
Very good point; being a dinosaur I don't write OO code so didn't even think of it... :)
Guillaume
le 31 Juil 2018
class hasn't got much to do with OOP actually. Too often do we ask the OP, "what is class(thevariable_that_generate_the_error) ?". Case in point, here, it would be useful to know what the 'sample class' actually is.
dpb
le 31 Juil 2018
Well, there's that use of class, too... :)
Had been in a conversation over on comp.lang.fortran comparing/contrasting newer features in it to C++ and had those kinds of classes on the brain at the time...
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!