总感觉计算机会欺骗人类,这里就是说的我 , 对自己写下去的代码总是怀疑计算机不能按照我的意思执行

 

这个什么毛病 ?

不相信电脑,Do not believe in Computer

Here  I would like to show a case about my code when doing machine learning in Matlab.

this is logic problem which 1’m weakness at this.

you have a dataset includeing 100 example (we call the training set), and every example has a classification target, you could image this as 1 2 3

here what you need to do is pick them out and gourp them . finally you will get the mean of point and square error.

The stupid way:

for

for

if

end

 

end

 

end

 

many course we had learned taught us to vectorized them as

 

try to use the find and sum  function in matlab which is very useful  to mark the index of data point and matrix.

 

then we go

 

for k=1:K

point-indeces=find(idx==k)

centroids(k, :) = sum(X(point_indeces, :)) ./ length(point_indeces);

end