欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: k均值算法的matlab源代碼 [打印本頁]

作者: playgamewy    時間: 2019-2-10 15:20
標題: k均值算法的matlab源代碼
用于實現k均值算法的matlab源代碼,簡單易懂,方便理解。自己可以參考注釋修改源代碼,以便深入的了解該算法的本質。
  1. x1=[0 1 0 1 2 1 2 3 6 7 8 6 7 8 9 7 8 9 8 9];
  2. x2=[0 0 1 1 1 2 2 2 6 6 6 7 7 7 7 8 8 9 9 9];
  3. cities = [x1;x2];   
  4. num = size(cities,2);   
  5. m1 = round(rand()*num);   
  6. m2 = round(rand()*num);
  7. while m1==m2               
  8.     m2 = round(rand()*num);
  9. end               
  10. u1 = cities(:,m1);      
  11. u2 = cities(:,m2);
  12. u_old = [u1,u2];
  13. u_new = [u2,u1];
  14. while u_old ~= u_new   
  15.     u_old = u_new ;   
  16.     for j=1:num      
  17.         dis1 = norm(cities(:,j)-u1);  
  18.         dis2 = norm(cities(:,j)-u2);
  19.         if dis1>=dis2  c(j) = 2;   
  20.         else c(j) = 1;
  21.         end
  22.     end
  23.     index1 = find(c==1);   
  24.     index2 = find(c==2);   
  25.     sum1 = sum(cities(:,index1),2);  
  26.     sum2 = sum(cities(:,index2),2);  
  27.     u1 = sum1/length(index1);      
  28.     u2 = sum2/length(index2);     
  29.     u_new = [u1,u2];        
  30. end
  31. hold on,plot(cities(1,index1),cities(2,index1),'*');  
  32. hold on,plot(cities(1,index2),cities(2,index2),'+');  
  33. hold on,plot(u1(1),u1(2),'o',u2(1),u2(2),'o');
  34. mean = u_new;
復制代碼


源程序.docx

13.37 KB, 下載次數: 2, 下載積分: 黑幣 -5






歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1