How to Reassign Wrong cluster Values.

Hello, I hope you are doing well. I have the dataset,Which is wrongly clusters into 4 cluster, but there should be 3 Clusters.
The cluster 2 (cell 2) and cluster 3 (cell 3) have almost similar values. I want to rearrange the clusters to make 3 clusters
How can i do that in Matlab. Can anybody help me with that?

 Accepted Answer

How are you clustering it? If you use kmeans you can tell it (force it) to use 4 clusters and it will find 4 clusters.

5 Comments

@Image Analyst Yes, i am using K-means by the following command, its says optimal clusters are 4, but my groundtruth have 3 clusters
eva = evalclusters(dataset,'kmeans','silhouette','KList',[1:4]);
@Image Analyst Can you please comment on this?
I read in your data and found this:
s = load('Dataset.mat')
s = struct with fields:
clusters: {4×1 cell}
ca = s.clusters
ca = 4×1 cell array
{9469×4 double} {1500×4 double} { 630×4 double} { 323×4 double}
plotColors = lines(numel(ca));
% Plot first 3 columns
subplot(2, 1, 1);
for k = 1 : numel(ca)
thisCluster = ca{k}
plot3(thisCluster(:, 1), thisCluster(:, 2), thisCluster(:, 3), '.', 'Color',plotColors(k, :))
hold on
end
thisCluster = 9469×4
1.0e+06 * 0.5716 0.0000 0.0000 0.0000 0.5717 0.0000 0.0000 0.0000 0.5717 0.0000 0.0000 0.0000 0.5718 0.0000 0.0000 0.0000 0.5719 0.0000 0.0000 0.0000 0.5719 0.0000 0.0000 0.0000 0.5719 0.0000 0.0000 0.0000 0.5719 0.0000 0.0000 0.0000 0.5720 0.0000 0.0000 0.0000 0.5720 0.0000 0.0000 0.0000
thisCluster = 1500×4
1.0e+06 * 0.1716 0.0001 0.0000 0.0000 0.1746 0.0001 0.0000 0.0000 0.1855 0.0001 0.0000 0.0000 0.1888 0.0001 0.0000 0.0000 0.2012 0.0001 0.0000 0.0000 0.2046 0.0001 0.0000 0.0000 0.2052 0.0001 0.0000 0.0000 0.2063 0.0001 0.0000 0.0000 0.2069 0.0001 0.0000 0.0000 0.2074 0.0001 0.0000 0.0000
thisCluster = 630×4
1.0e+06 * 0.1719 0.0001 0.0000 0.0000 0.1743 0.0001 0.0000 0.0000 0.1749 0.0001 0.0000 0.0000 0.1845 0.0001 0.0000 0.0000 0.1871 0.0001 0.0000 0.0000 0.1993 0.0001 0.0000 0.0000 0.2038 0.0001 0.0000 0.0000 0.2050 0.0001 0.0000 0.0000 0.2061 0.0001 0.0000 0.0000 0.2066 0.0001 0.0000 0.0000
thisCluster = 323×4
1.0e+06 * 1.4845 0.0000 0.0000 0.0000 1.4848 0.0000 0.0000 0.0000 1.4855 0.0000 0.0000 0.0000 1.5088 0.0000 0.0000 0.0000 1.5095 0.0000 0.0000 0.0000 1.5099 0.0000 0.0000 0.0000 1.5102 0.0000 0.0000 0.0000 1.5126 0.0000 0.0000 0.0000 1.5129 0.0000 0.0000 0.0000 1.5136 0.0000 0.0000 0.0000
xlabel('Column1')
ylabel('Column2')
zlabel('Column3')
grid on
% Plot last 3 columns
subplot(2, 1, 2);
for k = 1 : numel(ca)
thisCluster = ca{k};
plot3(thisCluster(:, 2), thisCluster(:, 3), thisCluster(:, 4), '.', 'Color',plotColors(k, :))
hold on
end
xlabel('Column2')
ylabel('Column3')
zlabel('Column4')
grid on
So it seems reasonable that there could be 4 clusters. Can you tell me what the 4 columns mean? Is it possible one of them should not be used in the decision as to what class a row belongs in?
@Image Analyst The all four columns are the features which are used to identify the cluster.
I used column 2 and column 4 for K-means clustering.
Your data called "clusters" has 4 datasets, so why do you say that there should be 3? When you run it, it looks like 4 clusters is reasonable. Which sets should be combined? And when you told kmeans there were 3, which sets did it combine?
s = load('Dataset.mat')
s = struct with fields:
clusters: {4×1 cell}
ca = s.clusters;
plotColors = lines(numel(ca));
% Plot first 3 columns
for k = 1 : numel(ca)
thisCluster = ca{k};
plot(thisCluster(:, 2), thisCluster(:, 4), '.', 'Color', plotColors(k, :), 'MarkerSize', 40)
hold on
end
xlabel('Column2')
ylabel('Column4')
grid on

Sign in to comment.

More Answers (1)

Hi, your clusters contain just matrices organized in four columns, so you can easily e.g. put two of them together (concatenate versitcally) like this:
clusters{3} = [clusters{3};clusters{4}];
And to remove the fourth cluster, you can use:
clusters = clusters(1:3);

3 Comments

@Jiri Hajek But i want it to be using any algorithm, not like merging into one another
Jiri Hajek
Jiri Hajek on 14 Dec 2022
Edited: Jiri Hajek on 14 Dec 2022
Since you did not mention any specific algorithm, this was actually a valid response.:-) But jokes aside, try to explain what you need. You want to rearrange but not to merge - so perhaps you should try to explain wat you want to achieve with the data, exactly.
@Jiri Hajek Let me explain this to you, I have apply clustering algorithm on this, There should be 3 Clusters, but the clustering algorithm solve this into 4 clusters
The cell 2 and cell 3 are mostly similar values, we want to apply any algorithm which have similar values or values near to each other should be in 1 cell.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!