mirror of
https://github.com/jlengrand/MachineLearningCoursera.git
synced 2026-03-10 15:51:17 +00:00
Implements means computation
This commit is contained in:
@@ -26,12 +26,20 @@ centroids = zeros(K, n);
|
||||
% Note: You can use a for-loop over the centroids to compute this.
|
||||
%
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
% this could be vectorized but today is Christmas and I have family talking
|
||||
% loud everywhere around.
|
||||
for i = 1:K
|
||||
temp = [];
|
||||
for j = 1:m
|
||||
if idx(j) == i
|
||||
temp = [temp; X(j, :)];
|
||||
end
|
||||
end
|
||||
|
||||
s = size(temp, 1);
|
||||
centroids(i, :) = sum(temp)./s;
|
||||
|
||||
end
|
||||
|
||||
% =============================================================
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ fprintf(' %d', idx(1:3));
|
||||
fprintf('\n(the closest centroids should be 1, 3, 2 respectively)\n');
|
||||
|
||||
fprintf('Program paused. Press enter to continue.\n');
|
||||
pause;
|
||||
% pause;
|
||||
|
||||
%% ===================== Part 2: Compute Means =========================
|
||||
% After implementing the closest centroids function, you should now
|
||||
@@ -63,7 +63,7 @@ fprintf(' [ 5.813503 2.633656 ]\n');
|
||||
fprintf(' [ 7.119387 3.616684 ]\n\n');
|
||||
|
||||
fprintf('Program paused. Press enter to continue.\n');
|
||||
pause;
|
||||
% pause;
|
||||
|
||||
|
||||
%% =================== Part 3: K-Means Clustering ======================
|
||||
@@ -93,7 +93,7 @@ initial_centroids = [3 3; 6 2; 8 5];
|
||||
fprintf('\nK-Means Done.\n\n');
|
||||
|
||||
fprintf('Program paused. Press enter to continue.\n');
|
||||
pause;
|
||||
% pause;
|
||||
|
||||
%% ============= Part 4: K-Means Clustering on Pixels ===============
|
||||
% In this exercise, you will use K-Means to compress an image. To do this,
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user