{"id":91387,"date":"2026-08-07T20:16:41","date_gmt":"2026-08-07T12:16:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/91387.html"},"modified":"2026-08-07T20:16:41","modified_gmt":"2026-08-07T12:16:41","slug":"%e5%88%9d%e8%af%86%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%ef%bc%88%e6%9c%b4%e7%b4%a0%e8%b4%9d%e5%8f%b6%e6%96%af%e5%92%8ck-means%e8%81%9a%e7%b1%bb%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/91387.html","title":{"rendered":"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09"},"content":{"rendered":"<h3>\u4e00\u3001\u673a\u5668\u5b66\u4e60\u5341\u5927\u5e38\u89c1\u7b97\u6cd5<\/h3>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u5b83\u901a\u8fc7\u5df2\u77e5\u7684\u6807\u7b7e\u6570\u636e&#xff0c;\u5b66\u4e60\u5982\u4f55\u5bf9\u65b0\u7684\u6837\u672c\u8fdb\u884c\u5206\u7c7b\u3002<\/p>\n<p>K-Means\u805a\u7c7b\u6b63\u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6280\u672f\u4e4b\u4e00\u3002<\/p>\n<p>\u5982\u679c\u8bf4\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u5728\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u9884\u6d4b&#xff0c;\u90a3\u4e48K-Means\u5c31\u662f\u5728\u6ca1\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u63a2\u7d22\u3002\u4e24\u8005\u4ee3\u8868\u4e86\u673a\u5668\u5b66\u4e60\u7684\u4e24\u5927\u65b9\u5411&#xff0c;\u672c\u7bc7\u4e3b\u8981\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u7b97\u6cd5\u3002<\/p>\n<h3>\u4e8c\u3001\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;Naive Bayes&#xff09;<\/h3>\n<h4>2.1 \u4ec0\u4e48\u662f\u6734\u7d20\u8d1d\u53f6\u65af<\/h4>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u4e00\u79cd\u57fa\u4e8e\u8d1d\u53f6\u65af\u5b9a\u7406\u7684\u7b80\u5355\u800c\u9ad8\u6548\u7684\u6982\u7387\u5206\u7c7b\u7b97\u6cd5\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u901a\u8fc7\u5df2\u77e5\u7684\u67d0\u4e9b\u7279\u5f81&#xff0c;\u6765\u8ba1\u7b97\u67d0\u4e2a\u4e8b\u4ef6\u53d1\u751f\u7684\u6982\u7387&#xff0c;\u5e76\u9009\u62e9\u6982\u7387\u6700\u9ad8\u7684\u7c7b\u522b\u4f5c\u4e3a\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u201c\u6734\u7d20\u201d\u4e4b\u5904\u5728\u4e8e\u4e00\u4e2a\u5173\u952e\u5047\u8bbe&#xff1a;\u6240\u6709\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5728\u5224\u65ad\u51b3\u7b56\u662f\u5426\u9002\u5408\u6216\u6b63\u786e\u65f6&#xff0c;\u6bcf\u4e2a\u7279\u5f81\u5bf9\u4f60\u7684\u51b3\u7b56\u5f71\u54cd\u662f\u4e92\u4e0d\u76f8\u5173\u7684\u3002\u867d\u7136\u5728\u73b0\u5b9e\u4e2d&#xff0c;\u7279\u5f81\u4e4b\u95f4\u5e38\u6709\u8054\u7cfb&#xff0c;\u4f46\u8fd9\u4e2a\u7b80\u5316\u7684\u5047\u8bbe\u8ba9\u8ba1\u7b97\u53d8\u5f97\u975e\u5e38\u9ad8\u6548\u3002<\/p>\n<h4>2.2 \u6838\u5fc3\u539f\u7406&#xff1a;\u8d1d\u53f6\u65af\u5b9a\u7406<\/h4>\n<p>\u8981\u7406\u89e3\u6734\u7d20\u8d1d\u53f6\u65af&#xff0c;\u5fc5\u987b\u5148\u4e86\u89e3\u5b83\u7684\u57fa\u77f3\u2014\u2014\u8d1d\u53f6\u65af\u5b9a\u7406\u3002\u8d1d\u53f6\u65af\u5b9a\u7406\u63cf\u8ff0\u4e86\u5728\u5df2\u77e5\u4e00\u4e9b\u6761\u4ef6\u7684\u60c5\u51b5\u4e0b&#xff0c;\u5982\u4f55\u66f4\u65b0\u67d0\u4e2a\u4e8b\u4ef6\u53d1\u751f\u7684\u6982\u7387\u3002<\/p>\n<p>\u8d1d\u53f6\u65af\u516c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"P(A|B) = \\\\frac{P(B|A) \\\\times P(A)}{P(B)}\" class=\"mathcode\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807121639-6a75cca7ceb3c.png\" \/><\/p>\n<\/p>\n<p>\u516c\u5f0f\u770b\u8d77\u6765\u53ef\u80fd\u6709\u70b9\u62bd\u8c61&#xff0c;\u6211\u4eec\u7528\u5224\u65ad\u4e00\u5c01\u90ae\u4ef6\u662f\u5426\u662f\u5783\u573e\u90ae\u4ef6\u7684\u4f8b\u5b50\u6765\u7406\u89e3\u5b83&#xff1a;<\/p>\n<p>A&#xff1a;\u90ae\u4ef6\u662f\u201c\u5783\u573e\u90ae\u4ef6\u201d\u8fd9\u4e2a\u4e8b\u4ef6\u3002<\/p>\n<p>B&#xff1a;\u90ae\u4ef6\u4e2d\u5305\u542b\u201c\u514d\u8d39\u201d\u8fd9\u4e2a\u8bcd\u8fd9\u4e2a\u7279\u5f81\u3002<\/p>\n<p>P(A)&#xff1a;\u5148\u9a8c\u6982\u7387\u2014\u2014\u4efb\u610f\u4e00\u5c01\u90ae\u4ef6\u662f\u5783\u573e\u90ae\u4ef6\u7684\u6982\u7387\u3002\u6bd4\u5982\u6839\u636e\u5386\u53f2\u6570\u636e&#xff0c;100\u5c01\u90ae\u4ef6\u91cc\u670920\u5c01\u662f\u5783\u573e\u90ae\u4ef6&#xff0c;\u90a3\u4e48\u00a0P(\u5783\u573e\u90ae\u4ef6)&#061;0.2P(\u5783\u573e\u90ae\u4ef6)&#061;0.2\u3002<\/p>\n<p>P(B|A)&#xff1a;\u6761\u4ef6\u6982\u7387&#xff08;\u4f3c\u7136&#xff09;\u2014\u2014\u5728\u5df2\u77e5\u90ae\u4ef6\u662f\u5783\u573e\u90ae\u4ef6\u7684\u60c5\u51b5\u4e0b&#xff0c;\u5176\u4e2d\u51fa\u73b0\u201c\u514d\u8d39\u201d\u8fd9\u4e2a\u8bcd\u7684\u6982\u7387\u3002\u6bd4\u5982\u5783\u573e\u90ae\u4ef6\u4e2d80%\u90fd\u5305\u542b\u201c\u514d\u8d39\u201d&#xff0c;\u90a3\u4e48\u00a0P(\u514d\u8d39\u2223\u5783\u573e\u90ae\u4ef6)&#061;0.8P(\u514d\u8d39\u2223\u5783\u573e\u90ae\u4ef6)&#061;0.8\u3002<\/p>\n<p>P(B)&#xff1a;\u8bc1\u636e\u2014\u2014\u4efb\u610f\u4e00\u5c01\u90ae\u4ef6\u4e2d\u51fa\u73b0\u201c\u514d\u8d39\u201d\u8fd9\u4e2a\u8bcd\u7684\u603b\u6982\u7387\u3002<\/p>\n<p>P(A|B)&#xff1a;\u540e\u9a8c\u6982\u7387\u2014\u2014\u6211\u4eec\u6700\u7ec8\u60f3\u6c42\u7684&#xff1a;\u5728\u5df2\u77e5\u90ae\u4ef6\u5305\u542b\u201c\u514d\u8d39\u201d\u8fd9\u4e2a\u8bcd\u7684\u6761\u4ef6\u4e0b&#xff0c;\u8fd9\u5c01\u90ae\u4ef6\u662f\u5783\u573e\u90ae\u4ef6\u7684\u6982\u7387\u3002<\/p>\n<p>\u8d1d\u53f6\u65af\u5b9a\u7406\u7684\u7cbe\u9ad3\u5728\u4e8e&#xff1a;\u5b83\u5229\u7528\u4e86\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u7684\u4fe1\u606f&#xff08;\u5783\u573e\u90ae\u4ef6\u7684\u666e\u904d\u89c4\u5f8b\u00a0P(A)\u00a0\u548c\u5783\u573e\u90ae\u4ef6\u7528\u8bcd\u4e60\u60ef\u00a0P(B\u2223A)&#xff09;&#xff0c;\u7ed3\u5408\u65b0\u89c2\u5bdf\u5230\u7684\u8bc1\u636e&#xff08;\u8fd9\u5c01\u90ae\u4ef6\u91cc\u6709\u201c\u514d\u8d39\u201d&#xff09;&#xff0c;\u6765\u4fee\u6b63\u6211\u4eec\u5bf9\u8fd9\u4e2a\u5177\u4f53\u4e8b\u4ef6\u7684\u5224\u65ad&#xff08;\u8fd9\u5c01\u90ae\u4ef6\u662f\u5783\u573e\u90ae\u4ef6\u7684\u53ef\u80fd\u6027\u00a0P(A\u2223B)&#xff09;\u3002<\/p>\n<h4>2.3 \u201c\u6734\u7d20\u201d\u5728\u54ea\u91cc&#xff1f;<\/h4>\n<p>\u771f\u6b63\u7684\u8d1d\u53f6\u65af\u5206\u7c7b\u5668\u5728\u8ba1\u7b97\u00a0P(B\u2223A)\u65f6&#xff0c;\u9700\u8981\u8003\u8651\u6240\u6709\u7279\u5f81\u00a0B1,B2,B3&#8230;\u00a0\u7684\u8054\u5408\u6982\u7387\u00a0P(B1,B2,B3&#8230;\u2223A)&#xff0c;\u8fd9\u975e\u5e38\u590d\u6742\u3002<\/p>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u505a\u51fa\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u7b80\u5316\u5047\u8bbe&#xff1a;\u6240\u6709\u7279\u5f81\u90fd\u76f8\u4e92\u6761\u4ef6\u72ec\u7acb\u3002\u8fd9\u610f\u5473\u7740&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"P(B_1, B_2, B_3... | A) \\\\approx P(B_1|A) \\\\times P(B_2|A) \\\\times P(B_3|A) \\\\times ...\" class=\"mathcode\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807121640-6a75cca80f04c.png\" \/><\/p>\n<p>\u8fd9\u4e2a\u5047\u8bbe\u5c06\u590d\u6742\u7684\u8054\u5408\u6982\u7387\u8ba1\u7b97&#xff0c;\u7b80\u5316\u6210\u4e86\u591a\u4e2a\u7b80\u5355\u6982\u7387\u7684\u4e58\u6cd5&#xff0c;\u6781\u5927\u5730\u964d\u4f4e\u4e86\u8ba1\u7b97\u6210\u672c\u3002<\/p>\n<h4>2.4 \u6734\u7d20\u8d1d\u53f6\u65af\u7684\u4e09\u79cd\u5e38\u89c1\u53d8\u4f53<\/h4>\n<p>\u6839\u636e\u7279\u5f81\u6570\u636e\u7c7b\u578b\u7684\u4e0d\u540c&#xff0c;\u6734\u7d20\u8d1d\u53f6\u65af\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u53d8\u4f53&#xff1a;<\/p>\n<table>\n<tr>\u5206\u7c7b\u5668\u7c7b\u578b\u9002\u7528\u7279\u5f81\u6570\u636e\u7c7b\u578b\u6838\u5fc3\u5047\u8bbe\u4e0e\u8bf4\u660e\u5178\u578b\u5e94\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u9ad8\u65af\u6734\u7d20\u8d1d\u53f6\u65af<\/td>\n<td>\u8fde\u7eed\u578b\u6570\u636e<\/td>\n<td>\u5047\u8bbe\u6bcf\u4e2a\u7279\u5f81\u5728\u6bcf\u4e2a\u7c7b\u522b\u4e0b\u670d\u4ece\u9ad8\u65af\u5206\u5e03&#xff08;\u6b63\u6001\u5206\u5e03&#xff09;<\/td>\n<td>\u6839\u636e\u8eab\u9ad8\u3001\u4f53\u91cd\u5206\u7c7b\u6027\u522b&#xff1b;\u6839\u636e\u82b1\u74e3\u5c3a\u5bf8\u5206\u7c7b\u9e22\u5c3e\u82b1\u54c1\u79cd<\/td>\n<\/tr>\n<tr>\n<td>\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af<\/td>\n<td>\u79bb\u6563\u578b\u8ba1\u6570\u6570\u636e<\/td>\n<td>\u5047\u8bbe\u7279\u5f81\u662f\u7531\u591a\u9879\u5f0f\u5206\u5e03\u751f\u6210\u7684<\/td>\n<td>\u5783\u573e\u90ae\u4ef6\u8fc7\u6ee4\u3001\u65b0\u95fb\u4e3b\u9898\u5206\u7c7b\u3001\u60c5\u611f\u5206\u6790<\/td>\n<\/tr>\n<tr>\n<td>\u4f2f\u52aa\u5229\u6734\u7d20\u8d1d\u53f6\u65af<\/td>\n<td>\u4e8c\u503c\u578b\u6570\u636e&#xff08;0\/1&#xff09;<\/td>\n<td>\u5047\u8bbe\u7279\u5f81\u662f\u4e8c\u503c\u7684&#xff0c;\u5173\u6ce8\u201c\u662f\u5426\u51fa\u73b0\u201d\u800c\u975e\u201c\u51fa\u73b0\u591a\u5c11\u6b21\u201d<\/td>\n<td>\u6587\u672c\u4e2d\u5173\u952e\u8bcd\u662f\u5426\u51fa\u73b0\u7684\u4e8c\u503c\u7279\u5f81\u573a\u666f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.5 \u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af\u5b9e\u6218&#xff1a;\u9e22\u5c3e\u82b1\u5206\u7c7b<\/h4>\n<p>\u4e0b\u9762\u901a\u8fc7\u9e22\u5c3e\u82b1\u6570\u636e\u96c6\u6765\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u00a0MultinomialNB&#xff08;\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af&#xff09;\u8fdb\u884c\u5206\u7c7b&#xff1a;<\/p>\n<p>import pandas as pd<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.naive_bayes import MultinomialNB<br \/>\nfrom sklearn import metrics<\/p>\n<p># \u8bfb\u53d6\u6570\u636e<br \/>\ndata &#061; pd.read_csv(&#034;iris.csv&#034;)<br \/>\nx &#061; data.iloc[:, :-1]      # \u7279\u5f81&#xff1a;\u82b1\u843c\u957f\u5ea6\u3001\u82b1\u843c\u5bbd\u5ea6\u3001\u82b1\u74e3\u957f\u5ea6\u3001\u82b1\u74e3\u5bbd\u5ea6<br \/>\ny &#061; data.iloc[:, -1]       # \u76ee\u6807&#xff1a;\u9e22\u5c3e\u82b1\u54c1\u79cd<\/p>\n<p># \u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6&#xff08;80%\u8bad\u7ec3&#xff0c;20%\u6d4b\u8bd5&#xff09;<br \/>\ntrain_x, test_x, train_y, test_y &#061; train_test_split(<br \/>\n    x, y, test_size&#061;0.2, random_state&#061;0<br \/>\n)<\/p>\n<p># \u521b\u5efa\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af\u6a21\u578b&#xff0c;alpha&#061;1 \u4e3a\u62c9\u666e\u62c9\u65af\u5e73\u6ed1\u53c2\u6570<br \/>\nmodel &#061; MultinomialNB(alpha&#061;1)<br \/>\nmodel.fit(train_x, train_y)<\/p>\n<p># \u8bad\u7ec3\u96c6\u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ntrain_pred &#061; model.predict(train_x)<br \/>\nprint(metrics.classification_report(train_y, train_pred))<\/p>\n<p># \u6d4b\u8bd5\u96c6\u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ntest_pred &#061; model.predict(test_x)<br \/>\nprint(metrics.classification_report(test_y, test_pred))<\/p>\n<p>\u6570\u636e\u8bfb\u53d6&#xff1a;\u4f7f\u7528\u00a0pandas.read_csv\u00a0\u52a0\u8f7d\u9e22\u5c3e\u82b1\u6570\u636e\u96c6\u3002\u9e22\u5c3e\u82b1\u6570\u636e\u96c6\u5305\u542b150\u4e2a\u6837\u672c&#xff0c;\u6bcf\u4e2a\u6837\u672c\u67094\u4e2a\u8fde\u7eed\u578b\u7279\u5f81&#xff08;\u82b1\u843c\u957f\u5ea6\u3001\u82b1\u843c\u5bbd\u5ea6\u3001\u82b1\u74e3\u957f\u5ea6\u3001\u82b1\u74e3\u5bbd\u5ea6&#xff09;\u548c1\u4e2a\u6807\u7b7e&#xff08;Setosa\u3001Versicolour\u3001Virginica \u4e09\u4e2a\u54c1\u79cd&#xff09;\u3002<\/p>\n<p>\u6570\u636e\u5212\u5206&#xff1a;train_test_split\u00a0\u5c06\u6570\u636e\u968f\u673a\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6&#xff08;80%&#xff09;\u548c\u6d4b\u8bd5\u96c6&#xff08;20%&#xff09;&#xff0c;random_state&#061;0\u00a0\u4fdd\u8bc1\u6bcf\u6b21\u8fd0\u884c\u5212\u5206\u7ed3\u679c\u4e00\u81f4\u3002<\/p>\n<p>\u6a21\u578b\u6784\u5efa&#xff1a;MultinomialNB(alpha&#061;1)\u00a0\u521b\u5efa\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af\u5206\u7c7b\u5668\u3002\u53c2\u6570\u00a0alpha\u00a0\u662f\u62c9\u666e\u62c9\u65af\u5e73\u6ed1\u7cfb\u6570&#xff0c;\u7528\u4e8e\u89e3\u51b3\u67d0\u4e9b\u7279\u5f81\u503c\u5728\u8bad\u7ec3\u96c6\u4e2d\u672a\u51fa\u73b0\u5bfc\u81f4\u6982\u7387\u4e3a\u96f6\u7684\u95ee\u9898\u3002alpha&#061;1\u00a0\u662f\u5e38\u7528\u9ed8\u8ba4\u503c&#xff0c;\u5e73\u6ed1\u7a0b\u5ea6\u9002\u4e2d\u3002<\/p>\n<p>\u8bad\u7ec3&#xff1a;model.fit(train_x, train_y)\u00a0\u8ba9\u6a21\u578b\u5b66\u4e60\u8bad\u7ec3\u6570\u636e\u4e2d\u7279\u5f81\u4e0e\u6807\u7b7e\u7684\u5173\u7cfb\u3002\u5bf9\u4e8e\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af&#xff0c;\u5b83\u4f1a\u7edf\u8ba1\u6bcf\u4e2a\u7c7b\u522b\u4e0b\u5404\u7279\u5f81\u7684\u8ba1\u6570&#xff0c;\u5e76\u8ba1\u7b97\u76f8\u5e94\u7684\u6761\u4ef6\u6982\u7387\u3002<\/p>\n<p>\u9884\u6d4b&#xff1a;model.predict()\u00a0\u5bf9\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u5206\u522b\u8fdb\u884c\u9884\u6d4b&#xff0c;\u8fd4\u56de\u9884\u6d4b\u7c7b\u522b\u6807\u7b7e\u3002<\/p>\n<p>\u8bc4\u4f30&#xff1a;classification_report\u00a0\u8f93\u51fa\u7cbe\u786e\u7387&#xff08;Precision&#xff09;\u3001\u53ec\u56de\u7387&#xff08;Recall&#xff09;\u3001F1-score \u7b49\u8be6\u7ec6\u6307\u6807&#xff0c;\u5e2e\u52a9\u6211\u4eec\u5168\u9762\u4e86\u89e3\u6a21\u578b\u7684\u5206\u7c7b\u6027\u80fd\u3002<\/p>\n<h3>\u4e09\u3001K-Means\u805a\u7c7b<\/h3>\n<h4>3.1 \u4ec0\u4e48\u662f\u805a\u7c7b<\/h4>\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d&#xff0c;\u805a\u7c7b\u8981\u505a\u7684\u662f\u5b8c\u5168\u9760\u7279\u5f81\u81ea\u53d1\u5730\u5206\u51fa\u7c7b\u522b\u3002\u5b83\u662f\u4e00\u79cd\u65e0\u76d1\u7763\u5b66\u4e60\u65b9\u6cd5&#xff0c;\u76ee\u6807\u662f\u5728\u6ca1\u6709\u9884\u5148\u6807\u6ce8\u7b54\u6848&#xff08;\u5373\u6ca1\u6709\u201c\u6807\u7b7e\u201d&#xff09;\u7684\u6570\u636e\u4e2d&#xff0c;\u53d1\u73b0\u5176\u5185\u5728\u7684\u7ed3\u6784\u548c\u5206\u7ec4\u3002<\/p>\n<p>\u805a\u7c7b\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6837\u672c\u5212\u5206\u6210\u82e5\u5e72\u4e2a\u4e92\u4e0d\u76f8\u4ea4\u7684\u5b50\u96c6&#xff08;\u79f0\u4e3a\u7c07&#xff09;&#xff0c;\u4f7f\u5f97\u540c\u4e00\u4e2a\u7c07\u5185\u7684\u6837\u672c\u5f7c\u6b64\u76f8\u4f3c&#xff0c;\u800c\u4e0d\u540c\u7c07\u4e2d\u7684\u6837\u672c\u5f7c\u6b64\u4e0d\u76f8\u4f3c\u3002\u8fd9\u91cc\u7684\u201c\u76f8\u4f3c\u201d\u901a\u5e38\u901a\u8fc7\u6570\u5b66\u4e0a\u7684\u8ddd\u79bb\u6765\u8861\u91cf&#xff08;\u5982\u6b27\u6c0f\u8ddd\u79bb&#xff09;&#xff0c;\u8ddd\u79bb\u8d8a\u8fd1&#xff0c;\u76f8\u4f3c\u5ea6\u8d8a\u9ad8\u3002<\/p>\n<h4>3.2 K-Means\u7b97\u6cd5\u539f\u7406<\/h4>\n<p>K-Means\u662f\u6700\u8457\u540d\u3001\u6700\u5e38\u7528\u7684\u805a\u7c7b\u7b97\u6cd5\u4e4b\u4e00&#xff0c;\u5176\u601d\u60f3\u76f4\u89c2&#xff0c;\u5b9e\u73b0\u76f8\u5bf9\u7b80\u5355\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u628aK-Means\u7684\u8fc7\u7a0b\u60f3\u8c61\u6210\u7ade\u9009\u4ee3\u8868\u5e76\u91cd\u65b0\u5212\u533a&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u786e\u5b9a\u7c07\u7684\u6570\u91cf K<br \/>\n\u9996\u5148&#xff0c;\u4f60\u9700\u8981\u51b3\u5b9a\u60f3\u628a\u6570\u636e\u5206\u6210\u51e0\u7c7b\u3002\u8fd9\u4e2a K \u503c\u9700\u8981\u9884\u5148\u6307\u5b9a&#xff0c;\u8fd9\u662f K-Means \u7684\u4e00\u4e2a\u5173\u952e\u53c2\u6570\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;\u521d\u59cb\u5316\u4ee3\u8868&#xff08;\u8d28\u5fc3&#xff09;<br \/>\n\u968f\u673a\u5728\u6570\u636e\u7a7a\u95f4\u4e2d\u9009\u53d6 K \u4e2a\u70b9&#xff0c;\u4f5c\u4e3a\u6bcf\u4e2a\u7c07\u7684\u521d\u59cb\u201c\u4e2d\u5fc3\u70b9\u201d&#xff0c;\u6211\u4eec\u79f0\u4e4b\u4e3a\u8d28\u5fc3\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u5206\u914d\u5c45\u6c11&#xff08;\u6837\u672c&#xff09;<br \/>\n\u8ba1\u7b97\u6570\u636e\u96c6\u4e2d\u6bcf\u4e00\u4e2a\u6837\u672c\u70b9\u5230\u8fd9 K \u4e2a\u8d28\u5fc3\u7684\u8ddd\u79bb\u3002\u9075\u5faa\u201c\u8fd1\u8005\u5f52\u5176\u7c7b\u201d\u7684\u539f\u5219&#xff0c;\u5c06\u6bcf\u4e2a\u6837\u672c\u5206\u914d\u7ed9\u8ddd\u79bb\u5b83\u6700\u8fd1\u7684\u90a3\u4e2a\u8d28\u5fc3\u6240\u5728\u7684\u7c07\u3002<\/p>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u6539\u9009\u65b0\u4ee3\u8868&#xff08;\u66f4\u65b0\u8d28\u5fc3&#xff09;<br \/>\n\u73b0\u5728&#xff0c;\u6bcf\u4e2a\u7c07\u91cc\u90fd\u6709\u4e86\u4e00\u6279\u6837\u672c\u3002\u91cd\u65b0\u8ba1\u7b97\u6bcf\u4e2a\u7c07\u7684\u8d28\u5fc3&#xff0c;\u65b0\u7684\u8d28\u5fc3\u5c31\u662f\u8be5\u7c07\u5185\u6240\u6709\u6837\u672c\u70b9\u7684\u5e73\u5747\u503c&#xff08;\u5747\u503c\u70b9&#xff09;\u3002<\/p>\n<p>\u7b2c\u4e94\u6b65&#xff1a;\u91cd\u590d\u4e0e\u6536\u655b<br \/>\n\u91cd\u590d\u7b2c\u4e09\u6b65\u548c\u7b2c\u56db\u6b65&#xff0c;\u76f4\u5230\u8d28\u5fc3\u7684\u4f4d\u7f6e\u4e0d\u518d\u53d1\u751f\u663e\u8457\u53d8\u5316&#xff08;\u5373\u7b97\u6cd5\u6536\u655b&#xff09;\u3002<\/p>\n<h4>3.3 K-Means\u7684\u5173\u952e\u53c2\u6570<\/h4>\n<p>\u5728\u00a0sklearn\u00a0\u7684\u00a0KMeans\u00a0\u4e2d&#xff0c;\u4ee5\u4e0b\u53c2\u6570\u6700\u4e3a\u5173\u952e&#xff1a;<\/p>\n<table>\n<tr>\u53c2\u6570\u542b\u4e49\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>n_clusters<\/td>\n<td>\u7c07\u7684\u6570\u91cf K<\/td>\n<td>\u6700\u91cd\u8981\u7684\u53c2\u6570&#xff0c;\u9700\u8981\u9884\u5148\u6307\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>init<\/td>\n<td>\u521d\u59cb\u5316\u65b9\u6cd5<\/td>\n<td>\u53ef\u9009\u00a0&#039;k-means&#043;&#043;&#039;&#xff08;\u9ed8\u8ba4&#xff09;\u3001&#039;random&#039;<\/td>\n<\/tr>\n<tr>\n<td>n_init<\/td>\n<td>\u521d\u59cb\u5316\u6b21\u6570<\/td>\n<td>\u7b97\u6cd5\u4f1a\u8fd0\u884c\u591a\u6b21\u5e76\u9009\u62e9\u6700\u4f18\u7ed3\u679c&#xff0c;\u9ed8\u8ba410\u6b21<\/td>\n<\/tr>\n<tr>\n<td>max_iter<\/td>\n<td>\u6700\u5927\u8fed\u4ee3\u6b21\u6570<\/td>\n<td>\u9ed8\u8ba4300\u6b21<\/td>\n<\/tr>\n<tr>\n<td>random_state<\/td>\n<td>\u968f\u673a\u79cd\u5b50<\/td>\n<td>\u8bbe\u7f6e\u540e\u53ef\u4fdd\u8bc1\u7ed3\u679c\u53ef\u590d\u73b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.4 \u5982\u4f55\u9009\u62e9\u6700\u4f73K\u503c&#xff1f;<\/h4>\n<p>\u9009\u62e9\u6700\u4f73\u7684 K \u503c\u662f K-Means \u4e2d\u6700\u5173\u952e\u7684\u95ee\u9898\u4e4b\u4e00\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u6709&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8098\u90e8\u6cd5\u5219&#xff08;Elbow Method&#xff09;&#xff1a;\u8ba1\u7b97\u4e0d\u540c K \u503c\u4e0b\u7684\u7c07\u5185\u8bef\u5dee\u5e73\u65b9\u548c&#xff08;SSE&#xff09;&#xff0c;\u968f\u7740 K \u589e\u5927&#xff0c;SSE \u4f1a\u9010\u6e10\u51cf\u5c0f\u3002\u5f53 SSE \u7684\u4e0b\u964d\u901f\u5ea6\u7a81\u7136\u53d8\u7f13\u65f6&#xff0c;\u5bf9\u5e94\u7684 K \u503c\u5c31\u662f\u201c\u8098\u90e8\u201d\u70b9&#xff0c;\u901a\u5e38\u88ab\u8ba4\u4e3a\u662f\u6700\u4f73 K \u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u8f6e\u5ed3\u7cfb\u6570&#xff08;Silhouette Coefficient&#xff09;&#xff1a;\u8861\u91cf\u6837\u672c\u4e0e\u5176\u6240\u5728\u7c07\u7684\u76f8\u4f3c\u5ea6\u4e0e\u5176\u4ed6\u7c07\u7684\u5dee\u5f02\u5ea6&#xff0c;\u53d6\u503c\u8303\u56f4\u5728 [-1, 1] \u4e4b\u95f4&#xff0c;\u503c\u8d8a\u5927\u8868\u793a\u805a\u7c7b\u6548\u679c\u8d8a\u597d\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3.5 K-Means\u805a\u7c7b\u5b9e\u6218&#xff1a;\u9152\u54c1\u79cd\u81ea\u52a8\u5206\u7fa4<\/h4>\n<p>\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5b9e\u9645\u6570\u636e\u96c6\u6765\u6f14\u793a\u5982\u4f55\u5229\u7528\u8f6e\u5ed3\u7cfb\u6570\u81ea\u52a8\u9009\u62e9\u6700\u4f73K\u503c&#xff0c;\u5e76\u8fdb\u884c\u805a\u7c7b&#xff1a;<\/p>\n<p>import pandas as pd<br \/>\nimport numpy as np<br \/>\nfrom sklearn.cluster import KMeans<br \/>\nfrom sklearn import metrics<br \/>\nfrom sklearn.model_selection import train_test_split<\/p>\n<p># 1. \u8bfb\u53d6\u6570\u636e&#xff08;\u5047\u8bbe\u6570\u636e\u6587\u4ef6\u4e3a data.txt&#xff0c;\u7528\u7a7a\u683c\u5206\u9694&#xff0c;\u5305\u542b&#039;name&#039;\u5217\u548c\u82e5\u5e72\u7279\u5f81\u5217&#xff09;<br \/>\ndata &#061; pd.read_table(&#034;data.txt&#034;, sep&#061;&#034; &#034;, encoding&#061;&#034;utf-8&#034;, engine&#061;&#034;python&#034;)<br \/>\n# \u53bb\u6389&#039;name&#039;\u5217&#xff08;\u975e\u6570\u503c\u7279\u5f81&#xff09;&#xff0c;\u5269\u4f59\u5217\u4e3a\u7279\u5f81\u6570\u636e<br \/>\nx &#061; data.drop(&#034;name&#034;, axis&#061;1)<\/p>\n<p># 2. \u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6&#xff08;\u7528\u4e8e\u9a8c\u8bc1\u805a\u7c7b\u6a21\u578b\u7684\u7a33\u5b9a\u6027&#xff09;<br \/>\ntrain_x, test_x &#061; train_test_split(x, test_size&#061;0.2, random_state&#061;0)<\/p>\n<p># 3. \u901a\u8fc7\u8f6e\u5ed3\u7cfb\u6570\u9009\u62e9\u6700\u4f73K\u503c&#xff08;K\u8303\u56f42~9&#xff09;<br \/>\nscores &#061; []<br \/>\nfor i in range(2, 10):<br \/>\n    model &#061; KMeans(n_clusters&#061;i, random_state&#061;0)<br \/>\n    # \u8ba1\u7b97\u8bad\u7ec3\u96c6\u7684\u8f6e\u5ed3\u7cfb\u6570&#xff0c;metric&#061;&#039;euclidean&#039;\u8868\u793a\u4f7f\u7528\u6b27\u6c0f\u8ddd\u79bb<br \/>\n    score &#061; metrics.silhouette_score(train_x, model.fit_predict(train_x), metric&#061;&#039;euclidean&#039;)<br \/>\n    scores.append(score)<\/p>\n<p># 4. \u9009\u51fa\u8f6e\u5ed3\u7cfb\u6570\u6700\u9ad8\u7684K\u503c<br \/>\nbest_k &#061; [2, 3, 4, 5, 6, 7, 8, 9][np.argmax(scores)]<br \/>\nprint(f&#034;\u6700\u4f73K\u503c\u4e3a&#xff1a;{best_k}&#034;)<\/p>\n<p># 5. \u4f7f\u7528\u6700\u4f73K\u503c\u91cd\u65b0\u8bad\u7ec3\u6a21\u578b<br \/>\nmodel &#061; KMeans(n_clusters&#061;best_k, random_state&#061;0)<br \/>\nmodel.fit(train_x)<\/p>\n<p># 6. \u5bf9\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u8fdb\u884c\u9884\u6d4b<br \/>\ntrain_pred &#061; model.predict(train_x)<br \/>\ntest_pred &#061; model.predict(test_x)<\/p>\n<p># 7. \u5206\u522b\u8ba1\u7b97\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u7684\u8f6e\u5ed3\u7cfb\u6570&#xff0c;\u8bc4\u4f30\u805a\u7c7b\u6548\u679c<br \/>\ntrain_score &#061; metrics.silhouette_score(train_x, train_pred)<br \/>\ntest_score &#061; metrics.silhouette_score(test_x, test_pred)<\/p>\n<p>print(f&#034;\u8bad\u7ec3\u96c6\u8f6e\u5ed3\u7cfb\u6570&#xff1a;{train_score}&#034;)<br \/>\nprint(f&#034;\u6d4b\u8bd5\u96c6\u8f6e\u5ed3\u7cfb\u6570&#xff1a;{test_score}&#034;)<\/p>\n<p>\u6570\u636e\u52a0\u8f7d&#xff1a;pd.read_table\u00a0\u8bfb\u53d6\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u6587\u672c\u6587\u4ef6\u3002data.txt\u00a0\u5305\u542b\u4e00\u5217\u00a0name&#xff08;\u53ef\u80fd\u662f\u6837\u672cID\u6216\u540d\u79f0&#xff09;\u548c\u82e5\u5e72\u6570\u503c\u7279\u5f81\u3002\u6211\u4eec\u4f7f\u7528\u00a0drop(&#034;name&#034;, axis&#061;1)\u00a0\u79fb\u9664\u975e\u6570\u503c\u5217&#xff0c;\u53ea\u4fdd\u7559\u7279\u5f81\u7528\u4e8e\u805a\u7c7b\u3002<\/p>\n<p>\u6570\u636e\u5212\u5206&#xff1a;train_test_split\u00a0\u5c06\u7279\u5f81\u6570\u636e\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002\u867d\u7136\u805a\u7c7b\u662f\u65e0\u76d1\u7763\u5b66\u4e60&#xff0c;\u4f46\u5212\u5206\u6d4b\u8bd5\u96c6\u53ef\u4ee5\u8bc4\u4f30\u6a21\u578b\u5728\u672a\u89c1\u6837\u672c\u4e0a\u7684\u7a33\u5b9a\u6027\u2014\u2014\u5982\u679c\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u7684\u8f6e\u5ed3\u7cfb\u6570\u76f8\u8fd1&#xff0c;\u8bf4\u660e\u805a\u7c7b\u7ed3\u6784\u662f\u7a33\u5b9a\u7684\u3002<\/p>\n<p>\u8f6e\u5ed3\u7cfb\u6570&#xff08;Silhouette Score&#xff09;&#xff1a;\u5bf9\u4e8e\u6bcf\u4e2a\u6837\u672c&#xff0c;\u8f6e\u5ed3\u7cfb\u6570\u00a0s(i)\u00a0\u5b9a\u4e49\u4e3a&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"s(i) = \\\\frac{b(i) - a(i)}{\\\\max\\\\{a(i), b(i)\\\\}}\" class=\"mathcode\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807121640-6a75cca8190f0.png\" \/><\/p>\n<p>\u5176\u4e2d\u00a0a(i)a(i)\u00a0\u662f\u6837\u672c\u4e0e\u540c\u7c07\u5176\u4ed6\u70b9\u7684\u5e73\u5747\u8ddd\u79bb&#xff08;\u7c07\u5185\u51dd\u805a\u5ea6&#xff09;&#xff0c;b(i)b(i)\u00a0\u662f\u6837\u672c\u4e0e\u6700\u8fd1\u5176\u4ed6\u7c07\u7684\u5e73\u5747\u8ddd\u79bb&#xff08;\u7c07\u95f4\u5206\u79bb\u5ea6&#xff09;\u3002\u6574\u4f53\u8f6e\u5ed3\u7cfb\u6570\u53d6\u6240\u6709\u6837\u672c\u7684\u5e73\u5747\u503c&#xff0c;\u8303\u56f4 [-1, 1]&#xff0c;\u503c\u8d8a\u5927\u8868\u793a\u805a\u7c7b\u6548\u679c\u8d8a\u597d\u3002<\/p>\n<p>\u5faa\u73af\u9009\u62e9K\u503c&#xff1a;\u5728 K&#061;2 \u5230 9 \u7684\u8303\u56f4\u5185&#xff0c;\u5bf9\u6bcf\u4e2aK\u503c\u8bad\u7ec3 KMeans \u6a21\u578b&#xff0c;\u8ba1\u7b97\u8bad\u7ec3\u96c6\u7684\u8f6e\u5ed3\u7cfb\u6570&#xff0c;\u4fdd\u5b58\u5728\u00a0scores\u00a0\u5217\u8868\u4e2d\u3002<\/p>\n<p>\u9009\u53d6\u6700\u4f73K&#xff1a;\u4f7f\u7528\u00a0np.argmax(scores)\u00a0\u627e\u5230\u6700\u5927\u8f6e\u5ed3\u7cfb\u6570\u5bf9\u5e94\u7684\u7d22\u5f15&#xff0c;\u518d\u4ece\u9884\u5b9a\u4e49\u7684K\u503c\u5217\u8868\u00a0[2,3,4,5,6,7,8,9]\u00a0\u4e2d\u53d6\u51fa\u5bf9\u5e94\u7684K\u503c\u3002<\/p>\n<p>\u6700\u7ec8\u6a21\u578b\u8bad\u7ec3\u4e0e\u8bc4\u4f30&#xff1a;\u7528\u6700\u4f73K\u503c\u91cd\u65b0\u8bad\u7ec3 KMeans \u6a21\u578b&#xff0c;\u5bf9\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u5206\u522b\u9884\u6d4b\u805a\u7c7b\u6807\u7b7e&#xff0c;\u5e76\u8ba1\u7b97\u5404\u81ea\u7684\u8f6e\u5ed3\u7cfb\u6570\u3002\u4e24\u4e2a\u5206\u6570\u76f8\u8fd1\u4e14\u90fd\u8f83\u9ad8&#xff0c;\u8bf4\u660e\u805a\u7c7b\u7ed3\u679c\u7a33\u5b9a\u4e14\u6709\u6548\u3002<\/p>\n<h4>3.6 K-Means\u7684\u4f18\u7f3a\u70b9<\/h4>\n<table>\n<tr>\u4f18\u70b9\u7f3a\u70b9<\/tr>\n<tbody>\n<tr>\n<td>\u7b97\u6cd5\u7b80\u5355&#xff0c;\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0<\/td>\n<td>\u9700\u8981\u9884\u5148\u6307\u5b9a K \u503c<\/td>\n<\/tr>\n<tr>\n<td>\u8ba1\u7b97\u6548\u7387\u9ad8&#xff0c;\u9002\u5408\u5927\u89c4\u6a21\u6570\u636e<\/td>\n<td>\u5bf9\u521d\u59cb\u8d28\u5fc3\u7684\u9009\u62e9\u654f\u611f<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u655b\u901f\u5ea6\u5feb<\/td>\n<td>\u5bf9\u5f02\u5e38\u503c\u654f\u611f<\/td>\n<\/tr>\n<tr>\n<td>\u7ed3\u679c\u6613\u4e8e\u89e3\u91ca<\/td>\n<td>\u53ea\u9002\u7528\u4e8e\u7403\u5f62\u7c07&#xff0c;\u5bf9\u590d\u6742\u5f62\u72b6\u7684\u7c07\u6548\u679c\u4e0d\u4f73<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u673a\u5668\u5b66\u4e60\u5341\u5927\u5e38\u89c1\u7b97\u6cd5\u6734\u7d20\u8d1d\u53f6\u65af\u5b83\u901a\u8fc7\u5df2\u77e5\u7684\u6807\u7b7e\u6570\u636e&#xff0c;\u5b66\u4e60\u5982\u4f55\u5bf9\u65b0\u7684\u6837\u672c\u8fdb\u884c\u5206\u7c7b\u3002K-Means\u805a\u7c7b\u6b63\u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6280\u672f\u4e4b\u4e00\u3002\u5982\u679c\u8bf4\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u5728\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u9884\u6d4b&#xff0c;\u90a3\u4e48K-Means\u5c31\u662f\u5728\u6ca1\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u63a2\u7d22\u3002\u4e24\u8005\u4ee3\u8868\u4e86\u673a\u5668\u5b66\u4e60\u7684\u4e24\u5927\u65b9\u5411&#xff0c;\u672c\u7bc7\u4e3b\u8981\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u7b97\u6cd5\u3002\u4e8c\u3001\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;Naive Bayes&#xff09;2.1 \u4ec0\u4e48\u662f\u6734\u7d20\u8d1d\u53f6\u65af\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u4e00\u79cd\u57fa\u4e8e\u8d1d\u53f6\u65af\u5b9a\u7406\u7684\u7b80\u5355\u800c\u9ad8\u6548\u7684\u6982\u7387\u5206\u7c7b<\/p>\n","protected":false},"author":2,"featured_media":91384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5296,207,3548],"topic":[],"class_list":["post-91387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-kmeans","tag-207","tag-3548"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/91387.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u673a\u5668\u5b66\u4e60\u5341\u5927\u5e38\u89c1\u7b97\u6cd5\u6734\u7d20\u8d1d\u53f6\u65af\u5b83\u901a\u8fc7\u5df2\u77e5\u7684\u6807\u7b7e\u6570\u636e&#xff0c;\u5b66\u4e60\u5982\u4f55\u5bf9\u65b0\u7684\u6837\u672c\u8fdb\u884c\u5206\u7c7b\u3002K-Means\u805a\u7c7b\u6b63\u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6280\u672f\u4e4b\u4e00\u3002\u5982\u679c\u8bf4\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u5728\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u9884\u6d4b&#xff0c;\u90a3\u4e48K-Means\u5c31\u662f\u5728\u6ca1\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u63a2\u7d22\u3002\u4e24\u8005\u4ee3\u8868\u4e86\u673a\u5668\u5b66\u4e60\u7684\u4e24\u5927\u65b9\u5411&#xff0c;\u672c\u7bc7\u4e3b\u8981\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u7b97\u6cd5\u3002\u4e8c\u3001\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;Naive Bayes&#xff09;2.1 \u4ec0\u4e48\u662f\u6734\u7d20\u8d1d\u53f6\u65af\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u4e00\u79cd\u57fa\u4e8e\u8d1d\u53f6\u65af\u5b9a\u7406\u7684\u7b80\u5355\u800c\u9ad8\u6548\u7684\u6982\u7387\u5206\u7c7b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/91387.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-07T12:16:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807121639-6a75cca7ceb3c.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91387.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/91387.html\",\"name\":\"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-07T12:16:41+00:00\",\"dateModified\":\"2026-08-07T12:16:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/91387.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/91387.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91387.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/91387.html","og_locale":"zh_CN","og_type":"article","og_title":"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u673a\u5668\u5b66\u4e60\u5341\u5927\u5e38\u89c1\u7b97\u6cd5\u6734\u7d20\u8d1d\u53f6\u65af\u5b83\u901a\u8fc7\u5df2\u77e5\u7684\u6807\u7b7e\u6570\u636e&#xff0c;\u5b66\u4e60\u5982\u4f55\u5bf9\u65b0\u7684\u6837\u672c\u8fdb\u884c\u5206\u7c7b\u3002K-Means\u805a\u7c7b\u6b63\u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6280\u672f\u4e4b\u4e00\u3002\u5982\u679c\u8bf4\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u5728\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u9884\u6d4b&#xff0c;\u90a3\u4e48K-Means\u5c31\u662f\u5728\u6ca1\u6709\u6807\u51c6\u7b54\u6848\u7684\u60c5\u51b5\u4e0b\u505a\u63a2\u7d22\u3002\u4e24\u8005\u4ee3\u8868\u4e86\u673a\u5668\u5b66\u4e60\u7684\u4e24\u5927\u65b9\u5411&#xff0c;\u672c\u7bc7\u4e3b\u8981\u4ecb\u7ecd\u8fd9\u4e24\u79cd\u7b97\u6cd5\u3002\u4e8c\u3001\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;Naive Bayes&#xff09;2.1 \u4ec0\u4e48\u662f\u6734\u7d20\u8d1d\u53f6\u65af\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u4e00\u79cd\u57fa\u4e8e\u8d1d\u53f6\u65af\u5b9a\u7406\u7684\u7b80\u5355\u800c\u9ad8\u6548\u7684\u6982\u7387\u5206\u7c7b","og_url":"https:\/\/www.wsisp.com\/helps\/91387.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-07T12:16:41+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260807121639-6a75cca7ceb3c.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/91387.html","url":"https:\/\/www.wsisp.com\/helps\/91387.html","name":"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-07T12:16:41+00:00","dateModified":"2026-08-07T12:16:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/91387.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/91387.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/91387.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u521d\u8bc6\u673a\u5668\u5b66\u4e60\uff08\u6734\u7d20\u8d1d\u53f6\u65af\u548cK-means\u805a\u7c7b\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/91387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=91387"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/91387\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/91384"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=91387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=91387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=91387"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=91387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}