{"id":49783,"date":"2025-07-30T19:46:51","date_gmt":"2025-07-30T11:46:51","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/49783.html"},"modified":"2025-07-30T19:46:51","modified_gmt":"2025-07-30T11:46:51","slug":"%e3%80%8a%e9%9b%b6%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a8ai%ef%bc%9a%e4%bc%a0%e7%bb%9f%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e6%a0%b8%e5%bf%83%e7%ae%97%e6%b3%95%e8%a7%a3%e6%9e%90%ef%bc%88knn%e3%80%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/49783.html","title":{"rendered":"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b"},"content":{"rendered":"<h5>\u4e00\u3001Scikit-Learn\u673a\u5668\u5b66\u4e60\u6982\u8ff0<\/h5>\n<p>Scikit-Learn&#xff08;sklearn&#xff09;\u662fPython\u6700\u5e38\u7528\u7684\u673a\u5668\u5b66\u4e60\u5e93&#xff0c;\u7279\u70b9\u5305\u62ec&#xff1a;<\/p>\n<li>\u7edf\u4e00API\u8bbe\u8ba1&#xff1a;\u6240\u6709\u7b97\u6cd5\u90fd\u9075\u5faafit()&#xff08;\u8bad\u7ec3&#xff09;\u3001predict()&#xff08;\u9884\u6d4b&#xff09;\u7684\u7edf\u4e00\u63a5\u53e3<\/li>\n<li>\u7b97\u6cd5\u8986\u76d6\u5168\u9762&#xff1a;\u5305\u542b\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u3001\u964d\u7ef4\u7b49\u4f20\u7edfML\u7b97\u6cd5<\/li>\n<li>\u6570\u636e\u5904\u7406\u5de5\u5177&#xff1a;\u63d0\u4f9b\u7279\u5f81\u5de5\u7a0b\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bc4\u4f30\u7b49\u5168\u5957\u5de5\u5177<\/li>\n<li>\u6587\u6863\u5b8c\u5584&#xff1a;\u6bcf\u4e2aAPI\u90fd\u6709\u8be6\u7ec6\u8bf4\u660e\u548c\u793a\u4f8b&#xff08;\u901a\u8fc7?\u67e5\u770b&#xff09;<\/li>\n<p>\u6838\u5fc3\u8bbe\u8ba1\u601d\u60f3&#xff1a;\u5c06\u673a\u5668\u5b66\u4e60\u6d41\u7a0b\u6807\u51c6\u5316\u4e3a&#034;\u6570\u636e\u8f93\u5165 \u2192 \u7279\u5f81\u5904\u7406 \u2192 \u6a21\u578b\u8bad\u7ec3 \u2192 \u9884\u6d4b\u8f93\u51fa&#034;\u7684\u6d41\u6c34\u7ebf<\/p>\n<hr \/>\n<h5>\u4e8c\u3001KNN\u7b97\u6cd5&#xff08;K\u6700\u8fd1\u90bb\u5206\u7c7b&#xff09;<\/h5>\n<p>1. \u6837\u672c\u8ddd\u79bb\u5224\u65ad<br \/>\nKNN\u7684\u6838\u5fc3\u662f\u8ba1\u7b97\u6837\u672c\u95f4\u7684\u8ddd\u79bb&#xff0c;\u5e38\u7528\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6b27\u6c0f\u8ddd\u79bb&#xff08;\u76f4\u7ebf\u8ddd\u79bb&#xff09;&#xff1a;<br \/>\n( d &#061; \\\\sqrt{\\\\sum_{i&#061;1}^{n}(x_i &#8211; y_i)^2} )<br \/>\n\u4f8b\u5982&#xff1a;\u70b9A(1,2)\u548c\u70b9B(4,6)\u7684\u8ddd\u79bb &#061; (\\\\sqrt{(1-4)^2 &#043; (2-6)^2} &#061; 5)<\/p>\n<\/li>\n<li>\n<p>\u66fc\u54c8\u987f\u8ddd\u79bb&#xff08;\u57ce\u5e02\u8857\u533a\u8ddd\u79bb&#xff09;&#xff1a;<br \/>\n( d &#061; \\\\sum_{i&#061;1}^{n}|x_i &#8211; y_i| )<br \/>\n\u540c\u4e0a\u4f8b&#xff1a;|1-4| &#043; |2-6| &#061; 3 &#043; 4 &#061; 7<\/p>\n<\/li>\n<\/ul>\n<p>2. \u7b97\u6cd5\u539f\u7406<br \/>\n\u6838\u5fc3\u601d\u60f3&#xff1a;\u201c\u7269\u4ee5\u7c7b\u805a\u201d\u2014\u2014\u672a\u77e5\u6837\u672c\u7684\u7c7b\u522b\u7531\u5176k\u4e2a\u6700\u8fd1\u90bb\u5c45\u7684\u591a\u6570\u6295\u7968\u51b3\u5b9a<br \/>\n\u5de5\u4f5c\u6d41\u7a0b&#xff1a;<\/p>\n<li>\u8ba1\u7b97\u672a\u77e5\u6837\u672c\u4e0e\u6240\u6709\u8bad\u7ec3\u6837\u672c\u7684\u8ddd\u79bb<\/li>\n<li>\u9009\u53d6\u8ddd\u79bb\u6700\u5c0f\u7684k\u4e2a\u6837\u672c<\/li>\n<li>\u7edf\u8ba1k\u4e2a\u6837\u672c\u4e2d\u5404\u7c7b\u522b\u7684\u6570\u91cf<\/li>\n<li>\u5c06\u672a\u77e5\u6837\u672c\u5f52\u4e3a\u6570\u91cf\u6700\u591a\u7684\u7c7b\u522b<\/li>\n<p>3. \u5173\u952e\u53c2\u6570\u4e0e\u7f3a\u70b9<\/p>\n<ul>\n<li>k\u503c\u9009\u62e9&#xff1a;\n<ul>\n<li>k\u592a\u5c0f \u2192 \u5bf9\u566a\u58f0\u654f\u611f&#xff08;\u8fc7\u62df\u5408&#xff09;<\/li>\n<li>k\u592a\u5927 \u2192 \u5ffd\u7565\u5c40\u90e8\u7279\u5f81&#xff08;\u6b20\u62df\u5408&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<ul>\n<li>\u8ba1\u7b97\u6548\u7387\u4f4e&#xff08;\u9ad8\u65f6\u95f4\u590d\u6742\u5ea6&#xff09;&#xff1a;KNN\u9700\u8981\u8ba1\u7b97\u6d4b\u8bd5\u6837\u672c\u4e0e\u6240\u6709\u8bad\u7ec3\u6837\u672c\u7684\u8ddd\u79bb&#xff08;\u5982\u6b27\u6c0f\u8ddd\u79bb&#xff09;&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)&#xff08;n\u4e3a\u8bad\u7ec3\u6837\u672c\u6570&#xff09;\u3002\u5f53\u6570\u636e\u91cf\u5f88\u5927\u65f6&#xff0c;\u9884\u6d4b\u901f\u5ea6\u6781\u6162\u3002<\/li>\n<li>\u5b58\u50a8\u7a7a\u95f4\u9700\u6c42\u5927&#xff1a;KNN\u662f\u201c\u60f0\u6027\u5b66\u4e60\u201d&#xff08;Lazy Learning&#xff09;&#xff0c;\u8bad\u7ec3\u9636\u6bb5\u4ec5\u5b58\u50a8\u6570\u636e&#xff0c;\u4e0d\u751f\u6210\u663e\u5f0f\u6a21\u578b\u3002\u56e0\u6b64&#xff0c;\u9884\u6d4b\u65f6\u9700\u4fdd\u7559\u5168\u90e8\u8bad\u7ec3\u6570\u636e&#xff0c;\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\u3002<\/li>\n<li>\u5bf9\u9ad8\u7ef4\u6570\u636e\u654f\u611f&#xff08;\u7ef4\u5ea6\u707e\u96be&#xff09;&#xff1a;\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u6837\u672c\u95f4\u8ddd\u79bb\u5dee\u5f02\u53d8\u5c0f&#xff08;\u6240\u6709\u70b9\u8d8b\u4e8e\u7b49\u8ddd&#xff09;&#xff0c;\u5bfc\u81f4KNN\u96be\u4ee5\u627e\u5230\u771f\u6b63\u76f8\u4f3c\u7684\u90bb\u5c45\u3002<\/li>\n<li>\u4e0d\u5e73\u8861\u6570\u636e\u7684\u5206\u7c7b\u504f\u5dee&#xff1a;\u82e5\u5404\u7c7b\u522b\u6837\u672c\u6570\u91cf\u5dee\u5f02\u5927&#xff0c;KNN\u53ef\u80fd\u504f\u5411\u591a\u6570\u7c7b&#xff0c;\u5ffd\u7565\u5c11\u6570\u7c7b\u3002\u3010\u89e3\u51b3\u65b9\u6cd5&#xff1a;\u52a0\u6743\u6295\u7968&#xff08;\u6839\u636e\u8ddd\u79bb\u8d4b\u4e88\u4e0d\u540c\u6743\u91cd&#xff09;&#xff0c;\u91c7\u6837\u5e73\u8861\u6570\u636e&#xff08;\u8fc7\u91c7\u6837\u5c11\u6570\u7c7b\u6216\u6b20\u91c7\u6837\u591a\u6570\u7c7b&#xff09;\u3011<\/li>\n<li>\u53c2\u6570K\u7684\u9009\u62e9\u654f\u611f&#xff1a;K\u503c&#xff08;\u90bb\u5c45\u6570\u91cf&#xff09;\u5bf9\u7ed3\u679c\u5f71\u54cd\u663e\u8457&#xff1a;<br \/>\nK\u8fc7\u5c0f&#xff1a;\u6a21\u578b\u5bf9\u566a\u58f0\u654f\u611f&#xff0c;\u5bb9\u6613\u8fc7\u62df\u5408&#xff08;\u5982K&#061;1\u65f6&#xff0c;\u9884\u6d4b\u4ec5\u4f9d\u8d56\u6700\u8fd1\u4e00\u4e2a\u6837\u672c&#xff09;\u3002<br \/>\nK\u8fc7\u5927&#xff1a;\u6a21\u578b\u53ef\u80fd\u5ffd\u7565\u5c40\u90e8\u7ed3\u6784&#xff0c;\u5bfc\u81f4\u6b20\u62df\u5408&#xff08;\u5982K&#061;\u8bad\u7ec3\u96c6\u5927\u5c0f\u65f6&#xff0c;\u9884\u6d4b\u7ed3\u679c\u6052\u4e3a\u591a\u6570\u7c7b&#xff09;\u3002\u3010\u89e3\u51b3\u65b9\u6cd5&#xff1a;\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u9009\u62e9\u6700\u4f18K&#xff0c;\u4f46\u589e\u52a0\u8ba1\u7b97\u6210\u672c\u3011<\/li>\n<li>\u5bf9\u566a\u58f0\u548c\u5f02\u5e38\u503c\u654f\u611f&#xff1a;KNN\u7684\u9884\u6d4b\u57fa\u4e8e\u5c40\u90e8\u90bb\u5c45&#xff0c;\u82e5\u90bb\u5c45\u4e2d\u5305\u542b\u566a\u58f0\u6216\u5f02\u5e38\u503c&#xff0c;\u7ed3\u679c\u4f1a\u88ab\u5e72\u6270\u3002\u3010\u7f13\u89e3\u65b9\u6cd5&#xff1a;\u6570\u636e\u6e05\u6d17&#xff08;\u53bb\u9664\u5f02\u5e38\u503c&#xff09;&#xff0c;\u4f7f\u7528\u52a0\u6743KNN&#xff08;\u8ddd\u79bb\u8d8a\u8fd1\u7684\u90bb\u5c45\u6743\u91cd\u8d8a\u9ad8&#xff09;\u3011<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>4. sklearn API<\/p>\n<p><span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>neighbors <span class=\"token keyword\">import<\/span> KNeighborsClassifier<br \/>\nmodel <span class=\"token operator\">&#061;<\/span> KNeighborsClassifier<span class=\"token punctuation\">(<\/span>n_neighbors<span class=\"token operator\">&#061;<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> metric<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;euclidean&#039;<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># metric\u53ef\u9009&#039;manhattan&#039;<\/span><\/p>\n<p>5. \u5b9e\u6218\u793a\u4f8b&#xff1a;\u9e22\u5c3e\u82b1\u5206\u7c7b<\/p>\n<p><span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>datasets <span class=\"token keyword\">import<\/span> load_iris<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>model_selection <span class=\"token keyword\">import<\/span> train_test_split<\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u6570\u636e<\/span><br \/>\niris <span class=\"token operator\">&#061;<\/span> load_iris<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nX<span class=\"token punctuation\">,<\/span> y <span class=\"token operator\">&#061;<\/span> iris<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">,<\/span> iris<span class=\"token punctuation\">.<\/span>target<\/p>\n<p><span class=\"token comment\"># \u5212\u5206\u6570\u636e\u96c6<\/span><br \/>\nX_train<span class=\"token punctuation\">,<\/span> X_test<span class=\"token punctuation\">,<\/span> y_train<span class=\"token punctuation\">,<\/span> y_test <span class=\"token operator\">&#061;<\/span> train_test_split<span class=\"token punctuation\">(<\/span>X<span class=\"token punctuation\">,<\/span> y<span class=\"token punctuation\">,<\/span> test_size<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0.2<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8bad\u7ec3\u6a21\u578b<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> KNeighborsClassifier<span class=\"token punctuation\">(<\/span>n_neighbors<span class=\"token operator\">&#061;<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><br \/>\nmodel<span class=\"token punctuation\">.<\/span>fit<span class=\"token punctuation\">(<\/span>X_train<span class=\"token punctuation\">,<\/span> y_train<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8bc4\u4f30\u51c6\u786e\u7387<\/span><br \/>\naccuracy <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>score<span class=\"token punctuation\">(<\/span>X_test<span class=\"token punctuation\">,<\/span> y_test<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa\u59820.95<\/span><\/p>\n<p>6. \u6a21\u578b\u4fdd\u5b58\u4e0e\u52a0\u8f7d<\/p>\n<p><span class=\"token keyword\">import<\/span> joblib<\/p>\n<p><span class=\"token comment\"># \u4fdd\u5b58\u6a21\u578b<\/span><br \/>\njoblib<span class=\"token punctuation\">.<\/span>dump<span class=\"token punctuation\">(<\/span>model<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;knn_model.pkl&#039;<\/span><span class=\"token punctuation\">)<\/span> <\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u6a21\u578b<\/span><br \/>\nloaded_model <span class=\"token operator\">&#061;<\/span> joblib<span class=\"token punctuation\">.<\/span>load<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;knn_model.pkl&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h5>\u4e09\u3001\u6a21\u578b\u9009\u62e9\u4e0e\u8c03\u4f18<\/h5>\n<p>1. \u4e3a\u4ec0\u4e48\u9700\u8981\u8c03\u4f18&#xff1f;<\/p>\n<ul>\n<li>\u95ee\u9898&#xff1a;\u4f20\u7edf\u8bad\u7ec3\/\u6d4b\u8bd5\u96c6\u5212\u5206\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u5229\u7528\u4e0d\u5145\u5206\u6216\u8bc4\u4f30\u504f\u5dee&#xff08;\u5982\u968f\u673a\u5212\u5206\u65f6\u6d4b\u8bd5\u96c6\u6070\u597d\u5305\u542b\u7b80\u5355\u6837\u672c&#xff09;\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u901a\u8fc7\u591a\u6b21\u5212\u5206\u6570\u636e&#xff0c;\u66f4\u53ef\u9760\u5730\u4f30\u8ba1\u6a21\u578b\u5728\u672a\u89c1\u6570\u636e\u4e0a\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/li>\n<\/ul>\n<p>2. \u4ea4\u53c9\u9a8c\u8bc1&#xff08;Cross-Validation&#xff09;<br \/>\n\u89e3\u51b3\u7684\u95ee\u9898&#xff1a;\u5355\u6b21\u6570\u636e\u5212\u5206\u53ef\u80fd\u5f15\u5165\u968f\u673a\u504f\u5dee<br \/>\n&#xff08;1&#xff09;K\u6298\u4ea4\u53c9\u9a8c\u8bc1\u6d41\u7a0b&#xff08;K-Fold CV&#xff09;<\/p>\n<p>&#xff08;\u4ee55\u6298\u4e3a\u4f8b&#xff09;&#xff1a;<\/p>\n<li>\u5c06\u8bad\u7ec3\u96c6\u5747\u5206\u4e3a5\u4efd<\/li>\n<li>\u8f6e\u6d41\u7528\u5176\u4e2d4\u4efd\u8bad\u7ec3&#xff0c;1\u4efd\u9a8c\u8bc1<\/li>\n<li>\u91cd\u590d5\u6b21&#xff0c;\u53d6\u5e73\u5747\u51c6\u786e\u7387<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730114649-688a062981802.png\" alt=\"\" \/><\/li>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u6570\u636e\u5229\u7528\u7387\u9ad8&#xff08;\u6bcf\u4e2a\u6837\u672c\u5747\u53c2\u4e0e\u9a8c\u8bc1&#xff09;\u3002<\/li>\n<li>\u51cf\u5c11\u56e0\u5355\u6b21\u5212\u5206\u5bfc\u81f4\u7684\u8bc4\u4f30\u6ce2\u52a8\u3002<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;\u8ba1\u7b97\u6210\u672c\u968fK\u589e\u52a0\u800c\u4e0a\u5347&#xff08;K\u901a\u5e38\u53d65\u621610&#xff09;\u3002<\/p>\n<p>&#xff08;2&#xff09;\u7559\u4e00\u6cd5\u4ea4\u53c9\u9a8c\u8bc1&#xff08;LOOCV&#xff09;<\/p>\n<ul>\n<li>\u6b65\u9aa4&#xff1a;K\u6298CV\u7684\u7279\u4f8b&#xff0c;K&#061;\u6837\u672c\u6570&#xff0c;\u6bcf\u6b21\u4ec5\u75591\u4e2a\u6837\u672c\u9a8c\u8bc1\u3002<\/li>\n<li>\u4f18\u70b9&#xff1a;\u504f\u5dee\u6781\u4f4e&#xff08;\u51e0\u4e4e\u7528\u5168\u90e8\u6570\u636e\u8bad\u7ec3&#xff09;\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u8ba1\u7b97\u91cf\u6781\u5927&#xff08;\u5c24\u5176\u5927\u6570\u636e\u96c6&#xff09;\u3002<\/li>\n<\/ul>\n<p>&#xff08;3&#xff09;\u5206\u5c42K\u6298\u4ea4\u53c9\u9a8c\u8bc1&#xff08;Stratified K-Fold&#xff09;<\/p>\n<ul>\n<li>\u9002\u7528\u573a\u666f&#xff1a;\u5206\u7c7b\u4efb\u52a1\u4e2d\u7c7b\u522b\u4e0d\u5e73\u8861\u65f6\u3002<\/li>\n<li>\u6539\u8fdb&#xff1a;\u786e\u4fdd\u6bcf\u6298\u4e2d\u5404\u7c7b\u522b\u6bd4\u4f8b\u4e0e\u539f\u59cb\u6570\u636e\u96c6\u4e00\u81f4&#xff0c;\u907f\u514d\u56e0\u5212\u5206\u5bfc\u81f4\u9a8c\u8bc1\u96c6\u7c7b\u522b\u5206\u5e03\u5931\u771f\u3002<\/li>\n<\/ul>\n<p>3. \u8d85\u53c2\u6570\u641c\u7d22<\/p>\n<ul>\n<li>\u7f51\u683c\u641c\u7d22&#xff08;Grid Search&#xff09;&#xff1a;\u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u53c2\u6570\u7ec4\u5408<\/li>\n<li>\u968f\u673a\u641c\u7d22&#xff08;Random Search&#xff09;&#xff1a;\u968f\u673a\u62bd\u6837\u53c2\u6570\u7ec4\u5408&#xff08;\u6548\u7387\u66f4\u9ad8&#xff09;<\/li>\n<\/ul>\n<p>4. sklearn API<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">sklearn<\/span><span class=\"token punctuation\">.<\/span>model_selection<span class=\"token punctuation\">.<\/span>GridSearchCV<span class=\"token punctuation\">(<\/span>estimator<span class=\"token punctuation\">,<\/span> param_grid<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8bf4\u660e&#xff1a;<br \/>\n\u540c\u65f6\u8fdb\u884c\u4ea4\u53c9\u9a8c\u8bc1<span class=\"token punctuation\">(<\/span>CV<span class=\"token punctuation\">)<\/span>\u3001\u548c\u7f51\u683c\u641c\u7d22<span class=\"token punctuation\">(<\/span>GridSearch<span class=\"token punctuation\">)<\/span>&#xff0c;GridSearchCV\u5b9e\u9645\u4e0a\u4e5f\u662f\u4e00\u4e2a\u4f30\u8ba1\u5668<span class=\"token punctuation\">(<\/span>estimator<span class=\"token punctuation\">)<\/span>&#xff0c;\u540c\u65f6\u5b83\u6709\u51e0\u4e2a\u91cd\u8981\u5c5e\u6027&#xff1a;<br \/>\n      best_params_  \u6700\u4f73\u53c2\u6570<br \/>\n      best_score_ \u5728\u8bad\u7ec3\u96c6\u4e2d\u7684\u51c6\u786e\u7387<br \/>\n      best_estimator_ \u6700\u4f73\u4f30\u8ba1\u5668<br \/>\n      cv_results_ \u4ea4\u53c9\u9a8c\u8bc1\u8fc7\u7a0b\u63cf\u8ff0<br \/>\n      best_index_\u6700\u4f73k\u5728\u5217\u8868\u4e2d\u7684\u4e0b\u6807<br \/>\n\u53c2\u6570&#xff1a;<br \/>\nestimator&#xff1a; scikit<span class=\"token operator\">&#8211;<\/span>learn\u4f30\u8ba1\u5668\u5b9e\u4f8b<br \/>\nparam_grid<span class=\"token punctuation\">:<\/span>\u4ee5\u53c2\u6570\u540d\u79f0&#xff08;<span class=\"token builtin\">str<\/span>&#xff09;\u4f5c\u4e3a\u952e&#xff0c;\u5c06\u53c2\u6570\u8bbe\u7f6e\u5217\u8868\u5c1d\u8bd5\u4f5c\u4e3a\u503c\u7684\u5b57\u5178<br \/>\n\u793a\u4f8b&#xff1a; <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;n_neighbors&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">7<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">9<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">11<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><br \/>\n    cv<span class=\"token punctuation\">:<\/span> \u786e\u5b9a\u4ea4\u53c9\u9a8c\u8bc1\u5207\u5206\u7b56\u7565<span class=\"token punctuation\">,<\/span>\u503c\u4e3a<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token boolean\">None<\/span>  \u9ed8\u8ba4<span class=\"token number\">5<\/span>\u6298<br \/>\n        <span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span>integer  \u8bbe\u7f6e\u591a\u5c11\u6298<br \/>\n        \u5982\u679c\u4f30\u8ba1\u5668\u662f\u5206\u7c7b\u5668&#xff0c;\u4f7f\u7528<span class=\"token string\">&#034;\u5206\u5c42k-\u6298\u4ea4\u53c9\u9a8c\u8bc1(StratifiedKFold)&#034;<\/span>\u3002\u5728\u6240\u6709\u5176\u4ed6\u60c5\u51b5\u4e0b&#xff0c;\u4f7f\u7528KFold\u3002<\/p>\n<p>5. \u793a\u4f8b&#xff1a;\u9e22\u5c3e\u82b1\u5206\u7c7b\u8c03\u4f18<\/p>\n<p><span class=\"token comment\"># \u7528KNN\u7b97\u6cd5\u5bf9\u9e22\u5c3e\u82b1\u8fdb\u884c\u5206\u7c7b&#xff0c;\u6dfb\u52a0\u7f51\u683c\u641c\u7d22\u548c\u4ea4\u53c9\u9a8c\u8bc1<\/span><br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>datasets <span class=\"token keyword\">import<\/span> load_iris<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>model_selection <span class=\"token keyword\">import<\/span> train_test_split<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>preprocessing <span class=\"token keyword\">import<\/span> StandardScaler<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>neighbors <span class=\"token keyword\">import<\/span> KNeighborsClassifier<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>model_selection <span class=\"token keyword\">import<\/span> GridSearchCV<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">knn_iris_gscv<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># 1&#xff09;\u83b7\u53d6\u6570\u636e<\/span><br \/>\n    iris <span class=\"token operator\">&#061;<\/span> load_iris<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># 2&#xff09;\u5212\u5206\u6570\u636e\u96c6<\/span><br \/>\n    x_train<span class=\"token punctuation\">,<\/span> x_test<span class=\"token punctuation\">,<\/span> y_train<span class=\"token punctuation\">,<\/span> y_test <span class=\"token operator\">&#061;<\/span> train_test_split<span class=\"token punctuation\">(<\/span>iris<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">,<\/span> iris<span class=\"token punctuation\">.<\/span>target<span class=\"token punctuation\">,<\/span> random_state<span class=\"token operator\">&#061;<\/span><span class=\"token number\">22<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># 3&#xff09;\u7279\u5f81\u5de5\u7a0b&#xff1a;\u6807\u51c6\u5316<\/span><br \/>\n    transfer <span class=\"token operator\">&#061;<\/span> StandardScaler<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    x_train <span class=\"token operator\">&#061;<\/span> transfer<span class=\"token punctuation\">.<\/span>fit_transform<span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">)<\/span><br \/>\n    x_test <span class=\"token operator\">&#061;<\/span> transfer<span class=\"token punctuation\">.<\/span>transform<span class=\"token punctuation\">(<\/span>x_test<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># 4&#xff09;KNN\u7b97\u6cd5\u9884\u4f30\u5668, \u8fd9\u91cc\u5c31\u4e0d\u4f20\u53c2\u6570n_neighbors\u4e86&#xff0c;\u4ea4\u7ed9GridSearchCV\u6765\u4f20\u9012<\/span><br \/>\n    estimator <span class=\"token operator\">&#061;<\/span> KNeighborsClassifier<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u52a0\u5165\u7f51\u683c\u641c\u7d22\u4e0e\u4ea4\u53c9\u9a8c\u8bc1, GridSearchCV\u4f1a\u8ba9k\u5206\u522b\u7b49\u4e8e1,2,5,7,9,11\u8fdb\u884c\u7f51\u683c\u641c\u7d22\u507f\u8bd5\u3002cv&#061;10\u8868\u793a\u8fdb\u884c10\u6b21\u4ea4\u53c9\u9a8c\u8bc1<\/span><br \/>\n    estimator <span class=\"token operator\">&#061;<\/span> GridSearchCV<span class=\"token punctuation\">(<\/span>estimator<span class=\"token punctuation\">,<\/span> param_grid<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;n_neighbors&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">7<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">9<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">11<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span> cv<span class=\"token operator\">&#061;<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    estimator<span class=\"token punctuation\">.<\/span>fit<span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">,<\/span> y_train<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># 5&#xff09;\u6a21\u578b\u8bc4\u4f30<\/span><br \/>\n    <span class=\"token comment\"># \u65b9\u6cd51&#xff1a;\u76f4\u63a5\u6bd4\u5bf9\u771f\u5b9e\u503c\u548c\u9884\u6d4b\u503c<\/span><br \/>\n    y_predict <span class=\"token operator\">&#061;<\/span> estimator<span class=\"token punctuation\">.<\/span>predict<span class=\"token punctuation\">(<\/span>x_test<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;y_predict:\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> y_predict<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u76f4\u63a5\u6bd4\u5bf9\u771f\u5b9e\u503c\u548c\u9884\u6d4b\u503c:\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> y_test <span class=\"token operator\">&#061;&#061;<\/span> y_predict<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u65b9\u6cd52&#xff1a;\u8ba1\u7b97\u51c6\u786e\u7387<\/span><br \/>\n    score <span class=\"token operator\">&#061;<\/span> estimator<span class=\"token punctuation\">.<\/span>score<span class=\"token punctuation\">(<\/span>x_test<span class=\"token punctuation\">,<\/span> y_test<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5728\u6d4b\u8bd5\u96c6\u4e2d\u7684\u51c6\u786e\u7387\u4e3a&#xff1a;\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> score<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">#0.9736842105263158<\/span><\/p>\n<p>    <span class=\"token comment\"># \u6700\u4f73\u53c2\u6570&#xff1a;best_params_<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6700\u4f73\u53c2\u6570&#xff1a;\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> estimator<span class=\"token punctuation\">.<\/span>best_params_<span class=\"token punctuation\">)<\/span> <span class=\"token comment\">#{&#039;n_neighbors&#039;: 3}&#xff0c; \u8bf4\u660ek&#061;3\u65f6\u6700\u597d<\/span><br \/>\n    <span class=\"token comment\"># \u6700\u4f73\u7ed3\u679c&#xff1a;best_score_<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5728\u8bad\u7ec3\u96c6\u4e2d\u7684\u51c6\u786e\u7387&#xff1a;\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> estimator<span class=\"token punctuation\">.<\/span>best_score_<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">#0.9553030303030303<\/span><br \/>\n    <span class=\"token comment\"># \u6700\u4f73\u4f30\u8ba1\u5668&#xff1a;best_estimator_<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6700\u4f73\u4f30\u8ba1\u5668:\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> estimator<span class=\"token punctuation\">.<\/span>best_estimator_<span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># KNeighborsClassifier(n_neighbors&#061;3)<\/span><br \/>\n    <span class=\"token comment\"># \u4ea4\u53c9\u9a8c\u8bc1\u7ed3\u679c&#xff1a;cv_results_<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u4ea4\u53c9\u9a8c\u8bc1\u8fc7\u7a0b\u63cf\u8ff0:\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> estimator<span class=\"token punctuation\">.<\/span>cv_results_<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">#\u6700\u4f73\u53c2\u6570\u7ec4\u5408\u7684\u7d22\u5f15:\u6700\u4f73k\u5728\u5217\u8868\u4e2d\u7684\u4e0b\u6807<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6700\u4f73\u53c2\u6570\u7ec4\u5408\u7684\u7d22\u5f15:\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span>estimator<span class=\"token punctuation\">.<\/span>best_index_<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\">#\u901a\u5e38\u60c5\u51b5\u4e0b&#xff0c;\u76f4\u63a5\u4f7f\u7528best_params_\u66f4\u4e3a\u65b9\u4fbf<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>knn_iris_gscv<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h5>\u56db\u3001\u6734\u7d20\u8d1d\u53f6\u65af\u5206\u7c7b<\/h5>\n<p>1. \u7b97\u6cd5\u57fa\u7840<\/p>\n<ul>\n<li>\u6761\u4ef6\u6982\u7387&#xff1a;\u4e8b\u4ef6A\u5728\u4e8b\u4ef6B\u5df2\u53d1\u751f\u65f6\u7684\u6982\u7387 ( P(A|B) &#061; \\\\frac{P(A \\\\cap B)}{P(B)} )<\/li>\n<li>\u5168\u6982\u7387\u516c\u5f0f&#xff1a;\u82e5\u4e8b\u4ef6B\u7531\u4e92\u65a5\u4e8b\u4ef6( A_1,\u2026,A_n )\u5f15\u53d1&#xff0c;\u5219<br \/>\n( P(B) &#061; \\\\sum_{i&#061;1}^{n} P(B|A_i)P(A_i) )<\/li>\n<\/ul>\n<p>2. \u8d1d\u53f6\u65af\u5b9a\u7406<br \/>\n( P(A|B) &#061; \\\\frac{P(B|A)P(A)}{P(B)} )<br \/>\n\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>( P(A|B) )&#xff1a;\u540e\u9a8c\u6982\u7387&#xff08;\u6211\u4eec\u8981\u6c42\u89e3\u7684&#xff09;<\/li>\n<li>( P(B|A) )&#xff1a;\u4f3c\u7136\u6982\u7387<\/li>\n<li>( P(A) )&#xff1a;\u5148\u9a8c\u6982\u7387<\/li>\n<\/ul>\n<p>3. \u6734\u7d20\u8d1d\u53f6\u65af\u539f\u7406<br \/>\n&#034;\u6734\u7d20&#034;\u5047\u8bbe&#xff1a;\u7279\u5f81\u4e4b\u95f4\u76f8\u4e92\u72ec\u7acb&#xff08;\u7b80\u5316\u8ba1\u7b97&#xff09;<br \/>\n\u5206\u7c7b\u51b3\u7b56&#xff1a;\u8ba1\u7b97\u6837\u672c\u5c5e\u4e8e\u5404\u7c7b\u522b\u7684\u6982\u7387&#xff0c;\u53d6\u6700\u5927\u503c<br \/>\n( P(y_k|x) &#061; \\\\frac{P(x|y_k)P(y_k)}{P(x)} \\\\propto P(y_k) \\\\prod_{i} P(x_i|y_k) )<\/p>\n<p>4. \u62c9\u666e\u62c9\u65af\u5e73\u6ed1<br \/>\n\u95ee\u9898&#xff1a;\u5f53\u67d0\u4e2a\u7279\u5f81\u503c\u672a\u51fa\u73b0\u65f6&#xff0c;( P(x_i|y_k)&#061;0 )\u5bfc\u81f4\u6574\u4f53\u6982\u7387\u4e3a0<br \/>\n\u89e3\u51b3\u65b9\u6848&#xff1a;\u6dfb\u52a0\u5e73\u6ed1\u7cfb\u6570\u03b1 &#xff08;\u5982\u03b1  &#061; 1&#xff09;<br \/>\n( P(x_i|y_k) &#061; \\\\frac{N_{y_k,x_i} &#043; \\\\alpha}{N_{y_k} &#043; \\\\alpha n} )<br \/>\n\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>( N_{y_k,x_i} )&#xff1a;\u7c7b\u522b( y_k )\u4e2d\u7279\u5f81( x_i )\u51fa\u73b0\u7684\u6b21\u6570<\/li>\n<li>( N_{y_k} )&#xff1a;\u7c7b\u522b( y_k )\u7684\u603b\u6837\u672c\u6570<\/li>\n<li>( n )&#xff1a;\u7279\u5f81\u7684\u53ef\u80fd\u53d6\u503c\u6570<\/li>\n<\/ul>\n<p>5. sklearn API<\/p>\n<p><span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>naive_bayes <span class=\"token keyword\">import<\/span> MultinomialNB  <span class=\"token comment\"># \u9002\u7528\u4e8e\u79bb\u6563\u7279\u5f81<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> MultinomialNB<span class=\"token punctuation\">(<\/span>alpha<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1.0<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># alpha\u5373\u5e73\u6ed1\u7cfb\u6570<\/span><\/p>\n<p>6. \u793a\u4f8b&#xff1a;\u65b0\u95fb\u5206\u7c7b<\/p>\n<p><span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>datasets <span class=\"token keyword\">import<\/span> fetch_20newsgroups<br \/>\n<span class=\"token keyword\">from<\/span> sklearn<span class=\"token punctuation\">.<\/span>feature_extraction<span class=\"token punctuation\">.<\/span>text <span class=\"token keyword\">import<\/span> CountVectorizer<\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u6570\u636e<\/span><br \/>\nnewsgroups <span class=\"token operator\">&#061;<\/span> fetch_20newsgroups<span class=\"token punctuation\">(<\/span>subset<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;train&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nX<span class=\"token punctuation\">,<\/span> y <span class=\"token operator\">&#061;<\/span> newsgroups<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">,<\/span> newsgroups<span class=\"token punctuation\">.<\/span>target<\/p>\n<p><span class=\"token comment\"># \u6587\u672c\u7279\u5f81\u63d0\u53d6<\/span><br \/>\nvectorizer <span class=\"token operator\">&#061;<\/span> CountVectorizer<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nX_vec <span class=\"token operator\">&#061;<\/span> vectorizer<span class=\"token punctuation\">.<\/span>fit_transform<span class=\"token punctuation\">(<\/span>X<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8bad\u7ec3\u6734\u7d20\u8d1d\u53f6\u65af<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> MultinomialNB<span class=\"token punctuation\">(<\/span>alpha<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0.01<\/span><span class=\"token punctuation\">)<\/span><br \/>\nmodel<span class=\"token punctuation\">.<\/span>fit<span class=\"token punctuation\">(<\/span>X_vec<span class=\"token punctuation\">,<\/span> y<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u9884\u6d4b\u65b0\u6587\u672c<\/span><br \/>\nnew_text <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;GPU performance comparison&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\nnew_vec <span class=\"token operator\">&#061;<\/span> vectorizer<span class=\"token punctuation\">.<\/span>transform<span class=\"token punctuation\">(<\/span>new_text<span class=\"token punctuation\">)<\/span><br \/>\npred <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>predict<span class=\"token punctuation\">(<\/span>new_vec<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa\u7c7b\u522b\u7f16\u53f7<\/span><\/p>\n<hr \/>\n<h4>\u5173\u952e\u77e5\u8bc6\u70b9\u603b\u7ed3<\/h4>\n<table>\n<tr>\u7b97\u6cd5\u9002\u7528\u573a\u666f\u4f18\u52bf\u6ce8\u610f\u4e8b\u9879<\/tr>\n<tbody>\n<tr>\n<td>KNN<\/td>\n<td>\u5c0f\u6570\u636e\u96c6&#xff0c;\u4f4e\u7ef4\u5ea6<\/td>\n<td>\u76f4\u89c2\u6613\u7406\u89e3<\/td>\n<td>\u8ba1\u7b97\u6548\u7387\u4f4e&#xff0c;\u9700\u7279\u5f81\u7f29\u653e<\/td>\n<\/tr>\n<tr>\n<td>\u6734\u7d20\u8d1d\u53f6\u65af<\/td>\n<td>\u6587\u672c\u5206\u7c7b&#xff0c;\u9ad8\u7ef4\u5ea6<\/td>\n<td>\u8ba1\u7b97\u9ad8\u6548&#xff0c;\u6297\u566a\u58f0<\/td>\n<td>\u7279\u5f81\u72ec\u7acb\u6027\u5047\u8bbe\u53ef\u80fd\u4e0d\u6210\u7acb<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u578b\u8c03\u4f18<\/td>\n<td>\u6240\u6709\u7b97\u6cd5<\/td>\n<td>\u663e\u8457\u63d0\u5347\u6a21\u578b\u6027\u80fd<\/td>\n<td>\u8ba1\u7b97\u6210\u672c\u9ad8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb193\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u7edf\u4e00API\u8bbe\u8ba1\uff1a\u6240\u6709\u7b97\u6cd5\u90fd\u9075\u5faafit()\uff08\u8bad\u7ec3\uff09\u3001predict()\uff08\u9884\u6d4b\uff09\u7684\u7edf\u4e00\u63a5\u53e3\u7b97\u6cd5\u8986\u76d6\u5168\u9762\uff1a\u5305\u542b\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u3001\u964d\u7ef4\u7b49\u4f20\u7edfML\u7b97\u6cd5\u6570\u636e\u5904\u7406\u5de5\u5177\uff1a\u63d0\u4f9b\u7279\u5f81\u5de5\u7a0b\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bc4\u4f30\u7b49\u5168\u5957\u5de5\u5177\u6587\u6863\u5b8c\u5584\uff1a\u6bcf\u4e2aAPI\u90fd\u6709\u8be6\u7ec6\u8bf4\u660e\u548c\u793a\u4f8b\uff08\u901a\u8fc7?\u67e5\u770b\uff09\u6838\u5fc3\u8bbe\u8ba1\u601d\u60f3\uff1a\u5c06\u673a\u5668\u5b66\u4e60\u6d41\u7a0b\u6807\u51c6\u5316\u4e3a&quot;\u6570\u636e\u8f93\u5165 \u2192 \u7279\u5f81\u5904\u7406 \u2192 \u6a21\u578b\u8bad\u7ec3 \u2192 \u9884\u6d4b\u8f93\u51fa&quot;\u7684\u6d41\u6c34\u7ebf\u7b97\u6cd5\u9002\u7528\u573a\u666f\u4f18\u52bf\u6ce8\u610f\u4e8b\u9879KNN\u5c0f\u6570\u636e\u96c6\uff0c\u4f4e\u7ef4\u5ea6\u76f4\u89c2\u6613\u7406\u89e3\u8ba1\u7b97\u6548\u7387\u4f4e\uff0c\u9700\u7279\u5f81\u7f29\u653e\u6734\u7d20\u8d1d\u53f6\u65af\u6587\u672c\u5206\u7c7b\uff0c\u9ad8\u7ef4\u5ea6\u8ba1\u7b97\u9ad8\u6548\uff0c\u6297\u566a\u58f0\u3002<\/p>\n","protected":false},"author":2,"featured_media":49782,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50,207,427],"topic":[],"class_list":["post-49783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-50","tag-207","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \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\/49783.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb193\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u7edf\u4e00API\u8bbe\u8ba1\uff1a\u6240\u6709\u7b97\u6cd5\u90fd\u9075\u5faafit()\uff08\u8bad\u7ec3\uff09\u3001predict()\uff08\u9884\u6d4b\uff09\u7684\u7edf\u4e00\u63a5\u53e3\u7b97\u6cd5\u8986\u76d6\u5168\u9762\uff1a\u5305\u542b\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u3001\u964d\u7ef4\u7b49\u4f20\u7edfML\u7b97\u6cd5\u6570\u636e\u5904\u7406\u5de5\u5177\uff1a\u63d0\u4f9b\u7279\u5f81\u5de5\u7a0b\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bc4\u4f30\u7b49\u5168\u5957\u5de5\u5177\u6587\u6863\u5b8c\u5584\uff1a\u6bcf\u4e2aAPI\u90fd\u6709\u8be6\u7ec6\u8bf4\u660e\u548c\u793a\u4f8b\uff08\u901a\u8fc7?\u67e5\u770b\uff09\u6838\u5fc3\u8bbe\u8ba1\u601d\u60f3\uff1a\u5c06\u673a\u5668\u5b66\u4e60\u6d41\u7a0b\u6807\u51c6\u5316\u4e3a&quot;\u6570\u636e\u8f93\u5165 \u2192 \u7279\u5f81\u5904\u7406 \u2192 \u6a21\u578b\u8bad\u7ec3 \u2192 \u9884\u6d4b\u8f93\u51fa&quot;\u7684\u6d41\u6c34\u7ebf\u7b97\u6cd5\u9002\u7528\u573a\u666f\u4f18\u52bf\u6ce8\u610f\u4e8b\u9879KNN\u5c0f\u6570\u636e\u96c6\uff0c\u4f4e\u7ef4\u5ea6\u76f4\u89c2\u6613\u7406\u89e3\u8ba1\u7b97\u6548\u7387\u4f4e\uff0c\u9700\u7279\u5f81\u7f29\u653e\u6734\u7d20\u8d1d\u53f6\u65af\u6587\u672c\u5206\u7c7b\uff0c\u9ad8\u7ef4\u5ea6\u8ba1\u7b97\u9ad8\u6548\uff0c\u6297\u566a\u58f0\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/49783.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T11:46:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730114649-688a062981802.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\/49783.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/49783.html\",\"name\":\"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T11:46:51+00:00\",\"dateModified\":\"2025-07-30T11:46:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/49783.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/49783.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49783.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b\"}]},{\"@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":"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \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\/49783.html","og_locale":"zh_CN","og_type":"article","og_title":"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb193\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u7edf\u4e00API\u8bbe\u8ba1\uff1a\u6240\u6709\u7b97\u6cd5\u90fd\u9075\u5faafit()\uff08\u8bad\u7ec3\uff09\u3001predict()\uff08\u9884\u6d4b\uff09\u7684\u7edf\u4e00\u63a5\u53e3\u7b97\u6cd5\u8986\u76d6\u5168\u9762\uff1a\u5305\u542b\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u3001\u964d\u7ef4\u7b49\u4f20\u7edfML\u7b97\u6cd5\u6570\u636e\u5904\u7406\u5de5\u5177\uff1a\u63d0\u4f9b\u7279\u5f81\u5de5\u7a0b\u3001\u6570\u636e\u9884\u5904\u7406\u3001\u6a21\u578b\u8bc4\u4f30\u7b49\u5168\u5957\u5de5\u5177\u6587\u6863\u5b8c\u5584\uff1a\u6bcf\u4e2aAPI\u90fd\u6709\u8be6\u7ec6\u8bf4\u660e\u548c\u793a\u4f8b\uff08\u901a\u8fc7?\u67e5\u770b\uff09\u6838\u5fc3\u8bbe\u8ba1\u601d\u60f3\uff1a\u5c06\u673a\u5668\u5b66\u4e60\u6d41\u7a0b\u6807\u51c6\u5316\u4e3a&quot;\u6570\u636e\u8f93\u5165 \u2192 \u7279\u5f81\u5904\u7406 \u2192 \u6a21\u578b\u8bad\u7ec3 \u2192 \u9884\u6d4b\u8f93\u51fa&quot;\u7684\u6d41\u6c34\u7ebf\u7b97\u6cd5\u9002\u7528\u573a\u666f\u4f18\u52bf\u6ce8\u610f\u4e8b\u9879KNN\u5c0f\u6570\u636e\u96c6\uff0c\u4f4e\u7ef4\u5ea6\u76f4\u89c2\u6613\u7406\u89e3\u8ba1\u7b97\u6548\u7387\u4f4e\uff0c\u9700\u7279\u5f81\u7f29\u653e\u6734\u7d20\u8d1d\u53f6\u65af\u6587\u672c\u5206\u7c7b\uff0c\u9ad8\u7ef4\u5ea6\u8ba1\u7b97\u9ad8\u6548\uff0c\u6297\u566a\u58f0\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/49783.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T11:46:51+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730114649-688a062981802.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\/49783.html","url":"https:\/\/www.wsisp.com\/helps\/49783.html","name":"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T11:46:51+00:00","dateModified":"2025-07-30T11:46:51+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/49783.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/49783.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/49783.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u300a\u96f6\u57fa\u7840\u5165\u95e8AI\uff1a\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6838\u5fc3\u7b97\u6cd5\u89e3\u6790\uff08KNN\u3001\u6a21\u578b\u8c03\u4f18\u4e0e\u6734\u7d20\u8d1d\u53f6\u65af\uff09\u300b"}]},{"@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\/49783","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=49783"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49783\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/49782"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=49783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=49783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=49783"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=49783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}