How to perform fuzzy c means clustering using custom initializations (initial fuzzy membership metric, datapoints, cluster centers.. etc)?

2 Ansichten (letzte 30 Tage)
% Define the data points as coordinates (X, Y)
Data = [
1, 3;
8, 2;
1, 2;
3, 1
];
% Defining total number of clusters
NumOfClusters = 2;
% Create the initial fuzzy partition matrix (U0)
U0 = [
1, 1, 0, 0;
0, 0, 1, 1
]; % Provided initial partition matrix
% Define initial cluster center values
initial_centers = [
2.0, 2.35;
2.15, 1.9
];
% Fuzzy c-means options
fuzzy_options = [2.0];
% Perform Fuzzy C-Means clustering with initializations
[~, cluster_centers, membership] = fcm(Data', NumOfClusters, fuzzy_options, U0, [], initial_centers);
% Displaying the updated partition matrix
disp('Updated Partition Matrix (Membership):');
disp(membership);
% Plotting the clustered data with different colors for each cluster
colors = distinguishable_colors(NumOfClusters); % Generate distinct colors for clusters
figure;
for i = 1:NumOfClusters
idx = find(membership(i, :) == max(membership));
scatter(Data(idx, 1), Data(idx, 2), 100, colors(i, :), 'filled');
hold on;
end
plot(cluster_centers(:, 1), cluster_centers(:, 2), 'kx', 'MarkerSize', 15, 'LineWidth', 2); % Plot cluster centers
hold off;
% Creating a legend dynamically based on the number of clusters
legend_strings = cell(1, NumOfClusters);
for i = 1:NumOfClusters
legend_strings{i} = ['Cluster ' num2str(i)];
end
legend_strings{NumOfClusters + 1} = 'Cluster Centers';
legend(legend_strings);
title('Fuzzy C-Means Clustering with Initializations');
I want to initialize the datapoints, initial fuzzy partition matrix U0, initial_cluster centers but i am getting the following error:
Error using fcm Too many input arguments. Error in (line 28) [~, cluster_centers, membership] = fcm(Data', NumOfClusters, fuzzy_options, U0, [], initial_centers);
When i remove the initial fuzzy partition matrix U0 and initial cluster centers the code works.

Antworten (0)

Kategorien

Mehr zu Data Clustering finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by