Machine Learning Week8 findClosestCentroids.m
来源:互联网 发布:网络算法与复杂性理论 编辑:程序博客网 时间:2024/05/19 18:42
增加一个临时变量dist记录当前最短的距离
loop over centroids计算属于哪一个聚类中心。
function idx = findClosestCentroids(X, centroids)%FINDCLOSESTCENTROIDS computes the centroid memberships for every example% idx = FINDCLOSESTCENTROIDS (X, centroids) returns the closest centroids% in idx for a dataset X where each row is a single example. idx = m x 1 % vector of centroid assignments (i.e. each entry in range [1..K])%% Set KK = size(centroids, 1);% You need to return the following variables correctly.idx = zeros(size(X,1), 1);% ====================== YOUR CODE HERE ======================% Instructions: Go over every example, find its closest centroid, and store% the index inside idx at the appropriate location.% Concretely, idx(i) should contain the index of the centroid% closest to example i. Hence, it should be a value in the % range 1..K%% Note: You can use a for-loop over the examples to compute this.%dist = 100*ones(size(X,1),1);for i = 1:K cent = centroids(i,:); cent = repmat(cent,size(X,1),1); curdist = sum((X-cent).^2,2); ind = curdist<dist; dist(ind) = curdist(ind); idx(ind) = i;end% =============================================================end
1 0
- Machine Learning Week8 findClosestCentroids.m
- Machine Learning Week8 computeCentroids.m
- Machine Learning(Andrew)Week8(上)
- Machine Learning(Andrew)Week8(下)
- [week8] machine learning:clustering(聚类)
- Machine Learning displayData.m
- Machine Learning Week4 lrCostFunction.m
- Machine Learning Week4 predictOneVsAll.m
- Machine Learning Week4 oneVsAll.m
- Machine Learning Week4 ex3_nn.m
- Machine Learning Week4 ex4.m
- NG week8 unsupervised learning
- S. M. Ali Eslami / Patterns for Research in Machine Learning
- 《(1997)Machine Learning [CMU+T.M. Mitchell] 》读书笔记 - 第二章
- 《(1997)Machine Learning [CMU+T.M. Mitchell] 》读书笔记 - 第三章
- (1997)Machine Learning [CMU+T.M. Mitchell] 读书笔记 - [第一章]
- machine learning
- Machine Learning
- 终极解决java获取路径问题
- Mac下Android Studio中获取SHA1和MD5
- github搜索技巧
- View的滚动与Scroller
- 【NOIP2005】谁拿了最多奖学金
- Machine Learning Week8 findClosestCentroids.m
- vs debug 调试 快捷键
- hdu2874 Connections between cities (LCA离线)
- listView及ScrollView等PadingTop显示问题:android:clipToPadding="false"
- .caffemodel的生成和利用
- JDBC读取MySQL的BLOB类型
- [Android]如何导入已有的外部数据库
- 剑指Offer:二叉搜索树的后序遍历序列
- 前端构建利器:AngularJS + Bower + Grunt