Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 8/Programming Assignment - 7/ex7/plotProgresskMeans.m
863 views
1
function plotProgresskMeans(X, centroids, previous, idx, K, i)
2
%PLOTPROGRESSKMEANS is a helper function that displays the progress of
3
%k-Means as it is running. It is intended for use only with 2D data.
4
% PLOTPROGRESSKMEANS(X, centroids, previous, idx, K, i) plots the data
5
% points with colors assigned to each centroid. With the previous
6
% centroids, it also plots a line between the previous locations and
7
% current locations of the centroids.
8
%
9
10
% Plot the examples
11
plotDataPoints(X, idx, K);
12
13
% Plot the centroids as black x's
14
plot(centroids(:,1), centroids(:,2), 'x', ...
15
'MarkerEdgeColor','k', ...
16
'MarkerSize', 10, 'LineWidth', 3);
17
18
% Plot the history of the centroids with lines
19
for j=1:size(centroids,1)
20
drawLine(centroids(j, :), previous(j, :));
21
end
22
23
% Title
24
title(sprintf('Iteration number %d', i))
25
26
end
27
28
29