Professional Documents
Culture Documents
Exp 5
Exp 5
AIM:
To study clustering with the application of the K means algorithm in MATLAB
Description:
Centroids: The k-means algorithm defines a centroid for each cluster. This is a representative
point that acts as the "center" of the cluster, calculated as the average of all data points within
that cluster.
Euclidean Distance: The most common distance metric used in k-means is the Euclidean
distance. It measures the "straight-line" distance between two data points. Other distance
metrics can be used, but Euclidean distance is often chosen for its simplicity and efficiency.
% Select specific features (sepal length, sepal width, petal length, petal width)
data = meas(:, 2:end);
% Perform k-means clustering using Euclidean distance, 5 replicates, and final display
[idx, c] = kmeans(data, k, "Distance", "sqeuclidean", "Replicates", 5, "Options", opts);
% Create a scatter plot using the first two features (sepal length and sepal width)
figure;
scatter(data(:, 1), data(:, 2), 10, idx, 'filled');
Results: