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/submit.m
863 views
1
function submit()
2
addpath('./lib');
3
4
conf.assignmentSlug = 'k-means-clustering-and-pca';
5
conf.itemName = 'K-Means Clustering and PCA';
6
conf.partArrays = { ...
7
{ ...
8
'1', ...
9
{ 'findClosestCentroids.m' }, ...
10
'Find Closest Centroids (k-Means)', ...
11
}, ...
12
{ ...
13
'2', ...
14
{ 'computeCentroids.m' }, ...
15
'Compute Centroid Means (k-Means)', ...
16
}, ...
17
{ ...
18
'3', ...
19
{ 'pca.m' }, ...
20
'PCA', ...
21
}, ...
22
{ ...
23
'4', ...
24
{ 'projectData.m' }, ...
25
'Project Data (PCA)', ...
26
}, ...
27
{ ...
28
'5', ...
29
{ 'recoverData.m' }, ...
30
'Recover Data (PCA)', ...
31
}, ...
32
};
33
conf.output = @output;
34
35
submitWithConfiguration(conf);
36
end
37
38
function out = output(partId, auxstring)
39
% Random Test Cases
40
X = reshape(sin(1:165), 15, 11);
41
Z = reshape(cos(1:121), 11, 11);
42
C = Z(1:5, :);
43
idx = (1 + mod(1:15, 3))';
44
if partId == '1'
45
idx = findClosestCentroids(X, C);
46
out = sprintf('%0.5f ', idx(:));
47
elseif partId == '2'
48
centroids = computeCentroids(X, idx, 3);
49
out = sprintf('%0.5f ', centroids(:));
50
elseif partId == '3'
51
[U, S] = pca(X);
52
out = sprintf('%0.5f ', abs([U(:); S(:)]));
53
elseif partId == '4'
54
X_proj = projectData(X, Z, 5);
55
out = sprintf('%0.5f ', X_proj(:));
56
elseif partId == '5'
57
X_rec = recoverData(X(:,1:5), Z, 5);
58
out = sprintf('%0.5f ', X_rec(:));
59
end
60
end
61
62