フィルターのクリア

How to plot k-means output?

6 ビュー (過去 30 日間)
Mnr
Mnr 2014 年 3 月 23 日
コメント済み: Image Analyst 2020 年 10 月 18 日
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.

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 23 日
How about using scatter and have each class be plotted with different color markers? I think that's the most common way.
  4 件のコメント
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh 2020 年 10 月 18 日
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 2020 年 10 月 18 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by