Assigning class +1/-1 to a 100x2 matrix

1 visualización (últimos 30 días)
Deepayan Bhadra
Deepayan Bhadra el 20 de Feb. de 2018
Comentada: Deepayan Bhadra el 20 de Feb. de 2018
I have a 100x2 matrix D. A scatter plot is attached. I have a 100x1 vector 'c'. If a point in D is to the left, I want to assign it as +1 and -1 otherwise. I know it sounds easy and I was trying this snippet:
if D(1:100,1)<mean(D(:,1)) c(:,1) = 1; else c(:,1) = -1; end
but it somehow doesn't do the job. I think we don't even need an if loop. Thanks for your comments.

Respuesta aceptada

Cam Salzberger
Cam Salzberger el 20 de Feb. de 2018
Hello Deepayan,
You probably are trying to use logical indexing, so you don't need the conditional.
c = ones(size(D, 1), 1);
c(D(:, 1) > mean(D(:, 1))) = -1;
On the other hand, you've got some very nice clusters here, and this code depends on you having roughly equal number of points in each cluster. Rather than mean, it would probably make sense to use some form of cluster analysis to figure out where the clusters are, and which points belong to which. kmeans is one of the most common methods, and would probably suffice here.
-Cam
  1 comentario
Deepayan Bhadra
Deepayan Bhadra el 20 de Feb. de 2018
Thanks, Cam! Pretty much what I needed and I will also check the clustering bit.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by