{"id":6267,"date":"2025-12-07T11:39:06","date_gmt":"2025-12-07T03:39:06","guid":{"rendered":"https:\/\/blog.coolcoding.cn\/?p=6267"},"modified":"2025-12-07T11:40:27","modified_gmt":"2025-12-07T03:40:27","slug":"%e5%ad%a6%e4%b9%a0-k-means-%e8%81%9a%e7%b1%bb%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=6267","title":{"rendered":"\u5b66\u4e60K-Means \u805a\u7c7b\u7b97\u6cd5"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.nvidia.cn\/glossary\/k-means\/\">https:\/\/www.nvidia.cn\/glossary\/k-means\/<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/357072839\">https:\/\/zhuanlan.zhihu.com\/p\/357072839<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u805a\u7c7b\u4e0e\u5206\u7c7b\u7684\u533a\u522b<\/strong><\/h2>\n\n\n\n<p>\u5206\u7c7b\uff1a\u7c7b\u522b\u662f\u5df2\u77e5\u7684\uff0c\u901a\u8fc7\u5bf9\u5df2\u77e5\u7c7b\u522b\u7684\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\u548c\u5b66\u4e60\uff0c\u627e\u5230\u8fd9\u4e9b\u4e0d\u540c\u7c7b\u7684\u7279\u5f81\uff0c\u518d\u5bf9\u672a\u77e5\u7c7b\u522b\u7684\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u3002\u5c5e\u4e8e\u76d1\u7763\u5b66\u4e60\u3002<\/p>\n\n\n\n<p>\u805a\u7c7b\uff1a\u4e8b\u5148\u4e0d\u77e5\u9053\u6570\u636e\u4f1a\u5206\u4e3a\u51e0\u7c7b\uff0c\u901a\u8fc7\u805a\u7c7b\u5206\u6790\u5c06\u6570\u636e\u805a\u5408\u6210\u51e0\u4e2a\u7fa4\u4f53\u3002\u805a\u7c7b\u4e0d\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u8bad\u7ec3\u548c\u5b66\u4e60\u3002\u5c5e\u4e8e\u65e0\u76d1\u7763\u5b66\u4e60\u3002<\/p>\n\n\n\n<p>\u5173\u4e8e\u76d1\u7763\u5b66\u4e60\u548c\u65e0\u76d1\u7763\u5b66\u4e60\uff0c\u8fd9\u91cc\u7ed9\u4e00\u4e2a\u7b80\u5355\u7684\u4ecb\u7ecd\uff1a\u4e00\u822c\u800c\u8a00\uff0c\u662f\u5426\u6709\u76d1\u7763\uff0c\u5c31\u770b\u8f93\u5165\u6570\u636e\u662f\u5426\u6709\u6807\u7b7e\uff0c\u8f93\u5165\u6570\u636e\u6709\u6807\u7b7e\uff0c\u5219\u4e3a\u6709\u76d1\u7763\u5b66\u4e60\uff0c\u5426\u5219\u4e3a\u65e0\u76d1\u7763\u5b66\u4e60\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>K-means \u805a\u7c7b\u539f\u7406\u7b80\u8ff0<\/strong><\/h2>\n\n\n\n<p>\u805a\u7c7b\u7b97\u6cd5\u6709\u5f88\u591a\u79cd\uff0cK-Means \u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u7684\u6700\u5e38\u7528\u7684\u4e00\u79cd\uff0c\u7b97\u6cd5\u6700\u5927\u7684\u7279\u70b9\u662f\u7b80\u5355\uff0c\u597d\u7406\u89e3\uff0c\u8fd0\u7b97\u901f\u5ea6\u5feb\uff0c\u4f46\u662f\u53ea\u80fd\u5e94\u7528\u4e8e\u8fde\u7eed\u578b\u7684\u6570\u636e\uff0c\u5e76\u4e14\u4e00\u5b9a\u8981\u5728\u805a\u7c7b\u524d\u9700\u8981\u624b\u5de5\u6307\u5b9a\u8981\u5206\u6210\u51e0\u7c7b\u3002<\/p>\n\n\n\n<p>K-Means \u805a\u7c7b\u7b97\u6cd5\u7684\u5927\u81f4\u601d\u60f3\u5c31\u662f\u201c\u7269\u4ee5\u7c7b\u805a\uff0c\u4eba\u4ee5\u7fa4\u5206\u201d\uff1a<\/p>\n\n\n\n<ol>\n<li>\u9996\u5148\u8f93\u5165 k \u7684\u503c\uff0c\u5373\u6211\u4eec\u6307\u5b9a\u5e0c\u671b\u901a\u8fc7\u805a\u7c7b\u5f97\u5230 k \u4e2a\u5206\u7ec4\uff1b<\/li>\n\n\n\n<li>\u4ece\u6570\u636e\u96c6\u4e2d\u968f\u673a\u9009\u53d6 k \u4e2a\u6570\u636e\u70b9\u4f5c\u4e3a\u521d\u59cb\u5927\u4f6c\uff08<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=167479141&amp;content_type=Article&amp;match_order=1&amp;q=%E8%B4%A8%E5%BF%83&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">\u8d28\u5fc3<\/a>\uff09\uff1b<\/li>\n\n\n\n<li>\u5bf9\u96c6\u5408\u4e2d\u6bcf\u4e00\u4e2a\u5c0f\u5f1f\uff0c\u8ba1\u7b97\u4e0e\u6bcf\u4e00\u4e2a\u5927\u4f6c\u7684\u8ddd\u79bb\uff0c\u79bb\u54ea\u4e2a\u5927\u4f6c\u8ddd\u79bb\u8fd1\uff0c\u5c31\u8ddf\u5b9a\u54ea\u4e2a\u5927\u4f6c\uff1b<\/li>\n\n\n\n<li>\u8fd9\u65f6\u6bcf\u4e00\u4e2a\u5927\u4f6c\u624b\u4e0b\u90fd\u805a\u96c6\u4e86\u4e00\u7968\u5c0f\u5f1f\uff0c\u8fd9\u65f6\u5019\u53ec\u5f00\u9009\u4e3e\u5927\u4f1a\uff0c\u6bcf\u4e00\u7fa4\u9009\u51fa\u65b0\u7684\u5927\u4f6c\uff08\u5373\u901a\u8fc7\u7b97\u6cd5\u9009\u51fa\u65b0\u7684\u8d28\u5fc3\uff09\uff1b<\/li>\n\n\n\n<li>\u5982\u679c\u65b0\u5927\u4f6c\u548c\u8001\u5927\u4f6c\u4e4b\u95f4\u7684\u8ddd\u79bb\u5c0f\u4e8e\u67d0\u4e00\u4e2a\u8bbe\u7f6e\u7684\u9608\u503c\uff08\u8868\u793a\u91cd\u65b0\u8ba1\u7b97\u7684\u8d28\u5fc3\u7684\u4f4d\u7f6e\u53d8\u5316\u4e0d\u5927\uff0c\u8d8b\u4e8e\u7a33\u5b9a\uff0c\u6216\u8005\u8bf4\u6536\u655b\uff09\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u6211\u4eec\u8fdb\u884c\u7684\u805a\u7c7b\u5df2\u7ecf\u8fbe\u5230\u671f\u671b\u7684\u7ed3\u679c\uff0c\u7b97\u6cd5\u7ec8\u6b62\uff1b<\/li>\n\n\n\n<li>\u5982\u679c\u65b0\u5927\u4f6c\u548c\u8001\u5927\u4f6c\u8ddd\u79bb\u53d8\u5316\u5f88\u5927\uff0c\u9700\u8981<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=167479141&amp;content_type=Article&amp;match_order=1&amp;q=%E8%BF%AD%E4%BB%A3&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">\u8fed\u4ee3<\/a>3~5\u6b65\u9aa4\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5b9e\u4f8b\u6f14\u793a<\/strong><\/h2>\n\n\n\n<p>\u770b\u4e86\u4e0a\u9762\u7684\u539f\u7406\u7b80\u8ff0\uff0c\u4f30\u8ba1\u8fd8\u662f\u6709\u70b9\u7cca\u6d82\uff0c\u4e0b\u9762\u4e3e\u4e00\u4e2a\u975e\u5e38\u5f62\u8c61\u7b80\u5355\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u67096\u4e2a\u70b9\uff0c\u4ece\u56fe\u4e0a\u770b\u5e94\u8be5\u53ef\u4ee5\u5206\u6210\u4e24\u5806\uff0c\u524d\u4e09\u4e2a\u70b9\u4e00\u5806\uff0c\u540e\u4e09\u4e2a\u70b9\u53e6\u4e00\u5806\u3002\u73b0\u5728\u6211\u624b\u5de5\u5730\u628a k-means \u8ba1\u7b97\u8fc7\u7a0b\u6f14\u793a\u4e00\u4e0b\uff0c\u540c\u65f6\u68c0\u9a8c\u662f\u4e0d\u662f\u548c\u9884\u671f\u4e00\u81f4\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2025\/12\/v2-60c4cf1252d94804fcbd56aa13b2448f_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>1. \u8bbe\u5b9a k \u503c\u4e3a2\uff1b<\/strong><\/p>\n\n\n\n<p><strong>2. \u9009\u62e9\u521d\u59cb\u5927\u4f6c\uff08\u5c31\u9009 P1 \u548c P2\uff09\uff1b<\/strong><\/p>\n\n\n\n<p><strong>3. \u8ba1\u7b97\u5c0f\u5f1f\u4e0e\u5927\u4f6c\u7684\u8ddd\u79bb\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2025\/12\/v2-2e5b337d7ddd2fc47f26191c30d83fc2_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u6240\u6709\u7684\u5c0f\u5f1f\u90fd\u79bb P2 \u66f4\u8fd1\uff0c\u6240\u4ee5\u6b21\u7ad9\u961f\u7684\u7ed3\u679c\u662f\uff1a<\/p>\n\n\n\n<p>A \u7ec4\uff1aP1<br>B \u7ec4\uff1aP2\u3001P3\u3001P4\u3001P5\u3001P6<\/p>\n\n\n\n<p><strong>4. \u53ec\u5f00\u9009\u4e3e\u5927\u4f1a\uff1a<\/strong><\/p>\n\n\n\n<p>A \u7ec4\u6ca1\u4ec0\u4e48\u53ef\u9009\u7684\uff0c\u5927\u4f6c\u5c31\u662f\u81ea\u5df1;<br>B \u7ec4\u67095\u4e2a\u4eba\uff0c\u9700\u8981\u91cd\u65b0\u9009\u5927\u4f6c\uff0c\u8fd9\u91cc\u8981\u6ce8\u610f\u9009\u5927\u4f6c\u7684\u65b9\u6cd5\u662f\u6bcf\u4e2a\u4eba X \u5750\u6807\u7684\u5e73\u5747\u503c\u548c Y \u5750\u6807\u7684\u5e73\u5747\u503c\u7ec4\u6210\u7684\u65b0\u7684\u70b9\uff0c\u4e3a\u65b0\u5927\u4f6c\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2a\u5927\u4f6c\u662f\u201c\u865a\u62df\u7684\u201d\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0cB \u7ec4\u9009\u51fa\u65b0\u5927\u54e5\u7684\u5750\u6807\u4e3a\uff1aP \u54e5 ((1+3+8+9+10)\/5, (2+1+8+10+7)\/5)=(6.2, 5.6)\u3002<\/p>\n\n\n\n<p>\u7efc\u5408\u4e24\u7ec4\uff0c\u65b0\u5927\u54e5\u4e3a P1\uff080\uff0c0\uff09\uff0cP\u54e5\uff086.2\uff0c5.6\uff09\uff0c\u800cP2-P6\u91cd\u65b0\u6210\u4e3a\u5c0f\u5f1f\u3002<\/p>\n\n\n\n<p><strong>5. \u518d\u6b21\u8ba1\u7b97\u5c0f\u5f1f\u5230\u5927\u4f6c\u7684\u8ddd\u79bb\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2025\/12\/v2-e02faaa5a9ac9ac741840cb8e28d7db5_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u8fd9\u65f6\u53ef\u4ee5\u770b\u5230P2\u3001P3\u79bbP1\u66f4\u8fd1\uff0cP4\u3001P5\u3001P6\u79bbP\u54e5\u66f4\u8fd1\uff0c\u6240\u4ee5\u7b2c\u4e8c\u6b21\u7ad9\u961f\u7684\u7ed3\u679c\u662f\uff1a<\/p>\n\n\n\n<p>A \u7ec4\uff1aP1\u3001P2\u3001P3<br>B \u7ec4\uff1aP4\u3001P5\u3001P6\uff08\u865a\u62df\u5927\u54e5\u8fd9\u65f6\u5019\u6d88\u5931\uff09<\/p>\n\n\n\n<p><strong>6. \u7b2c\u4e8c\u5c4a\u9009\u4e3e\u5927\u4f1a\uff1a<\/strong><br>\u540c\u6837\u7684\u65b9\u6cd5\u9009\u51fa\u65b0\u7684\u865a\u62df\u5927\u4f6c\uff1aP\u54e51\uff081.33\uff0c1\uff09\uff0cP\u54e52\uff089\uff0c8.33\uff09\uff0cP1-P6\u90fd\u6210\u4e3a\u5c0f\u5f1f\u3002<\/p>\n\n\n\n<p><strong>7.\u7b2c\u4e09\u6b21\u8ba1\u7b97\u5c0f\u5f1f\u5230\u5927\u4f6c\u7684\u8ddd\u79bb\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2025\/12\/v2-e6ab5947ecc01a879106f9b4550e2c96_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u8fd9\u65f6\u53ef\u4ee5\u770b\u5230 P1\u3001P2\u3001P3 \u79bb P\u54e51 \u66f4\u8fd1\uff0cP4\u3001P5\u3001P6\u79bb P\u54e52 \u66f4\u8fd1\uff0c\u6240\u4ee5\u7b2c\u4e8c\u6b21\u7ad9\u961f\u7684\u7ed3\u679c\u662f\uff1a<br>A \u7ec4\uff1aP1\u3001P2\u3001P3<br>B \u7ec4\uff1aP4\u3001P5\u3001P6<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u8fd9\u6b21\u7ad9\u961f\u7684\u7ed3\u679c\u548c\u4e0a\u6b21\u6ca1\u6709\u4efb\u4f55\u53d8\u5316\u4e86\uff0c\u8bf4\u660e\u5df2\u7ecf\u6536\u655b\uff0c\u805a\u7c7b\u7ed3\u675f\uff0c\u805a\u7c7b\u7ed3\u679c\u548c\u6211\u4eec\u6700\u5f00\u59cb\u8bbe\u60f3\u7684\u7ed3\u679c\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>K-means \u805a\u7c7b\u7b80\u6613\u5e94\u7528\u793a\u4f8b<\/strong><\/h2>\n\n\n\n<p>\u5173\u4e8e K-Means \u7684\u7b97\u6cd5\u5177\u4f53\u4ee3\u7801\uff0c\u7f51\u4e0a\u6709\u5404\u79cd\u7248\u672c\uff0c\u8fd9\u91cc\u5c31\u4e0d\u8d58\u8ff0\u4e86\uff0c\u4e0b\u9762\u7ed3\u5408&nbsp;<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=167479141&amp;content_type=Article&amp;match_order=1&amp;q=MATLAB&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">MATLAB<\/a>&nbsp;\u4e2d\u7684\u4e00\u4e9b\u51fd\u6570\u7ed9\u51fa\u4e00\u4e2a\u8f83\u4e3a\u7b80\u6d01\u7684\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>X2 = zscore(X);      % zscore\u65b9\u6cd5\u6807\u51c6\u5316\u6570\u636e  \nY2 = pdist(X2);      % \u8ba1\u7b97\u8ddd\u79bb\uff08\u9ed8\u8ba4\u6b27\u5f0f\u8ddd\u79bb\uff09\nZ2 = linkage(Y2);    % \u5b9a\u4e49\u53d8\u91cf\u4e4b\u95f4\u7684\u8fde\u63a5\uff0c\u7528\u6307\u5b9a\u7684\u7b97\u6cd5\u8ba1\u7b97\u7cfb\u7edf\u805a\u7c7b\u6811\nT = cluster(Z2,6);   % \u521b\u5efa\u805a\u7c7b\nH = dendrogram(Z2);  % \u4f5c\u51fa\u7cfb\u8c31\u56fe\uff08\u6563\u70b9\u805a\u7c7b\u56fe\u770b\u817b\u4e86\uff0c\u8fd9\u91cc\u753b\u4e2a\u7cfb\u8c31\u56fe\uff09<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2025\/12\/v2-37357ba7cfa954bc597984f81f7a99bd_1440w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5f53\u7136\uff0cMATLAB \u4ee5\u53ca&nbsp;<a href=\"https:\/\/zhida.zhihu.com\/search?content_id=167479141&amp;content_type=Article&amp;match_order=1&amp;q=sklearn&amp;zhida_source=entity\" target=\"_blank\" rel=\"noreferrer noopener\">sklearn<\/a>&nbsp;\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684 kmeans() \u51fd\u6570\u53ef\u4f9b\u76f4\u63a5\u805a\u7c7b\u4f7f\u7528\uff0c\u8be6\u7ec6\u53c2\u6570\u7ec6\u8282\u53ef\u53c2\u8003\u5176\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.nvidia.cn\/glossary\/k-means\/ https:\/\/zhuanla [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6267"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6267"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6267\/revisions"}],"predecessor-version":[{"id":6276,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/6267\/revisions\/6276"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}