Borrar filtros
Borrar filtros

How to plot k-means output?

6 visualizaciones (últimos 30 días)
Mnr
Mnr el 23 de Mzo. de 2014
Comentada: Image Analyst el 18 de Oct. de 2020
Hello all,
I have some data in 8 text files, I have used 5 of them as my training data and the rest as the testing data. I have classified them using k-means. I would like to visualize the output; in other words, I would like to see the membership of each data point in a graph. Can anybody help me please? Thanks in advance.

Respuesta aceptada

Image Analyst
Image Analyst el 23 de Mzo. de 2014
How about using scatter and have each class be plotted with different color markers? I think that's the most common way.
  4 comentarios
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh el 18 de Oct. de 2020
Hi,
I am using your idea and takethis code, but when I am running it, my data are not spread like scatter plot. All of them are in the same line. can you help me regarding that please?
Image Analyst
Image Analyst el 18 de Oct. de 2020
I copied and pasted the code:
x = rand(1000, 1); % 1000 random x,y points
y = rand(1000, 1); % 1000 random x,y points
% Create classes. Class 1 is if x<y. Class 2 otherwise
classes = (x < y);
% Make class 1 blue and class 2 red
classColors = zeros(length(x), 3);
markerSizes = zeros(length(x), 1);
for row = 1 : length(x)
if classes(row)
% Class 1 = blue
classColors(row,:) = [0, 0, 1];
markerSizes(row) = 10;
else
% Class 2 = red
classColors(row, :) = [1, 0, 0];
markerSizes(row) = 40;
end
end
scatter(x,y, markerSizes, classColors, 'LineWidth', 2);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
and it gives this image.
Not sure what you did to change it since you forgot to attach your modified code. Attach it with your data and code to read in your data and we'll see if we can fix it. By the way, I do have the stats toolbox now, so I can do kmeans() if needed.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by