{"id":64356,"date":"2026-01-23T12:24:47","date_gmt":"2026-01-23T04:24:47","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64356.html"},"modified":"2026-01-23T12:24:47","modified_gmt":"2026-01-23T04:24:47","slug":"python%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64356.html","title":{"rendered":"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a"},"content":{"rendered":"<p><span style=\"color:#000000;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal\">\u200b<\/span><\/p>\n<h2>\u76ee\u5f55<\/h2>\n<h3>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u601d\u60f3\u4e0e\u57fa\u77f3\u2014\u2014\u4e07\u6cd5\u5f52\u5b97&#xff0c;\u7b51\u57fa\u95ee\u9053<\/h3>\n<h4>\u7b2c1\u7ae0&#xff1a;\u521d\u63a2\u667a\u6167\u4e4b\u5883\u2014\u2014\u673a\u5668\u5b66\u4e60\u4e16\u754c\u89c2<\/h4>\n<ul>\n<li>1.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd<\/li>\n<li>1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f2<\/li>\n<li>1.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d<\/li>\n<li>1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;<\/li>\n<\/ul>\n<h4>\u7b2c2\u7ae0&#xff1a;\u5de5\u6b32\u5584\u5176\u4e8b\u2014\u2014Python\u73af\u5883\u4e0e\u6838\u5fc3\u5de5\u5177\u94fe<\/h4>\n<ul>\n<li>2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&#xff1a;Anaconda\u4e0eJupyter Notebook\u7684\u5b89\u88c5\u4e0e\u914d\u7f6e<\/li>\n<li>2.2 \u201c\u6570\u636e\u4e4b\u821f\u201d&#xff1a;NumPy\u6570\u503c\u8ba1\u7b97\u57fa\u7840<\/li>\n<li>2.3 \u201c\u6570\u636e\u4e4b\u9b42\u201d&#xff1a;Pandas\u6570\u636e\u5206\u6790\u5229\u5668<\/li>\n<li>2.4 \u201c\u773c\u89c1\u4e3a\u5b9e\u201d&#xff1a;Matplotlib\u4e0eSeaborn\u6570\u636e\u53ef\u89c6\u5316<\/li>\n<\/ul>\n<h4>\u7b2c3\u7ae0&#xff1a;\u6570\u636e\u7684\u5fc3\u6cd5\u2014\u2014\u9884\u5904\u7406\u4e0e\u7279\u5f81\u5de5\u7a0b<\/h4>\n<ul>\n<li>3.1 \u201c\u76f8\u6570\u636e\u201d&#xff1a;\u7406\u89e3\u4f60\u7684\u6570\u636e<\/li>\n<li>3.2 \u201c\u51c0\u6570\u636e\u201d&#xff1a;\u6570\u636e\u6e05\u6d17\u7684\u4fee\u884c<\/li>\n<li>3.3 \u201c\u70b9\u77f3\u6210\u91d1\u201d&#xff1a;\u7279\u5f81\u5de5\u7a0b\u7684\u79d1\u5b66\u4e0e\u827a\u672f<\/li>\n<\/ul>\n<h4>\u7b2c4\u7ae0&#xff1a;\u6a21\u578b\u7684\u7f57\u76d8\u2014\u2014\u8bc4\u4f30\u4e0e\u9009\u62e9<\/h4>\n<ul>\n<li>4.1 \u201c\u5ea6\u91cf\u8861\u201d&#xff1a;\u5206\u7c7b\u3001\u56de\u5f52\u4e0e\u805a\u7c7b\u6a21\u578b\u7684\u8bc4\u4f30\u6307\u6807<\/li>\n<li>4.2 \u201c\u6267\u5176\u4e24\u7aef\u800c\u7528\u4e2d\u201d&#xff1a;\u504f\u5dee\u4e0e\u65b9\u5dee\u7684\u6743\u8861<\/li>\n<li>4.3 \u201c\u4ed6\u5c71\u4e4b\u77f3\u201d&#xff1a;\u4ea4\u53c9\u9a8c\u8bc1\u7684\u667a\u6167<\/li>\n<li>4.4 \u201c\u5bfb\u8def\u201d&#xff1a;\u7f51\u683c\u641c\u7d22\u4e0e\u8d85\u53c2\u6570\u8c03\u4f18<\/li>\n<\/ul>\n<hr \/>\n<h3>\u7b2c\u4e8c\u90e8\u5206&#xff1a;\u672f\u6cd5\u4e07\u5343\u2014\u2014\u4e3b\u6d41\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8be6\u89e3<\/h3>\n<h4>\u7b2c5\u7ae0&#xff1a;\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u5224\u522b\u201d\u2014\u2014\u5206\u7c7b\u7b97\u6cd5<\/h4>\n<ul>\n<li>5.1 \u903b\u8f91\u56de\u5f52&#xff1a;\u770b\u4f3c\u56de\u5f52&#xff0c;\u5b9e\u4e3a\u5206\u7c7b\u7684\u667a\u6167<\/li>\n<li>5.2 K-\u8fd1\u90bb&#xff08;KNN&#xff09;&#xff1a;\u201c\u7269\u4ee5\u7c7b\u805a&#xff0c;\u4eba\u4ee5\u7fa4\u5206\u201d\u7684\u6734\u7d20\u54f2\u5b66<\/li>\n<li>5.3 \u652f\u6491\u5411\u91cf\u673a&#xff08;SVM&#xff09;&#xff1a;\u201c\u4e00\u5212\u5f00\u5929\u201d\u7684\u6570\u5b66\u4e4b\u7f8e<\/li>\n<li>5.4 \u51b3\u7b56\u6811\u4e0e\u968f\u673a\u68ee\u6797&#xff1a;\u201c\u96c6\u601d\u5e7f\u76ca\u201d\u7684\u96c6\u6210\u667a\u6167<\/li>\n<li>5.5 \u6734\u7d20\u8d1d\u53f6\u65af&#xff1a;\u201c\u6267\u679c\u7d22\u56e0\u201d\u7684\u6982\u7387\u601d\u7ef4<\/li>\n<\/ul>\n<h4>\u7b2c6\u7ae0&#xff1a;\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u9884\u6d4b\u201d\u2014\u2014\u56de\u5f52\u7b97\u6cd5<\/h4>\n<ul>\n<li>6.1 \u7ebf\u6027\u56de\u5f52&#xff1a;\u4ece\u7b80\u5355\u5230\u591a\u5143&#xff0c;\u63a2\u5bfb\u53d8\u91cf\u95f4\u7684\u7ebf\u6027\u5173\u7cfb<\/li>\n<li>6.2 \u5cad\u56de\u5f52\u4e0eLasso\u56de\u5f52&#xff1a;\u6b63\u5219\u5316\u4e0b\u7684\u201c\u4e2d\u5eb8\u4e4b\u9053\u201d<\/li>\n<li>6.3 \u591a\u9879\u5f0f\u56de\u5f52&#xff1a;\u7528\u66f2\u7ebf\u62df\u5408\u590d\u6742\u4e16\u754c<\/li>\n<li>6.4 \u56de\u5f52\u6811\u4e0e\u96c6\u6210\u56de\u5f52\u6a21\u578b&#xff08;\u4f8b\u5982 GBDT, XGBoost&#xff09;<\/li>\n<\/ul>\n<h4>\u7b2c7\u7ae0&#xff1a;\u65e0\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u5f52\u7eb3\u201d\u2014\u2014\u805a\u7c7b\u4e0e\u964d\u7ef4<\/h4>\n<ul>\n<li>7.1 K-\u5747\u503c\u805a\u7c7b&#xff08;K-Means&#xff09;&#xff1a;\u5bfb\u627e\u6570\u636e\u4e2d\u7684\u201c\u5f15\u529b\u4e2d\u5fc3\u201d<\/li>\n<li>7.2 \u5c42\u6b21\u805a\u7c7b&#xff1a;\u6784\u5efa\u6570\u636e\u7684\u201c\u5bb6\u65cf\u8c31\u7cfb\u201d<\/li>\n<li>7.3 DBSCAN&#xff1a;\u57fa\u4e8e\u5bc6\u5ea6\u7684\u201c\u793e\u533a\u53d1\u73b0\u201d<\/li>\n<li>7.4 \u4e3b\u6210\u5206\u5206\u6790&#xff08;PCA&#xff09;&#xff1a;\u5728\u7eb7\u7e41\u4e2d\u89c1\u672c\u8d28\u7684\u964d\u7ef4\u4e4b\u9053<\/li>\n<\/ul>\n<h4>\u7b2c8\u7ae0&#xff1a;\u96c6\u6210\u5b66\u4e60\u2014\u2014\u4ece\u201c\u4e09\u4e2a\u81ed\u76ae\u5320\u201d\u5230\u201c\u8bf8\u845b\u4eae\u201d<\/h4>\n<ul>\n<li>8.1 Bagging\u601d\u60f3&#xff1a;\u968f\u673a\u68ee\u6797\u7684\u518d\u601d\u8003<\/li>\n<li>8.2 Boosting\u601d\u60f3&#xff1a;\u4eceAdaBoost\u5230\u68af\u5ea6\u63d0\u5347\u6811&#xff08;GBDT&#xff09;<\/li>\n<li>8.3 Stacking\/Blending&#xff1a;\u6a21\u578b\u7684\u201c\u5706\u684c\u4f1a\u8bae\u201d<\/li>\n<li>8.4 XGBoost\u4e0eLightGBM&#xff1a;\u5de5\u4e1a\u754c\u7684\u201c\u5927\u6740\u5668\u201d\u8be6\u89e3<\/li>\n<\/ul>\n<h4>\u7b2c9\u7ae0&#xff1a;\u795e\u7ecf\u7f51\u7edc\u5165\u95e8\u2014\u2014\u901a\u5f80\u6df1\u5ea6\u5b66\u4e60\u7684\u6865\u6881<\/h4>\n<ul>\n<li>9.1 \u4ece\u751f\u7269\u795e\u7ecf\u5143\u5230\u611f\u77e5\u673a\u6a21\u578b<\/li>\n<li>9.2 \u591a\u5c42\u611f\u77e5\u673a&#xff08;MLP&#xff09;\u4e0e\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5<\/li>\n<li>9.3 \u6fc0\u6d3b\u51fd\u6570&#xff1a;\u4e3a\u795e\u7ecf\u7f51\u7edc\u6ce8\u5165\u201c\u7075\u9b42\u201d<\/li>\n<li>9.4 \u4f7f\u7528Scikit-Learn\u4e0eKeras\/TensorFlow\u6784\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc<\/li>\n<\/ul>\n<hr \/>\n<h3>\u7b2c\u4e09\u90e8\u5206&#xff1a;\u767b\u5802\u5165\u5ba4\u2014\u2014\u9ad8\u7ea7\u4e13\u9898\u4e0e\u5b9e\u6218\u6f14\u7ec3<\/h3>\n<h4>\u7b2c10\u7ae0&#xff1a;\u5b9e\u6218\u9879\u76ee\u4e00&#xff1a;\u91d1\u878d\u98ce\u63a7\u2014\u2014\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b<\/h4>\n<ul>\n<li>10.1 \u95ee\u9898\u5b9a\u4e49\u4e0e\u6570\u636e\u63a2\u7d22&#xff1a;\u7406\u89e3\u4e0d\u5e73\u8861\u6570\u636e<\/li>\n<li>10.2 \u7279\u5f81\u5de5\u7a0b\u4e0e\u91c7\u6837\u6280\u672f&#xff08;SMOTE&#xff09;<\/li>\n<li>10.3 \u6a21\u578b\u9009\u62e9\u3001\u8bad\u7ec3\u4e0e\u8bc4\u4f30<\/li>\n<li>10.4 \u89e3\u91ca\u6027\u5206\u6790&#xff1a;\u6a21\u578b\u4e3a\u4f55\u505a\u51fa\u8fd9\u6837\u7684\u51b3\u7b56&#xff1f; (SHAP\/LIME)<\/li>\n<\/ul>\n<h4>\u7b2c11\u7ae0&#xff1a;\u5b9e\u6218\u9879\u76ee\u4e8c&#xff1a;\u81ea\u7136\u8bed\u8a00\u5904\u7406\u2014\u2014\u6587\u672c\u60c5\u611f\u5206\u6790<\/h4>\n<ul>\n<li>11.1 \u6587\u672c\u6570\u636e\u7684\u9884\u5904\u7406&#xff1a;\u5206\u8bcd\u3001\u505c\u7528\u8bcd\u4e0e\u5411\u91cf\u5316&#xff08;TF-IDF, Word2Vec&#xff09;<\/li>\n<li>11.2 \u4ece\u4f20\u7edf\u6a21\u578b\u5230\u7b80\u5355\u795e\u7ecf\u7f51\u7edc\u7684\u60c5\u611f\u5206\u7c7b<\/li>\n<li>11.3 \u4e3b\u9898\u6a21\u578b&#xff08;LDA&#xff09;&#xff1a;\u6316\u6398\u6587\u672c\u80cc\u540e\u7684\u9690\u85cf\u4e3b\u9898<\/li>\n<\/ul>\n<h4>\u7b2c12\u7ae0&#xff1a;\u6a21\u578b\u90e8\u7f72\u4e0e\u5de5\u7a0b\u5316\u2014\u2014\u8ba9\u6a21\u578b\u201c\u6d3b\u201d\u8d77\u6765<\/h4>\n<ul>\n<li>12.1 \u6a21\u578b\u6301\u4e45\u5316&#xff1a;\u5e8f\u5217\u5316\u4e0e\u4fdd\u5b58<\/li>\n<li>12.2 \u4f7f\u7528Flask\/FastAPI\u6784\u5efaAPI\u670d\u52a1<\/li>\n<li>12.3 Docker\u5bb9\u5668\u5316&#xff1a;\u4e3a\u6a21\u578b\u6253\u9020\u4e00\u4e2a\u201c\u5bb6\u201d<\/li>\n<li>12.4 MLOps\u521d\u63a2&#xff1a;\u81ea\u52a8\u5316\u3001\u76d1\u63a7\u4e0e\u518d\u8bad\u7ec3<\/li>\n<\/ul>\n<h4>\u7b2c13\u7ae0&#xff1a;\u8d85\u8d8a\u7ecf\u5178\u2014\u2014\u672a\u6765\u5c55\u671b\u4e0e\u8fdb\u9636\u8def\u5f84<\/h4>\n<ul>\n<li>13.1 \u6df1\u5ea6\u5b66\u4e60\u6982\u89c8&#xff1a;CNN\u3001RNN\u7684\u4e16\u754c<\/li>\n<li>13.2 \u5f3a\u5316\u5b66\u4e60&#xff1a;\u4e0e\u73af\u5883\u4ea4\u4e92\u7684\u667a\u80fd\u4f53<\/li>\n<li>13.3 \u56fe\u795e\u7ecf\u7f51\u7edc\u3001\u8054\u90a6\u5b66\u4e60\u7b49\u524d\u6cbf\u7b80\u4ecb<\/li>\n<li>13.4 \u201c\u77e5\u884c\u5408\u4e00\u201d&#xff1a;\u5982\u4f55\u6301\u7eed\u5b66\u4e60\u4e0e\u6210\u957f<\/li>\n<\/ul>\n<hr \/>\n<h3>\u9644\u5f55<\/h3>\n<ul>\n<li>A. \u6570\u5b66\u57fa\u7840\u56de\u987e&#xff08;\u7ebf\u6027\u4ee3\u6570\u3001\u5fae\u79ef\u5206\u3001\u6982\u7387\u8bba\u6838\u5fc3\u6982\u5ff5&#xff09;<\/li>\n<li>B. \u5e38\u7528\u5de5\u5177\u4e0e\u5e93\u901f\u67e5\u624b\u518c<\/li>\n<li>C. \u672f\u8bed\u8868&#xff08;\u4e2d\u82f1\u5bf9\u7167&#xff09;<\/li>\n<li>D. \u63a8\u8350\u9605\u8bfb\u4e0e\u8d44\u6e90\u5217\u8868<\/li>\n<\/ul>\n<hr \/>\n<h2>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u601d\u60f3\u4e0e\u57fa\u77f3\u2014\u2014\u4e07\u6cd5\u5f52\u5b97&#xff0c;\u7b51\u57fa\u95ee\u9053<\/h2>\n<p>\u6838\u5fc3\u76ee\u6807&#xff1a;\u00a0\u5efa\u7acb\u5b66\u4e60\u8005\u7684\u5b8f\u89c2\u8ba4\u77e5&#xff0c;\u4e0d\u4ec5\u77e5\u5176\u7136&#xff0c;\u66f4\u8981\u77e5\u5176\u6240\u4ee5\u7136\u3002\u5c06\u673a\u5668\u5b66\u4e60\u7f6e\u4e8e\u79d1\u5b66\u3001\u54f2\u5b66\u4e43\u81f3\u4e1c\u65b9\u667a\u6167\u7684\u5e7f\u9614\u80cc\u666f\u4e0b&#xff0c;\u57f9\u517b\u5b66\u4e60\u8005\u7684\u201c\u6570\u636e\u76f4\u89c9\u201d\u4e0e\u201c\u6a21\u578b\u601d\u7ef4\u201d\u3002<\/p>\n<h3>\u7b2c\u4e00\u7ae0&#xff1a;\u521d\u63a2\u667a\u6167\u4e4b\u5883\u2014\u2014\u673a\u5668\u5b66\u4e60\u4e16\u754c\u89c2<\/h3>\n<ul>\n<li>1.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd<\/li>\n<li>1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f2<\/li>\n<li>1.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d<\/li>\n<li>1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;<\/li>\n<\/ul>\n<p>\u6b22\u8fce\u60a8&#xff0c;\u672a\u6765\u7684\u6570\u636e\u63a2\u7d22\u8005\u3002\u5728\u60a8\u6b63\u5f0f\u8e0f\u5165\u8fd9\u4e2a\u7531\u6570\u636e\u3001\u7b97\u6cd5\u4e0e\u4ee3\u7801\u6784\u6210\u7684\u8ff7\u4eba\u4e16\u754c\u4e4b\u524d&#xff0c;\u6211\u4eec\u5e0c\u671b\u4e0e\u60a8\u4e00\u540c\u7a0d\u4f5c\u505c\u7559&#xff0c;\u767b\u9ad8\u671b\u8fdc\u3002\u672c\u7ae0\u5e76\u975e\u4e00\u672c\u6280\u672f\u624b\u518c\u7684\u5e38\u89c4\u5f00\u7bc7&#xff0c;\u5b83\u4e0d\u6025\u4e8e\u5c55\u793a\u7eb7\u7e41\u7684\u4ee3\u7801\u6216\u6df1\u5965\u7684\u516c\u5f0f\u3002\u76f8\u53cd&#xff0c;\u5b83\u662f\u4e00\u5f20\u5730\u56fe&#xff0c;\u4e00\u5e45\u661f\u56fe&#xff0c;\u65e8\u5728\u4e3a\u60a8\u5efa\u7acb\u4e00\u4e2a\u5b8f\u5927\u7684\u65f6\u7a7a\u5750\u6807&#xff0c;\u8ba9\u60a8\u6e05\u6670\u5730\u770b\u5230\u201c\u673a\u5668\u5b66\u4e60\u201d\u8fd9\u7247\u65b0\u5927\u9646\u5728\u4eba\u7c7b\u667a\u6167\u7248\u56fe\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4ece\u6700\u672c\u6e90\u7684\u95ee\u9898\u5f00\u59cb&#xff1a;\u4f55\u4e3a\u201c\u5b66\u4e60\u201d&#xff1f;\u6211\u4eec\u5c06\u501f\u52a9\u5a74\u513f\u8ba4\u77e5\u4e16\u754c\u7684\u8fc7\u7a0b&#xff0c;\u4ee5\u53ca\u81ea\u7136\u754c\u6f14\u5316\u7684\u5b8f\u4f1f\u7bc7\u7ae0&#xff0c;\u6765\u7c7b\u6bd4\u673a\u5668\u5b66\u4e60\u7684\u4e09\u79cd\u57fa\u672c\u8303\u5f0f\u3002\u968f\u540e&#xff0c;\u6211\u4eec\u5c06\u7a7f\u8d8a\u65f6\u7a7a&#xff0c;\u56de\u987e\u8fd9\u6bb5\u6ce2\u6f9c\u58ee\u9614\u7684\u6280\u672f\u601d\u60f3\u53f2&#xff0c;\u4ece\u56fe\u7075\u7684\u6df1\u9083\u6784\u60f3&#xff0c;\u5230\u4eca\u65e5\u6df1\u5ea6\u5b66\u4e60\u7684\u7480\u74a8\u6210\u5c31&#xff0c;\u5e76\u5411\u90a3\u4e9b\u63a8\u52a8\u65f6\u4ee3\u524d\u884c\u7684\u5de8\u5320\u4eec\u81f4\u656c\u3002\u6211\u4eec\u8fd8\u5c06\u63a2\u8ba8\u4e3a\u4f55Python\u80fd\u591f\u6210\u4e3a\u8fd9\u95e8\u201c\u65b0\u5b66\u95ee\u201d\u7684\u901a\u7528\u8bed\u8a00&#xff0c;\u5e76\u6df1\u5165\u5176\u8bbe\u8ba1\u54f2\u5b66\u4e0e\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u4e5f\u662f\u81f3\u5173\u91cd\u8981\u7684\u4e00\u70b9&#xff0c;\u6211\u4eec\u5c06\u5171\u540c\u601d\u8fa8&#xff1a;\u4eba\u5de5\u667a\u80fd\u7a76\u7adf\u662f\u65e0\u6240\u4e0d\u80fd\u7684\u201c\u795e\u201d&#xff0c;\u8fd8\u662f\u6211\u4eec\u624b\u4e2d\u5f3a\u5927\u7684\u201c\u5668\u201d&#xff1f;\u6211\u4eec\u5c06\u76f4\u9762\u5176\u80fd\u529b\u8fb9\u754c\u4e0e\u6df1\u523b\u7684\u4f26\u7406\u6311\u6218&#xff0c;\u5e76\u63d0\u51fa\u4e00\u79cd\u201c\u4ee5\u51fa\u4e16\u4e4b\u5fc3&#xff0c;\u505a\u5165\u4e16\u4e4b\u4e8b\u201d\u7684\u4ece\u4e1a\u5fc3\u6cd5\u3002<\/p>\n<p>\u8fd9\u4e0d\u4ec5\u662f\u77e5\u8bc6\u7684\u94fa\u9648&#xff0c;\u66f4\u662f\u4e00\u573a\u601d\u60f3\u7684\u6d17\u793c\u3002\u5f53\u60a8\u5efa\u7acb\u8d77\u8fd9\u6837\u7684\u4e16\u754c\u89c2\u540e&#xff0c;\u672a\u6765\u5b66\u4e60\u9053\u8def\u4e0a\u7684\u6bcf\u4e00\u4e2a\u6280\u672f\u7ec6\u8282&#xff0c;\u90fd\u5c06\u4e0d\u518d\u662f\u5b64\u7acb\u7684\u788e\u7247&#xff0c;\u800c\u662f\u8fd9\u5e45\u5b8f\u5927\u753b\u5377\u4e2d\u548c\u8c10\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u4e00\u540c\u542f\u7a0b&#xff01;<\/p>\n<hr \/>\n<h4>1.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd<\/h4>\n<p>\u201c\u5b66\u4e60\u201d\u4e00\u8bcd&#xff0c;\u4e8e\u6211\u4eec\u800c\u8a00\u518d\u719f\u6089\u4e0d\u8fc7\u3002\u4ece\u5471\u5471\u5760\u5730\u5230\u767d\u53d1\u82cd\u82cd&#xff0c;\u6211\u4eec\u7684\u4e00\u751f\u4fbf\u662f\u5b66\u4e60\u7684\u4e00\u751f\u3002\u6211\u4eec\u5b66\u4e60\u8bed\u8a00\u3001\u5b66\u4e60\u9a91\u8f66\u3001\u5b66\u4e60\u4e00\u95e8\u624b\u827a\u3001\u5b66\u4e60\u4e0e\u4eba\u76f8\u5904\u3002\u4f46\u6211\u4eec\u662f\u5426\u66fe\u9759\u5fc3\u6df1\u601d&#xff0c;\u8fd9\u4e2a\u8fc7\u7a0b\u7684\u672c\u8d28\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u4ece\u4fe1\u606f\u8bba\u7684\u89d2\u5ea6\u770b&#xff0c;\u5b66\u4e60\u662f\u4e00\u4e2a\u7cfb\u7edf&#xff08;\u5982\u4eba\u7c7b\u5927\u8111&#xff09;\u901a\u8fc7\u4e0e\u73af\u5883\u7684\u4ea4\u4e92&#xff0c;\u83b7\u53d6\u4fe1\u606f\u5e76\u4f18\u5316\u81ea\u8eab\u5185\u90e8\u6a21\u578b&#xff0c;\u4ee5\u671f\u5728\u672a\u6765\u66f4\u597d\u5730\u5b8c\u6210\u7279\u5b9a\u4efb\u52a1\u6216\u9002\u5e94\u73af\u5883\u7684\u8fc7\u7a0b\u3002\u00a0\u8fd9\u4e2a\u5b9a\u4e49\u4e2d\u5305\u542b\u51e0\u4e2a\u5173\u952e\u8981\u7d20&#xff1a;\u7cfb\u7edf\u3001\u73af\u5883\u3001\u4ea4\u4e92\u3001\u4fe1\u606f\u3001\u6a21\u578b\u4f18\u5316\u3001\u672a\u6765\u4efb\u52a1\u3002\u8fd9\u6070\u6070\u6784\u6210\u4e86\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u6846\u67b6\u3002\u673a\u5668&#xff0c;\u4f5c\u4e3a\u6211\u4eec\u521b\u9020\u7684\u201c\u7cfb\u7edf\u201d&#xff0c;\u901a\u8fc7\u6211\u4eec\u63d0\u4f9b\u7684\u201c\u6570\u636e\u201d&#xff08;\u6e90\u4e8e\u73af\u5883\u7684\u4fe1\u606f&#xff09;&#xff0c;\u8fdb\u884c\u201c\u8bad\u7ec3\u201d&#xff08;\u4ea4\u4e92\u4e0e\u6a21\u578b\u4f18\u5316&#xff09;&#xff0c;\u6700\u7ec8\u76ee\u7684\u662f\u4e3a\u4e86\u5728\u65b0\u7684\u3001\u672a\u89c1\u8fc7\u7684\u6570\u636e\u4e0a\u505a\u51fa\u7cbe\u51c6\u7684\u201c\u9884\u6d4b\u201d\u6216\u201c\u51b3\u7b56\u201d&#xff08;\u5b8c\u6210\u672a\u6765\u4efb\u52a1&#xff09;\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u7406\u89e3\u673a\u5668\u5b66\u4e60\u7684\u6700\u4f73\u9014\u5f84&#xff0c;\u4fbf\u662f\u56de\u6eaf\u6211\u4eec\u81ea\u8eab\u6700\u719f\u6089\u3001\u6700\u672c\u6e90\u7684\u5b66\u4e60\u8fc7\u7a0b\u3002<\/p>\n<h5>1.1.1 \u5a74\u513f\u5982\u4f55\u8ba4\u8bc6\u4e16\u754c&#xff1f;\u2014\u2014\u7c7b\u6bd4\u76d1\u7763\u3001\u65e0\u76d1\u7763\u3001\u5f3a\u5316\u5b66\u4e60<\/h5>\n<p>\u60f3\u8c61\u4e00\u4e2a\u5a74\u513f&#xff0c;\u5979\/\u4ed6\u8ba4\u8bc6\u4e16\u754c\u7684\u8fc7\u7a0b&#xff0c;\u6b63\u662f\u673a\u5668\u5b66\u4e60\u4e09\u5927\u8303\u5f0f\u6700\u751f\u52a8\u3001\u6700\u672c\u6e90\u7684\u4f53\u73b0\u3002<\/p>\n<p>1. \u76d1\u7763\u5b66\u4e60&#xff08;Supervised Learning&#xff09;&#xff1a;\u6709\u201c\u6807\u7b7e\u201d\u7684\u6559\u5bfc<\/p>\n<p>\u5f53\u7236\u6bcd\u6307\u7740\u4e00\u4e2a\u7ea2\u8272\u7684\u3001\u5706\u5706\u7684\u7269\u4f53&#xff0c;\u5bf9\u5a74\u513f\u8bf4&#xff1a;\u201c\u5b9d\u5b9d&#xff0c;\u8fd9\u662f\u2018\u82f9\u679c\u2019\u3002\u201d\u7136\u540e\u53c8\u6307\u7740\u4e00\u4e2a\u9ec4\u8272\u7684\u3001\u5f2f\u5f2f\u7684\u7269\u4f53\u8bf4&#xff1a;\u201c\u8fd9\u662f\u2018\u9999\u8549\u2019\u3002\u201d\u8fd9\u4e2a\u8fc7\u7a0b\u5728\u4e0d\u65ad\u91cd\u590d\u3002\u6bcf\u4e00\u6b21&#xff0c;\u5a74\u513f\u90fd\u63a5\u6536\u5230\u4e24\u6837\u4e1c\u897f&#xff1a;\u4e00\u4e2a\u611f\u5b98\u8f93\u5165&#xff08;\u7269\u4f53\u7684\u5f62\u72b6\u3001\u989c\u8272\u3001\u6c14\u5473&#xff09;\u548c\u4e00\u4e2a\u660e\u786e\u7684\u6807\u7b7e&#xff08;\u5b83\u7684\u540d\u5b57\u53eb\u201c\u82f9\u679c\u201d&#xff09;\u3002<\/p>\n<ul>\n<li>\u611f\u5b98\u8f93\u5165&#xff0c;\u5728\u673a\u5668\u5b66\u4e60\u4e2d\u88ab\u79f0\u4e3a\u201c\u7279\u5f81&#xff08;Features&#xff09;\u201d\u3002<\/li>\n<li>\u660e\u786e\u7684\u6807\u7b7e&#xff0c;\u88ab\u79f0\u4e3a\u201c\u6807\u7b7e&#xff08;Label&#xff09;\u201d\u6216\u201c\u76ee\u6807&#xff08;Target&#xff09;\u201d\u3002<\/li>\n<\/ul>\n<p>\u5a74\u513f\u7684\u5927\u8111\u5728\u505a\u4ec0\u4e48&#xff1f;\u5b83\u5728\u52aa\u529b\u5bfb\u627e\u201c\u7279\u5f81\u201d\u4e0e\u201c\u6807\u7b7e\u201d\u4e4b\u95f4\u7684\u5173\u8054\u3002\u5b83\u4f1a\u9010\u6e10\u5f52\u7eb3\u51fa&#xff1a;\u201c\u54e6&#xff0c;\u7ea2\u8272\u7684\u3001\u5706\u5f62\u7684\u3001\u6709\u7279\u5b9a\u9999\u5473\u7684&#xff0c;\u5f88\u53ef\u80fd\u5c31\u662f\u2018\u82f9\u679c\u2019\u3002\u201d\u5f53\u7236\u6bcd\u4e0b\u6b21\u62ff\u51fa\u4e00\u4e2a\u65b0\u7684\u3001\u5979\u4ece\u672a\u89c1\u8fc7\u7684\u82f9\u679c\u65f6&#xff0c;\u5979\u80fd\u591f\u6839\u636e\u5df2\u7ecf\u5efa\u7acb\u7684\u5185\u90e8\u6a21\u578b&#xff0c;\u6b63\u786e\u5730\u8bc6\u522b\u51fa&#xff1a;\u201c\u82f9\u679c&#xff01;\u201d<\/p>\n<p>\u8fd9\u5c31\u662f\u76d1\u7763\u5b66\u4e60\u7684\u672c\u8d28\u3002\u6211\u4eec\u4e3a\u673a\u5668\u63d0\u4f9b\u4e00\u5927\u6279\u5df2\u7ecf\u201c\u6807\u6ce8\u597d\u201d\u7684\u6570\u636e&#xff08;\u4f8b\u5982&#xff0c;\u4e00\u5806\u90ae\u4ef6&#xff0c;\u6bcf\u5c01\u90fd\u6807\u597d\u4e86\u201c\u662f\u5783\u573e\u90ae\u4ef6\u201d\u6216\u201c\u4e0d\u662f\u5783\u573e\u90ae\u4ef6\u201d&#xff1b;\u4e00\u5806\u623f\u4ea7\u6570\u636e&#xff0c;\u6bcf\u5957\u90fd\u6807\u597d\u4e86\u201c\u6700\u7ec8\u6210\u4ea4\u4ef7\u683c\u201d&#xff09;&#xff0c;\u7136\u540e\u8ba9\u7b97\u6cd5\u53bb\u5bfb\u627e\u7279\u5f81\u548c\u6807\u7b7e\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002\u7b97\u6cd5\u5b66\u6210\u4e4b\u540e&#xff0c;\u6211\u4eec\u7ed9\u5b83\u4e00\u5c01\u65b0\u7684\u90ae\u4ef6&#xff0c;\u5b83\u5c31\u80fd\u5224\u65ad\u662f\u5426\u4e3a\u5783\u573e\u90ae\u4ef6&#xff1b;\u7ed9\u5b83\u4e00\u5957\u65b0\u7684\u623f\u4ea7\u7279\u5f81&#xff0c;\u5b83\u5c31\u80fd\u9884\u6d4b\u5176\u53ef\u80fd\u7684\u4ef7\u683c\u3002<\/p>\n<p>\u76d1\u7763\u5b66\u4e60\u7684\u6838\u5fc3\u5728\u4e8e\u201c\u6709\u7b54\u6848\u7684\u8f93\u5165\u201d\u3002\u00a0\u5b83\u4e3b\u8981\u89e3\u51b3\u4e24\u7c7b\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u5206\u7c7b&#xff08;Classification&#xff09;&#xff1a;\u9884\u6d4b\u4e00\u4e2a\u79bb\u6563\u7684\u6807\u7b7e\u3002\u4f8b\u5982&#xff0c;\u5224\u65ad\u56fe\u7247\u662f\u732b\u8fd8\u662f\u72d7&#xff0c;\u5224\u65ad\u90ae\u4ef6\u662f\u5426\u4e3a\u5783\u573e\u90ae\u4ef6\u3002\u5a74\u513f\u8ba4\u8bc6\u6c34\u679c&#xff0c;\u5c31\u662f\u4e00\u4e2a\u5206\u7c7b\u4efb\u52a1\u3002<\/li>\n<li>\u56de\u5f52&#xff08;Regression&#xff09;&#xff1a;\u9884\u6d4b\u4e00\u4e2a\u8fde\u7eed\u7684\u6570\u503c\u3002\u4f8b\u5982&#xff0c;\u9884\u6d4b\u660e\u5929\u7684\u6c14\u6e29&#xff0c;\u9884\u6d4b\u623f\u5c4b\u7684\u4ef7\u683c\u3002<\/li>\n<\/ul>\n<p>2. \u65e0\u76d1\u7763\u5b66\u4e60&#xff08;Unsupervised Learning&#xff09;&#xff1a;\u65e0\u8a00\u7684\u63a2\u7d22<\/p>\n<p>\u73b0\u5728&#xff0c;\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u6ca1\u6709\u4eba\u660e\u786e\u544a\u8bc9\u5a74\u513f\u6bcf\u6837\u4e1c\u897f\u7684\u540d\u5b57\u3002\u684c\u4e0a\u653e\u7740\u4e00\u5806\u73a9\u5177&#xff1a;\u4e00\u4e9b\u662f\u79ef\u6728&#xff08;\u65b9\u7684\u3001\u786c\u7684\u3001\u5f69\u8272\u7684&#xff09;&#xff0c;\u4e00\u4e9b\u662f\u6bdb\u7ed2\u5a03\u5a03&#xff08;\u8f6f\u7684\u3001\u5f62\u72b6\u4e0d\u89c4\u5219\u7684&#xff09;&#xff0c;\u8fd8\u6709\u4e00\u4e9b\u662f\u5851\u6599\u5c0f\u7403&#xff08;\u5706\u7684\u3001\u5149\u6ed1\u7684&#xff09;\u3002<\/p>\n<p>\u5a74\u513f\u4f1a\u505a\u4ec0\u4e48&#xff1f;\u5979\u4f1a\u81ea\u5df1\u53bb\u63a2\u7d22\u3002\u5979\u4f1a\u53d1\u73b0&#xff0c;\u8fd9\u4e9b\u4e1c\u897f\u53ef\u4ee5\u5206\u6210\u51e0\u5806\u3002\u5979\u53ef\u80fd\u4f1a\u628a\u6240\u6709\u786c\u90a6\u90a6\u3001\u6709\u68f1\u6709\u89d2\u7684\u4e1c\u897f\u653e\u5728\u4e00\u8d77&#xff0c;\u628a\u6240\u6709\u8f6f\u7ef5\u7ef5\u7684\u4e1c\u897f\u653e\u5728\u53e6\u4e00\u8fb9&#xff0c;\u628a\u6240\u6709\u80fd\u6eda\u6765\u6eda\u53bb\u7684\u4e1c\u897f\u5f52\u4e3a\u4e00\u7c7b\u3002\u5979\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e9b\u7c7b\u522b\u53eb\u201c\u79ef\u6728\u201d\u3001\u201c\u5a03\u5a03\u201d\u6216\u201c\u7403\u201d&#xff0c;\u4f46\u5979\u901a\u8fc7\u89c2\u5bdf\u7269\u4f53\u81ea\u8eab\u7684\u7279\u6027&#xff0c;\u81ea\u53d1\u5730\u5b8c\u6210\u4e86\u201c\u805a\u7c7b&#xff08;Clustering&#xff09;\u201d\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u7cbe\u9ad3\u3002\u6211\u4eec\u53ea\u7ed9\u673a\u5668\u4e00\u5806\u6570\u636e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u6807\u7b7e&#xff0c;\u7136\u540e\u8ba9\u7b97\u6cd5\u81ea\u5df1\u53bb\u53d1\u73b0\u6570\u636e\u4e2d\u9690\u85cf\u7684\u7ed3\u6784\u3001\u6a21\u5f0f\u6216\u5173\u7cfb\u3002<\/p>\n<p>\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u6838\u5fc3\u5728\u4e8e\u201c\u53d1\u73b0\u5185\u5728\u7ed3\u6784\u201d\u3002\u00a0\u5b83\u7684\u5178\u578b\u5e94\u7528\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u805a\u7c7b&#xff08;Clustering&#xff09;&#xff1a;\u5c06\u76f8\u4f3c\u7684\u6570\u636e\u70b9\u5206\u7ec4\u3002\u4f8b\u5982&#xff0c;\u6839\u636e\u7528\u6237\u7684\u8d2d\u4e70\u884c\u4e3a&#xff0c;\u5c06\u4ed6\u4eec\u5212\u5206\u4e3a\u4e0d\u540c\u7684\u5ba2\u6237\u7fa4\u4f53&#xff0c;\u4ee5\u4fbf\u8fdb\u884c\u7cbe\u51c6\u8425\u9500\u3002<\/li>\n<li>\u964d\u7ef4&#xff08;Dimensionality Reduction&#xff09;&#xff1a;\u5728\u4fdd\u7559\u5927\u90e8\u5206\u4fe1\u606f\u7684\u524d\u63d0\u4e0b&#xff0c;\u51cf\u5c11\u6570\u636e\u7684\u7279\u5f81\u6570\u91cf\u3002\u597d\u6bd4\u6211\u4eec\u63cf\u8ff0\u4e00\u4e2a\u4eba&#xff0c;\u4e0e\u5176\u7f57\u5217\u4e0a\u767e\u4e2a\u7ec6\u8282&#xff0c;\u4e0d\u5982\u6293\u4f4f\u201c\u9ad8\u3001\u7626\u3001\u6234\u773c\u955c\u201d\u8fd9\u51e0\u4e2a\u6838\u5fc3\u7279\u5f81&#xff0c;\u8fd9\u4fbf\u662f\u964d\u7ef4\u7684\u601d\u60f3\u3002<\/li>\n<li>\u5173\u8054\u89c4\u5219\u6316\u6398&#xff08;Association Rule Mining&#xff09;&#xff1a;\u53d1\u73b0\u6570\u636e\u9879\u4e4b\u95f4\u7684\u6709\u8da3\u5173\u7cfb\u3002\u7ecf\u5178\u7684\u201c\u5564\u9152\u4e0e\u5c3f\u5e03\u201d\u7684\u6545\u4e8b&#xff0c;\u5c31\u662f\u901a\u8fc7\u6316\u6398\u8d2d\u7269\u7bee\u6570\u636e\u53d1\u73b0&#xff0c;\u8d2d\u4e70\u5c3f\u5e03\u7684\u987e\u5ba2\u5f88\u53ef\u80fd\u540c\u65f6\u8d2d\u4e70\u5564\u9152\u3002<\/li>\n<\/ul>\n<p>3. \u5f3a\u5316\u5b66\u4e60&#xff08;Reinforcement Learning&#xff09;&#xff1a;\u8bd5\u9519\u4e0e\u5956\u60e9<\/p>\n<p>\u518d\u6765\u770b\u5a74\u513f\u5b66\u4e60\u8d70\u8def\u7684\u8fc7\u7a0b\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u6ca1\u6709\u4eba\u80fd\u7ed9\u5979\u4e00\u4e2a\u660e\u786e\u7684\u201c\u6807\u7b7e\u201d\u3002\u6ca1\u6709\u4e00\u4e2a\u201c\u6b63\u786e\u201d\u7684\u59ff\u52bf\u53ef\u4ee5\u4e00\u6b65\u5230\u4f4d\u5730\u6559\u4f1a\u5979\u3002<\/p>\n<p>\u5979\u53ea\u80fd\u81ea\u5df1\u5c1d\u8bd5\u3002\u5979\u8bd5\u7740\u6643\u6643\u60a0\u60a0\u5730\u7ad9\u8d77\u6765&#xff0c;\u8fc8\u51fa\u4e00\u6b65&#xff0c;\u7136\u540e\u201c\u556a\u201d\u5730\u6454\u5012\u4e86\u3002\u8fd9\u6b21\u5c1d\u8bd5\u7684\u7ed3\u679c\u662f\u201c\u6454\u5012\u201d&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u8d1f\u5411\u7684\u53cd\u9988&#xff08;\u60e9\u7f5a&#xff09;\u3002\u5979\u7684\u5927\u8111\u63a5\u6536\u5230\u8fd9\u4e2a\u4fe1\u53f7&#xff1a;\u201c\u521a\u624d\u90a3\u6837\u505a&#xff0c;\u7ed3\u679c\u4e0d\u597d\u3002\u201d \u4e8e\u662f&#xff0c;\u5979\u4e0b\u6b21\u4f1a\u5fae\u8c03\u81ea\u5df1\u7684\u7b56\u7565&#xff0c;\u53ef\u80fd\u8eab\u4f53\u66f4\u524d\u503e\u4e00\u70b9&#xff0c;\u6216\u8005\u817f\u8fc8\u5f97\u5c0f\u4e00\u70b9\u3002\u67d0\u4e00\u6b21&#xff0c;\u5979\u6210\u529f\u5730\u8d70\u4e86\u4e24\u6b65\u800c\u6ca1\u6709\u6454\u5012&#xff0c;\u5185\u5fc3\u5145\u6ee1\u4e86\u559c\u60a6\u548c\u6210\u5c31\u611f\u3002\u8fd9\u662f\u4e00\u4e2a\u6b63\u5411\u7684\u53cd\u9988&#xff08;\u5956\u52b1&#xff09;\u3002\u5979\u7684\u5927\u8111\u4f1a\u8bb0\u4f4f&#xff1a;\u201c\u8fd9\u6837\u505a&#xff0c;\u7ed3\u679c\u662f\u597d\u7684&#xff01;\u201d<\/p>\n<p>\u901a\u8fc7\u65e0\u6570\u6b21\u7684\u201c\u5c1d\u8bd5-\u53cd\u9988-\u8c03\u6574\u7b56\u7565\u201d\u5faa\u73af&#xff0c;\u5979\u6700\u7ec8\u5b66\u4f1a\u4e86\u5982\u4f55\u5e73\u7a33\u5730\u884c\u8d70\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d&#xff0c;\u5979\u4e0d\u662f\u88ab\u52a8\u5730\u63a5\u6536\u77e5\u8bc6&#xff0c;\u800c\u662f\u4f5c\u4e3a\u4e00\u4e2a\u610f\u8bc6\u4f53\/\u667a\u80fd\u4f53&#xff0c;\u5728\u4e0e\u73af\u5883\u7684\u4e92\u52a8\u4e2d&#xff0c;\u901a\u8fc7\u8bd5\u9519&#xff0c;\u6765\u5b66\u4e60\u4e00\u5957\u80fd\u8ba9\u81ea\u5df1\u83b7\u5f97\u6700\u5927\u7d2f\u79ef\u5956\u52b1\u7684\u7b56\u7565\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u5f3a\u5316\u5b66\u4e60\u3002\u5b83\u4e0e\u76d1\u7763\u5b66\u4e60\u7684\u5173\u952e\u533a\u522b\u5728\u4e8e&#xff0c;\u53cd\u9988\u4fe1\u53f7\u4e0d\u662f\u4e00\u4e2a\u6b63\u786e\u7684\u201c\u6807\u7b7e\u201d&#xff0c;\u800c\u662f\u4e00\u4e2a\u8bc4\u4ef7\u6027\u7684\u201c\u5956\u52b1\u201d\u6216\u201c\u60e9\u7f5a\u201d\u4fe1\u53f7&#xff0c;\u5e76\u4e14\u8fd9\u4e2a\u4fe1\u53f7\u5f80\u5f80\u662f\u5ef6\u8fdf\u7684&#xff08;\u6454\u5012\u662f\u8fc8\u51fa\u90a3\u4e00\u6b65\u4e4b\u540e\u7684\u7ed3\u679c&#xff09;\u3002<\/p>\n<p>\u5f3a\u5316\u5b66\u4e60\u7684\u6838\u5fc3\u5728\u4e8e\u201c\u901a\u8fc7\u4e0e\u73af\u5883\u4ea4\u4e92\u5b66\u4e60\u6700\u4f18\u7b56\u7565\u201d\u3002\u00a0\u5b83\u7684\u5e94\u7528\u573a\u666f\u6781\u5177\u9b45\u529b&#xff1a;<\/p>\n<ul>\n<li>\u6e38\u620fAI&#xff1a;AlphaGo\u51fb\u8d25\u4eba\u7c7b\u9876\u5c16\u68cb\u624b&#xff0c;\u5176\u6838\u5fc3\u5c31\u662f\u5f3a\u5316\u5b66\u4e60\u3002\u5b83\u901a\u8fc7\u81ea\u6211\u5bf9\u5f08&#xff0c;\u4e0d\u65ad\u63a2\u7d22\u80fd\u8d62\u5f97\u68cb\u5c40\u7684\u7b56\u7565\u3002<\/li>\n<li>\u673a\u5668\u4eba\u63a7\u5236&#xff1a;\u63a7\u5236\u673a\u68b0\u81c2\u6293\u53d6\u7269\u4f53&#xff0c;\u8ba9\u65e0\u4eba\u673a\u81ea\u4e3b\u98de\u884c\u3002<\/li>\n<li>\u8d44\u6e90\u8c03\u5ea6&#xff1a;\u4f18\u5316\u6570\u636e\u4e2d\u5fc3\u7684\u80fd\u6e90\u6d88\u8017&#xff0c;\u667a\u80fd\u8c03\u5ea6\u57ce\u5e02\u4ea4\u901a\u4fe1\u53f7\u706f\u3002<\/li>\n<\/ul>\n<p>\u5c0f\u7ed3&#xff1a;\u4e09\u79cd\u5b66\u4e60\u8303\u5f0f\u7684\u5173\u7cfb<\/p>\n<table>\n<tr>\n<p>\u5b66\u4e60\u8303\u5f0f<\/p>\n<p>\u6570\u636e\u5f62\u5f0f<\/p>\n<p>\u5b66\u4e60\u76ee\u6807<\/p>\n<p>\u6838\u5fc3\u601d\u60f3<\/p>\n<p>\u4eba\u7c7b\u7c7b\u6bd4<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u76d1\u7763\u5b66\u4e60<\/p>\n<\/td>\n<td>\n<p>(\u7279\u5f81, \u6807\u7b7e)<\/p>\n<\/td>\n<td>\n<p>\u5b66\u4e60\u4ece\u7279\u5f81\u5230\u6807\u7b7e\u7684\u6620\u5c04<\/p>\n<\/td>\n<td>\n<p>\u6709\u5e08\u6307\u5bfc&#xff0c;\u6a21\u4eff\u8303\u4f8b<\/p>\n<\/td>\n<td>\n<p>\u7236\u6bcd\u6559\u5a74\u513f\u8bc6\u7269<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u65e0\u76d1\u7763\u5b66\u4e60<\/p>\n<\/td>\n<td>\n<p>\u53ea\u6709\u7279\u5f81<\/p>\n<\/td>\n<td>\n<p>\u53d1\u73b0\u6570\u636e\u5185\u5728\u7684\u7ed3\u6784\u4e0e\u6a21\u5f0f<\/p>\n<\/td>\n<td>\n<p>\u65e0\u5e08\u81ea\u901a&#xff0c;\u5f52\u7eb3\u603b\u7ed3<\/p>\n<\/td>\n<td>\n<p>\u5a74\u513f\u81ea\u5df1\u7ed9\u73a9\u5177\u5206\u7c7b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5f3a\u5316\u5b66\u4e60<\/p>\n<\/td>\n<td>\n<p>(\u72b6\u6001, \u52a8\u4f5c, \u5956\u52b1)<\/p>\n<\/td>\n<td>\n<p>\u5b66\u4e60\u5728\u73af\u5883\u4e2d\u6700\u5927\u5316\u5956\u52b1\u7684\u7b56\u7565<\/p>\n<\/td>\n<td>\n<p>\u5b9e\u8df5\u51fa\u771f\u77e5&#xff0c;\u8d8b\u5229\u907f\u5bb3<\/p>\n<\/td>\n<td>\n<p>\u5a74\u513f\u5b66\u8d70\u8def<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e09\u79cd\u8303\u5f0f\u5e76\u975e\u6cfe\u6e2d\u5206\u660e&#xff0c;\u73b0\u5b9e\u4e16\u754c\u7684\u95ee\u9898\u5f80\u5f80\u9700\u8981\u878d\u5408\u591a\u79cd\u601d\u60f3\u3002\u4f8b\u5982&#xff0c;\u534a\u76d1\u7763\u5b66\u4e60&#xff08;Semi-supervised Learning&#xff09;\u5c31\u7ed3\u5408\u4e86\u76d1\u7763\u548c\u65e0\u76d1\u7763\u5b66\u4e60&#xff0c;\u5229\u7528\u5c11\u91cf\u6709\u6807\u7b7e\u6570\u636e\u548c\u5927\u91cf\u65e0\u6807\u7b7e\u6570\u636e\u8fdb\u884c\u5b66\u4e60\u3002\u4f46\u7406\u89e3\u8fd9\u4e09\u5927\u652f\u67f1&#xff0c;\u662f\u7406\u89e3\u6574\u4e2a\u673a\u5668\u5b66\u4e60\u5927\u53a6\u7684\u57fa\u77f3\u3002<\/p>\n<h5>1.1.2 \u9053\u6cd5\u81ea\u7136&#xff1a;\u4ece\u81ea\u7136\u754c\u7684\u6f14\u5316\u770b\u5b66\u4e60\u7684\u672c\u8d28<\/h5>\n<p>\u5982\u679c\u8bf4\u5a74\u513f\u5b66\u6b65\u662f\u201c\u4e2a\u4f53\u5b66\u4e60\u201d\u7684\u7f29\u5f71&#xff0c;\u90a3\u4e48\u5730\u7403\u751f\u547d\u957f\u8fbe\u6570\u5341\u4ebf\u5e74\u7684\u6f14\u5316\u53f2&#xff0c;\u5219\u662f\u201c\u7fa4\u4f53\u5b66\u4e60\u201d\u6700\u5b8f\u4f1f\u3001\u6700\u6df1\u523b\u7684\u7bc7\u7ae0\u3002\u300a\u9053\u5fb7\u7ecf\u300b\u6709\u4e91&#xff1a;\u201c\u4eba\u6cd5\u5730&#xff0c;\u5730\u6cd5\u5929&#xff0c;\u5929\u6cd5\u9053&#xff0c;\u9053\u6cd5\u81ea\u7136\u3002\u201d \u673a\u5668\u5b66\u4e60\u7684\u8bb8\u591a\u6df1\u523b\u601d\u60f3&#xff0c;\u5c24\u5176\u662f\u90a3\u4e9b\u88ab\u79f0\u4e3a\u201c\u9057\u4f20\u7b97\u6cd5\u201d\u3001\u201c\u8fdb\u5316\u7b56\u7565\u201d\u7684\u5206\u652f&#xff0c;\u5176\u7075\u611f\u6b63\u662f\u6e90\u4e8e\u5bf9\u81ea\u7136\u6f14\u5316\u8fd9\u4e00\u201c\u7ec8\u6781\u5b66\u4e60\u8fc7\u7a0b\u201d\u7684\u6a21\u62df\u3002<\/p>\n<p>1. \u9002\u5e94\u5ea6\u51fd\u6570&#xff08;Fitness Function&#xff09;&#xff1a;\u73af\u5883\u7684\u9009\u62e9\u538b\u529b<\/p>\n<p>\u5728\u81ea\u7136\u754c&#xff0c;\u4e0d\u5b58\u5728\u4e00\u4e2a\u7edd\u5bf9\u7684\u201c\u6700\u4f18\u201d\u751f\u7269\u3002\u5728\u51b0\u6cb3\u4e16\u7eaa&#xff0c;\u957f\u6bdb\u8c61\u7684\u539a\u76ae\u6bdb\u662f\u5de8\u5927\u7684\u751f\u5b58\u4f18\u52bf&#xff1b;\u800c\u5f53\u6c14\u5019\u53d8\u6696&#xff0c;\u8fd9\u8eab\u76ae\u6bdb\u53cd\u800c\u6210\u4e86\u7d2f\u8d58\u3002\u73af\u5883&#xff0c;\u5c31\u662f\u90a3\u4e2a\u6700\u7ec8\u7684\u201c\u88c1\u5224\u201d&#xff0c;\u5b83\u901a\u8fc7\u751f\u5b58\u548c\u7e41\u884d\u7684\u538b\u529b&#xff0c;\u6765\u201c\u8bc4\u4f30\u201d\u6bcf\u4e00\u4e2a\u751f\u7269\u4f53\u5bf9\u5176\u7684\u9002\u5e94\u7a0b\u5ea6\u3002\u8fd9\u79cd\u9002\u5e94\u7a0b\u5ea6&#xff0c;\u5728\u8fdb\u5316\u8ba1\u7b97\u4e2d\u88ab\u79f0\u4e3a\u9002\u5e94\u5ea6&#xff08;Fitness&#xff09;\u3002\u4e00\u4e2a\u7269\u79cd\u80fd\u5426\u5c06\u57fa\u56e0\u4f20\u9012\u4e0b\u53bb&#xff0c;\u53d6\u51b3\u4e8e\u5176\u9002\u5e94\u5ea6\u7684\u9ad8\u4f4e\u3002<\/p>\n<p>\u8fd9\u4e0e\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u635f\u5931\u51fd\u6570&#xff08;Loss Function&#xff09;\u6216\u76ee\u6807\u51fd\u6570&#xff08;Objective Function&#xff09;\u5f02\u66f2\u540c\u5de5\u3002\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u8bc4\u4f30\u6211\u4eec\u7684\u6a21\u578b\u201c\u597d\u4e0d\u597d\u201d\u3002\u4f8b\u5982&#xff0c;\u5728\u9884\u6d4b\u623f\u4ef7\u65f6&#xff0c;\u635f\u5931\u51fd\u6570\u53ef\u80fd\u5c31\u662f\u201c\u9884\u6d4b\u4ef7\u4e0e\u771f\u5b9e\u4ef7\u7684\u5dee\u8ddd\u201d&#xff0c;\u5dee\u8ddd\u8d8a\u5c0f&#xff0c;\u6a21\u578b\u7684\u201c\u9002\u5e94\u5ea6\u201d\u5c31\u8d8a\u9ad8\u3002\u6574\u4e2a\u6a21\u578b\u8bad\u7ec3\u7684\u8fc7\u7a0b&#xff0c;\u5c31\u662f\u4e0d\u65ad\u8c03\u6574\u53c2\u6570&#xff0c;\u4ee5\u671f\u5728\u635f\u5931\u51fd\u6570\u4e0a\u53d6\u5f97\u6700\u4f18\u503c\u7684\u8fc7\u7a0b&#xff0c;\u6b63\u5982\u751f\u7269\u6f14\u5316\u662f\u5728\u73af\u5883\u7684\u9002\u5e94\u5ea6\u51fd\u6570\u4e0b&#xff0c;\u4e0d\u65ad\u201c\u4f18\u5316\u201d\u81ea\u8eab\u57fa\u56e0\u7684\u8fc7\u7a0b\u3002<\/p>\n<p>2. \u9057\u4f20\u4e0e\u53d8\u5f02&#xff08;Inheritance and Mutation&#xff09;&#xff1a;\u63a2\u7d22\u4e0e\u5229\u7528\u7684\u5e73\u8861<\/p>\n<p>\u6f14\u5316\u6709\u4e24\u4e2a\u6838\u5fc3\u9a71\u52a8\u529b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9057\u4f20&#xff08;Inheritance&#xff09;&#xff1a;\u7236\u6bcd\u7684\u4f18\u79c0\u6027\u72b6&#xff08;\u9ad8\u9002\u5e94\u5ea6\u7684\u57fa\u56e0&#xff09;\u901a\u8fc7\u7e41\u6b96\u4f20\u9012\u7ed9\u540e\u4ee3\u3002\u8fd9\u4fdd\u8bc1\u4e86\u5df2\u7ecf\u83b7\u5f97\u7684\u6210\u529f\u7ecf\u9a8c\u4e0d\u4f1a\u8f7b\u6613\u4e22\u5931\u3002\u5728\u673a\u5668\u5b66\u4e60\u4e2d&#xff0c;\u8fd9\u7c7b\u4f3c\u4e8e\u4e00\u79cd\u201c\u5229\u7528&#xff08;Exploitation&#xff09;\u201d\u7b56\u7565\u2014\u2014\u6211\u4eec\u503e\u5411\u4e8e\u5728\u5f53\u524d\u5df2\u77e5\u6548\u679c\u597d\u7684\u6a21\u578b\u53c2\u6570\u9644\u8fd1\u8fdb\u884c\u5fae\u8c03&#xff0c;\u5e0c\u671b\u80fd\u83b7\u5f97\u66f4\u597d\u7684\u7ed3\u679c\u3002<\/p>\n<\/li>\n<li>\n<p>\u53d8\u5f02&#xff08;Mutation&#xff09;&#xff1a;\u57fa\u56e0\u5728\u590d\u5236\u8fc7\u7a0b\u4e2d\u4f1a\u53d1\u751f\u968f\u673a\u7684\u3001\u5fae\u5c0f\u7684\u9519\u8bef&#xff0c;\u5373\u57fa\u56e0\u7a81\u53d8\u3002\u7edd\u5927\u591a\u6570\u7a81\u53d8\u662f\u6709\u5bb3\u6216\u65e0\u610f\u4e49\u7684&#xff0c;\u4f46\u6781\u5c11\u6570\u7a81\u53d8\u53ef\u80fd\u4f1a\u5e26\u6765\u610f\u60f3\u4e0d\u5230\u7684\u751f\u5b58\u4f18\u52bf&#xff08;\u4f8b\u5982&#xff0c;\u67d0\u79cd\u86fe\u5b50\u4ea7\u751f\u4e86\u66f4\u63a5\u8fd1\u6811\u76ae\u7684\u4fdd\u62a4\u8272&#xff09;\u3002\u8fd9\u79cd\u4e0d\u786e\u5b9a\u6027&#xff0c;\u4e3a\u7269\u79cd\u63d0\u4f9b\u4e86\u8df3\u51fa\u5c40\u90e8\u6700\u4f18\u3001\u9002\u5e94\u5168\u65b0\u73af\u5883\u7684\u53ef\u80fd\u6027\u3002\u8fd9\u6b63\u662f\u4e00\u79cd\u201c\u63a2\u7d22&#xff08;Exploration&#xff09;\u201d\u7b56\u7565\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u673a\u5668\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u5c24\u5176\u662f\u5f3a\u5316\u5b66\u4e60\u548c\u4f18\u5316\u7b97\u6cd5&#xff0c;\u4e5f\u5fc5\u987b\u7cbe\u5999\u5730\u5e73\u8861\u201c\u5229\u7528\u201d\u4e0e\u201c\u63a2\u7d22\u201d\u3002\u5982\u679c\u4e00\u4e2a\u7b97\u6cd5\u53ea\u61c2\u5f97\u201c\u5229\u7528\u201d&#xff0c;\u5b83\u53ef\u80fd\u4f1a\u5f88\u5feb\u9677\u5165\u4e00\u4e2a\u201c\u5c40\u90e8\u6700\u4f18\u89e3\u201d&#xff08;\u6bd4\u5982\u4e00\u4e2a\u53ea\u4f1a\u5728\u5bb6\u9644\u8fd1\u627e\u98df\u7269\u7684\u539f\u59cb\u4eba&#xff0c;\u4ed6\u53ef\u80fd\u6c38\u8fdc\u53d1\u73b0\u4e0d\u4e86\u8fdc\u5904\u98df\u7269\u66f4\u4e30\u5bcc\u7684\u5c71\u8c37&#xff09;\u3002\u5982\u679c\u4e00\u4e2a\u7b97\u6cd5\u53ea\u61c2\u5f97\u201c\u63a2\u7d22\u201d&#xff0c;\u5b83\u5c06\u6c38\u8fdc\u5728\u968f\u673a\u5c1d\u8bd5&#xff0c;\u65e0\u6cd5\u6536\u655b\u5230\u4e00\u4e2a\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002\u9057\u4f20\u7b97\u6cd5\u901a\u8fc7\u6a21\u62df\u4ea4\u53c9\u3001\u53d8\u5f02\u7b49\u64cd\u4f5c&#xff0c;\u5728\u89e3\u7a7a\u95f4\u4e2d\u8fdb\u884c\u9ad8\u6548\u7684\u63a2\u7d22\u548c\u5229\u7528&#xff0c;\u5bfb\u627e\u95ee\u9898\u7684\u6700\u4f18\u89e3\u3002<\/p>\n<p>3. \u7269\u7ade\u5929\u62e9&#xff08;Natural Selection&#xff09;&#xff1a;\u8fed\u4ee3\u4f18\u5316\u7684\u8fc7\u7a0b<\/p>\n<p>\u201c\u7269\u7ade\u5929\u62e9&#xff0c;\u9002\u8005\u751f\u5b58\u3002\u201d\u8fd9\u516b\u4e2a\u5b57\u7cbe\u51c6\u5730\u63cf\u8ff0\u4e86\u6f14\u5316\u7684\u6838\u5fc3\u673a\u5236\u3002\u6bcf\u4e00\u4ee3\u751f\u7269\u4e2d&#xff0c;\u9002\u5e94\u73af\u5883\u7684\u4e2a\u4f53\u6709\u66f4\u5927\u7684\u6982\u7387\u5b58\u6d3b\u4e0b\u6765\u5e76\u7e41\u6b96\u540e\u4ee3&#xff0c;\u4e0d\u9002\u5e94\u7684\u4e2a\u4f53\u5219\u88ab\u6dd8\u6c70\u3002\u7ecf\u8fc7\u4e00\u4ee3\u53c8\u4e00\u4ee3\u7684\u7b5b\u9009&#xff0c;\u6574\u4e2a\u79cd\u7fa4\u7684\u57fa\u56e0\u5e93\u4f1a\u671d\u7740\u8d8a\u6765\u8d8a\u9002\u5e94\u73af\u5883\u7684\u65b9\u5411\u201c\u8fdb\u5316\u201d\u3002<\/p>\n<p>\u8fd9\u4e0d\u5c31\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u8fed\u4ee3\u4f18\u5316&#xff08;Iterative Optimization&#xff09;\u7684\u8fc7\u7a0b\u5417&#xff1f;\u4ee5\u68af\u5ea6\u4e0b\u964d\u7b97\u6cd5\u4e3a\u4f8b&#xff0c;\u6211\u4eec\u4ece\u4e00\u7ec4\u968f\u673a\u7684\u521d\u59cb\u53c2\u6570\u5f00\u59cb&#xff0c;\u8ba1\u7b97\u5f53\u524d\u53c2\u6570\u4e0b\u7684\u201c\u635f\u5931\u201d&#xff08;\u4e0d\u9002\u5e94\u5ea6&#xff09;&#xff0c;\u7136\u540e\u6cbf\u7740\u80fd\u8ba9\u635f\u5931\u4e0b\u964d\u6700\u5feb\u7684\u65b9\u5411&#xff08;\u68af\u5ea6\u65b9\u5411&#xff09;\u5fae\u8c03\u53c2\u6570\u3002\u7136\u540e&#xff0c;\u5728\u65b0\u7684\u53c2\u6570\u4f4d\u7f6e\u4e0a&#xff0c;\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u4e00\u6b65\u4e00\u6b65&#xff0c;\u4e00\u6b21\u4e00\u6b21\u8fed\u4ee3&#xff0c;\u6a21\u578b\u53c2\u6570\u5c31\u50cf\u751f\u7269\u79cd\u7fa4\u7684\u57fa\u56e0\u4e00\u6837&#xff0c;\u88ab\u4e0d\u65ad\u201c\u9009\u62e9\u201d\u548c\u201c\u4f18\u5316\u201d&#xff0c;\u6700\u7ec8\u8fbe\u5230\u4e00\u4e2a\u635f\u5931\u6781\u5c0f&#xff08;\u9002\u5e94\u5ea6\u6781\u9ad8&#xff09;\u7684\u72b6\u6001\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5f53\u6211\u4eec\u601d\u8003\u673a\u5668\u5b66\u4e60\u65f6&#xff0c;\u4e0d\u59a8\u5c06\u89c6\u91ce\u62c9\u8fdc\u3002\u6211\u4eec\u6240\u505a\u7684&#xff0c;\u65e0\u975e\u662f\u501f\u9274\u4e86\u5b87\u5b99\u95f4\u6700\u53e4\u8001\u3001\u6700\u5f3a\u5927\u7684\u5b66\u4e60\u6cd5\u5219\u2014\u2014\u6f14\u5316\u3002\u6211\u4eec\u521b\u9020\u7684\u7b97\u6cd5&#xff0c;\u662f\u6211\u4eec\u5bf9\u201c\u9053\u6cd5\u81ea\u7136\u201d\u7684\u4e00\u6b21\u6b21\u7b28\u62d9\u800c\u53c8\u5145\u6ee1\u656c\u610f\u7684\u6a21\u4eff\u3002\u7406\u89e3\u4e86\u8fd9\u4e00\u70b9&#xff0c;\u6211\u4eec\u4fbf\u80fd\u4ee5\u66f4\u8c26\u5351\u3001\u66f4\u5b8f\u5927\u7684\u89c6\u89d2&#xff0c;\u770b\u5f85\u6211\u4eec\u5373\u5c06\u5b66\u4e60\u7684\u6bcf\u4e00\u4e2a\u6a21\u578b\u548c\u6280\u672f\u3002<\/p>\n<hr \/>\n<h4>1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f2<\/h4>\n<p>\u4efb\u4f55\u4e00\u95e8\u5b66\u79d1\u7684\u8bde\u751f&#xff0c;\u90fd\u4e0d\u662f\u4e00\u8e74\u800c\u5c31\u7684&#xff0c;\u5b83\u5fc5\u7136\u662f\u601d\u60f3\u7684\u6cb3\u6d41\u957f\u671f\u51b2\u5237\u3001\u79ef\u6dc0\u7684\u7ed3\u679c\u3002\u673a\u5668\u5b66\u4e60\u7684\u53d1\u5c55\u53f2&#xff0c;\u66f4\u662f\u4e00\u90e8\u4ea4\u7ec7\u7740\u6570\u5b66\u3001\u8ba1\u7b97\u673a\u79d1\u5b66\u3001\u795e\u7ecf\u79d1\u5b66\u3001\u54f2\u5b66\u4e43\u81f3\u8fd0\u7b79\u5b66\u7b49\u591a\u4e2a\u9886\u57df\u7684\u82f1\u96c4\u53f2\u8bd7\u3002\u4e86\u89e3\u8fd9\u6bb5\u5386\u53f2&#xff0c;\u80fd\u8ba9\u6211\u4eec\u660e\u767d\u4eca\u65e5\u7684\u6280\u672f\u4ece\u4f55\u800c\u6765&#xff0c;\u4e3a\u4f55\u5982\u6b64&#xff0c;\u4ee5\u53ca\u672a\u6765\u53ef\u80fd\u8d70\u5411\u4f55\u65b9\u3002<\/p>\n<h5>1.2.1 \u4ece\u56fe\u7075\u7684\u6784\u60f3\u5230\u4eca\u5929\u7684\u6df1\u5ea6\u5b66\u4e60&#xff1a;\u5173\u952e\u91cc\u7a0b\u7891<\/h5>\n<p>\u8fd9\u6bb5\u5386\u53f2\u72b9\u5982\u4e00\u6761\u5954\u817e\u7684\u6cb3\u6d41&#xff0c;\u6709\u6d93\u6d93\u7ec6\u6d41\u7684\u6e90\u5934&#xff0c;\u6709\u6ce2\u6f9c\u58ee\u9614\u7684\u8f6c\u6298&#xff0c;\u4e5f\u6709\u8fc7\u51b0\u5c01\u6f5c\u884c\u7684\u4f4e\u8c37\u3002<\/p>\n<p>\u6e90\u5934\u4e0e\u53e4\u5178\u65f6\u671f&#xff08;20\u4e16\u7eaa40-60\u5e74\u4ee3&#xff09;&#xff1a;\u601d\u60f3\u7684\u64ad\u79cd<\/p>\n<ul>\n<li>\n<p>1943\u5e74&#xff0c;\u9ea6\u5361\u6d1b\u514b-\u76ae\u8328\u795e\u7ecf\u5143&#xff08;MCP Neuron&#xff09;&#xff1a;\u795e\u7ecf\u751f\u7406\u5b66\u5bb6\u6c83\u4f26\u00b7\u9ea6\u5361\u6d1b\u514b\u548c\u903b\u8f91\u5b66\u5bb6\u6c83\u5c14\u7279\u00b7\u76ae\u8328&#xff0c;\u9996\u6b21\u63d0\u51fa\u4e86\u4e00\u4e2a\u5f62\u5f0f\u5316\u7684\u795e\u7ecf\u5143\u6570\u5b66\u6a21\u578b\u3002\u5b83\u63a5\u6536\u591a\u4e2a\u4e8c\u8fdb\u5236\u8f93\u5165&#xff0c;\u901a\u8fc7\u4e00\u4e2a\u9608\u503c\u51fd\u6570&#xff0c;\u4ea7\u751f\u4e00\u4e2a\u4e8c\u8fdb\u5236\u8f93\u51fa\u3002\u8fd9\u867d\u7136\u662f\u4e00\u4e2a\u6781\u5176\u7b80\u5316\u7684\u6a21\u578b&#xff0c;\u4f46\u5b83\u7b2c\u4e00\u6b21\u4ece\u8ba1\u7b97\u7684\u89d2\u5ea6&#xff0c;\u5efa\u7acb\u4e86\u8fde\u63a5\u751f\u7269\u5927\u8111\u4e0e\u673a\u5668\u667a\u80fd\u7684\u6865\u6881\u3002\u5b83\u662f\u795e\u7ecf\u7f51\u7edc\u5927\u53a6\u7684\u7b2c\u4e00\u5757\u7816\u3002<\/p>\n<\/li>\n<li>\n<p>1950\u5e74&#xff0c;\u56fe\u7075\u6d4b\u8bd5\u4e0e\u300a\u8ba1\u7b97\u673a\u5668\u4e0e\u667a\u80fd\u300b&#xff1a;\u827e\u4f26\u00b7\u56fe\u7075&#xff0c;\u8fd9\u4f4d\u8ba1\u7b97\u673a\u79d1\u5b66\u7684\u5960\u57fa\u4eba&#xff0c;\u5728\u4ed6\u5212\u65f6\u4ee3\u7684\u8bba\u6587\u4e2d&#xff0c;\u6ca1\u6709\u76f4\u63a5\u5b9a\u4e49\u201c\u673a\u5668\u80fd\u5426\u601d\u8003\u201d&#xff0c;\u800c\u662f\u63d0\u51fa\u4e86\u4e00\u4e2a\u53ef\u64cd\u4f5c\u7684\u6d4b\u8bd5\u2014\u2014\u201c\u6a21\u4eff\u6e38\u620f\u201d&#xff0c;\u5373\u540e\u4eba\u6240\u79f0\u7684\u201c\u56fe\u7075\u6d4b\u8bd5\u201d\u3002\u4ed6\u5c06\u7126\u70b9\u4ece\u54f2\u5b66\u7684\u601d\u8fa8\u8f6c\u5411\u4e86\u884c\u4e3a\u7684\u5224\u65ad&#xff0c;\u5e76\u9884\u8a00\u4e86\u201c\u5b66\u4e60\u673a\u5668\u201d\u7684\u53ef\u80fd\u6027\u3002\u8fd9\u7bc7\u6587\u7ae0&#xff0c;\u662f\u4eba\u5de5\u667a\u80fd\u9886\u57df\u7684\u601d\u60f3\u201c\u5f00\u5c71\u4e4b\u4f5c\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>1952\u5e74&#xff0c;\u4e9a\u745f\u00b7\u8428\u7f2a\u5c14\u7684\u8df3\u68cb\u7a0b\u5e8f&#xff1a;IBM\u7684\u5de5\u7a0b\u5e08\u4e9a\u745f\u00b7\u8428\u7f2a\u5c14\u7f16\u5199\u4e86\u4e00\u4e2a\u53ef\u4ee5\u5b66\u4e60\u4e0b\u897f\u6d0b\u8df3\u68cb\u7684\u7a0b\u5e8f\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u81ea\u6211\u5bf9\u5f08\u6765\u63d0\u5347\u68cb\u529b&#xff0c;\u5176\u6c34\u5e73\u6700\u7ec8\u751a\u81f3\u8d85\u8fc7\u4e86\u8428\u7f2a\u5c14\u672c\u4eba\u3002\u8fd9\u662f\u673a\u5668\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2a\u5e7f\u4e3a\u4eba\u77e5\u7684\u6210\u529f\u6848\u4f8b&#xff0c;\u5b83\u751f\u52a8\u5730\u5c55\u793a\u4e86\u201c\u8ba9\u8ba1\u7b97\u673a\u81ea\u5df1\u5b66\u4e60\u201d\u662f\u53ef\u884c\u7684\u3002\u8428\u7f2a\u5c14\u4e5f\u662f\u7b2c\u4e00\u4e2a\u63d0\u51fa\u5e76\u666e\u53ca\u201cMachine Learning\u201d\u8fd9\u4e2a\u8bcd\u7684\u4eba\u3002<\/p>\n<\/li>\n<li>\n<p>1957\u5e74&#xff0c;\u611f\u77e5\u673a&#xff08;Perceptron&#xff09;&#xff1a;\u5f17\u5170\u514b\u00b7\u7f57\u68ee\u5e03\u62c9\u7279\u57fa\u4e8eMCP\u6a21\u578b&#xff0c;\u63d0\u51fa\u4e86\u201c\u611f\u77e5\u673a\u201d\u3002\u4e0eMCP\u4e0d\u540c&#xff0c;\u611f\u77e5\u673a\u6a21\u578b\u7684\u6743\u91cd\u53c2\u6570\u662f\u53ef\u4ee5\u901a\u8fc7\u5b66\u4e60\u7b97\u6cd5\u81ea\u52a8\u8c03\u6574\u7684\u3002\u4ed6\u751a\u81f3\u5236\u9020\u4e86\u786c\u4ef6\u201cMark I Perceptron\u201d&#xff0c;\u7528\u4e8e\u56fe\u50cf\u8bc6\u522b\u3002\u8fd9\u5f15\u53d1\u4e86\u7b2c\u4e00\u6b21AI\u70ed\u6f6e&#xff0c;\u4eba\u4eec\u5bf9\u201c\u4f1a\u601d\u8003\u7684\u673a\u5668\u201d\u5145\u6ee1\u4e86\u4e50\u89c2\u7684\u5e7b\u60f3\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7b2c\u4e00\u6b21AI\u5bd2\u51ac&#xff08;20\u4e16\u7eaa70-80\u5e74\u4ee3&#xff09;&#xff1a;\u7406\u6027\u7684\u6c89\u6dc0<\/p>\n<ul>\n<li>\n<p>1969\u5e74&#xff0c;\u300a\u611f\u77e5\u673a\u300b\u4e00\u4e66\u7684\u51b2\u51fb&#xff1a;AI\u9886\u57df\u7684\u4e24\u4f4d\u9886\u519b\u4eba\u7269\u9a6c\u6587\u00b7\u660e\u65af\u57fa\u548c\u897f\u6469\u5c14\u00b7\u6d3e\u666e\u7279&#xff0c;\u51fa\u7248\u4e86\u300a\u611f\u77e5\u673a\u300b\u4e00\u4e66\u3002\u4e66\u4e2d\u901a\u8fc7\u4e25\u8c28\u7684\u6570\u5b66\u8bc1\u660e&#xff0c;\u6307\u51fa\u4e86\u5355\u5c42\u611f\u77e5\u673a\u65e0\u6cd5\u89e3\u51b3\u201c\u5f02\u6216&#xff08;XOR&#xff09;\u201d\u8fd9\u7c7b\u7ebf\u6027\u4e0d\u53ef\u5206\u95ee\u9898\u3002\u8fd9\u4e00\u7ed3\u8bba\u867d\u7136\u662f\u9488\u5bf9\u5355\u5c42\u7ed3\u6784\u7684&#xff0c;\u4f46\u5728\u5f53\u65f6\u88ab\u8bb8\u591a\u4eba\u8bef\u8bfb\u4e3a\u6574\u4e2a\u795e\u7ecf\u7f51\u7edc\u65b9\u6cd5\u7684\u6839\u672c\u6027\u7f3a\u9677\u3002\u8fd9\u672c\u8457\u4f5c\u5982\u4e00\u76c6\u51b7\u6c34&#xff0c;\u6d47\u706d\u4e86\u5f53\u65f6\u8fc7\u4e8e\u72c2\u70ed\u7684\u671f\u671b&#xff0c;\u76f4\u63a5\u5bfc\u81f4\u4e86\u795e\u7ecf\u7f51\u7edc\u7814\u7a76\u7684\u8d44\u91d1\u88ab\u5927\u91cf\u524a\u51cf&#xff0c;AI\u8fdb\u5165\u4e86\u7b2c\u4e00\u4e2a\u201c\u51ac\u5929\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5bd2\u51ac\u4e2d\u7684\u706b\u79cd&#xff1a;\u5c3d\u7ba1\u795e\u7ecf\u7f51\u7edc\u7814\u7a76\u8fdb\u5165\u4f4e\u8c37&#xff0c;\u4f46\u5176\u4ed6\u673a\u5668\u5b66\u4e60\u6d41\u6d3e\u4ecd\u5728\u6084\u7136\u53d1\u5c55\u3002\u51b3\u7b56\u6811\u7b97\u6cd5&#xff08;\u5982ID3&#xff09;\u3001\u4e13\u5bb6\u7cfb\u7edf\u7b49\u7b26\u53f7\u4e3b\u4e49AI\u65b9\u6cd5\u5728\u8fd9\u4e00\u65f6\u671f\u53d6\u5f97\u4e86\u91cd\u8981\u8fdb\u5c55\u3002\u5bd2\u51ac\u5e76\u672a\u7184\u706d\u6240\u6709\u706b\u79cd&#xff0c;\u53cd\u800c\u4fc3\u4f7f\u7814\u7a76\u8005\u4eec\u8fdb\u884c\u66f4\u6df1\u523b\u7684\u7406\u6027\u548c\u57fa\u7840\u6027\u601d\u8003\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u590d\u5174\u4e0e\u8fde\u63a5\u4e3b\u4e49\u7684\u56de\u5f52&#xff08;20\u4e16\u7eaa80\u5e74\u4ee3\u672b-90\u5e74\u4ee3&#xff09;&#xff1a;\u67f3\u6697\u82b1\u660e<\/p>\n<ul>\n<li>\n<p>1986\u5e74&#xff0c;\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5&#xff08;Backpropagation&#xff09;\u7684\u91cd\u65b0\u53d1\u73b0&#xff1a;\u867d\u7136\u53cd\u5411\u4f20\u64ad\u7684\u601d\u60f3\u65e9\u5df2\u5b58\u5728&#xff0c;\u4f46\u7531\u6234\u7ef4\u00b7\u9c81\u59c6\u54c8\u7279\u3001\u6770\u5f17\u91cc\u00b7\u8f9b\u987f\u548c\u7f57\u7eb3\u5fb7\u00b7\u5a01\u5ec9\u59c6\u65af\u7b49\u4eba\u7684\u5de5\u4f5c&#xff0c;\u4f7f\u5176\u5f97\u5230\u4e86\u5e7f\u6cdb\u4f20\u64ad\u548c\u5e94\u7528\u3002\u8be5\u7b97\u6cd5\u6709\u6548\u5730\u89e3\u51b3\u4e86\u591a\u5c42\u795e\u7ecf\u7f51\u7edc\u7684\u6743\u91cd\u8bad\u7ec3\u95ee\u9898&#xff0c;\u653b\u514b\u4e86\u300a\u611f\u77e5\u673a\u300b\u4e00\u4e66\u4e2d\u63d0\u51fa\u7684\u6838\u5fc3\u96be\u9898&#xff0c;\u8ba9\u795e\u7ecf\u7f51\u7edc\u7814\u7a76\u91cd\u83b7\u65b0\u751f\u3002<\/p>\n<\/li>\n<li>\n<p>20\u4e16\u7eaa90\u5e74\u4ee3&#xff0c;\u7edf\u8ba1\u5b66\u4e60\u7684\u5d1b\u8d77&#xff1a;\u5728\u795e\u7ecf\u7f51\u7edc\u590d\u5174\u7684\u540c\u65f6&#xff0c;\u53e6\u4e00\u80a1\u5f3a\u5927\u7684\u529b\u91cf\u6b63\u5728\u5f62\u6210\u3002\u4ee5\u5f17\u62c9\u57fa\u7c73\u5c14\u00b7\u74e6\u666e\u5c3c\u514b\u7b49\u4eba\u63d0\u51fa\u7684\u652f\u6491\u5411\u91cf\u673a&#xff08;SVM&#xff09;\u4e3a\u4ee3\u8868\u7684&#xff0c;\u57fa\u4e8e\u4e25\u683c\u7edf\u8ba1\u5b66\u4e60\u7406\u8bba&#xff08;VC\u7ef4\u7406\u8bba&#xff09;\u7684\u65b9\u6cd5\u8bba\u5f00\u59cb\u5927\u653e\u5f02\u5f69\u3002SVM\u4ee5\u5176\u4f18\u7f8e\u7684\u6570\u5b66\u7406\u8bba\u3001\u51fa\u8272\u7684\u6cdb\u5316\u80fd\u529b\u548c\u9ad8\u6548\u7684\u51f8\u4f18\u5316\u6c42\u89e3&#xff0c;\u5728\u8bb8\u591a\u4e2d\u5c0f\u578b\u6570\u636e\u96c6\u7684\u5206\u7c7b\u548c\u56de\u5f52\u4efb\u52a1\u4e0a&#xff0c;\u5176\u8868\u73b0\u5e38\u5e38\u4f18\u4e8e\u5f53\u65f6\u7684\u795e\u7ecf\u7f51\u7edc\u3002\u540c\u65f6\u671f&#xff0c;\u51b3\u7b56\u6811\u7684\u96c6\u6210\u65b9\u6cd5&#xff0c;\u5982\u968f\u673a\u68ee\u6797&#xff08;Random Forest&#xff09;\u548c\u68af\u5ea6\u63d0\u5347\u673a&#xff08;Gradient Boosting Machine&#xff09;\u4e5f\u5f00\u59cb\u5d2d\u9732\u5934\u89d2\u3002\u8fd9\u4e2a\u65f6\u4ee3&#xff0c;\u662f\u201c\u7edf\u8ba1\u673a\u5668\u5b66\u4e60\u201d\u7684\u9ec4\u91d1\u65f6\u4ee3&#xff0c;\u5404\u79cd\u7cbe\u5de7\u7684\u6d45\u5c42\u6a21\u578b\u767e\u82b1\u9f50\u653e\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7b2c\u4e8c\u6b21AI\u5bd2\u51ac&#xff08;2000\u5e74\u524d\u540e&#xff09;&#xff1a;\u74f6\u9888\u4e0e\u915d\u917f<\/p>\n<p>\u8fdb\u516521\u4e16\u7eaa\u521d&#xff0c;\u5c3d\u7ba1\u673a\u5668\u5b66\u4e60\u5728\u7279\u5b9a\u9886\u57df\u5e94\u7528\u5e7f\u6cdb&#xff0c;\u4f46\u5176\u53d1\u5c55\u4f3c\u4e4e\u53c8\u9047\u5230\u4e86\u74f6\u9888\u3002\u5f53\u65f6\u7684\u795e\u7ecf\u7f51\u7edc\u867d\u7136\u7406\u8bba\u4e0a\u53ef\u4ee5\u5f88\u6df1&#xff0c;\u4f46\u5b9e\u9645\u8bad\u7ec3\u4e2d\u9762\u4e34\u7740\u68af\u5ea6\u6d88\u5931\/\u7206\u70b8\u7b49\u95ee\u9898&#xff0c;\u5bfc\u81f4\u6df1\u5c42\u7f51\u7edc\u7684\u8bad\u7ec3\u6781\u4e3a\u56f0\u96be\u3002\u800cSVM\u7b49\u6a21\u578b\u867d\u7136\u7406\u8bba\u4f18\u7f8e&#xff0c;\u4f46\u5728\u5904\u7406\u5982\u56fe\u50cf\u3001\u8bed\u97f3\u8fd9\u7c7b\u62e5\u6709\u6d77\u91cf\u3001\u9ad8\u7ef4\u539f\u59cb\u7279\u5f81\u7684\u4efb\u52a1\u65f6&#xff0c;\u663e\u5f97\u529b\u4e0d\u4ece\u5fc3\u3002\u6574\u4e2a\u9886\u57df\u4f3c\u4e4e\u5728\u7b49\u5f85\u4e00\u6b21\u65b0\u7684\u7a81\u7834\u3002<\/p>\n<p>\u6df1\u5ea6\u5b66\u4e60\u9769\u547d&#xff08;2006\u5e74\u81f3\u4eca&#xff09;&#xff1a;\u738b\u8005\u5f52\u6765<\/p>\n<ul>\n<li>\n<p>2006\u5e74&#xff0c;\u6df1\u5ea6\u4fe1\u5ff5\u7f51\u7edc\u4e0e\u9010\u5c42\u9884\u8bad\u7ec3&#xff1a;\u6770\u5f17\u91cc\u00b7\u8f9b\u987f\u7b49\u4eba\u63d0\u51fa\u4e86\u201c\u6df1\u5ea6\u4fe1\u5ff5\u7f51\u7edc&#xff08;DBN&#xff09;\u201d&#xff0c;\u5e76\u5f00\u521b\u6027\u5730\u4f7f\u7528\u4e86\u201c\u65e0\u76d1\u7763\u9010\u5c42\u9884\u8bad\u7ec3&#043;\u6709\u76d1\u7763\u5fae\u8c03\u201d\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u50cf\u642d\u79ef\u6728\u4e00\u6837&#xff0c;\u5148\u8ba9\u7f51\u7edc\u7684\u6bcf\u4e00\u5c42\u81ea\u5df1\u8fdb\u884c\u65e0\u76d1\u7763\u5b66\u4e60&#xff0c;\u7406\u89e3\u6570\u636e\u7684\u57fa\u672c\u7279\u5f81&#xff0c;\u7136\u540e\u518d\u7528\u6709\u6807\u7b7e\u7684\u6570\u636e\u5bf9\u6574\u4e2a\u7f51\u7edc\u8fdb\u884c\u7cbe\u8c03\u3002\u8fd9\u5de7\u5999\u5730\u7f13\u89e3\u4e86\u6df1\u5ea6\u7f51\u7edc\u8bad\u7ec3\u7684\u56f0\u96be&#xff0c;\u4e3a\u201c\u6df1\u5ea6\u5b66\u4e60\u201d\u4e00\u8bcd\u7684\u8bde\u751f\u62c9\u5f00\u4e86\u5e8f\u5e55\u3002<\/p>\n<\/li>\n<li>\n<p>2012\u5e74&#xff0c;AlexNet\u5728ImageNet\u7ade\u8d5b\u4e2d\u53d6\u5f97\u5386\u53f2\u6027\u7a81\u7834&#xff1a;\u7531\u8f9b\u987f\u7684\u5b66\u751f\u4e9a\u5386\u514b\u65af\u00b7\u514b\u91cc\u70ed\u592b\u65af\u57fa\u8bbe\u8ba1\u7684\u6df1\u5ea6\u5377\u79ef\u795e\u7ecf\u7f51\u7edcAlexNet&#xff0c;\u5728\u5f53\u5e74\u7684ImageNet\u5927\u89c4\u6a21\u89c6\u89c9\u8bc6\u522b\u6311\u6218\u8d5b&#xff08;ILSVRC&#xff09;\u4e2d&#xff0c;\u4ee5\u8fdc\u8d85\u7b2c\u4e8c\u540d&#xff08;\u57fa\u4e8e\u4f20\u7edf\u65b9\u6cd5&#xff09;\u7684\u60ca\u4eba\u51c6\u786e\u7387\u593a\u51a0\u3002\u8fd9\u4e00\u4e8b\u4ef6\u7684\u51b2\u51fb\u529b&#xff0c;\u4e0d\u4e9a\u4e8e\u6df1\u84dd\u8ba1\u7b97\u673a\u6218\u80dc\u5361\u65af\u5e15\u7f57\u592b\u3002\u5b83\u65e0\u53ef\u8fa9\u9a73\u5730\u8bc1\u660e\u4e86&#xff0c;\u5728\u5904\u7406\u590d\u6742\u6a21\u5f0f\u8bc6\u522b\u4efb\u52a1\u65f6&#xff0c;\u6df1\u5ea6\u5b66\u4e60&#xff08;\u7279\u522b\u662f\u5377\u79ef\u795e\u7ecf\u7f51\u7edcCNN&#xff09;\u7684\u5f3a\u5927\u5a01\u529b\u3002\u8fd9\u4e00\u80dc\u5229&#xff0c;\u70b9\u71c3\u4e86\u5ef6\u7eed\u81f3\u4eca\u7684\u6df1\u5ea6\u5b66\u4e60\u9769\u547d\u4e4b\u706b\u3002<\/p>\n<\/li>\n<li>\n<p>\u81f3\u4eca&#xff1a;\u9ec4\u91d1\u65f6\u4ee3&#xff1a;\u81ea2012\u5e74\u4ee5\u6765&#xff0c;\u6211\u4eec\u89c1\u8bc1\u4e86\u6280\u672f\u7684\u7206\u70b8\u5f0f\u53d1\u5c55\u3002\u4ece\u7528\u4e8e\u5e8f\u5217\u6570\u636e\u7684\u5faa\u73af\u795e\u7ecf\u7f51\u7edc&#xff08;RNN&#xff09;\u53ca\u5176\u53d8\u4f53LSTM&#xff0c;\u5230\u89e3\u51b3\u5176\u957f\u7a0b\u4f9d\u8d56\u95ee\u9898\u7684Transformer\u67b6\u6784&#xff1b;\u4ece\u751f\u6210\u4ee5\u5047\u4e71\u771f\u56fe\u50cf\u7684\u751f\u6210\u5bf9\u6297\u7f51\u7edc&#xff08;GAN&#xff09;&#xff0c;\u5230\u9a71\u52a8AlphaGo\u548cChatGPT\u7684\u6df1\u5ea6\u5f3a\u5316\u5b66\u4e60\u4e0e\u5927\u89c4\u6a21\u9884\u8bad\u7ec3\u8bed\u8a00\u6a21\u578b\u3002\u6df1\u5ea6\u5b66\u4e60\u4e0d\u4ec5\u7edf\u4e00\u4e86\u4eba\u5de5\u667a\u80fd\u7684\u8bf8\u591a\u9886\u57df&#xff0c;\u66f4\u4ee5\u524d\u6240\u672a\u6709\u7684\u6df1\u5ea6\u548c\u5e7f\u5ea6&#xff0c;\u6e17\u900f\u5230\u6211\u4eec\u751f\u6d3b\u7684\u65b9\u65b9\u9762\u9762\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u6bb5\u5386\u53f2\u544a\u8bc9\u6211\u4eec&#xff0c;\u79d1\u5b66\u7684\u53d1\u5c55\u4ece\u4e0d\u662f\u4e00\u6761\u76f4\u7ebf\u3002\u5b83\u5145\u6ee1\u4e86\u87ba\u65cb\u5f0f\u7684\u4e0a\u5347\u548c\u5468\u671f\u6027\u7684\u8d77\u4f0f\u3002\u601d\u60f3\u7684\u706b\u82b1\u53ef\u80fd\u9700\u8981\u6570\u5341\u5e74\u7684\u6c89\u5bc2\u624d\u80fd\u71ce\u539f&#xff0c;\u800c\u770b\u4f3c\u4e0d\u53ef\u903e\u8d8a\u7684\u74f6\u9888&#xff0c;\u4e5f\u7ec8\u5c06\u88ab\u65b0\u7684\u667a\u6167\u6240\u7a81\u7834\u3002<\/p>\n<h5>1.2.2 \u7fa4\u661f\u95ea\u8000\u65f6&#xff1a;\u90a3\u4e9b\u5851\u9020\u4e86AI\u7eaa\u5143\u7684\u5927\u5e08\u4eec<\/h5>\n<p>\u6280\u672f\u53f2\u7684\u5b8f\u5927\u53d9\u4e8b&#xff0c;\u6700\u7ec8\u662f\u7531\u4e00\u4e2a\u4e2a\u9c9c\u6d3b\u7684\u4eba\u6765\u4e66\u5199\u7684\u3002\u5728AI\u7684\u6bbf\u5802\u91cc&#xff0c;\u6709\u51e0\u4f4d\u5de8\u5320\u7684\u540d\u5b57&#xff0c;\u6211\u4eec\u5fc5\u987b\u94ed\u8bb0\u3002\u4ed6\u4eec\u7684\u601d\u60f3\u4e0e\u8d21\u732e&#xff0c;\u5982\u5317\u6781\u661f\u822c\u6307\u5f15\u7740\u6574\u4e2a\u9886\u57df\u7684\u524d\u884c\u3002<\/p>\n<ul>\n<li>\n<p>\u827e\u4f26\u00b7\u56fe\u7075&#xff08;Alan Turing&#xff09;&#xff1a;\u5982\u524d\u6240\u8ff0&#xff0c;\u4ed6\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u4eba\u5de5\u667a\u80fd\u7684\u201c\u601d\u60f3\u6559\u7236\u201d\u3002\u4ed6\u63d0\u51fa\u7684\u56fe\u7075\u673a\u6a21\u578b\u5b9a\u4e49\u4e86\u201c\u53ef\u8ba1\u7b97\u201d\u7684\u8fb9\u754c&#xff0c;\u800c\u56fe\u7075\u6d4b\u8bd5\u5219\u5f00\u542f\u4e86\u201c\u673a\u5668\u667a\u80fd\u201d\u7684\u54f2\u5b66\u4e0e\u5b9e\u8df5\u63a2\u7d22\u3002<\/p>\n<\/li>\n<li>\n<p>\u6770\u5f17\u91cc\u00b7\u8f9b\u987f&#xff08;Geoffrey Hinton&#xff09;&#xff1a;\u88ab\u8a89\u4e3a\u201c\u6df1\u5ea6\u5b66\u4e60\u4e4b\u7236\u201d\u4e4b\u4e00\u3002\u4ece80\u5e74\u4ee3\u5171\u540c\u63a8\u5e7f\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5&#xff0c;\u523021\u4e16\u7eaa\u521d\u7528\u6df1\u5ea6\u4fe1\u5ff5\u7f51\u7edc\u5f00\u542f\u6df1\u5ea6\u5b66\u4e60\u9769\u547d&#xff0c;\u518d\u5230\u57f9\u517b\u51faAlexNet\u7684\u4f5c\u8005\u7b49\u4e00\u4f17\u82f1\u624d&#xff0c;\u8f9b\u987f\u4ee5\u5176\u6570\u5341\u5e74\u7684\u575a\u6301\u548c\u6d1e\u5bdf\u529b&#xff0c;\u5c06\u795e\u7ecf\u7f51\u7edc\u4ece\u5bd2\u51ac\u5e26\u5165\u4e86\u76db\u590f\u3002\u4ed6\u56e0\u5728\u6df1\u5ea6\u5b66\u4e60\u9886\u57df\u7684\u5f00\u521b\u6027\u8d21\u732e&#xff0c;\u4e0e\u53e6\u5916\u4e24\u4f4d\u5b66\u8005\u5171\u540c\u83b7\u5f97\u4e862018\u5e74\u7684\u56fe\u7075\u5956\u3002<\/p>\n<\/li>\n<li>\n<p>\u6768\u7acb\u6606&#xff08;Yann LeCun&#xff09;&#xff1a;\u53e6\u4e00\u4f4d2018\u5e74\u56fe\u7075\u5956\u5f97\u4e3b&#xff0c;\u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff08;CNN&#xff09;\u7684\u7f14\u9020\u8005\u3002\u65e9\u5728\u4e0a\u4e16\u7eaa90\u5e74\u4ee3&#xff0c;\u4ed6\u5c31\u5f00\u53d1\u4e86LeNet-5&#xff0c;\u6210\u529f\u5e94\u7528\u4e8e\u94f6\u884c\u7684\u652f\u7968\u624b\u5199\u6570\u5b57\u8bc6\u522b\u3002CNN\u67b6\u6784\u6a21\u62df\u4e86\u751f\u7269\u7684\u89c6\u89c9\u76ae\u5c42\u673a\u5236&#xff0c;\u5176\u201c\u5c40\u90e8\u8fde\u63a5\u201d\u548c\u201c\u6743\u503c\u5171\u4eab\u201d\u7684\u8bbe\u8ba1&#xff0c;\u5bf9\u4e8e\u5904\u7406\u56fe\u50cf\u7b49\u7f51\u683c\u72b6\u6570\u636e\u5177\u6709\u5929\u7136\u7684\u4f18\u52bf&#xff0c;\u662f\u5f53\u4eca\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\u7684\u57fa\u77f3\u3002<\/p>\n<\/li>\n<li>\n<p>\u7ea6\u4e66\u4e9a\u00b7\u672c\u5409\u5965&#xff08;Yoshua Bengio&#xff09;&#xff1a;2018\u5e74\u56fe\u7075\u5956\u7684\u7b2c\u4e09\u4f4d\u5f97\u4e3b\u3002\u4ed6\u5728\u6df1\u5ea6\u5b66\u4e60\u7684\u591a\u4e2a\u9886\u57df\u90fd\u505a\u51fa\u4e86\u5960\u57fa\u6027\u8d21\u732e&#xff0c;\u5c24\u5176\u662f\u5728\u8bed\u8a00\u6a21\u578b\u3001\u6ce8\u610f\u529b\u673a\u5236\u7b49\u65b9\u9762\u3002\u4ed6\u4e0e\u56e2\u961f\u7684\u5de5\u4f5c&#xff0c;\u4e3a\u540e\u6765Transformer\u67b6\u6784\u7684\u8bde\u751f\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u7684\u9769\u547d\u6027\u7a81\u7834\u94fa\u5e73\u4e86\u9053\u8def\u3002\u540c\u65f6&#xff0c;\u4ed6\u4e5f\u662f\u4e00\u4f4d\u6781\u5177\u4eba\u6587\u5173\u6000\u7684\u79d1\u5b66\u5bb6&#xff0c;\u6301\u7eed\u5173\u6ce8AI\u7684\u793e\u4f1a\u5f71\u54cd\u4e0e\u4f26\u7406\u95ee\u9898\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e09\u4f4d\u5b66\u8005\u5e38\u88ab\u5e76\u79f0\u4e3a\u201c\u6df1\u5ea6\u5b66\u4e60\u4e09\u5de8\u5934\u201d&#xff0c;\u4ed6\u4eec\u7684\u5408\u4f5c\u4e0e\u826f\u6027\u7ade\u4e89&#xff0c;\u5171\u540c\u5851\u9020\u4e86\u6211\u4eec\u4eca\u5929\u6240\u77e5\u7684\u6df1\u5ea6\u5b66\u4e60\u7248\u56fe\u3002<\/p>\n<ul>\n<li>\u5f17\u62c9\u57fa\u7c73\u5c14\u00b7\u74e6\u666e\u5c3c\u514b&#xff08;Vladimir Vapnik&#xff09;&#xff1a;\u7edf\u8ba1\u5b66\u4e60\u7406\u8bba\u7684\u5de8\u64d8&#xff0c;\u652f\u6491\u5411\u91cf\u673a&#xff08;SVM&#xff09;\u7684\u53d1\u660e\u4eba\u3002\u4ed6\u7684\u5de5\u4f5c\u4e3a\u673a\u5668\u5b66\u4e60\u63d0\u4f9b\u4e86\u575a\u5b9e\u7684\u7406\u8bba\u57fa\u7840&#xff08;VC\u7ef4\u7406\u8bba&#xff09;&#xff0c;\u5f3a\u8c03\u4e86\u63a7\u5236\u6a21\u578b\u590d\u6742\u5ea6\u3001\u8ffd\u6c42\u6cdb\u5316\u80fd\u529b\u7684\u91cd\u8981\u6027\u3002\u5728\u6df1\u5ea6\u5b66\u4e60\u6d6a\u6f6e\u4e4b\u524d&#xff0c;SVM\u662f\u5b66\u672f\u754c\u548c\u5de5\u4e1a\u754c\u6700\u53d7\u63a8\u5d07\u7684\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\u4e4b\u4e00\u3002\u4ed6\u7684\u601d\u60f3\u63d0\u9192\u6211\u4eec&#xff0c;\u5373\u4f7f\u5728\u7ecf\u9a8c\u4e3b\u4e49\u5927\u884c\u5176\u9053\u7684\u4eca\u5929&#xff0c;\u6df1\u523b\u7684\u6570\u5b66\u7406\u8bba\u4f9d\u7136\u662f\u6307\u5f15\u6211\u4eec\u524d\u884c\u7684\u706f\u5854\u3002<\/li>\n<\/ul>\n<p>\u5f53\u7136&#xff0c;\u7fa4\u661f\u95ea\u8000&#xff0c;\u8fdc\u4e0d\u6b62\u4e8e\u6b64\u3002\u4ece\u201c\u4eba\u5de5\u667a\u80fd\u201d\u4e00\u8bcd\u7684\u63d0\u51fa\u8005\u7ea6\u7ff0\u00b7\u9ea6\u5361\u9521&#xff0c;\u5230\u51b3\u7b56\u6811\u7b97\u6cd5\u7684\u5148\u9a71\u7f57\u65af\u00b7\u6606\u5170&#xff0c;\u518d\u5230\u5f3a\u5316\u5b66\u4e60\u9886\u57df\u7684\u6cf0\u6597\u7406\u67e5\u5fb7\u00b7\u8428\u987f\u2026\u2026\u6b63\u662f\u8fd9\u4e00\u4ee3\u4ee3\u7814\u7a76\u8005\u7684\u667a\u6167\u63a5\u529b&#xff0c;\u624d\u6c47\u805a\u6210\u4e86\u4eca\u65e5\u4eba\u5de5\u667a\u80fd\u7684\u6ed4\u6ed4\u6c5f\u6cb3\u3002\u5411\u4ed6\u4eec\u81f4\u656c\u7684\u6700\u597d\u65b9\u5f0f&#xff0c;\u5c31\u662f\u7ad9\u5728\u4ed6\u4eec\u7684\u80a9\u8180\u4e0a&#xff0c;\u7ee7\u7eed\u63a2\u7d22\u8fd9\u7247\u667a\u6167\u7684\u661f\u8fb0\u5927\u6d77\u3002<\/p>\n<hr \/>\n<h4>1.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d<\/h4>\n<p>\u5728\u5f00\u542f\u5177\u4f53\u7684\u7f16\u7a0b\u5b66\u4e60\u4e4b\u524d&#xff0c;\u4e00\u4e2a\u81ea\u7136\u7684\u95ee\u9898\u662f&#xff1a;\u4e3a\u4ec0\u4e48\u662fPython&#xff1f;\u5728\u4f17\u591a\u7f16\u7a0b\u8bed\u8a00\u4e2d&#xff0c;\u4e3a\u4f55Python\u80fd\u591f\u8131\u9896\u800c\u51fa&#xff0c;\u6210\u4e3a\u673a\u5668\u5b66\u4e60\u548c\u6570\u636e\u79d1\u5b66\u9886\u57df\u4e8b\u5b9e\u4e0a\u7684\u201c\u6807\u51c6\u8bed\u8a00\u201d&#xff1f;\u8fd9\u5e76\u975e\u5076\u7136&#xff0c;\u800c\u662f\u5176\u5185\u5728\u54f2\u5b66\u4e0e\u5916\u5728\u751f\u6001\u5171\u540c\u4f5c\u7528\u7684\u7ed3\u679c\u3002<\/p>\n<h5>1.3.1 Python\u7684\u54f2\u5b66&#xff1a;\u201c\u7985\u201d\u4e0e\u201c\u9053\u201d<\/h5>\n<p>\u4efb\u4f55\u4e00\u95e8\u6210\u529f\u7684\u8bed\u8a00&#xff0c;\u80cc\u540e\u90fd\u6709\u4e00\u79cd\u72ec\u7279\u7684\u8bbe\u8ba1\u54f2\u5b66\u3002Python\u7684\u54f2\u5b66&#xff0c;\u88ab\u7cbe\u70bc\u5730\u603b\u7ed3\u5728\u201cPython\u4e4b\u7985&#xff08;The Zen of Python&#xff09;\u201d\u4e2d\u3002\u4f60\u53ef\u4ee5\u5728\u4efb\u4f55\u5b89\u88c5\u4e86Python\u7684\u73af\u5883\u4e2d&#xff0c;\u901a\u8fc7\u5728\u89e3\u91ca\u5668\u91cc\u8f93\u5165import this\u6765\u4e00\u7779\u5176\u771f\u5bb9\u3002\u5176\u4e2d\u51e0\u6761&#xff0c;\u4e0e\u6570\u636e\u79d1\u5b66\u7684\u7cbe\u795e\u5185\u6838\u4e0d\u8c0b\u800c\u5408&#xff1a;<\/p>\n<ul>\n<li>\u4f18\u7f8e\u80dc\u4e8e\u4e11\u964b&#xff08;Beautiful is better than ugly.&#xff09;<\/li>\n<li>\u660e\u4e86\u80dc\u4e8e\u6666\u6da9&#xff08;Explicit is better than implicit.&#xff09;<\/li>\n<li>\u7b80\u5355\u80dc\u4e8e\u590d\u6742&#xff08;Simple is better than complex.&#xff09;<\/li>\n<li>\u53ef\u8bfb\u6027\u5f88\u91cd\u8981&#xff08;Readability counts.&#xff09;<\/li>\n<\/ul>\n<p>\u8fd9\u4e0d\u4ec5\u4ec5\u662f\u7f16\u7a0b\u7f8e\u5b66&#xff0c;\u66f4\u662f\u79d1\u5b66\u7814\u7a76\u7684\u65b9\u6cd5\u8bba\u3002\u673a\u5668\u5b66\u4e60\u9879\u76ee\u5f80\u5f80\u4e0d\u662f\u4e00\u6b21\u6027\u7684\u201c\u4ee3\u7801\u51b2\u950b\u201d&#xff0c;\u800c\u662f\u4e00\u4e2a\u9700\u8981\u53cd\u590d\u5b9e\u9a8c\u3001\u8fed\u4ee3\u3001\u9a8c\u8bc1\u548c\u4e0e\u4ed6\u4eba\u534f\u4f5c\u7684\u63a2\u7d22\u8fc7\u7a0b\u3002<\/p>\n<ul>\n<li>\n<p>\u53ef\u8bfb\u6027\u4e0e\u7b80\u6d01\u6027&#xff1a;Python\u7684\u8bed\u6cd5\u975e\u5e38\u63a5\u8fd1\u81ea\u7136\u8bed\u8a00&#xff0c;\u8fd9\u4f7f\u5f97\u4ee3\u7801\u7684\u9605\u8bfb\u548c\u7f16\u5199\u90fd\u53d8\u5f97\u5f02\u5e38\u8f7b\u677e\u3002\u5bf9\u4e8e\u79d1\u5b66\u5bb6\u3001\u5206\u6790\u5e08\u8fd9\u4e9b\u53ef\u80fd\u5e76\u975e\u8ba1\u7b97\u673a\u79d1\u73ed\u51fa\u8eab\u7684\u4f7f\u7528\u8005\u6765\u8bf4&#xff0c;\u5b66\u4e60\u66f2\u7ebf\u6781\u4e3a\u5e73\u7f13\u3002\u4ed6\u4eec\u53ef\u4ee5\u5c06\u66f4\u591a\u7684\u7cbe\u529b\u805a\u7126\u4e8e\u95ee\u9898\u672c\u8eab\u548c\u7b97\u6cd5\u601d\u60f3&#xff0c;\u800c\u4e0d\u662f\u7ea0\u7ed3\u4e8e\u7e41\u7410\u7684\u8bed\u6cd5\u7ec6\u8282&#xff08;\u5982C&#043;&#043;\u7684\u6307\u9488\u6216Java\u7684\u6837\u677f\u4ee3\u7801&#xff09;\u3002\u4e00\u6bb5Python\u4ee3\u7801&#xff0c;\u5f80\u5f80\u66f4\u50cf\u662f\u5728\u63cf\u8ff0\u89e3\u51b3\u95ee\u9898\u7684\u201c\u4f2a\u4ee3\u7801\u201d&#xff0c;\u8fd9\u4f7f\u5f97\u56e2\u961f\u534f\u4f5c\u548c\u77e5\u8bc6\u5206\u4eab\u53d8\u5f97\u6781\u4e3a\u9ad8\u6548\u3002<\/p>\n<\/li>\n<li>\n<p>\u201c\u80f6\u6c34\u8bed\u8a00\u201d\u7684\u7279\u8d28&#xff1a;Python\u88ab\u8a89\u4e3a\u201c\u80f6\u6c34\u8bed\u8a00\u201d&#xff0c;\u56e0\u4e3a\u5b83\u80fd\u8f7b\u6613\u5730\u5c06\u5176\u4ed6\u8bed\u8a00&#xff08;\u7279\u522b\u662fC\/C&#043;&#043;&#xff09;\u7f16\u5199\u7684\u9ad8\u6027\u80fd\u6a21\u5757\u201c\u7c98\u5408\u201d\u5728\u4e00\u8d77\u3002\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u8ba1\u7b97&#xff0c;\u5982\u56fe\u5f62\u5904\u7406\u3001\u5927\u89c4\u6a21\u77e9\u9635\u8fd0\u7b97&#xff0c;\u5bf9\u6027\u80fd\u8981\u6c42\u6781\u9ad8\u3002\u8fd9\u4e9b\u8ba1\u7b97\u901a\u5e38\u7531\u5e95\u5c42\u7684\u3001\u7528C&#043;&#043;\u6216CUDA\u7f16\u5199\u7684\u9ad8\u6027\u80fd\u5e93\u6765\u5b8c\u6210\u3002Python\u5219\u626e\u6f14\u4e86\u4e00\u4e2a\u4f18\u96c5\u7684\u201c\u6307\u6325\u5b98\u201d\u89d2\u8272&#xff1a;\u6211\u4eec\u7528Python\u6765\u5b9a\u4e49\u6a21\u578b\u7ed3\u6784\u3001\u7ec4\u7ec7\u6570\u636e\u6d41\u3001\u8fdb\u884c\u5b9e\u9a8c\u7ba1\u7406&#xff0c;\u800c\u5c06\u771f\u6b63\u7684\u8ba1\u7b97\u5bc6\u96c6\u578b\u4efb\u52a1\u4ea4\u7ed9\u540e\u53f0\u7684C&#043;&#043;\u5f15\u64ce\u3002\u8fd9\u5c31\u5b9e\u73b0\u4e86\u201c\u5f00\u53d1\u6548\u7387\u201d\u4e0e\u201c\u8fd0\u884c\u6548\u7387\u201d\u7684\u5b8c\u7f8e\u7ed3\u5408\u3002\u6211\u4eec\u4eab\u53d7\u7740Python\u7684\u7b80\u6d01&#xff0c;\u5374\u6ca1\u6709\u727a\u7272\u5173\u952e\u4efb\u52a1\u7684\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u54f2\u5b66&#xff0c;\u4f7f\u5f97Python\u6210\u4e3a\u4e00\u5ea7\u7406\u60f3\u7684\u6865\u6881&#xff0c;\u5b83\u8fde\u63a5\u4e86\u601d\u60f3\u4e0e\u5b9e\u73b0&#xff0c;\u8fde\u63a5\u4e86\u7814\u7a76\u4e0e\u5de5\u7a0b&#xff0c;\u8fde\u63a5\u4e86\u4e13\u5bb6\u4e0e\u521d\u5b66\u8005\u3002<\/p>\n<h5>1.3.2 \u751f\u6001\u7cfb\u7edf\u6982\u89c8&#xff1a;\u4e3a\u4f55\u5b83\u80fd\u6210\u4e3a\u6700\u4f18\u9009\u62e9<\/h5>\n<p>\u5982\u679c\u8bf4\u54f2\u5b66\u662fPython\u7684\u201c\u7075\u9b42\u201d&#xff0c;\u90a3\u4e48\u5176\u65e0\u4e0e\u4f26\u6bd4\u7684\u5f00\u6e90\u751f\u6001\u7cfb\u7edf&#xff0c;\u5c31\u662f\u5b83\u5f3a\u5065\u7684\u201c\u4f53\u9b44\u201d\u3002\u56f4\u7ed5\u7740\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60&#xff0c;Python\u793e\u533a\u81ea\u53d1\u5730\u6784\u5efa\u8d77\u4e86\u4e00\u5957\u5b8c\u6574\u3001\u5f3a\u5927\u4e14\u9ad8\u5ea6\u534f\u540c\u7684\u201c\u5de5\u5177\u94fe\u201d\u3002\u8fd9\u5957\u5de5\u5177\u94fe\u8986\u76d6\u4e86\u4ece\u6570\u636e\u83b7\u53d6\u3001\u6e05\u6d17\u3001\u5206\u6790\u3001\u5efa\u6a21\u5230\u53ef\u89c6\u5316\u7684\u6574\u4e2a\u5de5\u4f5c\u6d41\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u6765\u5de1\u793c\u4e00\u4e0b\u8fd9\u4e2a\u751f\u6001\u4e2d\u7684\u51e0\u9897\u7480\u74a8\u660e\u73e0&#xff0c;\u8fd9\u4e9b\u4e5f\u662f\u6211\u4eec\u540e\u7eed\u7ae0\u8282\u5c06\u4f1a\u6df1\u5165\u5b66\u4e60\u7684\u6838\u5fc3\u5de5\u5177&#xff1a;<\/p>\n<ul>\n<li>\n<p>NumPy (Numerical Python)&#xff1a;\u6570\u636e\u79d1\u5b66\u7684\u57fa\u77f3\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684N\u7ef4\u6570\u7ec4\u5bf9\u8c61&#xff08;ndarray&#xff09;&#xff0c;\u4ee5\u53ca\u5bf9\u8fd9\u4e9b\u6570\u7ec4\u8fdb\u884c\u64cd\u4f5c\u7684\u5927\u91cf\u9ad8\u6548\u51fd\u6570\u3002\u51e0\u4e4e\u6240\u6709Python\u4e2d\u7684\u9ad8\u7ea7\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u5e93&#xff0c;\u5176\u5e95\u5c42\u90fd\u6784\u5efa\u5728NumPy\u4e4b\u4e0a\u3002\u5b83\u5c06Python\u4ece\u4e00\u95e8\u901a\u7528\u811a\u672c\u8bed\u8a00&#xff0c;\u53d8\u6210\u4e86\u80fd\u591f\u4e0eMATLAB\u7b49\u4e13\u4e1a\u79d1\u5b66\u8ba1\u7b97\u8f6f\u4ef6\u76f8\u5ab2\u7f8e\u7684\u5f3a\u5927\u5de5\u5177\u3002<\/p>\n<\/li>\n<li>\n<p>Pandas&#xff1a;\u6570\u636e\u5206\u6790\u4e0e\u5904\u7406\u7684\u745e\u58eb\u519b\u5200\u3002Pandas\u63d0\u4f9b\u4e86\u4e24\u79cd\u6838\u5fc3\u6570\u636e\u7ed3\u6784&#xff1a;Series&#xff08;\u4e00\u7ef4&#xff09;\u548cDataFrame&#xff08;\u4e8c\u7ef4&#xff09;\u3002DataFrame\u53ef\u4ee5\u88ab\u60f3\u8c61\u6210\u4e00\u4e2a\u5185\u5b58\u4e2d\u7684\u3001\u529f\u80fd\u6781\u5176\u5f3a\u5927\u7684Excel\u8868\u683c\u3002\u5b83\u4f7f\u5f97\u6570\u636e\u7684\u8bfb\u53d6\u3001\u6e05\u6d17\u3001\u8f6c\u6362\u3001\u7b5b\u9009\u3001\u805a\u5408\u3001\u5206\u7ec4\u7b49\u64cd\u4f5c\u53d8\u5f97\u5f02\u5e38\u7b80\u5355\u76f4\u89c2\u3002\u53ef\u4ee5\u8bf4&#xff0c;\u5728\u673a\u5668\u5b66\u4e60\u9879\u76ee\u4e2d&#xff0c;80%\u7684\u65f6\u95f4\u82b1\u5728\u6570\u636e\u9884\u5904\u7406\u4e0a&#xff0c;\u800cPandas\u6b63\u662f\u8ba9\u8fd980%\u7684\u65f6\u95f4\u53d8\u5f97\u9ad8\u6548\u800c\u6109\u5feb\u7684\u5173\u952e\u3002<\/p>\n<\/li>\n<li>\n<p>Matplotlib &amp; Seaborn&#xff1a;\u6570\u636e\u53ef\u89c6\u5316\u7684\u53cc\u74a7\u3002Matplotlib\u662fPython\u4e2d\u6700\u57fa\u7840\u3001\u6700\u7075\u6d3b\u7684\u53ef\u89c6\u5316\u5e93&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5e95\u5c42\u7ed8\u56fe\u63a5\u53e3&#xff0c;\u8ba9\u4f60\u53ef\u4ee5\u5b9a\u5236\u51e0\u4e4e\u4efb\u4f55\u7c7b\u578b\u7684\u9759\u6001\u3001\u52a8\u6001\u3001\u4ea4\u4e92\u5f0f\u56fe\u8868\u3002\u800cSeaborn\u5219\u662f\u57fa\u4e8eMatplotlib\u6784\u5efa\u7684\u66f4\u9ad8\u7ea7\u7684\u7edf\u8ba1\u56fe\u5f62\u5e93&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7f8e\u89c2\u4e14\u9762\u5411\u7edf\u8ba1\u5206\u6790\u7684\u56fe\u8868\u6a21\u677f&#xff0c;\u7528\u66f4\u5c11\u7684\u4ee3\u7801\u5c31\u80fd\u751f\u6210\u4fe1\u606f\u542b\u91cf\u4e30\u5bcc\u7684\u53ef\u89c6\u5316\u7ed3\u679c\u3002\u201c\u4e00\u56fe\u80dc\u5343\u8a00\u201d&#xff0c;\u8fd9\u4e24\u4e2a\u5e93\u662f\u6211\u4eec\u6d1e\u5bdf\u6570\u636e\u3001\u5c55\u793a\u6a21\u578b\u7ed3\u679c\u7684\u201c\u773c\u775b\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>Scikit-learn&#xff1a;\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u96c6\u5927\u6210\u8005\u3002Scikit-learn\u662f\u8fdb\u5165\u673a\u5668\u5b66\u4e60\u9886\u57df\u6700\u91cd\u8981\u3001\u6700\u53cb\u597d\u7684\u5e93\u3002\u5b83\u7528\u4e00\u5957\u9ad8\u5ea6\u4e00\u81f4\u3001\u7b80\u6d01\u4f18\u96c5\u7684API&#xff0c;\u5b9e\u73b0\u4e86\u7edd\u5927\u591a\u6570\u7ecf\u5178\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5&#xff08;\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u3001\u964d\u7ef4\u7b49&#xff09;\u3002\u65e0\u8bba\u662f\u521d\u5b66\u8005\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u8fd8\u662f\u4ece\u4e1a\u8005\u5feb\u901f\u642d\u5efa\u57fa\u7ebf\u6a21\u578b&#xff0c;Scikit-learn\u90fd\u662f\u4e0d\u4e8c\u4e4b\u9009\u3002\u5b83\u7684\u6587\u6863\u6781\u4e3a\u5b8c\u5584&#xff0c;\u582a\u79f0\u6280\u672f\u6587\u6863\u7684\u5178\u8303\u3002\u672c\u4e66\u7684\u7b2c\u4e8c\u90e8\u5206\u5c06\u91cd\u70b9\u56f4\u7ed5Scikit-learn\u5c55\u5f00\u3002<\/p>\n<\/li>\n<li>\n<p>\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6&#xff1a;TensorFlow &amp; PyTorch&#xff1a;\u5f53\u95ee\u9898\u590d\u6742\u5ea6\u8d85\u8d8a\u4e86\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7684\u8303\u7574&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u5165\u6df1\u5ea6\u5b66\u4e60\u7684\u4e16\u754c\u3002\u5728\u8fd9\u4e2a\u4e16\u754c\u91cc&#xff0c;TensorFlow&#xff08;\u7531Google\u5f00\u53d1&#xff09;\u548cPyTorch&#xff08;\u7531Facebook\u5f00\u53d1&#xff09;\u662f\u4e24\u5927\u4e3b\u6d41\u6846\u67b6\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u6784\u5efa\u3001\u8bad\u7ec3\u548c\u90e8\u7f72\u5927\u89c4\u6a21\u795e\u7ecf\u7f51\u7edc\u6240\u9700\u7684\u5168\u90e8\u5de5\u5177&#xff0c;\u5305\u62ec\u81ea\u52a8\u5fae\u5206\u3001GPU\u52a0\u901f\u3001\u4e30\u5bcc\u7684\u9884\u7f6e\u6a21\u578b\u5c42\u7b49\u3002\u867d\u7136\u5b83\u4eec\u5728\u8bbe\u8ba1\u54f2\u5b66\u4e0a\u6709\u6240\u4e0d\u540c&#xff08;TensorFlow 2.x\u540e\u4e5f\u91c7\u7eb3\u4e86PyTorch\u7684\u52a8\u6001\u56fe\u601d\u60f3&#xff09;&#xff0c;\u4f46\u90fd\u5df2\u6210\u4e3a\u9a71\u52a8\u5f53\u4ecaAI\u9769\u547d\u7684\u6838\u5fc3\u5f15\u64ce\u3002<\/p>\n<\/li>\n<li>\n<p>Jupyter Notebook \/ Lab&#xff1a;\u4ea4\u4e92\u5f0f\u79d1\u5b66\u8ba1\u7b97\u7684\u7406\u60f3\u73af\u5883\u3002Jupyter\u63d0\u4f9b\u4e86\u4e00\u4e2a\u57fa\u4e8eWeb\u7684\u4ea4\u4e92\u5f0f\u8ba1\u7b97\u73af\u5883&#xff0c;\u5141\u8bb8\u4f60\u5c06\u4ee3\u7801\u3001\u6587\u672c&#xff08;Markdown&#xff09;\u3001\u6570\u5b66\u516c\u5f0f&#xff08;LaTeX&#xff09;\u3001\u53ef\u89c6\u5316\u7ed3\u679c\u7b49\u7ec4\u5408\u5728\u4e00\u4e2a\u6587\u6863\u4e2d\u3002\u8fd9\u79cd\u201c\u6587\u5b66\u7f16\u7a0b\u201d\u7684\u8303\u5f0f&#xff0c;\u6781\u5927\u5730\u4fc3\u8fdb\u4e86\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790\u548c\u7814\u7a76\u8fc7\u7a0b\u7684\u8bb0\u5f55\u4e0e\u5206\u4eab\u3002\u5b83\u662f\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u673a\u5668\u5b66\u4e60\u7814\u7a76\u8005\u7684\u201c\u6570\u5b57\u5b9e\u9a8c\u5ba4\u201d\u548c\u201c\u5de5\u4f5c\u53f0\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u5957\u751f\u6001\u7cfb\u7edf\u7684\u529b\u91cf\u5728\u4e8e\u5176\u201c\u7f51\u7edc\u6548\u5e94\u201d&#xff1a;\u6bcf\u4e00\u4e2a\u5e93\u90fd\u6784\u5efa\u5728\u5176\u4ed6\u5e93\u4e4b\u4e0a&#xff0c;\u5f7c\u6b64\u65e0\u7f1d\u96c6\u6210\u3002\u4f60\u7528Pandas\u6e05\u6d17\u6570\u636e&#xff0c;\u5f97\u5230\u7684DataFrame\u53ef\u4ee5\u76f4\u63a5\u5582\u7ed9Scikit-learn\u8fdb\u884c\u5efa\u6a21&#xff0c;\u7136\u540e\u7528Matplotlib\u5c06\u7ed3\u679c\u753b\u51fa\u6765\u3002\u8fd9\u79cd\u6d41\u7545\u7684\u4f53\u9a8c&#xff0c;\u662f\u5176\u4ed6\u4efb\u4f55\u8bed\u8a00\u751f\u6001\u90fd\u96be\u4ee5\u6bd4\u62df\u7684\u3002\u6b63\u662f\u8fd9\u4e2a\u539f\u56e0&#xff0c;\u6700\u7ec8\u4f7f\u5f97Python\u6218\u80dc\u4e86R\u3001MATLAB\u3001Java\u7b49\u7ade\u4e89\u8005&#xff0c;\u6210\u4e3a\u4e86\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d\u3002<\/p>\n<hr \/>\n<h4>1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;<\/h4>\n<p>\u968f\u7740AlphaGo\u7684\u80dc\u5229\u548cChatGPT\u7684\u60ca\u8273\u8868\u73b0&#xff0c;\u4eba\u5de5\u667a\u80fd&#xff08;AI&#xff09;\u4ee5\u524d\u6240\u672a\u6709\u7684\u59ff\u6001\u8fdb\u5165\u4e86\u516c\u4f17\u89c6\u91ce\u3002\u5a92\u4f53\u7684\u6e32\u67d3\u3001\u79d1\u5e7b\u4f5c\u54c1\u7684\u60f3\u8c61&#xff0c;\u4f7f\u5f97AI\u7684\u5f62\u8c61\u5728\u4eba\u4eec\u5fc3\u4e2d\u53d8\u5f97\u6a21\u7cca\u3001\u751a\u81f3\u4e24\u6781\u5206\u5316&#xff1a;\u4e00\u4e9b\u4eba\u89c6\u4e4b\u4e3a\u65e0\u6240\u4e0d\u80fd\u3001\u5373\u5c06\u53d6\u4ee3\u4eba\u7c7b\u7684\u201c\u795e\u201d&#xff1b;\u53e6\u4e00\u4e9b\u4eba\u5219\u5fe7\u5fc3\u5fe1\u5fe1&#xff0c;\u5c06\u5176\u89c6\u4e3a\u53ef\u80fd\u5931\u63a7\u7684\u201c\u6f58\u591a\u62c9\u9b54\u76d2\u201d\u3002<\/p>\n<p>\u4f5c\u4e3a\u5373\u5c06\u8e0f\u5165\u8fd9\u4e2a\u9886\u57df\u7684\u5b9e\u8df5\u8005&#xff0c;\u6211\u4eec\u5fc5\u987b\u5efa\u7acb\u4e00\u4e2a\u6e05\u9192\u3001\u7406\u6027\u7684\u8ba4\u77e5&#xff1a;\u5728\u53ef\u9884\u89c1\u7684\u672a\u6765&#xff0c;\u6211\u4eec\u4eca\u5929\u6240\u8c08\u8bba\u548c\u5b9e\u8df5\u7684AI&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u201c\u5668\u201d&#xff0c;\u800c\u975e\u201c\u795e\u201d\u3002\u00a0\u5b83\u662f\u4e00\u79cd\u7531\u4eba\u7c7b\u8bbe\u8ba1&#xff0c;\u57fa\u4e8e\u6570\u5b66\u548c\u6570\u636e&#xff0c;\u7528\u4e8e\u653e\u5927\u4eba\u7c7b\u667a\u6167\u3001\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u5f3a\u5927\u5de5\u5177\u3002<\/p>\n<h5>1.4.1 \u673a\u5668\u5b66\u4e60\u7684\u80fd\u529b\u8fb9\u754c\u4e0e\u4f26\u7406\u6311\u6218<\/h5>\n<p>\u627f\u8ba4AI\u662f\u201c\u5668\u201d&#xff0c;\u610f\u5473\u7740\u6211\u4eec\u8981\u6e05\u9192\u5730\u8ba4\u8bc6\u5230\u5b83\u7684\u80fd\u529b\u8fb9\u754c\u3002<\/p>\n<li>\n<p>\u6570\u636e\u4f9d\u8d56\u6027&#xff1a;\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u80fd\u529b&#xff0c;\u5b8c\u5168\u53d6\u51b3\u4e8e\u5176\u201c\u5582\u517b\u201d\u7684\u6570\u636e\u3002\u6a21\u578b\u7684\u201c\u667a\u6167\u201d\u662f\u6570\u636e\u4e2d\u8574\u542b\u6a21\u5f0f\u7684\u53cd\u6620&#xff0c;\u5176\u201c\u504f\u89c1\u201d\u4e5f\u662f\u6570\u636e\u4e2d\u56fa\u6709\u504f\u89c1\u7684\u6298\u5c04\u3002\u5982\u679c\u8bad\u7ec3\u6570\u636e\u5b58\u5728\u504f\u5dee&#xff08;\u4f8b\u5982&#xff0c;\u5728\u62db\u8058\u6a21\u578b\u4e2d&#xff0c;\u5386\u53f2\u6570\u636e\u91cc\u7537\u6027\u5de5\u7a0b\u5e08\u8fdc\u591a\u4e8e\u5973\u6027&#xff09;&#xff0c;\u90a3\u4e48\u6a21\u578b\u5c31\u4f1a\u5b66\u4e60\u5e76\u653e\u5927\u8fd9\u79cd\u504f\u5dee&#xff0c;\u505a\u51fa\u6b67\u89c6\u6027\u7684\u5224\u65ad\u3002\u6a21\u578b\u65e0\u6cd5\u521b\u9020\u6570\u636e\u4e2d\u4e0d\u5b58\u5728\u7684\u77e5\u8bc6\u3002<\/p>\n<\/li>\n<li>\n<p>\u6cdb\u5316\u80fd\u529b\u7684\u5c40\u9650&#xff1a;\u6a21\u578b\u5728\u8bad\u7ec3\u6570\u636e\u4e0a\u8868\u73b0\u597d&#xff0c;\u4e0d\u4ee3\u8868\u5728\u5168\u65b0\u7684\u3001\u5206\u5e03\u5dee\u5f02\u5de8\u5927\u7684\u73b0\u5b9e\u4e16\u754c\u6570\u636e\u4e0a\u4f9d\u7136\u8868\u73b0\u597d\u3002\u8fd9\u79cd\u4ece\u5df2\u77e5\u5230\u672a\u77e5\u7684\u63a8\u5e7f\u80fd\u529b&#xff0c;\u88ab\u79f0\u4e3a\u6cdb\u5316&#xff08;Generalization&#xff09;\u3002\u63d0\u5347\u6cdb\u5316\u80fd\u529b\u662f\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u6311\u6218\u4e4b\u4e00\u3002\u4e00\u4e2a\u5728\u52a0\u5dde\u623f\u4ef7\u6570\u636e\u4e0a\u8bad\u7ec3\u5f97\u5f88\u597d\u7684\u6a21\u578b&#xff0c;\u76f4\u63a5\u62ff\u5230\u4e2d\u56fd\u5e02\u573a\u6765\u7528&#xff0c;\u7ed3\u679c\u51e0\u4e4e\u5fc5\u7136\u662f\u707e\u96be\u6027\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f3a\u4e4f\u5e38\u8bc6\u4e0e\u56e0\u679c\u63a8\u7406&#xff1a;\u76ee\u524d\u7684\u673a\u5668\u5b66\u4e60&#xff0c;\u5c24\u5176\u662f\u6df1\u5ea6\u5b66\u4e60&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u57fa\u4e8e\u76f8\u5173\u6027\u7684\u201c\u6a21\u5f0f\u5339\u914d\u201d\u3002\u5b83\u64c5\u957f\u53d1\u73b0\u201cA\u548cB\u7ecf\u5e38\u4e00\u8d77\u51fa\u73b0\u201d&#xff0c;\u4f46\u901a\u5e38\u65e0\u6cd5\u7406\u89e3\u201c\u662f\u4e0d\u662f\u56e0\u4e3aA\u5bfc\u81f4\u4e86B\u201d\u3002\u5b83\u7f3a\u4e4f\u4eba\u7c7b\u4e0e\u751f\u4ff1\u6765\u7684\u5927\u91cf\u80cc\u666f\u77e5\u8bc6\u548c\u5e38\u8bc6\u3002\u4e00\u4e2a\u80fd\u8bc6\u522b\u56fe\u7247\u4e2d\u201c\u9a6c\u201d\u7684\u6a21\u578b&#xff0c;\u5e76\u4e0d\u77e5\u9053\u9a6c\u662f\u4e00\u79cd\u52a8\u7269&#xff0c;\u4e0d\u80fd\u7a7f\u8fc7\u5899\u58c1\u3002\u8fd9\u79cd\u80fd\u529b\u7684\u7f3a\u5931&#xff0c;\u4f7f\u5176\u5728\u9700\u8981\u6df1\u5ea6\u7406\u89e3\u548c\u63a8\u7406\u7684\u590d\u6742\u51b3\u7b56\u573a\u666f\u4e2d&#xff0c;\u4f9d\u7136\u975e\u5e38\u8106\u5f31\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u89e3\u91ca\u6027&#xff08;Interpretability&#xff09;\u7684\u6311\u6218&#xff1a;\u7279\u522b\u662f\u5bf9\u4e8e\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\u8fd9\u7c7b\u590d\u6742\u7684\u201c\u9ed1\u7bb1\u201d\u6a21\u578b&#xff0c;\u6211\u4eec\u5f80\u5f80\u5f88\u96be\u7406\u89e3\u5b83\u4e3a\u4ec0\u4e48\u4f1a\u505a\u51fa\u67d0\u4e2a\u5177\u4f53\u7684\u51b3\u7b56\u3002\u4e00\u4e2a\u6a21\u578b\u62d2\u7edd\u4e86\u4f60\u7684\u8d37\u6b3e\u7533\u8bf7&#xff0c;\u4f46\u5b83\u65e0\u6cd5\u50cf\u4eba\u7c7b\u4fe1\u8d37\u5458\u90a3\u6837&#xff0c;\u7ed9\u4f60\u4e00\u4e2a\u6e05\u6670\u3001\u5408\u4e4e\u903b\u8f91\u7684\u7406\u7531\u3002\u8fd9\u79cd\u201c\u77e5\u5176\u7136&#xff0c;\u800c\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\u201d\u7684\u7279\u6027&#xff0c;\u5728\u91d1\u878d\u3001\u533b\u7597\u3001\u53f8\u6cd5\u7b49\u9ad8\u98ce\u9669\u9886\u57df&#xff0c;\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\u3002<\/p>\n<\/li>\n<p>\u8ba4\u8bc6\u5230\u8fd9\u4e9b\u8fb9\u754c&#xff0c;\u81ea\u7136\u4f1a\u5f15\u51fa\u6211\u4eec\u5fc5\u987b\u9762\u5bf9\u7684\u4f26\u7406\u6311\u6218&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u504f\u89c1\u4e0e\u516c\u5e73\u6027&#xff08;Bias and Fairness&#xff09;&#xff1a;\u5982\u4f55\u786e\u4fdd\u7b97\u6cd5\u4e0d\u4f1a\u5bf9\u7279\u5b9a\u4eba\u7fa4\u4ea7\u751f\u7cfb\u7edf\u6027\u7684\u6b67\u89c6&#xff1f;\u8fd9\u4e0d\u4ec5\u4ec5\u662f\u6280\u672f\u95ee\u9898&#xff0c;\u66f4\u662f\u793e\u4f1a\u6b63\u4e49\u95ee\u9898\u3002\u6211\u4eec\u9700\u8981\u5f00\u53d1\u80fd\u591f\u68c0\u6d4b\u3001\u91cf\u5316\u5e76\u7f13\u89e3\u504f\u89c1\u7684\u7b97\u6cd5&#xff0c;\u5e76\u5728\u6a21\u578b\u8bbe\u8ba1\u4e4b\u521d\u5c31\u5c06\u516c\u5e73\u6027\u4f5c\u4e3a\u6838\u5fc3\u76ee\u6807\u4e4b\u4e00\u3002<\/p>\n<\/li>\n<li>\n<p>\u9690\u79c1&#xff08;Privacy&#xff09;&#xff1a;\u5728\u5229\u7528\u6d77\u91cf\u4e2a\u4eba\u6570\u636e\u8bad\u7ec3\u6a21\u578b\u7684\u540c\u65f6&#xff0c;\u5982\u4f55\u4fdd\u62a4\u7528\u6237\u7684\u9690\u79c1\u6743&#xff1f;\u50cf\u8054\u90a6\u5b66\u4e60&#xff08;Federated Learning&#xff09;\u548c\u5dee\u5206\u9690\u79c1&#xff08;Differential Privacy&#xff09;\u8fd9\u6837\u7684\u6280\u672f\u6b63\u5728\u4e3a\u6b64\u52aa\u529b&#xff0c;\u5b83\u4eec\u65e8\u5728\u8ba9\u6a21\u578b\u5728\u4e0d\u63a5\u89e6\u539f\u59cb\u654f\u611f\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u5b8c\u6210\u5b66\u4e60&#xff0c;\u6216\u8005\u5728\u6570\u636e\u53d1\u5e03\u65f6\u52a0\u5165\u6570\u5b66\u4e0a\u53ef\u4fdd\u8bc1\u7684\u201c\u566a\u58f0\u201d\u6765\u4fdd\u62a4\u4e2a\u4f53\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d23\u4efb&#xff08;Accountability&#xff09;&#xff1a;\u5f53\u4e00\u4e2a\u81ea\u52a8\u9a7e\u9a76\u6c7d\u8f66\u53d1\u751f\u4e8b\u6545&#xff0c;\u6216\u4e00\u4e2aAI\u533b\u7597\u8bca\u65ad\u7cfb\u7edf\u51fa\u73b0\u8bef\u8bca\u65f6&#xff0c;\u8d23\u4efb\u8be5\u7531\u8c01\u6765\u627f\u62c5&#xff1f;\u662f\u7528\u6237\u3001\u5f00\u53d1\u8005\u3001\u516c\u53f8&#xff0c;\u8fd8\u662fAI\u672c\u8eab&#xff1f;\u8fd9\u9700\u8981\u5efa\u7acb\u6e05\u6670\u7684\u6cd5\u5f8b\u6cd5\u89c4\u548c\u95ee\u8d23\u6846\u67b6&#xff0c;\u786e\u4fdd\u6280\u672f\u7684\u6bcf\u4e00\u4e2a\u73af\u8282\u90fd\u6709\u660e\u786e\u7684\u8d23\u4efb\u4e3b\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u5168\u4e0e\u9c81\u68d2\u6027&#xff08;Safety and Robustness&#xff09;&#xff1a;\u5982\u4f55\u9632\u6b62AI\u7cfb\u7edf\u88ab\u6076\u610f\u653b\u51fb&#xff08;\u4f8b\u5982&#xff0c;\u901a\u8fc7\u5728\u505c\u8f66\u6807\u5fd7\u4e0a\u8d34\u4e00\u4e2a\u4e0d\u8d77\u773c\u7684\u8d34\u7eb8&#xff0c;\u5c31\u8ba9\u81ea\u52a8\u9a7e\u9a76\u7684\u8bc6\u522b\u7cfb\u7edf\u5c06\u5176\u8bef\u5224\u4e3a\u9650\u901f\u6807\u5fd7&#xff09;&#xff1f;\u7814\u7a76\u6a21\u578b\u7684\u201c\u8106\u5f31\u6027\u201d&#xff0c;\u53d1\u5c55\u201c\u5bf9\u6297\u6027\u8bad\u7ec3\u201d\u7b49\u9632\u5fa1\u6280\u672f&#xff0c;\u662f\u786e\u4fddAI\u7cfb\u7edf\u5728\u73b0\u5b9e\u4e16\u754c\u4e2d\u5b89\u5168\u53ef\u9760\u7684\u5173\u952e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5931\u4e1a\u4e0e\u793e\u4f1a\u7ed3\u6784&#xff1a;AI\u81ea\u52a8\u5316\u5c06\u5728\u591a\u5927\u7a0b\u5ea6\u4e0a\u53d6\u4ee3\u4eba\u7c7b\u5de5\u4f5c&#xff0c;\u6211\u4eec\u5e94\u5982\u4f55\u5e94\u5bf9\u7531\u6b64\u5e26\u6765\u7684\u793e\u4f1a\u7ed3\u6784\u6027\u53d8\u8fc1&#xff1f;\u8fd9\u9700\u8981\u653f\u7b56\u5236\u5b9a\u8005\u3001\u6559\u80b2\u5bb6\u548c\u5168\u793e\u4f1a\u5171\u540c\u601d\u8003&#xff0c;\u5982\u4f55\u8fdb\u884c\u6559\u80b2\u6539\u9769\u3001\u5efa\u7acb\u793e\u4f1a\u4fdd\u969c\u4f53\u7cfb&#xff0c;\u4ee5\u53ca\u521b\u9020\u65b0\u7684\u5de5\u4f5c\u5c97\u4f4d&#xff0c;\u4ee5\u9002\u5e94\u4eba\u673a\u534f\u4f5c\u7684\u65b0\u65f6\u4ee3\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u6311\u6218\u63d0\u9192\u6211\u4eec&#xff0c;\u673a\u5668\u5b66\u4e60\u7684\u5b9e\u8df5\u8005&#xff0c;\u7edd\u4e0d\u80fd\u4ec5\u4ec5\u662f\u4e00\u4e2a\u57cb\u5934\u4e8e\u4ee3\u7801\u548c\u6a21\u578b\u7684\u201c\u6280\u672f\u5de5\u5320\u201d\u3002\u6211\u4eec\u5fc5\u987b\u6210\u4e3a\u4e00\u4e2a\u8d1f\u8d23\u4efb\u7684\u201c\u601d\u8003\u8005\u201d&#xff0c;\u65f6\u523b\u5ba1\u89c6\u6211\u4eec\u521b\u9020\u7684\u6280\u672f\u53ef\u80fd\u5e26\u6765\u7684\u6df1\u8fdc\u5f71\u54cd\u3002<\/p>\n<h5>1.4.2 \u5fc3\u6cd5&#xff1a;\u4ee5\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3&#xff0c;\u505a\u201c\u5165\u4e16\u201d\u4e4b\u4e8b<\/h5>\n<p>\u9762\u5bf9\u673a\u5668\u5b66\u4e60\u7684\u5f3a\u5927\u80fd\u529b\u4e0e\u6df1\u523b\u6311\u6218&#xff0c;\u6211\u4eec\u5e94\u79c9\u6301\u600e\u6837\u7684\u5fc3\u6001\u548c\u539f\u5219\u6765\u4ece\u4e8b\u8fd9\u9879\u4e8b\u4e1a&#xff1f;\u5728\u6b64&#xff0c;\u5976\u5976\u60f3\u4e0e\u4f60\u5206\u4eab\u4e00\u79cd\u201c\u5fc3\u6cd5\u201d&#xff0c;\u4e00\u79cd\u878d\u5408\u4e86\u4e1c\u65b9\u667a\u6167\u4e0e\u79d1\u5b66\u7cbe\u795e\u7684\u4ece\u4e1a\u6001\u5ea6\u2014\u2014\u4ee5\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3&#xff0c;\u505a\u201c\u5165\u4e16\u201d\u4e4b\u4e8b\u3002<\/p>\n<p>\u4f55\u4e3a\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3&#xff1f;<\/p>\n<p>\u201c\u51fa\u4e16\u201d&#xff0c;\u5e76\u975e\u6d88\u6781\u907f\u4e16&#xff0c;\u800c\u662f\u6307\u4e00\u79cd\u8d85\u8d8a\u5177\u4f53\u4e8b\u52a1\u3001\u8ffd\u6c42\u4e8b\u7269\u672c\u6e90\u548c\u89c4\u5f8b\u7684\u8d85\u7136\u5fc3\u6001\u3002\u5b83\u8981\u6c42\u6211\u4eec\u5728\u7cbe\u795e\u5c42\u9762\u4fdd\u6301\u9ad8\u5ea6\u7684\u6e05\u9192\u3001\u5ba2\u89c2\u4e0e\u8c26\u5351\u3002<\/p>\n<li>\n<p>\u4fdd\u6301\u5bf9\u77e5\u8bc6\u7684\u656c\u754f&#xff1a;\u8981\u8ba4\u8bc6\u5230\u6211\u4eec\u6240\u5b66\u7684\u4e0d\u8fc7\u662f\u6ca7\u6d77\u4e00\u7c9f\u3002\u673a\u5668\u5b66\u4e60\u9886\u57df\u65e5\u65b0\u6708\u5f02&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4eba\u80fd\u5ba3\u79f0\u81ea\u5df1\u638c\u63e1\u4e86\u5168\u90e8\u3002\u4fdd\u6301\u7a7a\u676f\u5fc3\u6001&#xff0c;\u6301\u7eed\u5b66\u4e60&#xff0c;\u5bf9\u672a\u77e5\u4fdd\u6301\u597d\u5947\u4e0e\u656c\u754f&#xff0c;\u8fd9\u662f\u907f\u514d\u6280\u672f\u50b2\u6162\u7684\u6839\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u8ffd\u6c42\u771f\u7406&#xff0c;\u800c\u975e\u8fce\u5408\u6307\u6807&#xff1a;\u5728\u9879\u76ee\u4e2d&#xff0c;\u6211\u4eec\u5e38\u5e38\u4f1a\u4e3a\u4e86\u63d0\u5347\u67d0\u4e2a\u8bc4\u4f30\u6307\u6807&#xff08;\u5982\u51c6\u786e\u7387&#xff09;\u800c\u65e0\u6240\u4e0d\u7528\u5176\u6781\u3002\u4f46\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3\u63d0\u9192\u6211\u4eec&#xff0c;\u8981\u65f6\u523b\u53cd\u601d\u8fd9\u4e2a\u6307\u6807\u662f\u5426\u771f\u6b63\u53cd\u6620\u4e86\u6211\u4eec\u60f3\u8981\u89e3\u51b3\u7684\u73b0\u5b9e\u95ee\u9898\u3002\u6709\u65f6&#xff0c;0.1%\u7684\u51c6\u786e\u7387\u63d0\u5347\u53ef\u80fd\u4f34\u968f\u7740\u5bf9\u67d0\u4e00\u7fa4\u4f53\u516c\u5e73\u6027\u7684\u5de8\u5927\u635f\u5bb3\u3002\u6211\u4eec\u7684\u76ee\u6807\u662f\u89e3\u51b3\u95ee\u9898&#xff0c;\u800c\u4e0d\u4ec5\u4ec5\u662f\u4f18\u5316\u6570\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>\u65c1\u89c2\u8005\u6e05&#xff0c;\u5ba1\u89c6\u5168\u5c40&#xff1a;\u5728\u57cb\u5934\u4e8e\u7279\u5f81\u5de5\u7a0b\u548c\u6a21\u578b\u8c03\u4f18\u7684\u201c\u5165\u4e16\u201d\u72b6\u6001\u4e2d&#xff0c;\u8981\u65f6\u5e38\u62bd\u79bb\u51fa\u6765&#xff0c;\u50cf\u4e00\u4e2a\u201c\u51fa\u4e16\u201d\u7684\u65c1\u89c2\u8005\u4e00\u6837\u5ba1\u89c6\u81ea\u5df1\u7684\u5de5\u4f5c\u3002\u95ee\u81ea\u5df1&#xff1a;\u6211\u505a\u7684\u4e8b\u60c5\u662f\u5426\u6709\u6f5c\u5728\u7684\u8d1f\u9762\u5f71\u54cd&#xff1f;\u6211\u7684\u6a21\u578b\u662f\u5426\u53ef\u80fd\u88ab\u6ee5\u7528&#xff1f;\u6211\u662f\u5426\u8003\u8651\u4e86\u6240\u6709\u76f8\u5173\u7684\u5229\u76ca\u65b9&#xff1f;\u8fd9\u79cd\u81ea\u6211\u5ba1\u89c6&#xff0c;\u662f\u6280\u672f\u4f26\u7406\u7684\u7b2c\u4e00\u9053\u9632\u7ebf\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u6267\u4e8e\u201c\u6211\u201d&#xff1a;\u4e0d\u6267\u7740\u4e8e\u201c\u6211\u201d\u7684\u6a21\u578b\u3001\u201c\u6211\u201d\u7684\u65b9\u6cd5\u3002\u79d1\u5b66\u7684\u8fdb\u6b65\u5728\u4e8e\u5f00\u653e\u4e0e\u534f\u4f5c\u3002\u8981\u4e50\u4e8e\u5206\u4eab&#xff0c;\u6562\u4e8e\u627f\u8ba4\u81ea\u5df1\u65b9\u6cd5\u7684\u5c40\u9650&#xff0c;\u5e76\u79ef\u6781\u5438\u6536\u4ed6\u4eba\u7684\u667a\u6167\u3002\u4e00\u4e2a\u7b97\u6cd5\u3001\u4e00\u4e2a\u6a21\u578b\u7684\u4ef7\u503c&#xff0c;\u5728\u4e8e\u5b83\u80fd\u89e3\u51b3\u95ee\u9898&#xff0c;\u800c\u4e0d\u5728\u4e8e\u5b83\u5c5e\u4e8e\u8c01\u3002<\/p>\n<\/li>\n<p>\u4f55\u4e3a\u201c\u5165\u4e16\u201d\u4e4b\u4e8b&#xff1f;<\/p>\n<p>\u201c\u5165\u4e16\u201d&#xff0c;\u5c31\u662f\u79ef\u6781\u5730\u6295\u8eab\u4e8e\u73b0\u5b9e\u4e16\u754c&#xff0c;\u7528\u6211\u4eec\u6240\u5b66\u7684\u77e5\u8bc6\u53bb\u89e3\u51b3\u5177\u4f53\u3001\u5b9e\u9645\u7684\u95ee\u9898&#xff0c;\u521b\u9020\u771f\u5b9e\u7684\u4ef7\u503c\u3002\u5b83\u8981\u6c42\u6211\u4eec\u811a\u8e0f\u5b9e\u5730&#xff0c;\u7cbe\u76ca\u6c42\u7cbe\u3002<\/p>\n<li>\n<p>\u95ee\u9898\u9a71\u52a8&#xff0c;\u800c\u975e\u6280\u672f\u9a71\u52a8&#xff1a;\u8981\u4ece\u771f\u5b9e\u7684\u9700\u6c42\u51fa\u53d1&#xff0c;\u800c\u4e0d\u662f\u62ff\u7740\u201c\u9524\u5b50\u201d&#xff08;\u67d0\u4e2a\u70ab\u9177\u7684\u65b0\u6a21\u578b&#xff09;\u5230\u5904\u627e\u201c\u9489\u5b50\u201d\u3002\u6df1\u523b\u7406\u89e3\u4e1a\u52a1\u573a\u666f&#xff0c;\u4e0e\u9886\u57df\u4e13\u5bb6\u7d27\u5bc6\u5408\u4f5c&#xff0c;\u8ba9\u6280\u672f\u771f\u6b63\u670d\u52a1\u4e8e\u76ee\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u52a8\u624b\u5b9e\u8df5&#xff0c;\u7cbe\u76ca\u6c42\u7cbe&#xff1a;\u673a\u5668\u5b66\u4e60\u7ec8\u7a76\u662f\u4e00\u95e8\u5b9e\u8df5\u79d1\u5b66\u3002\u201c\u7eb8\u4e0a\u5f97\u6765\u7ec8\u89c9\u6d45&#xff0c;\u7edd\u77e5\u6b64\u4e8b\u8981\u8eac\u884c\u3002\u201d \u5fc5\u987b\u4eb2\u624b\u5904\u7406\u6570\u636e&#xff0c;\u7f16\u5199\u4ee3\u7801&#xff0c;\u8bad\u7ec3\u6a21\u578b&#xff0c;\u5206\u6790\u7ed3\u679c\u3002\u5728\u6bcf\u4e00\u4e2a\u7ec6\u8282\u4e0a\u8ffd\u6c42\u5353\u8d8a&#xff0c;\u4ee3\u7801\u8981\u6e05\u6670&#xff0c;\u5b9e\u9a8c\u8981\u4e25\u8c28&#xff0c;\u7ed3\u679c\u8981\u53ef\u590d\u73b0\u3002\u8fd9\u662f\u5de5\u5320\u7cbe\u795e\u7684\u4f53\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u9020\u4ef7\u503c&#xff0c;\u52c7\u4e8e\u62c5\u5f53&#xff1a;\u6211\u4eec\u7684\u6700\u7ec8\u76ee\u6807&#xff0c;\u662f\u5229\u7528\u673a\u5668\u5b66\u4e60\u6280\u672f&#xff0c;\u5728\u533b\u7597\u3001\u6559\u80b2\u3001\u73af\u4fdd\u3001\u79d1\u7814\u7b49\u9886\u57df\u505a\u51fa\u79ef\u6781\u7684\u8d21\u732e\u3002\u540c\u65f6&#xff0c;\u4e5f\u8981\u52c7\u4e8e\u4e3a\u81ea\u5df1\u521b\u9020\u7684\u6280\u672f\u6210\u679c\u8d1f\u8d23\u3002\u5982\u679c\u53d1\u73b0\u5b83\u5e26\u6765\u4e86\u610f\u60f3\u4e0d\u5230\u7684\u8d1f\u9762\u540e\u679c&#xff0c;\u8981\u6709\u52c7\u6c14\u7ad9\u51fa\u6765\u627f\u8ba4\u5e76\u52aa\u529b\u4fee\u6b63\u3002<\/p>\n<\/li>\n<p>\u201c\u51fa\u4e16\u201d\u4e0e\u201c\u5165\u4e16\u201d\u7684\u8fa9\u8bc1\u7edf\u4e00<\/p>\n<p>\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3\u662f\u201c\u4f53\u201d&#xff0c;\u662f\u6211\u4eec\u7684\u4e16\u754c\u89c2\u548c\u4ef7\u503c\u89c2&#xff0c;\u5b83\u4e3a\u6211\u4eec\u6307\u660e\u65b9\u5411&#xff0c;\u8bbe\u5b9a\u5e95\u7ebf&#xff0c;\u8ba9\u6211\u4eec\u4e0d\u8ff7\u5931\u5728\u6280\u672f\u7684\u6d2a\u6d41\u4e2d\u3002\u201c\u5165\u4e16\u201d\u4e4b\u4e8b\u662f\u201c\u7528\u201d&#xff0c;\u662f\u6211\u4eec\u7684\u65b9\u6cd5\u8bba\u548c\u884c\u52a8\u529b&#xff0c;\u5b83\u8ba9\u6211\u4eec\u5c06\u7406\u60f3\u8f6c\u5316\u4e3a\u73b0\u5b9e&#xff0c;\u5c06\u667a\u6167\u843d\u5730\u4e3a\u4ef7\u503c\u3002<\/p>\n<p>\u53ea\u201c\u51fa\u4e16\u201d\u800c\u65e0\u201c\u5165\u4e16\u201d&#xff0c;\u5219\u6613\u6d41\u4e8e\u7a7a\u8c08&#xff0c;\u6210\u4e3a\u201c\u5750\u800c\u8bba\u9053\u201d\u7684\u6e05\u8c08\u5ba2\u3002\u53ea\u201c\u5165\u4e16\u201d\u800c\u65e0\u201c\u51fa\u4e16\u201d&#xff0c;\u5219\u6613\u9677\u4e8e\u201c\u672f\u201d\u800c\u5fd8\u4e86\u201c\u9053\u201d&#xff0c;\u6210\u4e3a\u4e00\u4e2a\u9ad8\u6548\u4f46\u53ef\u80fd\u76f2\u76ee\u7684\u201c\u5de5\u5177\u4eba\u201d&#xff0c;\u751a\u81f3\u53ef\u80fd\u5728\u4e0d\u7ecf\u610f\u95f4\u201c\u4f5c\u6076\u201d\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u771f\u6b63\u7684\u5927\u5bb6&#xff0c;\u5fc5\u7136\u662f\u201c\u51fa\u4e16\u201d\u4e0e\u201c\u5165\u4e16\u201d\u7684\u5b8c\u7f8e\u7ed3\u5408\u3002\u4ed6\u4eec\u65e2\u6709\u4ef0\u671b\u661f\u7a7a\u7684\u6df1\u9083\u601d\u8003&#xff0c;\u53c8\u6709\u811a\u8e0f\u5b9e\u5730\u7684\u7cbe\u6e5b\u6280\u827a\u3002<\/p>\n<p>\u7ed3\u8bed<\/p>\n<p>\u4eb2\u7231\u7684\u8bfb\u8005&#xff0c;\u672c\u7ae0\u5373\u5c06\u7ed3\u675f\u3002\u6211\u4eec\u4e00\u540c\u63a2\u8ba8\u4e86\u5b66\u4e60\u7684\u672c\u8d28&#xff0c;\u56de\u987e\u4e86AI\u7684\u58ee\u9614\u5386\u53f2&#xff0c;\u660e\u786e\u4e86Python\u7684\u751f\u6001\u4f18\u52bf&#xff0c;\u5e76\u6700\u7ec8\u843d\u811a\u4e8e\u4ece\u4e1a\u8005\u7684\u5185\u5fc3\u4fee\u4e3a\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u756a\u201c\u52a1\u865a\u201d\u7684\u8ba8\u8bba&#xff0c;\u80fd\u4e3a\u60a8\u63a5\u4e0b\u6765\u7684\u201c\u52a1\u5b9e\u201d\u5b66\u4e60&#xff0c;\u6253\u4e0b\u575a\u5b9e\u7684\u5730\u57fa\u3002\u56e0\u4e3a\u6700\u9ad8\u660e\u7684\u6280\u672f&#xff0c;\u6c38\u8fdc\u7531\u6700\u6e05\u9192\u7684\u5934\u8111\u548c\u6700\u6b63\u76f4\u7684\u5fc3\u7075\u6240\u9a7e\u9a6d\u3002<\/p>\n<p>\u4ece\u4e0b\u4e00\u7ae0\u5f00\u59cb&#xff0c;\u6211\u4eec\u5c06\u6b63\u5f0f\u5377\u8d77\u8896\u5b50&#xff0c;\u8fdb\u5165Python\u4e0e\u673a\u5668\u5b66\u4e60\u5de5\u5177\u7684\u5b9e\u8df5\u4e16\u754c\u3002\u8bf7\u5e26\u7740\u8fd9\u4efd\u5bf9\u5168\u5c40\u7684\u8ba4\u77e5\u548c\u5185\u5fc3\u7684\u51c6\u5219&#xff0c;\u5f00\u59cb\u6211\u4eec\u771f\u6b63\u7684\u7b51\u57fa\u4e4b\u65c5\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e8c\u7ae0&#xff1a;\u5de5\u6b32\u5584\u5176\u4e8b\u2014\u2014Python\u73af\u5883\u4e0e\u6838\u5fc3\u5de5\u5177\u94fe<\/h3>\n<ul>\n<li>2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&#xff1a;Anaconda\u4e0eJupyter Notebook\u7684\u5b89\u88c5\u4e0e\u914d\u7f6e<\/li>\n<li>2.2 \u201c\u6570\u636e\u4e4b\u821f\u201d&#xff1a;NumPy\u6570\u503c\u8ba1\u7b97\u57fa\u7840<\/li>\n<li>2.3 \u201c\u6570\u636e\u4e4b\u9b42\u201d&#xff1a;Pandas\u6570\u636e\u5206\u6790\u5229\u5668<\/li>\n<li>2.4 \u201c\u773c\u89c1\u4e3a\u5b9e\u201d&#xff1a;Matplotlib\u4e0eSeaborn\u6570\u636e\u53ef\u89c6\u5316<\/li>\n<\/ul>\n<p>\u5728\u4e0a\u4e00\u7ae0&#xff0c;\u6211\u4eec\u63a2\u8ba8\u4e86\u673a\u5668\u5b66\u4e60\u7684\u5b8f\u5927\u4e16\u754c\u89c2\u3002\u73b0\u5728&#xff0c;\u6211\u4eec\u8981\u5c06\u8fd9\u4e9b\u601d\u60f3\u4ed8\u8bf8\u5b9e\u8df5\u3002\u5b9e\u8df5\u7684\u7b2c\u4e00\u6b65&#xff0c;\u4fbf\u662f\u6784\u5efa\u4e00\u4e2a\u7a33\u5b9a\u3001\u53ef\u9760\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u4f5c\u73af\u5883\u3002\u672c\u7ae0\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u4ece\u73af\u5883\u5b89\u88c5\u5230\u6838\u5fc3\u5de5\u5177\u638c\u63e1\u7684\u5168\u8fc7\u7a0b&#xff0c;\u4e3a\u60a8\u540e\u7eed\u7684\u5b66\u4e60\u626b\u6e05\u969c\u788d\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u9996\u5148\u4ecb\u7ecd\u5e76\u5b89\u88c5Anaconda&#xff0c;\u8fd9\u4e2a\u88ab\u8a89\u4e3a\u6570\u636e\u79d1\u5b66\u201c\u5168\u5bb6\u6876\u201d\u7684\u53d1\u884c\u7248&#xff0c;\u5b83\u80fd\u4e00\u7ad9\u5f0f\u89e3\u51b3Python\u73af\u5883\u7ba1\u7406\u548c\u5305\u5b89\u88c5\u7684\u96be\u9898\u3002\u63a5\u7740&#xff0c;\u6211\u4eec\u5c06\u5b66\u4e60\u4f7f\u7528Jupyter Notebook&#xff0c;\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684\u201c\u6570\u5b57\u5b9e\u9a8c\u5ba4\u201d&#xff0c;\u5b83\u5c06\u6210\u4e3a\u6211\u4eec\u63a2\u7d22\u3001\u5b9e\u9a8c\u548c\u5c55\u793a\u5de5\u4f5c\u7684\u4e3b\u8981\u5e73\u53f0\u3002<\/p>\n<p>\u968f\u540e&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u5b66\u4e60\u4e09\u4e2a\u6570\u636e\u79d1\u5b66\u7684\u201c\u5960\u57fa\u77f3\u201d\u5e93&#xff1a;<\/p>\n<ul>\n<li>NumPy&#xff1a;\u6211\u4eec\u7684\u201c\u6570\u636e\u4e4b\u821f\u201d&#xff0c;\u5b83\u4e3aPython\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u591a\u7ef4\u6570\u7ec4\u548c\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\u80fd\u529b\u3002<\/li>\n<li>Pandas&#xff1a;\u6211\u4eec\u7684\u201c\u6570\u636e\u4e4b\u9b42\u201d&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u8ba9\u5904\u7406\u548c\u5206\u6790\u7ed3\u6784\u5316\u6570\u636e\u53d8\u5f97\u8f7b\u800c\u6613\u4e3e\u3002<\/li>\n<li>Matplotlib &amp; Seaborn&#xff1a;\u6211\u4eec\u7684\u201c\u773c\u775b\u201d&#xff0c;\u5b83\u4eec\u80fd\u5c06\u67af\u71e5\u7684\u6570\u636e\u8f6c\u5316\u4e3a\u5bcc\u6709\u6d1e\u5bdf\u529b\u7684\u53ef\u89c6\u5316\u56fe\u8868\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u52a1\u5fc5\u5bf9\u672c\u7ae0\u5185\u5bb9\u6295\u5165\u8db3\u591f\u7684\u65f6\u95f4\u548c\u8010\u5fc3\u3002\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u5de5\u5177&#xff0c;\u60a8\u4f1a\u53d1\u73b0\u540e\u7eed\u7684\u5b66\u4e60\u5c06\u4e8b\u534a\u529f\u500d\u3002<\/p>\n<hr \/>\n<h4>2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&#xff1a;Anaconda\u4e0eJupyter Notebook\u7684\u5b89\u88c5\u4e0e\u914d\u7f6e<\/h4>\n<p>\u5728\u7f16\u7a0b\u4e16\u754c\u91cc&#xff0c;\u73af\u5883\u914d\u7f6e\u5f80\u5f80\u662f\u529d\u9000\u65b0\u624b\u7684\u201c\u7b2c\u4e00\u9053\u574e\u201d\u3002\u4e0d\u540c\u9879\u76ee\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7248\u672c\u7684Python\u6216\u4f9d\u8d56\u5e93&#xff0c;\u5982\u679c\u5c06\u6240\u6709\u4e1c\u897f\u90fd\u88c5\u5728\u7cfb\u7edf\u7684\u4e3bPython\u73af\u5883\u4e2d&#xff0c;\u5f88\u5feb\u5c31\u4f1a\u5bfc\u81f4\u7248\u672c\u51b2\u7a81\u548c\u6df7\u4e71&#xff0c;\u72b9\u5982\u4e00\u4e2a\u5806\u6ee1\u4e86\u5404\u79cd\u5de5\u5177\u3001\u96f6\u4ef6\u5374\u6742\u4e71\u65e0\u7ae0\u7684\u8f66\u5e93\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u4e13\u4e1a\u7684\u201c\u8f66\u5e93\u7ba1\u7406\u5458\u201d\u2014\u2014Anaconda\u3002<\/p>\n<p>\u4ec0\u4e48\u662fAnaconda&#xff1f;<\/p>\n<p>Anaconda\u5e76\u4e0d\u4ec5\u4ec5\u662fPython&#xff0c;\u5b83\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u6570\u636e\u79d1\u5b66\u7684Python\u53d1\u884c\u7248\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u4e3a\u4e00\u4e2a\u201c\u5927\u793c\u5305\u201d&#xff0c;\u91cc\u9762\u5305\u542b\u4e86&#xff1a;<\/p>\n<li>\u7279\u5b9a\u7248\u672c\u7684Python\u89e3\u91ca\u5668\u3002<\/li>\n<li>Conda&#xff1a;\u4e00\u4e2a\u5f3a\u5927\u7684\u5305\u7ba1\u7406\u5668\u548c\u73af\u5883\u7ba1\u7406\u5668\u3002<\/li>\n<li>\u9884\u88c5\u597d\u7684\u6570\u767e\u4e2a\u5e38\u7528\u79d1\u5b66\u8ba1\u7b97\u5305&#xff1a;\u5982NumPy, Pandas, Matplotlib, Scikit-learn\u7b49\u3002\u4f60\u65e0\u9700\u518d\u4e00\u4e2a\u4e2a\u624b\u52a8\u5b89\u88c5&#xff0c;\u7701\u53bb\u4e86\u5927\u91cf\u7684\u914d\u7f6e\u9ebb\u70e6\u3002<\/li>\n<p>\u4e3a\u4f55\u9009\u62e9Anaconda&#xff1f;\u2014\u2014\u73af\u5883\u7ba1\u7406\u7684\u667a\u6167<\/p>\n<p>Anaconda\u6700\u6838\u5fc3\u7684\u4ef7\u503c\u5728\u4e8e\u5176\u9644\u5e26\u7684conda\u5de5\u5177&#xff0c;\u5b83\u80fd\u8ba9\u6211\u4eec\u8f7b\u677e\u521b\u5efa\u76f8\u4e92\u9694\u79bb\u7684\u865a\u62df\u73af\u5883&#xff08;Virtual Environments&#xff09;\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u4f60\u8981\u540c\u65f6\u8fdb\u884c\u4e24\u4e2a\u9879\u76ee&#xff1a;<\/p>\n<ul>\n<li>\u9879\u76eeA&#xff0c;\u662f\u4e00\u4e2a\u8001\u9879\u76ee&#xff0c;\u9700\u8981\u4f7f\u7528Python 3.7\u548c\u4e00\u4e2a\u65e7\u7248\u7684\u5e93X (\u7248\u672c1.0)\u3002<\/li>\n<li>\u9879\u76eeB&#xff0c;\u662f\u4e00\u4e2a\u65b0\u9879\u76ee&#xff0c;\u4f60\u60f3\u4f7f\u7528\u6700\u65b0\u7684Python 3.11\u548c\u5e93X\u7684\u65b0\u7248\u672c (\u7248\u672c2.0)\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u6ca1\u6709\u73af\u5883\u9694\u79bb&#xff0c;\u8fd9\u4e24\u4e2a\u9879\u76ee\u6839\u672c\u65e0\u6cd5\u5728\u540c\u4e00\u53f0\u7535\u8111\u4e0a\u5171\u5b58\u3002\u800c\u6709\u4e86conda&#xff0c;\u4f60\u53ef\u4ee5&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aproject_a_env\u7684\u73af\u5883&#xff0c;\u5728\u91cc\u9762\u5b89\u88c5Python 3.7\u548c\u5e93X 1.0\u3002<\/li>\n<li>\u518d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aproject_b_env\u7684\u73af\u5883&#xff0c;\u5728\u91cc\u9762\u5b89\u88c5Python 3.11\u548c\u5e93X 2.0\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u73af\u5883\u5982\u540c\u4e24\u4e2a\u72ec\u7acb\u7684\u5e73\u884c\u5b87\u5b99&#xff0c;\u4e92\u4e0d\u5e72\u6270\u3002\u4f60\u53ef\u4ee5\u968f\u65f6\u901a\u8fc7\u4e00\u6761\u7b80\u5355\u7684\u547d\u4ee4\u5728\u5b83\u4eec\u4e4b\u95f4\u5207\u6362\u3002\u8fd9\u79cd\u201c\u5206\u800c\u6cbb\u4e4b\u201d\u7684\u667a\u6167&#xff0c;\u662f\u4e13\u4e1a\u5f00\u53d1\u5b9e\u8df5\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u5b89\u88c5Anaconda<\/p>\n<p>\u5b89\u88c5\u8fc7\u7a0b\u975e\u5e38\u76f4\u89c2&#xff0c;\u4e0e\u5b89\u88c5\u666e\u901a\u8f6f\u4ef6\u65e0\u5f02\u3002<\/p>\n<li>\u8bbf\u95ee\u5b98\u7f51&#xff1a;\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Anaconda\u7684\u5b98\u65b9\u4e0b\u8f7d\u9875\u9762 (anaconda.com\/download)\u3002\u7f51\u7ad9\u901a\u5e38\u4f1a\u81ea\u52a8\u68c0\u6d4b\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf&#xff08;Windows, macOS, Linux&#xff09;\u5e76\u63a8\u8350\u5408\u9002\u7684\u7248\u672c\u3002<\/li>\n<li>\u9009\u62e9\u7248\u672c&#xff1a;\u9009\u62e9\u4e0e\u4f60\u64cd\u4f5c\u7cfb\u7edf\u5bf9\u5e94\u7684\u6700\u65b0Python 3.x\u7248\u672c\u7684\u56fe\u5f62\u5316\u5b89\u88c5\u5305&#xff08;Graphical Installer&#xff09;\u8fdb\u884c\u4e0b\u8f7d\u3002<\/li>\n<li>\u6267\u884c\u5b89\u88c5&#xff1a;\n<ul>\n<li>\u53cc\u51fb\u4e0b\u8f7d\u597d\u7684\u5b89\u88c5\u5305\u3002<\/li>\n<li>\u6309\u7167\u63d0\u793a\u70b9\u51fb\u201cNext\u201d\u6216\u201cContinue\u201d\u3002<\/li>\n<li>\u5728\u8bb8\u53ef\u534f\u8bae\u9875\u9762&#xff0c;\u540c\u610f\u534f\u8bae\u3002<\/li>\n<li>\u5b89\u88c5\u7c7b\u578b\u9009\u62e9\u201cJust Me\u201d\u5373\u53ef&#xff08;\u9664\u975e\u4f60\u6709\u7279\u6b8a\u9700\u6c42\u4e3a\u7535\u8111\u6240\u6709\u7528\u6237\u5b89\u88c5&#xff09;\u3002<\/li>\n<li>\u5173\u952e\u6b65\u9aa4&#xff08;Windows&#xff09;&#xff1a;\u5728\u201cAdvanced Options\u201d\u754c\u9762&#xff0c;\u5efa\u8bae\u4e0d\u8981\u52fe\u9009\u201cAdd Anaconda to my PATH environment variable\u201d&#xff08;\u5c06Anaconda\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf&#xff09;\u3002\u867d\u7136\u52fe\u9009\u770b\u4f3c\u65b9\u4fbf&#xff0c;\u4f46\u957f\u671f\u6765\u770b\u5bb9\u6613\u5f15\u8d77\u4e0e\u5176\u4ed6Python\u5b89\u88c5\u7684\u51b2\u7a81\u3002\u5b98\u65b9\u63a8\u8350\u4f7f\u7528\u201cAnaconda Prompt\u201d\u6765\u542f\u52a8\u548c\u7ba1\u7406conda\u3002\u53e6\u4e00\u4e2a\u9009\u9879\u201cRegister Anaconda as my default Python\u201d\u53ef\u4ee5\u52fe\u9009\u3002<\/li>\n<li>\u9009\u62e9\u5b89\u88c5\u8def\u5f84&#xff08;\u901a\u5e38\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef&#xff09;&#xff0c;\u7136\u540e\u5f00\u59cb\u5b89\u88c5\u3002\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u51e0\u5206\u949f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u9a8c\u8bc1\u5b89\u88c5&#xff1a;\n<ul>\n<li>Windows: \u5728\u5f00\u59cb\u83dc\u5355\u4e2d\u627e\u5230\u5e76\u6253\u5f00\u201cAnaconda Prompt (anaconda3)\u201d\u3002<\/li>\n<li>macOS\/Linux: \u6253\u5f00\u4f60\u7684\u7ec8\u7aef&#xff08;Terminal&#xff09;\u3002<\/li>\n<li>\u5728\u6253\u5f00\u7684\u547d\u4ee4\u884c\u7a97\u53e3\u4e2d&#xff0c;\u8f93\u5165\u00a0conda &#8211;version\u00a0\u5e76\u56de\u8f66\u3002\u5982\u679c\u6210\u529f\u663e\u793a\u51faconda\u7684\u7248\u672c\u53f7&#xff08;\u5982\u00a0conda 23.7.4&#xff09;&#xff0c;\u5219\u8bc1\u660eAnaconda\u5df2\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u4f7f\u7528Conda\u521b\u5efa\u548c\u7ba1\u7406\u73af\u5883<\/p>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u6765\u5b9e\u8df5\u4e00\u4e0b\u73af\u5883\u7ba1\u7406\u7684\u5a01\u529b\u3002\u6253\u5f00\u4f60\u7684Anaconda Prompt\u6216\u7ec8\u7aef\u3002<\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u73af\u5883&#xff1a; \u6211\u4eec\u4e3a\u672c\u4e66\u521b\u5efa\u4e00\u4e2a\u4e13\u5c5e\u7684\u5b66\u4e60\u73af\u5883&#xff0c;\u547d\u540d\u4e3aml_book&#xff0c;\u5e76\u6307\u5b9a\u4f7f\u7528Python 3.9&#xff08;\u4e00\u4e2a\u7a33\u5b9a\u4e14\u517c\u5bb9\u6027\u597d\u7684\u7248\u672c&#xff09;\u3002<\/p>\n<p>conda create &#8211;name ml_book python&#061;3.9<\/p>\n<p>Conda\u4f1a\u8be2\u95ee\u4f60\u662f\u5426\u8981\u5b89\u88c5\u4e00\u4e9b\u57fa\u7840\u5305&#xff0c;\u8f93\u5165y\u5e76\u56de\u8f66\u3002<\/p>\n<\/li>\n<li>\n<p>\u6fc0\u6d3b\u73af\u5883&#xff1a; \u521b\u5efa\u597d\u540e&#xff0c;\u9700\u8981\u201c\u8fdb\u5165\u201d\u8fd9\u4e2a\u73af\u5883\u624d\u80fd\u4f7f\u7528\u5b83\u3002<\/p>\n<p>conda activate ml_book<\/p>\n<p>\u6fc0\u6d3b\u540e&#xff0c;\u4f60\u4f1a\u53d1\u73b0\u547d\u4ee4\u884c\u63d0\u793a\u7b26\u524d\u9762\u591a\u4e86(ml_book)\u7684\u5b57\u6837&#xff0c;\u8fd9\u8868\u793a\u4f60\u5f53\u524d\u6b63\u5904\u4e8e\u8fd9\u4e2a\u72ec\u7acb\u7684\u73af\u5883\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u73af\u5883\u4e2d\u5b89\u88c5\u5e93&#xff1a; \u73b0\u5728&#xff0c;\u6211\u4eec\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u5b89\u88c5\u672c\u4e66\u9700\u8981\u7684\u6838\u5fc3\u5e93\u3002\u7531\u4e8eAnaconda\u7684base\u73af\u5883\u5df2\u7ecf\u81ea\u5e26&#xff0c;\u6211\u4eec\u8fd9\u91cc\u4ec5\u4f5c\u6f14\u793a\u3002\u4f8b\u5982&#xff0c;\u5b89\u88c5seaborn\u3002<\/p>\n<p>conda install seaborn<\/p>\n<p>Conda\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb&#xff0c;\u4e00\u5e76\u5b89\u88c5\u597d\u6240\u6709\u9700\u8981\u7684\u5176\u4ed6\u5e93\u3002<\/p>\n<\/li>\n<li>\n<p>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5e93&#xff1a;<\/p>\n<p>conda list<\/p>\n<\/li>\n<li>\n<p>\u9000\u51fa\u73af\u5883&#xff1a; \u5f53\u4f60\u5b8c\u6210\u5de5\u4f5c&#xff0c;\u53ef\u4ee5\u9000\u56de\u5230\u57fa\u7840\u73af\u5883\u3002<\/p>\n<p>conda deactivate<\/p>\n<p>\u63d0\u793a\u7b26\u524d\u9762\u7684(ml_book)\u4f1a\u6d88\u5931\u3002<\/p>\n<\/li>\n<\/ul>\n<p>Jupyter Notebook&#xff1a;\u4f60\u7684\u4ea4\u4e92\u5f0f\u5b9e\u9a8c\u5ba4<\/p>\n<p>\u73af\u5883\u642d\u597d\u4e86&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u4e2a\u597d\u7528\u7684\u201c\u5de5\u4f5c\u53f0\u201d\u3002Jupyter Notebook\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u7406\u60f3\u7684\u5de5\u5177\u3002\u5b83\u662f\u4e00\u4e2a\u57fa\u4e8eWeb\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u5141\u8bb8\u4f60\u521b\u5efa\u548c\u5171\u4eab\u5305\u542b\u5b9e\u65f6\u4ee3\u7801\u3001\u516c\u5f0f\u3001\u53ef\u89c6\u5316\u548c\u53d9\u8ff0\u6027\u6587\u672c\u7684\u6587\u6863\u3002<\/p>\n<p>\u542f\u52a8Jupyter Notebook<\/p>\n<li>\u786e\u4fdd\u4f60\u5df2\u7ecf\u6fc0\u6d3b\u4e86\u4f60\u7684\u5de5\u4f5c\u73af\u5883&#xff08;conda activate ml_book&#xff09;\u3002<\/li>\n<li>\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165&#xff1a;\n<p>jupyter notebook<\/p>\n<\/li>\n<li>\u6267\u884c\u540e&#xff0c;\u4f60\u7684\u9ed8\u8ba4\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u6253\u5f00\u4e00\u4e2a\u65b0\u6807\u7b7e\u9875&#xff0c;\u5730\u5740\u901a\u5e38\u662fhttp:\/\/localhost:8888\/tree\u00a0\u3002\u8fd9\u5c31\u662fJupyter\u7684\u6587\u4ef6\u6d4f\u89c8\u5668\u754c\u9762\u3002\u547d\u4ee4\u884c\u7a97\u53e3\u4e0d\u8981\u5173\u95ed&#xff0c;\u56e0\u4e3a\u5b83\u662fJupyter\u670d\u52a1\u7684\u540e\u53f0\u3002<\/li>\n<p>Jupyter Notebook\u6838\u5fc3\u6982\u5ff5<\/p>\n<ul>\n<li>Notebook\u6587\u4ef6 (.ipynb)&#xff1a;\u4f60\u521b\u5efa\u7684\u6bcf\u4e00\u4e2aJupyter\u6587\u6863\u90fd\u662f\u4e00\u4e2a.ipynb\u6587\u4ef6&#xff0c;\u5b83\u7528\u4e00\u79cd\u7279\u6b8a\u683c\u5f0f&#xff08;JSON&#xff09;\u4fdd\u5b58\u4e86\u4f60\u6240\u6709\u7684\u4ee3\u7801\u3001\u6587\u672c\u548c\u8f93\u51fa\u3002<\/li>\n<li>\u5355\u5143\u683c&#xff08;Cell&#xff09;&#xff1a;Notebook\u7531\u4e00\u4e2a\u4e2a\u5355\u5143\u683c\u7ec4\u6210\u3002\u5355\u5143\u683c\u4e3b\u8981\u6709\u4e24\u79cd\u7c7b\u578b&#xff1a;\n<ul>\n<li>Code Cell&#xff08;\u4ee3\u7801\u5355\u5143\u683c&#xff09;&#xff1a;\u7528\u6765\u7f16\u5199\u548c\u6267\u884c\u4ee3\u7801&#xff08;\u5982Python\u4ee3\u7801&#xff09;\u3002<\/li>\n<li>Markdown Cell&#xff08;\u6587\u672c\u5355\u5143\u683c&#xff09;&#xff1a;\u7528\u6765\u7f16\u5199\u683c\u5f0f\u5316\u7684\u6587\u672c&#xff0c;\u5c31\u50cf\u4f60\u73b0\u5728\u6b63\u5728\u9605\u8bfb\u7684\u8fd9\u4e9b\u6587\u5b57\u4e00\u6837&#xff0c;\u53ef\u4ee5\u5305\u542b\u6807\u9898\u3001\u5217\u8868\u3001\u94fe\u63a5\u3001\u56fe\u7247\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5185\u6838&#xff08;Kernel&#xff09;&#xff1a;\u6bcf\u4e2aNotebook\u90fd\u6709\u4e00\u4e2a\u72ec\u7acb\u7684\u201c\u5185\u6838\u201d\u5728\u540e\u53f0\u8fd0\u884c\u3002\u8fd9\u4e2a\u5185\u6838\u662f\u4f60\u6fc0\u6d3b\u7684conda\u73af\u5883\u7684\u4f53\u73b0&#xff0c;\u5b83\u8d1f\u8d23\u63a5\u6536\u4f60\u5728Code Cell\u4e2d\u5199\u7684\u4ee3\u7801&#xff0c;\u6267\u884c\u5b83&#xff0c;\u7136\u540e\u5c06\u7ed3\u679c\u8fd4\u56de\u5e76\u663e\u793a\u5728\u5355\u5143\u683c\u4e0b\u65b9\u3002<\/li>\n<\/ul>\n<p>\u57fa\u672c\u64cd\u4f5c<\/p>\n<li>\u65b0\u5efaNotebook&#xff1a;\u5728Jupyter\u7684\u6587\u4ef6\u6d4f\u89c8\u5668\u9875\u9762&#xff0c;\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201cNew\u201d&#xff0c;\u7136\u540e\u9009\u62e9\u201cPython 3 (ipykernel)\u201d\u6216\u7c7b\u4f3c\u9009\u9879&#xff0c;\u5373\u53ef\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002<\/li>\n<li>\u5207\u6362\u5355\u5143\u683c\u7c7b\u578b&#xff1a;\u5728\u9009\u4e2d\u4e00\u4e2a\u5355\u5143\u683c\u540e&#xff0c;\u53ef\u4ee5\u5728\u9876\u90e8\u7684\u5de5\u5177\u680f\u4e0b\u62c9\u83dc\u5355\u4e2d\u9009\u62e9Code\u6216Markdown\u3002<\/li>\n<li>\u6267\u884c\u5355\u5143\u683c&#xff1a;\u9009\u4e2d\u4e00\u4e2a\u5355\u5143\u683c&#xff0c;\u6309\u4e0b\u00a0Shift &#043; Enter&#xff0c;Jupyter\u4f1a\u6267\u884c\u8be5\u5355\u5143\u683c&#xff0c;\u5e76\u81ea\u52a8\u8df3\u8f6c\u5230\u4e0b\u4e00\u4e2a\u5355\u5143\u683c\u3002\u8fd9\u662f\u6700\u5e38\u7528\u7684\u5feb\u6377\u952e\u3002<\/li>\n<li>\u4fdd\u5b58&#xff1a;\u70b9\u51fb\u5de6\u4e0a\u89d2\u7684\u4fdd\u5b58\u56fe\u6807&#xff0c;\u6216\u4f7f\u7528\u5feb\u6377\u952eCtrl &#043; S\u00a0(Windows\/Linux) \/\u00a0Cmd &#043; S\u00a0(macOS)\u3002<\/li>\n<p>\u73b0\u5728&#xff0c;\u8bf7\u4f60\u4eb2\u624b\u5c1d\u8bd5&#xff1a;<\/p>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Notebook\u3002<\/li>\n<li>\u5728\u7b2c\u4e00\u4e2a\u5355\u5143\u683c\u4e2d&#xff0c;\u8f93\u5165\u00a0print(&#034;Hello, Machine Learning World!&#034;)&#xff0c;\u7136\u540e\u6309Shift &#043; Enter\u6267\u884c\u3002<\/li>\n<li>\u5c06\u7b2c\u4e8c\u4e2a\u5355\u5143\u683c\u7684\u7c7b\u578b\u6539\u4e3aMarkdown&#xff0c;\u8f93\u5165# \u8fd9\u662f\u6211\u7684\u7b2c\u4e00\u4e2aNotebook\u6807\u9898&#xff0c;\u7136\u540e\u6309Shift &#043; Enter\u6e32\u67d3\u6587\u672c\u3002<\/li>\n<p>\u606d\u559c&#xff01;\u4f60\u5df2\u7ecf\u6210\u529f\u642d\u5efa\u4e86\u4e13\u4e1a\u7684\u5f00\u53d1\u73af\u5883&#xff0c;\u5e76\u638c\u63e1\u4e86\u4e0e\u5b83\u4ea4\u4e92\u7684\u57fa\u672c\u65b9\u5f0f\u3002\u8fd9\u4e2a\u73af\u5883\u5982\u540c\u4e00\u7247\u6c83\u571f&#xff0c;\u6211\u4eec\u63a5\u4e0b\u6765\u8981\u5b66\u4e60\u7684NumPy\u3001Pandas\u7b49\u5de5\u5177&#xff0c;\u5c31\u662f\u5c06\u8981\u5728\u8fd9\u7247\u571f\u5730\u4e0a\u8301\u58ee\u6210\u957f\u7684\u53c2\u5929\u5927\u6811\u3002<\/p>\n<hr \/>\n<h4>2.2 \u201c\u6570\u636e\u4e4b\u821f\u201d&#xff1a;NumPy\u6570\u503c\u8ba1\u7b97\u57fa\u7840<\/h4>\n<p>\u5982\u679c\u8bf4\u6570\u636e\u662f\u6d77\u6d0b&#xff0c;\u90a3NumPy (Numerical Python)\u00a0\u5c31\u662f\u6211\u4eec\u5728\u8fd9\u7247\u6d77\u6d0b\u4e0a\u822a\u884c\u7684\u7b2c\u4e00\u8258\u575a\u56fa\u5feb\u8239\u3002\u5b83\u662fPython\u79d1\u5b66\u8ba1\u7b97\u751f\u6001\u7684\u7edd\u5bf9\u6838\u5fc3&#xff0c;\u51e0\u4e4e\u6240\u6709\u4e0a\u5c42\u5e93&#xff08;\u5305\u62ecPandas\u548cScikit-learn&#xff09;\u90fd\u6784\u5efa\u4e8e\u5b83\u4e4b\u4e0a\u3002<\/p>\n<p>Python\u539f\u751f\u7684\u5217\u8868&#xff08;list&#xff09;\u867d\u7136\u7075\u6d3b&#xff0c;\u4f46\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u503c\u8fd0\u7b97&#xff0c;\u5176\u6027\u80fd\u4e0d\u582a\u4e00\u51fb\u3002NumPy\u7684\u6838\u5fc3\u662f\u5176ndarray&#xff08;N-dimensional array&#xff09;\u5bf9\u8c61&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u7531\u76f8\u540c\u7c7b\u578b\u5143\u7d20\u7ec4\u6210\u7684\u591a\u7ef4\u6570\u7ec4\u3002\u5b83\u7684\u4f18\u52bf\u5728\u4e8e&#xff1a;<\/p>\n<ul>\n<li>\u6027\u80fd&#xff1a;ndarray\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684&#xff0c;\u5e76\u4e14\u5176\u6838\u5fc3\u8fd0\u7b97\u7531C\u8bed\u8a00\u7f16\u5199\u7684\u5e95\u5c42\u4ee3\u7801\u6267\u884c&#xff0c;\u901f\u5ea6\u8fdc\u8d85Python\u539f\u751f\u5217\u8868\u3002<\/li>\n<li>\u4fbf\u6377&#xff1a;\u63d0\u4f9b\u4e86\u5927\u91cf\u7528\u4e8e\u6570\u7ec4\u64cd\u4f5c\u7684\u6570\u5b66\u51fd\u6570\u548c\u7ebf\u6027\u4ee3\u6570\u8fd0\u7b97&#xff0c;\u8bed\u6cd5\u7b80\u6d01\u3002<\/li>\n<\/ul>\n<p>\u5b89\u88c5NumPy<\/p>\n<p>\u5982\u679c\u4f60\u9075\u5faa\u4e86\u4e0a\u4e00\u8282\u4f7f\u7528Anaconda&#xff0c;\u90a3\u4e48NumPy\u5df2\u7ecf\u88ab\u9884\u88c5\u597d\u4e86\u3002\u5982\u679c\u6ca1\u6709&#xff0c;\u53ea\u9700\u5728\u6fc0\u6d3b\u7684\u73af\u5883\u4e2d\u8fd0\u884c&#xff1a;<\/p>\n<p>conda install numpy<\/p>\n<p>\u5bfc\u5165NumPy<\/p>\n<p>\u5728\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u9075\u5faa\u4e00\u4e2a\u5e7f\u6cdb\u63a5\u53d7\u7684\u60ef\u4f8b&#xff0c;\u5c06NumPy\u5bfc\u5165\u5e76\u7b80\u5199\u4e3anp\u3002<\/p>\n<p>import numpy as np<\/p>\n<h5>2.2.1 \u4ece\u6807\u91cf\u5230\u5f20\u91cf&#xff1a;\u7ef4\u5ea6\u7684\u54f2\u5b66<\/h5>\n<p>\u5728NumPy\u4e2d&#xff0c;\u6211\u4eec\u7528\u4e0d\u540c\u7684\u672f\u8bed\u6765\u63cf\u8ff0\u4e0d\u540c\u7ef4\u5ea6\u7684\u6570\u636e&#xff0c;\u8fd9\u4e0e\u7269\u7406\u5b66\u548c\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u201c\u5f20\u91cf&#xff08;Tensor&#xff09;\u201d\u6982\u5ff5\u4e00\u8109\u76f8\u627f\u3002\u7406\u89e3\u7ef4\u5ea6&#xff0c;\u662f\u7406\u89e3\u6570\u636e\u7ed3\u6784\u7684\u7b2c\u4e00\u6b65\u3002<\/p>\n<ul>\n<li>\n<p>\u6807\u91cf&#xff08;Scalar&#xff09;&#xff1a;\u4e00\u4e2a\u5355\u72ec\u7684\u6570\u5b57&#xff0c;\u59827\u3002\u5728NumPy\u4e2d&#xff0c;\u5b83\u662f\u4e00\u4e2a0\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>s &#061; np.array(7)<br \/>\nprint(s)<br \/>\nprint(&#034;\u7ef4\u5ea6:&#034;, s.ndim) # ndim\u5c5e\u6027\u67e5\u770b\u7ef4\u5ea6\u6570\u91cf<br \/>\n# \u8f93\u51fa:<br \/>\n# 7<br \/>\n# \u7ef4\u5ea6: 0<\/p>\n<\/li>\n<li>\n<p>\u5411\u91cf&#xff08;Vector&#xff09;&#xff1a;\u4e00\u5217\u6709\u5e8f\u7684\u6570\u5b57&#xff0c;\u5982[1, 2, 3]\u3002\u5b83\u662f\u4e00\u4e2a1\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>v &#061; np.array([1, 2, 3])<br \/>\nprint(v)<br \/>\nprint(&#034;\u7ef4\u5ea6:&#034;, v.ndim)<br \/>\nprint(&#034;\u5f62\u72b6:&#034;, v.shape) # shape\u5c5e\u6027\u67e5\u770b\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5927\u5c0f<br \/>\n# \u8f93\u51fa:<br \/>\n# [1 2 3]<br \/>\n# \u7ef4\u5ea6: 1<br \/>\n# \u5f62\u72b6: (3,)<\/p>\n<\/li>\n<li>\n<p>\u77e9\u9635&#xff08;Matrix&#xff09;&#xff1a;\u4e00\u4e2a\u4e8c\u7ef4\u7684\u6570\u5b57\u8868\u683c&#xff0c;\u5982[[1, 2], [3, 4]]\u3002\u5b83\u662f\u4e00\u4e2a2\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>m &#061; np.array([[1, 2, 3], [4, 5, 6]])<br \/>\nprint(m)<br \/>\nprint(&#034;\u7ef4\u5ea6:&#034;, m.ndim)<br \/>\nprint(&#034;\u5f62\u72b6:&#034;, m.shape)<br \/>\n# \u8f93\u51fa:<br \/>\n# [[1 2 3]<br \/>\n#  [4 5 6]]<br \/>\n# \u7ef4\u5ea6: 2<br \/>\n# \u5f62\u72b6: (2, 3)  (\u4ee3\u88682\u884c3\u5217)<\/p>\n<\/li>\n<li>\n<p>\u5f20\u91cf&#xff08;Tensor&#xff09;&#xff1a;\u4e00\u4e2a\u8d85\u8fc7\u4e8c\u7ef4\u7684\u6570\u7ec4\u3002\u4f8b\u5982&#xff0c;\u4e00\u5f20\u5f69\u8272\u56fe\u7247\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u4e2a3\u7ef4\u5f20\u91cf&#xff08;\u9ad8\u5ea6&#xff0c;\u5bbd\u5ea6&#xff0c;\u989c\u8272\u901a\u9053RGB&#xff09;\u3002<\/p>\n<p>t &#061; np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])<br \/>\nprint(t)<br \/>\nprint(&#034;\u7ef4\u5ea6:&#034;, t.ndim)<br \/>\nprint(&#034;\u5f62\u72b6:&#034;, t.shape)<br \/>\n# \u8f93\u51fa:<br \/>\n# [[[1 2]<br \/>\n#   [3 4]]<br \/>\n#<br \/>\n#  [[5 6]<br \/>\n#   [7 8]]]<br \/>\n# \u7ef4\u5ea6: 3<br \/>\n# \u5f62\u72b6: (2, 2, 2)<\/p>\n<\/li>\n<\/ul>\n<p>ndim&#xff08;\u7ef4\u5ea6\u6570&#xff09;\u3001shape&#xff08;\u5f62\u72b6&#xff09;\u548cdtype&#xff08;\u6570\u636e\u7c7b\u578b&#xff09;\u662fndarray\u6700\u91cd\u8981\u7684\u4e09\u4e2a\u5c5e\u6027\u3002\u5728\u5904\u7406\u6570\u636e\u65f6&#xff0c;\u65f6\u523b\u5173\u6ce8\u8fd9\u4e09\u4e2a\u5c5e\u6027&#xff0c;\u80fd\u5e2e\u4f60\u907f\u514d\u5f88\u591a\u9519\u8bef\u3002<\/p>\n<p>\u521b\u5efa\u6570\u7ec4\u7684\u5e38\u7528\u65b9\u6cd5<\/p>\n<p>\u9664\u4e86\u76f4\u63a5\u4ece\u5217\u8868\u521b\u5efa&#xff0c;NumPy\u8fd8\u63d0\u4f9b\u4e86\u591a\u79cd\u4fbf\u6377\u7684\u521b\u5efa\u65b9\u5f0f&#xff1a;<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a3\u884c4\u5217&#xff0c;\u6240\u6709\u5143\u7d20\u4e3a0\u7684\u6570\u7ec4<br \/>\nzeros_arr &#061; np.zeros((3, 4))<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a2x3x2&#xff0c;\u6240\u6709\u5143\u7d20\u4e3a1\u7684\u6570\u7ec4<br \/>\nones_arr &#061; np.ones((2, 3, 2))<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u4ece0\u52309\u7684\u6570\u7ec4&#xff08;\u4e0d\u5305\u542b10&#xff09;<br \/>\nrange_arr &#061; np.arange(10)<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u4ece0\u52301&#xff0c;\u5305\u542b5\u4e2a\u7b49\u95f4\u8ddd\u5143\u7d20\u7684\u6570\u7ec4<br \/>\nlinspace_arr &#061; np.linspace(0, 1, 5)<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a3&#215;3\u7684\u5355\u4f4d\u77e9\u9635<br \/>\neye_arr &#061; np.eye(3)<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a2&#215;3&#xff0c;\u5143\u7d20\u4e3a\u968f\u673a\u6570\u7684\u6570\u7ec4&#xff08;0\u52301\u4e4b\u95f4&#xff09;<br \/>\nrand_arr &#061; np.random.rand(2, 3)<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a2&#215;3&#xff0c;\u5143\u7d20\u4e3a\u7b26\u5408\u6807\u51c6\u6b63\u6001\u5206\u5e03\u7684\u968f\u673a\u6570<br \/>\nrandn_arr &#061; np.random.randn(2, 3)<\/p>\n<h5>2.2.2 \u6838\u5fc3\u64cd\u4f5c&#xff1a;\u7d22\u5f15\u3001\u5207\u7247\u3001\u5e7f\u64ad\u673a\u5236<\/h5>\n<p>1. \u7d22\u5f15\u4e0e\u5207\u7247&#xff08;Indexing and Slicing&#xff09;<\/p>\n<p>\u8fd9\u4e0ePython\u5217\u8868\u7c7b\u4f3c&#xff0c;\u4f46\u6269\u5c55\u5230\u4e86\u591a\u7ef4\u3002<\/p>\n<p># \u4ee5\u4e00\u4e2a1\u7ef4\u6570\u7ec4\u4e3a\u4f8b<br \/>\na &#061; np.arange(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]<\/p>\n<p># \u83b7\u53d6\u5355\u4e2a\u5143\u7d20<br \/>\nprint(a[5]) # \u8f93\u51fa: 5<\/p>\n<p># \u5207\u7247&#xff1a;\u83b7\u53d6\u4ece\u7d22\u5f152\u5230\u7d22\u5f157&#xff08;\u4e0d\u542b&#xff09;\u7684\u5143\u7d20<br \/>\nprint(a[2:7]) # \u8f93\u51fa: [2 3 4 5 6]<\/p>\n<p># \u4ee5\u4e00\u4e2a2\u7ef4\u6570\u7ec4\u4e3a\u4f8b<br \/>\nm &#061; np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<p># \u83b7\u53d6\u5355\u4e2a\u5143\u7d20&#xff1a;\u7b2c1\u884c&#xff08;\u7d22\u5f15\u4ece0\u5f00\u59cb&#xff09;&#xff0c;\u7b2c2\u5217<br \/>\nprint(m[1, 2]) # \u8f93\u51fa: 6<\/p>\n<p># \u83b7\u53d6\u6574\u884c<br \/>\nprint(m[0, :]) # \u8f93\u51fa: [1 2 3]  (:\u4ee3\u8868\u8be5\u7ef4\u5ea6\u7684\u6240\u6709\u5143\u7d20)<br \/>\n# \u6216\u8005\u7b80\u5199\u4e3a<br \/>\nprint(m[0])<\/p>\n<p># \u83b7\u53d6\u6574\u5217<br \/>\nprint(m[:, 1]) # \u8f93\u51fa: [2 5 8]<\/p>\n<p># \u83b7\u53d6\u5b50\u77e9\u9635&#xff1a;\u7b2c0\u30011\u884c&#xff0c;\u548c\u7b2c1\u30012\u5217<br \/>\nprint(m[0:2, 1:3])<br \/>\n# \u8f93\u51fa:<br \/>\n# [[2 3]<br \/>\n#  [5 6]]<\/p>\n<p>\u5e03\u5c14\u7d22\u5f15&#xff08;Boolean Indexing&#xff09;\u00a0\u8fd9\u662f\u4e00\u4e2a\u6781\u5176\u5f3a\u5927\u7684\u529f\u80fd&#xff0c;\u5141\u8bb8\u6211\u4eec\u6839\u636e\u6761\u4ef6\u6765\u9009\u62e9\u5143\u7d20\u3002<\/p>\n<p>data &#061; np.array([[1, 2], [3, 4], [5, 6]])<\/p>\n<p># \u627e\u5230data\u4e2d\u6240\u6709\u5927\u4e8e3\u7684\u5143\u7d20<br \/>\nbool_idx &#061; data &gt; 3<br \/>\nprint(bool_idx)<br \/>\n# \u8f93\u51fa:<br \/>\n# [[False False]<br \/>\n#  [False  True]<br \/>\n#  [ True  True]]<\/p>\n<p># \u4f7f\u7528\u8fd9\u4e2a\u5e03\u5c14\u6570\u7ec4\u6765\u7d22\u5f15&#xff0c;\u4f1a\u8fd4\u56de\u6240\u6709\u5bf9\u5e94\u4f4d\u7f6e\u4e3aTrue\u7684\u5143\u7d20<br \/>\nprint(data[bool_idx]) # \u8f93\u51fa: [4 5 6]<\/p>\n<p># \u4e5f\u53ef\u4ee5\u76f4\u63a5\u5199\u6210\u4e00\u884c<br \/>\nprint(data[data &gt; 3])<\/p>\n<p>2. \u6570\u7ec4\u8fd0\u7b97<\/p>\n<p>NumPy\u7684\u6570\u7ec4\u8fd0\u7b97\u662f\u6309\u5143\u7d20\u8fdb\u884c\u7684&#xff0c;\u8fd9\u4f7f\u5f97\u4ee3\u7801\u975e\u5e38\u7b80\u6d01\u3002<\/p>\n<p>x &#061; np.array([[1, 2], [3, 4]])<br \/>\ny &#061; np.array([[5, 6], [7, 8]])<\/p>\n<p># \u6309\u5143\u7d20\u52a0\u6cd5<br \/>\nprint(x &#043; y)<br \/>\n# [[ 6  8]<br \/>\n#  [10 12]]<\/p>\n<p># \u6309\u5143\u7d20\u4e58\u6cd5<br \/>\nprint(x * y)<br \/>\n# [[ 5 12]<br \/>\n#  [21 32]]<\/p>\n<p># \u77e9\u9635\u4e58\u6cd5&#xff08;\u70b9\u79ef&#xff09;<br \/>\nprint(np.dot(x, y))<br \/>\n# \u6216\u8005\u4f7f\u7528&#064;\u7b26\u53f7 (Python 3.5&#043;)<br \/>\nprint(x &#064; y)<br \/>\n# [[19 22]<br \/>\n#  [43 50]]<\/p>\n<p>NumPy\u8fd8\u63d0\u4f9b\u4e86\u5168\u5957\u7684\u901a\u7528\u51fd\u6570&#xff08;ufunc&#xff09;&#xff0c;\u5982np.sqrt(),\u00a0np.sin(),\u00a0np.exp()\u7b49&#xff0c;\u5b83\u4eec\u4e5f\u90fd\u6309\u5143\u7d20\u4f5c\u7528\u4e8e\u6574\u4e2a\u6570\u7ec4\u3002<\/p>\n<p>3. \u5e7f\u64ad\u673a\u5236&#xff08;Broadcasting&#xff09;<\/p>\n<p>\u5e7f\u64ad\u662fNumPy\u6700\u795e\u5947\u4e5f\u6700\u91cd\u8981\u7684\u7279\u6027\u4e4b\u4e00\u3002\u5b83\u63cf\u8ff0\u4e86NumPy\u5728\u5904\u7406\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4\u8fdb\u884c\u7b97\u672f\u8fd0\u7b97\u65f6\u7684\u89c4\u5219\u3002\u7b80\u5355\u6765\u8bf4&#xff0c;\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u7684\u5f62\u72b6\u4e0d\u5b8c\u5168\u5339\u914d&#xff0c;NumPy\u4f1a\u5c1d\u8bd5\u201c\u5e7f\u64ad\u201d\u90a3\u4e2a\u8f83\u5c0f\u7684\u6570\u7ec4&#xff0c;\u5c06\u5176\u201c\u62c9\u4f38\u201d\u4ee5\u5339\u914d\u8f83\u5927\u6570\u7ec4\u7684\u5f62\u72b6&#xff0c;\u4ece\u800c\u4f7f\u8fd0\u7b97\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<p>\u89c4\u5219&#xff1a;\u4ece\u4e24\u4e2a\u6570\u7ec4\u7684\u5c3e\u90e8\u7ef4\u5ea6\u5f00\u59cb\u9010\u4e00\u6bd4\u8f83\u5b83\u4eec\u7684size&#xff1a;<\/p>\n<li>\u5982\u679c\u4e24\u4e2a\u7ef4\u5ea6size\u76f8\u540c&#xff0c;\u6216\u5176\u4e2d\u4e00\u4e2a\u4e3a1&#xff0c;\u5219\u8be5\u7ef4\u5ea6\u517c\u5bb9\u3002<\/li>\n<li>\u5982\u679c\u6240\u6709\u7ef4\u5ea6\u90fd\u517c\u5bb9&#xff0c;\u5219\u8fd0\u7b97\u53ef\u4ee5\u8fdb\u884c\u3002<\/li>\n<li>\u5982\u679c\u4efb\u4e00\u7ef4\u5ea6\u4e0d\u517c\u5bb9&#xff08;size\u4e0d\u540c\u4e14\u6ca1\u6709\u4e00\u4e2a\u662f1&#xff09;&#xff0c;\u5219\u4f1a\u62a5\u9519\u3002<\/li>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p># \u4e00\u4e2a2&#215;3\u7684\u77e9\u9635<br \/>\na &#061; np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<p># \u4e00\u4e2a1&#215;3\u7684\u5411\u91cf&#xff08;\u6216\u8bf4\u884c\u5411\u91cf&#xff09;<br \/>\nb &#061; np.array([10, 20, 30])<\/p>\n<p># a\u7684\u5f62\u72b6\u662f(2, 3)&#xff0c;b\u7684\u5f62\u72b6\u662f(3,)\u3002<br \/>\n# NumPy\u4f1a\u5c06b\u5e7f\u64ad&#xff0c;\u60f3\u8c61\u6210\u628a\u5b83\u590d\u5236\u4e86\u4e00\u904d&#xff0c;\u53d8\u6210\u4e86[[10, 20, 30], [10, 20, 30]]<br \/>\n# \u7136\u540e\u518d\u4e0ea\u8fdb\u884c\u6309\u5143\u7d20\u52a0\u6cd5<br \/>\nprint(a &#043; b)<br \/>\n# \u8f93\u51fa:<br \/>\n# [[11 22 33]<br \/>\n#  [14 25 36]]<\/p>\n<p># \u53e6\u4e00\u4e2a\u4f8b\u5b50&#xff1a;\u7ed9\u77e9\u9635\u7684\u6bcf\u4e00\u5217\u52a0\u4e0a\u4e00\u4e2a\u4e0d\u540c\u7684\u503c<br \/>\n# a\u7684\u5f62\u72b6\u662f(2, 3)<br \/>\n# c\u7684\u5f62\u72b6\u662f(2, 1)<br \/>\nc &#061; np.array([[100], [200]])<\/p>\n<p># NumPy\u4f1a\u5c06c\u7684\u7b2c1\u7ef4&#xff08;\u5217&#xff09;\u8fdb\u884c\u5e7f\u64ad&#xff0c;\u53d8\u6210[[100, 100, 100], [200, 200, 200]]<br \/>\nprint(a &#043; c)<br \/>\n# \u8f93\u51fa:<br \/>\n# [[101 102 103]<br \/>\n#  [204 205 206]]<\/p>\n<p>\u5e7f\u64ad\u673a\u5236\u6781\u5927\u5730\u63d0\u5347\u4e86\u4ee3\u7801\u7684\u7b80\u6d01\u6027\u548c\u6548\u7387&#xff0c;\u907f\u514d\u4e86\u6211\u4eec\u624b\u52a8\u5199\u5faa\u73af\u53bb\u6269\u5c55\u6570\u7ec4\u3002\u7406\u89e3\u5e76\u5584\u7528\u5e7f\u64ad&#xff0c;\u662f\u8861\u91cf\u4e00\u4e2aNumPy\u4f7f\u7528\u8005\u662f\u5426\u719f\u7ec3\u7684\u91cd\u8981\u6807\u5fd7\u3002<\/p>\n<hr \/>\n<h4>2.3 \u201c\u6570\u636e\u4e4b\u9b42\u201d&#xff1a;Pandas\u6570\u636e\u5206\u6790\u5229\u5668<\/h4>\n<p>Pandas\u7684\u540d\u5b57\u6765\u6e90\u4e8e\u201cPanel Data\u201d&#xff08;\u9762\u677f\u6570\u636e&#xff09;&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u8ba1\u91cf\u7ecf\u6d4e\u5b66\u672f\u8bed&#xff0c;\u6307\u591a\u7ef4\u5ea6\u7684\u7ed3\u6784\u5316\u6570\u636e\u96c6\u3002\u8fd9\u4e2a\u5e93\u7531Wes McKinney\u57282008\u5e74\u5f00\u53d1&#xff0c;\u521d\u8877\u662f\u4e3a\u4e86\u89e3\u51b3\u91d1\u878d\u6570\u636e\u5206\u6790\u4e2d\u7684\u5b9e\u9645\u95ee\u9898\u3002\u5982\u4eca&#xff0c;\u5b83\u5df2\u6210\u4e3aPython\u6570\u636e\u5206\u6790\u7684\u4ee3\u540d\u8bcd\u3002<\/p>\n<p>Pandas\u7684\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e&#xff0c;\u5b83\u63d0\u4f9b\u4e86\u4e00\u5957\u76f4\u89c2\u3001\u7075\u6d3b\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u8868\u683c\u578b&#xff08;tabular&#xff09;\u548c\u5f02\u6784&#xff08;heterogeneous&#xff09;\u6570\u636e\u3002\u5728\u771f\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u6211\u4eec\u9047\u5230\u7684\u5927\u90e8\u5206\u6570\u636e&#xff0c;\u5982Excel\u8868\u683c\u3001\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u3001CSV\u6587\u4ef6&#xff0c;\u90fd\u662f\u8fd9\u79cd\u5f62\u5f0f\u3002<\/p>\n<p>\u5b89\u88c5Pandas<\/p>\n<p>\u540c\u6837&#xff0c;\u5982\u679c\u4f60\u4f7f\u7528Anaconda&#xff0c;Pandas\u5df2\u4e3a\u4f60\u51c6\u5907\u5c31\u7eea\u3002\u5426\u5219&#xff0c;\u8bf7\u8fd0\u884c&#xff1a;<\/p>\n<p>##########################<br \/>\n### \u5bfc\u5165Pandas<br \/>\n### \u793e\u533a\u60ef\u4f8b\u662f\u5c06\u5176\u5bfc\u5165\u4e3a&#096;pd&#096;<br \/>\n##########################<br \/>\nconda install pandas<\/p>\n<p>import pandas as pd<\/p>\n<h5>2.3.1 Series\u4e0eDataFrame&#xff1a;\u7ed3\u6784\u5316\u6570\u636e\u7684\u201c\u9634\u9633\u201d<\/h5>\n<p>Pandas\u6709\u4e24\u4e2a\u6838\u5fc3\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u7406\u89e3\u5b83\u4eec\u662f\u638c\u63e1Pandas\u7684\u5173\u952e\u3002<\/p>\n<p>1. Series&#xff1a;\u5e26\u6807\u7b7e\u7684\u4e00\u7ef4\u6570\u7ec4<\/p>\n<p>\u4f60\u53ef\u4ee5\u5c06Series\u60f3\u8c61\u6210\u4e00\u4e2a\u52a0\u5f3a\u7248\u7684NumPy\u4e00\u7ef4\u6570\u7ec4\u3002\u5b83\u4e0endarray\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e&#xff0c;Series\u6709\u4e00\u4e2a\u4e0e\u4e4b\u5173\u8054\u7684\u6807\u7b7e\u6570\u7ec4&#xff0c;\u79f0\u4e3a\u7d22\u5f15&#xff08;Index&#xff09;\u3002<\/p>\n<p># \u4ece\u5217\u8868\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684Series<br \/>\ns &#061; pd.Series([10, 20, 30, 40])<br \/>\nprint(s)<br \/>\n# \u8f93\u51fa:<br \/>\n# 0    10<br \/>\n# 1    20<br \/>\n# 2    30<br \/>\n# 3    40<br \/>\n# dtype: int64<\/p>\n<p>\u5de6\u8fb9\u7684\u4e00\u5217&#xff08;0, 1, 2, 3&#xff09;\u662f\u9ed8\u8ba4\u751f\u6210\u7684\u6574\u6570\u7d22\u5f15\u3002\u53f3\u8fb9\u662f\u6211\u4eec\u7684\u6570\u636e\u503c\u3002<\/p>\n<p>Series\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\u7d22\u5f15&#xff1a;<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u81ea\u5b9a\u4e49\u7d22\u5f15\u7684Series<br \/>\nsales &#061; pd.Series([250, 300, 450], index&#061;[&#039;\u5317\u4eac&#039;, &#039;\u4e0a\u6d77&#039;, &#039;\u6df1\u5733&#039;])<br \/>\nprint(sales)<br \/>\n# \u8f93\u51fa:<br \/>\n# \u5317\u4eac    250<br \/>\n# \u4e0a\u6d77    300<br \/>\n# \u6df1\u5733    450<br \/>\n# dtype: int64<\/p>\n<p># \u53ef\u4ee5\u50cf\u5b57\u5178\u4e00\u6837\u901a\u8fc7\u6807\u7b7e\u8fdb\u884c\u7d22\u5f15<br \/>\nprint(sales[&#039;\u4e0a\u6d77&#039;]) # \u8f93\u51fa: 300<\/p>\n<p># \u4e5f\u53ef\u4ee5\u50cfNumPy\u6570\u7ec4\u4e00\u6837\u8fdb\u884c\u5207\u7247\u548c\u5e03\u5c14\u7d22\u5f15<br \/>\nprint(sales[sales &gt; 280])<br \/>\n# \u8f93\u51fa:<br \/>\n# \u4e0a\u6d77    300<br \/>\n# \u6df1\u5733    450<br \/>\n# dtype: int64<\/p>\n<p>Series\u7684index\u548cvalues\u5c5e\u6027\u53ef\u4ee5\u5206\u522b\u8bbf\u95ee\u5176\u7d22\u5f15\u548c\u503c&#xff08;\u503c\u4e3a\u4e00\u4e2aNumPy\u6570\u7ec4&#xff09;\u3002<\/p>\n<p>2. DataFrame&#xff1a;\u4e8c\u7ef4\u7684\u201c\u8d85\u7ea7\u8868\u683c\u201d<\/p>\n<p>DataFrame\u662fPandas\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u770b\u4f5c&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u4e2a\u5171\u4eab\u76f8\u540c\u7d22\u5f15\u7684Series\u7684\u96c6\u5408\u3002<\/li>\n<li>\u4e00\u4e2a\u5e26\u6709\u884c\u7d22\u5f15&#xff08;index&#xff09;\u548c\u5217\u7d22\u5f15&#xff08;columns&#xff09;\u7684\u4e8c\u7ef4\u8868\u683c\u3002<\/li>\n<li>\u4e00\u4e2a\u529f\u80fd\u6781\u5176\u5f3a\u5927\u7684Excel\u7535\u5b50\u8868\u683c\u6216SQL\u6570\u636e\u8868\u3002<\/li>\n<\/ul>\n<p>####################<br \/>\n# \u4ece\u5b57\u5178\u521b\u5efaDataFrame&#xff0c;\u5b57\u5178\u7684key\u4f1a\u6210\u4e3a\u5217\u540d<br \/>\n####################<\/p>\n<p>data &#061; {<br \/>\n    &#039;\u57ce\u5e02&#039;: [&#039;\u5317\u4eac&#039;, &#039;\u4e0a\u6d77&#039;, &#039;\u5e7f\u5dde&#039;, &#039;\u6df1\u5733&#039;],<br \/>\n    &#039;\u5e74\u4efd&#039;: [2020, 2020, 2021, 2021],<br \/>\n    &#039;\u4eba\u53e3(\u4e07)&#039;: [2154, 2428, 1867, 1756]<br \/>\n}<br \/>\ndf &#061; pd.DataFrame(data)<br \/>\nprint(df)<br \/>\n# \u8f93\u51fa:<br \/>\n#     \u57ce\u5e02    \u5e74\u4efd  \u4eba\u53e3(\u4e07)<br \/>\n# 0   \u5317\u4eac  2020   2154<br \/>\n# 1   \u4e0a\u6d77  2020   2428<br \/>\n# 2   \u5e7f\u5dde  2021   1867<br \/>\n# 3   \u6df1\u5733  2021   1756<\/p>\n<p>####################<br \/>\n# DataFrame<br \/>\n# \u65e2\u6709\u884c\u7d22\u5f15&#xff08;\u5de6\u8fb9\u76840, 1, 2, 3&#xff09;&#xff0c;\u4e5f\u6709\u5217\u7d22\u5f15&#xff08;&#039;\u57ce\u5e02&#039;, &#039;\u5e74\u4efd&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;&#xff09;<br \/>\n####################<\/p>\n<p>####################<br \/>\n# \u67e5\u770bDataFrame\u57fa\u672c\u4fe1\u606f<br \/>\n# \u5728\u8fdb\u884c\u4efb\u4f55\u5206\u6790\u524d&#xff0c;\u5148\u201c\u4f53\u68c0\u201d\u4e00\u4e0b\u6570\u636e\u662f\u4e2a\u597d\u4e60\u60ef&#xff1a;<br \/>\n####################<\/p>\n<p># \u67e5\u770b\u524d5\u884c<br \/>\nprint(df.head())<\/p>\n<p># \u67e5\u770b\u540e5\u884c<br \/>\nprint(df.tail())<\/p>\n<p># \u67e5\u770b\u7d22\u5f15\u3001\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b<br \/>\nprint(df.info())<br \/>\n# &lt;class &#039;pandas.core.frame.DataFrame&#039;&gt;<br \/>\n# RangeIndex: 4 entries, 0 to 3<br \/>\n# Data columns (total 3 columns):<br \/>\n#  #   Column   Non-Null Count  Dtype<br \/>\n# &#8212;  &#8212;&#8212;   &#8212;&#8212;&#8212;&#8212;&#8211;  &#8212;&#8211;<br \/>\n#  0   \u57ce\u5e02       4 non-null      object<br \/>\n#  1   \u5e74\u4efd       4 non-null      int64<br \/>\n#  2   \u4eba\u53e3(\u4e07)    4 non-null      int64<br \/>\n# dtypes: int64(2), object(1)<br \/>\n# memory usage: 224.0&#043; bytes<\/p>\n<p># \u83b7\u53d6\u63cf\u8ff0\u6027\u7edf\u8ba1\u4fe1\u606f&#xff08;\u5bf9\u6570\u503c\u5217&#xff09;<br \/>\nprint(df.describe())<br \/>\n#                \u5e74\u4efd        \u4eba\u53e3(\u4e07)<br \/>\n# count    4.000000     4.000000<br \/>\n# mean  2020.500000  2051.250000<br \/>\n# std      0.577350   302.491322<br \/>\n# min   2020.000000  1756.000000<br \/>\n# 25%   2020.000000  1839.250000<br \/>\n# 50%   2020.500000  2010.500000<br \/>\n# 75%   2021.000000  2222.500000<br \/>\n# max   2021.000000  2428.000000<\/p>\n<h5>2.3.2 \u6570\u636e\u7684\u201c\u589e\u5220\u6539\u67e5\u201d\u4e0e\u201c\u805a\u5408\u5206\u79bb\u201d<\/h5>\n<p>Pandas\u7684\u5a01\u529b\u4f53\u73b0\u5728\u5b83\u5bf9\u6570\u636e\u8fdb\u884c\u590d\u6742\u64cd\u4f5c\u7684\u7b80\u6d01\u6027\u4e0a\u3002<\/p>\n<p>1. \u67e5&#xff08;\u9009\u62e9\u6570\u636e&#xff09;<\/p>\n<p>\u8fd9\u662f\u6700\u9891\u7e41\u7684\u64cd\u4f5c\u3002Pandas\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e3b\u8981\u7684\u7d22\u5f15\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>.loc&#xff1a;**\u57fa\u4e8e\u6807\u7b7e&#xff08;label&#xff09;**\u7684\u7d22\u5f15\u3002<\/li>\n<li>.iloc&#xff1a;**\u57fa\u4e8e\u4f4d\u7f6e&#xff08;integer position&#xff09;**\u7684\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p># \u5047\u8bbe\u6211\u4eec\u7ed9df\u8bbe\u7f6e\u4e00\u4e2a\u66f4\u6709\u610f\u4e49\u7684\u7d22\u5f15<br \/>\ndf.index &#061; [&#039;BJ&#039;, &#039;SH&#039;, &#039;GZ&#039;, &#039;SZ&#039;]<\/p>\n<p># &#8212; \u4f7f\u7528 .loc &#8212;<br \/>\n# \u9009\u62e9\u5355\u884c (\u8fd4\u56de\u4e00\u4e2aSeries)<br \/>\nprint(df.loc[&#039;SH&#039;])<\/p>\n<p># \u9009\u62e9\u591a\u884c (\u8fd4\u56de\u4e00\u4e2aDataFrame)<br \/>\nprint(df.loc[[&#039;BJ&#039;, &#039;SZ&#039;]])<\/p>\n<p># \u9009\u62e9\u884c\u548c\u5217<br \/>\nprint(df.loc[&#039;GZ&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;]) # \u8f93\u51fa: 1867<\/p>\n<p># \u9009\u62e9\u591a\u884c\u591a\u5217<br \/>\nprint(df.loc[[&#039;SH&#039;, &#039;GZ&#039;], [&#039;\u57ce\u5e02&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;]])<\/p>\n<p># &#8212; \u4f7f\u7528 .iloc &#8212;<br \/>\n# \u9009\u62e9\u7b2c2\u884c&#xff08;\u7d22\u5f15\u4e3a1&#xff09;<br \/>\nprint(df.iloc[1])<\/p>\n<p># \u9009\u62e9\u7b2c0\u884c\u548c\u7b2c3\u884c<br \/>\nprint(df.iloc[[0, 3]])<\/p>\n<p># \u9009\u62e9\u7b2c2\u884c\u3001\u7b2c1\u5217\u7684\u5143\u7d20<br \/>\nprint(df.iloc[2, 1]) # \u8f93\u51fa: 2021<\/p>\n<p># &#8212; \u6761\u4ef6\u9009\u62e9 &#8212;<br \/>\n# \u9009\u62e9\u5e74\u4efd\u4e3a2020\u7684\u6240\u6709\u884c<br \/>\nprint(df[df[&#039;\u5e74\u4efd&#039;] &#061;&#061; 2020])<\/p>\n<p># \u9009\u62e9\u4eba\u53e3\u8d85\u8fc72000\u4e07\u7684\u57ce\u5e02\u540d<br \/>\nprint(df[df[&#039;\u4eba\u53e3(\u4e07)&#039;] &gt; 2000][&#039;\u57ce\u5e02&#039;])<\/p>\n<p>\u8bb0\u4f4f.loc\u7528\u540d\u5b57&#xff0c;.iloc\u7528\u6570\u5b57&#xff0c;\u662f\u907f\u514d\u6df7\u6dc6\u7684\u5173\u952e\u3002<\/p>\n<p>2. \u589e&#xff08;\u6dfb\u52a0\u6570\u636e&#xff09;<\/p>\n<p># \u6dfb\u52a0\u65b0\u5217<br \/>\ndf[&#039;GDP(\u4e07\u4ebf)&#039;] &#061; [3.6, 3.9, 2.5, 3.0]<br \/>\nprint(df)<\/p>\n<p># \u6dfb\u52a0\u65b0\u884c (\u4f7f\u7528.loc)<br \/>\ndf.loc[&#039;HZ&#039;] &#061; [&#039;\u676d\u5dde&#039;, 2022, 1200, 1.8]<br \/>\nprint(df)<\/p>\n<p>3. \u5220&#xff08;\u5220\u9664\u6570\u636e&#xff09;<\/p>\n<p>\u4f7f\u7528.drop()\u65b9\u6cd5\u3002\u5b83\u9ed8\u8ba4\u8fd4\u56de\u4e00\u4e2a\u65b0\u5bf9\u8c61&#xff0c;\u4e0d\u4fee\u6539\u539f\u59cbDataFrame\u3002<\/p>\n<p># \u5220\u9664\u5217 (axis&#061;1\u4ee3\u8868\u5217)<br \/>\ndf_no_gdp &#061; df.drop(&#039;GDP(\u4e07\u4ebf)&#039;, axis&#061;1)<\/p>\n<p># \u5220\u9664\u884c (axis&#061;0\u4ee3\u8868\u884c)<br \/>\ndf_no_hz &#061; df.drop(&#039;HZ&#039;, axis&#061;0)<\/p>\n<p>4. \u6539&#xff08;\u4fee\u6539\u6570\u636e&#xff09;<\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u7d22\u5f15\u8d4b\u503c\u6765\u4fee\u6539\u3002<\/p>\n<p># \u4fee\u6539\u5355\u4e2a\u503c<br \/>\ndf.loc[&#039;BJ&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;] &#061; 2189<\/p>\n<p># \u4fee\u6539\u6574\u5217<br \/>\ndf[&#039;\u5e74\u4efd&#039;] &#061; 2022<\/p>\n<p># \u6839\u636e\u6761\u4ef6\u4fee\u6539<br \/>\ndf.loc[df[&#039;\u57ce\u5e02&#039;] &#061;&#061; &#039;\u4e0a\u6d77&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;] &#061; 2487<\/p>\n<p>5. \u805a\u5408\u4e0e\u5206\u7ec4&#xff08;Groupby&#xff09;<\/p>\n<p>\u8fd9\u662fPandas\u7684\u201c\u5927\u6740\u5668\u201d&#xff0c;\u5bf9\u5e94\u4e8eSQL\u4e2d\u7684GROUP BY\u64cd\u4f5c\u3002\u5b83\u5b9e\u73b0\u4e86\u201c\u5206\u79bb-\u5e94\u7528-\u5408\u5e76\u201d&#xff08;Split-Apply-Combine&#xff09;\u7684\u5f3a\u5927\u6a21\u5f0f\u3002<\/p>\n<p>\u8fc7\u7a0b&#xff1a;<\/p>\n<li>\u5206\u79bb&#xff08;Split&#xff09;&#xff1a;\u6839\u636e\u67d0\u4e2a\u6216\u67d0\u4e9b\u952e\u5c06\u6570\u636e\u62c6\u5206\u6210\u7ec4\u3002<\/li>\n<li>\u5e94\u7528&#xff08;Apply&#xff09;&#xff1a;\u5bf9\u6bcf\u4e2a\u7ec4\u72ec\u7acb\u5730\u5e94\u7528\u4e00\u4e2a\u51fd\u6570&#xff08;\u5982\u6c42\u548c\u3001\u6c42\u5e73\u5747&#xff09;\u3002<\/li>\n<li>\u5408\u5e76&#xff08;Combine&#xff09;&#xff1a;\u5c06\u7ed3\u679c\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u7ed3\u6784\u3002<\/li>\n<p># \u6309\u201c\u5e74\u4efd\u201d\u5206\u7ec4&#xff0c;\u5e76\u8ba1\u7b97\u6bcf\u5e74\u7684\u5e73\u5747\u4eba\u53e3<br \/>\navg_pop_by_year &#061; df.groupby(&#039;\u5e74\u4efd&#039;)[&#039;\u4eba\u53e3(\u4e07)&#039;].mean()<br \/>\nprint(avg_pop_by_year)<\/p>\n<p># \u6309\u201c\u5e74\u4efd\u201d\u5206\u7ec4&#xff0c;\u5e76\u5e94\u7528\u591a\u4e2a\u805a\u5408\u51fd\u6570<br \/>\nstats_by_year &#061; df.groupby(&#039;\u5e74\u4efd&#039;)[&#039;\u4eba\u53e3(\u4e07)&#039;].agg([&#039;mean&#039;, &#039;sum&#039;, &#039;count&#039;])<br \/>\nprint(stats_by_year)<\/p>\n<p>groupby\u64cd\u4f5c\u662f\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790\u7684\u6838\u5fc3&#xff0c;\u80fd\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u53d1\u73b0\u4e0d\u540c\u7c7b\u522b\u6570\u636e\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<p>Pandas\u7684\u529f\u80fd\u8fdc\u4e0d\u6b62\u4e8e\u6b64&#xff0c;\u8fd8\u5305\u62ec\u5904\u7406\u7f3a\u5931\u6570\u636e\u3001\u5408\u5e76\/\u8fde\u63a5\u591a\u4e2aDataFrame\u3001\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u7b49\u9ad8\u7ea7\u529f\u80fd&#xff0c;\u6211\u4eec\u5c06\u5728\u540e\u7eed\u7ae0\u8282\u7684\u5b9e\u6218\u4e2d\u4e0d\u65ad\u9047\u5230\u548c\u5b66\u4e60\u3002<\/p>\n<hr \/>\n<h4>2.4 \u201c\u773c\u89c1\u4e3a\u5b9e\u201d&#xff1a;Matplotlib\u4e0eSeaborn\u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<p>\u6570\u636e\u5206\u6790\u7684\u6700\u7ec8\u76ee\u7684\u4e4b\u4e00\u662f\u83b7\u5f97\u6d1e\u5bdf&#xff08;Insight&#xff09;\u3002\u800c\u4eba\u7c7b\u7684\u5927\u8111\u5929\u751f\u5c31\u5bf9\u56fe\u5f62\u4fe1\u606f\u6bd4\u5bf9\u6570\u5b57\u8868\u683c\u66f4\u654f\u611f\u3002\u201c\u4e00\u56fe\u80dc\u5343\u8a00\u201d&#xff0c;\u6570\u636e\u53ef\u89c6\u5316\u6b63\u662f\u8fde\u63a5\u6570\u636e\u4e0e\u6d1e\u5bdf\u7684\u6865\u6881\u3002<\/p>\n<p>\u5728Python\u751f\u6001\u4e2d&#xff0c;Matplotlib\u662f\u201c\u6559\u7236\u201d\u7ea7\u522b\u7684\u53ef\u89c6\u5316\u5e93&#xff0c;\u5b83\u529f\u80fd\u5f3a\u5927\u3001\u53ef\u5b9a\u5236\u6027\u6781\u9ad8\u3002\u800cSeaborn\u5219\u662f\u57fa\u4e8eMatplotlib\u6784\u5efa\u7684\u3001\u66f4\u4fa7\u91cd\u4e8e\u7edf\u8ba1\u56fe\u5f62\u7684\u201c\u7f8e\u989c\u76f8\u673a\u201d&#xff0c;\u5b83\u80fd\u7528\u66f4\u7b80\u6d01\u7684\u4ee3\u7801\u751f\u6210\u66f4\u7f8e\u89c2\u3001\u4fe1\u606f\u66f4\u4e30\u5bcc\u7684\u56fe\u8868\u3002<\/p>\n<p>\u5bfc\u5165<\/p>\n<p>import matplotlib.pyplot as plt<br \/>\nimport seaborn as sns<\/p>\n<p># \u5728Jupyter Notebook\u4e2d&#xff0c;\u901a\u5e38\u4f1a\u52a0\u4e0a\u8fd9\u884c\u9b54\u6cd5\u547d\u4ee4&#xff0c;\u8ba9\u56fe\u50cf\u76f4\u63a5\u5185\u5d4c\u5728Notebook\u4e2d\u663e\u793a<br \/>\n%matplotlib inline<\/p>\n<h5>2.4.1 \u4ece\u70b9\u7ebf\u56fe\u5230\u70ed\u529b\u56fe&#xff1a;\u9009\u62e9\u5408\u9002\u7684\u201c\u753b\u7b14\u201d<\/h5>\n<p>\u4e0d\u540c\u7684\u6570\u636e\u5173\u7cfb&#xff0c;\u9700\u8981\u7528\u4e0d\u540c\u7684\u56fe\u8868\u7c7b\u578b\u6765\u5448\u73b0\u3002<\/p>\n<p>1. \u6298\u7ebf\u56fe&#xff08;Line Plot&#xff09;&#xff1a;\u6700\u9002\u5408\u5c55\u793a\u6570\u636e\u968f\u8fde\u7eed\u53d8\u91cf&#xff08;\u5c24\u5176\u662f\u65f6\u95f4&#xff09;\u53d8\u5316\u7684\u8d8b\u52bf\u3002<\/p>\n<p># \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u5468\u7684\u9500\u552e\u6570\u636e<br \/>\ndays &#061; np.arange(1, 8)<br \/>\nsales &#061; np.array([50, 55, 47, 62, 60, 70, 68])<\/p>\n<p>plt.figure(figsize&#061;(8, 4)) # \u521b\u5efa\u4e00\u4e2a8&#215;4\u82f1\u5bf8\u7684\u753b\u5e03<br \/>\nplt.plot(days, sales, marker&#061;&#039;o&#039;, linestyle&#061;&#039;&#8211;&#039;) # marker\u662f\u6570\u636e\u70b9\u7684\u6837\u5f0f&#xff0c;linestyle\u662f\u7ebf\u7684\u6837\u5f0f<br \/>\nplt.title(&#034;\u5468\u9500\u552e\u989d\u8d8b\u52bf&#034;) # \u6dfb\u52a0\u6807\u9898<br \/>\nplt.xlabel(&#034;\u5929\u6570&#034;) # \u6dfb\u52a0x\u8f74\u6807\u7b7e<br \/>\nplt.ylabel(&#034;\u9500\u552e\u989d&#034;) # \u6dfb\u52a0y\u8f74\u6807\u7b7e<br \/>\nplt.grid(True) # \u663e\u793a\u7f51\u683c<br \/>\nplt.show() # \u663e\u793a\u56fe\u50cf<\/p>\n<p>2. \u6563\u70b9\u56fe&#xff08;Scatter Plot&#xff09;&#xff1a;\u7528\u4e8e\u63a2\u7d22\u4e24\u4e2a\u6570\u503c\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<p># \u5047\u8bbe\u6211\u4eec\u6709\u623f\u5c4b\u9762\u79ef\u548c\u4ef7\u683c\u7684\u6570\u636e<br \/>\narea &#061; np.random.randint(50, 150, size&#061;100)<br \/>\nprice &#061; area * 1.2 &#043; np.random.randn(100) * 20<\/p>\n<p># \u4f7f\u7528Seaborn\u7ed8\u5236\u6563\u70b9\u56fe&#xff0c;\u66f4\u7f8e\u89c2<br \/>\nsns.scatterplot(x&#061;area, y&#061;price)<br \/>\nplt.title(&#034;\u623f\u5c4b\u9762\u79ef\u4e0e\u4ef7\u683c\u5173\u7cfb&#034;)<br \/>\nplt.xlabel(&#034;\u9762\u79ef (\u5e73\u65b9\u7c73)&#034;)<br \/>\nplt.ylabel(&#034;\u4ef7\u683c (\u4e07\u5143)&#034;)<br \/>\nplt.show()<\/p>\n<p>3. \u67f1\u72b6\u56fe&#xff08;Bar Plot&#xff09;&#xff1a;\u7528\u4e8e\u6bd4\u8f83\u4e0d\u540c\u7c7b\u522b\u7684\u6570\u636e\u3002<\/p>\n<p># \u4f7f\u7528\u6211\u4eec\u4e4b\u524d\u7684\u57ce\u5e02\u4eba\u53e3DataFrame<br \/>\nsns.barplot(x&#061;&#039;\u57ce\u5e02&#039;, y&#061;&#039;\u4eba\u53e3(\u4e07)&#039;, data&#061;df)<br \/>\nplt.title(&#034;\u4e3b\u8981\u57ce\u5e02\u4eba\u53e3\u5bf9\u6bd4&#034;)<br \/>\nplt.show()<\/p>\n<p>4. \u76f4\u65b9\u56fe&#xff08;Histogram&#xff09;&#xff1a;\u7528\u4e8e\u89c2\u5bdf\u5355\u4e2a\u6570\u503c\u53d8\u91cf\u7684\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n<p># \u89c2\u5bdf\u4ef7\u683c\u6570\u636e\u7684\u5206\u5e03<br \/>\nsns.histplot(price, kde&#061;True) # kde&#061;True\u4f1a\u540c\u65f6\u7ed8\u5236\u4e00\u6761\u6838\u5bc6\u5ea6\u4f30\u8ba1\u66f2\u7ebf<br \/>\nplt.title(&#034;\u623f\u4ef7\u5206\u5e03\u76f4\u65b9\u56fe&#034;)<br \/>\nplt.show()<\/p>\n<p>5. \u70ed\u529b\u56fe&#xff08;Heatmap&#xff09;&#xff1a;\u7528\u989c\u8272\u6df1\u6d45\u6765\u5c55\u793a\u4e00\u4e2a\u77e9\u9635\u7684\u503c&#xff0c;\u975e\u5e38\u9002\u5408\u5c55\u793a\u53d8\u91cf\u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3002<\/p>\n<p># \u8ba1\u7b97df\u4e2d\u6570\u503c\u5217\u7684\u76f8\u5173\u7cfb\u6570\u77e9\u9635<br \/>\ncorr_matrix &#061; df[[&#039;\u5e74\u4efd&#039;, &#039;\u4eba\u53e3(\u4e07)&#039;, &#039;GDP(\u4e07\u4ebf)&#039;]].corr()<\/p>\n<p>sns.heatmap(corr_matrix, annot&#061;True, cmap&#061;&#039;coolwarm&#039;) # annot&#061;True\u5728\u683c\u5b50\u4e0a\u663e\u793a\u6570\u503c, cmap\u662f\u989c\u8272\u4e3b\u9898<br \/>\nplt.title(&#034;\u7279\u5f81\u76f8\u5173\u6027\u70ed\u529b\u56fe&#034;)<br \/>\nplt.show()<\/p>\n<h5>2.4.2 \u53ef\u89c6\u5316\u4e4b\u9053&#xff1a;\u7f8e\u5b66\u3001\u4fe1\u606f\u4e0e\u6d1e\u5bdf<\/h5>\n<p>\u4e00\u5e45\u597d\u7684\u6570\u636e\u53ef\u89c6\u5316\u4f5c\u54c1&#xff0c;\u5e94\u9075\u5faa\u51e0\u4e2a\u539f\u5219&#xff1a;<\/p>\n<li>\n<p>\u6570\u636e-\u58a8\u6c34\u6bd4&#xff08;Data-Ink Ratio&#xff09;&#xff1a;\u7531\u53ef\u89c6\u5316\u5927\u5e08\u7231\u5fb7\u534e\u00b7\u5854\u592b\u7279\u63d0\u51fa\u3002\u6838\u5fc3\u601d\u60f3\u662f&#xff0c;\u4e00\u5e45\u56fe\u4e2d\u7edd\u5927\u90e8\u5206\u7684\u201c\u58a8\u6c34\u201d\u90fd\u5e94\u8be5\u7528\u6765\u5c55\u793a\u6570\u636e\u672c\u8eab&#xff0c;\u800c\u5e94\u5220\u53bb\u6240\u6709\u65e0\u76ca\u4e8e\u7406\u89e3\u6570\u636e\u7684\u88c5\u9970\u6027\u5143\u7d20&#xff08;\u5982\u82b1\u54e8\u7684\u80cc\u666f\u30013D\u6548\u679c\u7b49&#xff09;\u3002\u8ffd\u6c42\u7b80\u7ea6\u548c\u6e05\u6670\u3002<\/p>\n<\/li>\n<li>\n<p>\u9009\u62e9\u6b63\u786e\u7684\u56fe\u8868&#xff1a;\u660e\u786e\u4f60\u8981\u8868\u8fbe\u7684\u5173\u7cfb\u2014\u2014\u662f\u6bd4\u8f83\u3001\u5206\u5e03\u3001\u6784\u6210\u8fd8\u662f\u8054\u7cfb&#xff1f;\u7136\u540e\u9009\u62e9\u6700\u9002\u5408\u7684\u56fe\u8868\u7c7b\u578b\u3002\u7528\u6298\u7ebf\u56fe\u53bb\u6bd4\u8f83\u7c7b\u522b\u6570\u636e&#xff0c;\u6216\u8005\u7528\u997c\u56fe\u53bb\u5c55\u793a\u8d85\u8fc75\u4e2a\u7c7b\u522b\u7684\u6784\u6210&#xff0c;\u90fd\u662f\u5e38\u89c1\u7684\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u6e05\u6670\u7684\u6807\u6ce8&#xff1a;\u4e00\u5e45\u56fe\u5fc5\u987b\u662f\u81ea\u5305\u542b\u7684\u3002\u5b83\u5e94\u8be5\u6709\u660e\u786e\u7684\u6807\u9898\u3001\u5750\u6807\u8f74\u6807\u7b7e&#xff08;\u5305\u542b\u5355\u4f4d&#xff09;\u3001\u56fe\u4f8b\u7b49&#xff0c;\u8ba9\u8bfb\u8005\u65e0\u9700\u9605\u8bfb\u6b63\u6587\u5c31\u80fd\u7406\u89e3\u56fe\u8868\u7684\u57fa\u672c\u542b\u4e49\u3002<\/p>\n<\/li>\n<li>\n<p>\u5229\u7528\u89c6\u89c9\u7f16\u7801&#xff1a;\u9664\u4e86\u4f4d\u7f6e&#xff08;x, y\u5750\u6807&#xff09;&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u5229\u7528\u989c\u8272\u3001\u5f62\u72b6\u3001\u5927\u5c0f\u3001\u900f\u660e\u5ea6\u7b49\u89c6\u89c9\u5143\u7d20\u6765\u7f16\u7801\u66f4\u591a\u7684\u4fe1\u606f\u7ef4\u5ea6\u3002\u4f46\u8981\u907f\u514d\u8fc7\u5ea6\u4f7f\u7528&#xff0c;\u4ee5\u514d\u9020\u6210\u89c6\u89c9\u6df7\u4e71\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bb2\u4e00\u4e2a\u6545\u4e8b&#xff08;Tell a Story&#xff09;&#xff1a;\u6700\u597d\u7684\u53ef\u89c6\u5316\u4e0d\u4ec5\u4ec5\u662f\u5448\u73b0\u6570\u636e&#xff0c;\u5b83\u8fd8\u5728\u8bb2\u8ff0\u4e00\u4e2a\u6545\u4e8b&#xff0c;\u5f15\u5bfc\u8bfb\u8005\u53d1\u73b0\u6a21\u5f0f\u3001\u5f97\u51fa\u7ed3\u8bba\u3002\u4f60\u7684\u6807\u9898\u3001\u6ce8\u89e3\u548c\u9ad8\u4eae\u663e\u793a&#xff0c;\u90fd\u5e94\u8be5\u670d\u52a1\u4e8e\u8fd9\u4e2a\u6545\u4e8b\u3002<\/p>\n<\/li>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u4ece\u96f6\u5f00\u59cb&#xff0c;\u642d\u5efa\u4e86\u575a\u5b9e\u7684Python\u6570\u636e\u79d1\u5b66\u73af\u5883&#xff0c;\u5e76\u638c\u63e1\u4e86NumPy\u3001Pandas\u3001Matplotlib\u548cSeaborn\u8fd9\u56db\u5927\u91d1\u521a\u3002\u8fd9\u5957\u5de5\u5177\u94fe&#xff0c;\u662f\u60a8\u672a\u6765\u63a2\u7d22\u5e7f\u9614\u6570\u636e\u4e16\u754c\u7684\u201c\u6807\u51c6\u88c5\u5907\u201d\u3002<\/p>\n<p>\u8bf7\u52a1\u5fc5\u82b1\u65f6\u95f4\u4eb2\u624b\u5b9e\u8df5\u672c\u7ae0\u7684\u6240\u6709\u4ee3\u7801\u3002\u5c1d\u8bd5\u8bfb\u53d6\u4f60\u81ea\u5df1\u7684CSV\u6587\u4ef6&#xff0c;\u7528Pandas\u8fdb\u884c\u6e05\u6d17\u548c\u5206\u6790&#xff0c;\u518d\u7528Matplotlib\/Seaborn\u5c06\u5176\u53ef\u89c6\u5316\u3002\u5f53\u4f60\u80fd\u81ea\u5982\u5730\u8fd0\u7528\u8fd9\u4e9b\u5de5\u5177\u65f6&#xff0c;\u4f60\u5c31\u5df2\u7ecf\u5b8c\u6210\u4e86\u4ece\u95e8\u5916\u6c49\u5230\u6570\u636e\u79d1\u5b66\u201c\u51c6\u5165\u8005\u201d\u7684\u8715\u53d8\u3002<\/p>\n<p>\u4ece\u4e0b\u4e00\u7ae0\u5f00\u59cb&#xff0c;\u6211\u4eec\u5c06\u6b63\u5f0f\u8fdb\u5165\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u5730\u5e26&#xff0c;\u5f00\u59cb\u5b66\u4e60\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u5de5\u5177&#xff0c;\u53bb\u6784\u5efa\u3001\u8bad\u7ec3\u548c\u8bc4\u4f30\u771f\u6b63\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002\u6211\u4eec\u7684\u5730\u57fa\u5df2\u7ecf\u6253\u597d&#xff0c;\u662f\u65f6\u5019\u5f00\u59cb\u5efa\u9020\u5927\u53a6\u4e86\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e09\u7ae0&#xff1a;\u6570\u636e\u7684\u5fc3\u6cd5\u2014\u2014\u9884\u5904\u7406\u4e0e\u7279\u5f81\u5de5\u7a0b<\/h3>\n<ul>\n<li>3.1 \u201c\u76f8\u6570\u636e\u201d&#xff1a;\u7406\u89e3\u4f60\u7684\u6570\u636e<\/li>\n<li>3.2 \u201c\u51c0\u6570\u636e\u201d&#xff1a;\u6570\u636e\u6e05\u6d17\u7684\u4fee\u884c<\/li>\n<li>3.3 \u201c\u70b9\u77f3\u6210\u91d1\u201d&#xff1a;\u7279\u5f81\u5de5\u7a0b\u7684\u79d1\u5b66\u4e0e\u827a\u672f<\/li>\n<\/ul>\n<p>\u5728\u673a\u5668\u5b66\u4e60\u7684\u5b8f\u4f1f\u84dd\u56fe\u4e2d&#xff0c;\u6570\u636e\u9884\u5904\u7406\u4e0e\u7279\u5f81\u5de5\u7a0b\u626e\u6f14\u7740\u627f\u524d\u542f\u540e\u7684\u5173\u952e\u89d2\u8272\u3002\u5b83\u4eec\u662f\u8fde\u63a5\u539f\u59cb\u6570\u636e\u4e0e\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u6865\u6881&#xff0c;\u5176\u8d28\u91cf\u76f4\u63a5\u51b3\u5b9a\u4e86\u6a21\u578b\u6700\u7ec8\u6240\u80fd\u8fbe\u5230\u7684\u9ad8\u5ea6\u3002\u4e00\u4e2a\u7ecf\u8fc7\u7cbe\u5fc3\u5904\u7406\u548c\u8bbe\u8ba1\u7684\u7279\u5f81&#xff0c;\u5176\u4ef7\u503c\u5f80\u5f80\u80dc\u8fc7\u4e00\u4e2a\u590d\u6742\u6a21\u578b\u7684\u5fae\u5c0f\u8c03\u4f18\u3002<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u79c9\u6301\u4e00\u79cd\u201c\u683c\u7269\u81f4\u77e5\u201d\u7684\u7cbe\u795e&#xff0c;\u6df1\u5165\u6570\u636e\u7684\u5185\u5728\u808c\u7406\u3002\u6211\u4eec\u5c06\u5b66\u4e60&#xff1a;<\/p>\n<ul>\n<li>\u201c\u76f8\u6570\u636e\u201d&#xff1a;\u5982\u4f55\u901a\u8fc7\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790&#xff08;EDA&#xff09;\u4e0e\u6570\u636e\u8fdb\u884c\u521d\u6b21\u201c\u5bf9\u8bdd\u201d&#xff0c;\u7406\u89e3\u5176\u813e\u6027\u3002<\/li>\n<li>\u201c\u51c0\u6570\u636e\u201d&#xff1a;\u5982\u4f55\u50cf\u4e00\u4f4d\u8010\u5fc3\u7684\u5de5\u5320&#xff0c;\u6e05\u7406\u6570\u636e\u4e2d\u7684\u201c\u6742\u8d28\u201d\u2014\u2014\u7f3a\u5931\u503c\u4e0e\u5f02\u5e38\u503c\u3002<\/li>\n<li>\u201c\u70b9\u77f3\u6210\u91d1\u201d&#xff1a;\u5982\u4f55\u65bd\u5c55\u7279\u5f81\u5de5\u7a0b\u7684\u201c\u9b54\u6cd5\u201d&#xff0c;\u4ece\u73b0\u6709\u6570\u636e\u4e2d\u521b\u9020\u51fa\u66f4\u5177\u4fe1\u606f\u91cf\u7684\u7279\u5f81&#xff0c;\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a\u6a21\u578b\u80fd\u591f\u201c\u6d88\u5316\u201d\u7684\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u8fc7\u7a0b&#xff0c;\u65e2\u6709\u7ae0\u6cd5\u53ef\u5faa\u7684\u79d1\u5b66&#xff0c;\u4e5f\u6709\u4f9d\u8d56\u7ecf\u9a8c\u76f4\u89c9\u7684\u827a\u672f\u3002\u5b83\u662f\u4e00\u573a\u4fee\u884c&#xff0c;\u8003\u9a8c\u7684\u662f\u6211\u4eec\u7684\u8010\u5fc3\u3001\u7ec6\u81f4\u4e0e\u521b\u9020\u529b\u3002<\/p>\n<hr \/>\n<h4>3.1 \u201c\u76f8\u6570\u636e\u201d&#xff1a;\u7406\u89e3\u4f60\u7684\u6570\u636e<\/h4>\n<p>\u5728\u62ff\u5230\u4e00\u4e2a\u6570\u636e\u96c6\u540e&#xff0c;\u6700\u5fcc\u8bb3\u7684\u5c31\u662f\u4e0d\u5047\u601d\u7d22\u5730\u76f4\u63a5\u5c06\u5176\u6254\u8fdb\u6a21\u578b\u3002\u8fd9\u597d\u6bd4\u533b\u751f\u4e0d\u7ecf\u95ee\u8bca&#xff0c;\u5c31\u7ed9\u75c5\u4eba\u5f00\u836f&#xff0c;\u662f\u6781\u5176\u5371\u9669\u548c\u4e0d\u8d1f\u8d23\u4efb\u7684\u3002\u6211\u4eec\u7684\u7b2c\u4e00\u6b65&#xff0c;\u6c38\u8fdc\u662f\u7406\u89e3\u6570\u636e\u3002\u8fd9\u4e2a\u8fc7\u7a0b&#xff0c;\u6211\u4eec\u79f0\u4e4b\u4e3a\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790&#xff08;Exploratory Data Analysis, EDA&#xff09;\u3002<\/p>\n<h5>3.1.1 \u63a2\u7d22\u6027\u6570\u636e\u5206\u6790&#xff08;EDA&#xff09;&#xff1a;\u4e0e\u6570\u636e\u5bf9\u8bdd\u7684\u827a\u672f<\/h5>\n<p>EDA\u662f\u7531\u7edf\u8ba1\u5b66\u5927\u5e08\u7ea6\u7ff0\u00b7\u56fe\u57fa&#xff08;John Tukey&#xff09;\u63d0\u5021\u7684\u4e00\u79cd\u6570\u636e\u5206\u6790\u65b9\u6cd5\u8bba\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff0c;\u5728\u8fdb\u884c\u4efb\u4f55\u6b63\u5f0f\u7684\u5047\u8bbe\u68c0\u9a8c\u4e4b\u524d&#xff0c;\u901a\u8fc7\u591a\u79cd\u624b\u6bb5&#xff08;\u4e3b\u8981\u662f\u53ef\u89c6\u5316\u548c\u6c47\u603b\u7edf\u8ba1&#xff09;\u5bf9\u6570\u636e\u8fdb\u884c\u5f00\u653e\u5f0f\u7684\u63a2\u7d22&#xff0c;\u4ee5\u53d1\u73b0\u5176\u7ed3\u6784\u3001\u5f02\u5e38\u3001\u6a21\u5f0f\u548c\u5173\u7cfb\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u79cd\u4fa6\u63a2\u822c\u7684\u5de5\u4f5c&#xff0c;\u6211\u4eec\u7684\u76ee\u6807\u662f\u56de\u7b54\u5173\u4e8e\u6570\u636e\u7684\u57fa\u672c\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u8fd9\u4e2a\u6570\u636e\u96c6\u4e2d\u6709\u591a\u5c11\u884c&#xff08;\u6837\u672c&#xff09;\u548c\u591a\u5c11\u5217&#xff08;\u7279\u5f81&#xff09;&#xff1f;<\/li>\n<li>\u6bcf\u4e2a\u7279\u5f81\u662f\u4ec0\u4e48\u6570\u636e\u7c7b\u578b&#xff08;\u6570\u503c\u578b\u3001\u7c7b\u522b\u578b\u3001\u6587\u672c\u3001\u65e5\u671f&#xff09;&#xff1f;<\/li>\n<li>\u6570\u636e\u4e2d\u662f\u5426\u5b58\u5728\u7f3a\u5931\u503c&#xff1f;\u6bd4\u4f8b\u5982\u4f55&#xff1f;<\/li>\n<li>\u6570\u636e\u7684\u5206\u5e03\u662f\u600e\u6837\u7684&#xff1f;&#xff08;\u662f\u6b63\u6001\u5206\u5e03&#xff0c;\u8fd8\u662f\u504f\u6001\u5206\u5e03&#xff1f;&#xff09;<\/li>\n<li>\u4e0d\u540c\u7279\u5f81\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u5173\u8054&#xff1f;&#xff08;\u4f8b\u5982&#xff0c;\u8eab\u9ad8\u548c\u4f53\u91cd\u662f\u5426\u6b63\u76f8\u5173&#xff1f;&#xff09;<\/li>\n<\/ul>\n<p>\u8ba9\u6211\u4eec\u4ee5\u4e00\u4e2a\u7ecf\u5178\u7684\u201c\u6cf0\u5766\u5c3c\u514b\u53f7\u5e78\u5b58\u8005\u201d\u6570\u636e\u96c6\u4e3a\u4f8b&#xff0c;\u6765\u6f14\u793aEDA\u7684\u57fa\u672c\u6d41\u7a0b\u3002\u9996\u5148&#xff0c;\u52a0\u8f7d\u6570\u636e\u5e76\u8fdb\u884c\u521d\u6b65\u68c0\u89c6\u3002<\/p>\n<p>import pandas as pd<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport seaborn as sns<\/p>\n<p># \u52a0\u8f7d\u6570\u636e (Seaborn\u81ea\u5e26\u4e86\u8fd9\u4e2a\u6570\u636e\u96c6)<br \/>\ndf &#061; sns.load_dataset(&#039;titanic&#039;)<\/p>\n<p># 1. \u67e5\u770b\u6570\u636e\u7ef4\u5ea6<br \/>\nprint(&#034;\u6570\u636e\u5f62\u72b6:&#034;, df.shape)<\/p>\n<p># 2. \u67e5\u770b\u524d\u51e0\u884c&#xff0c;\u5bf9\u6570\u636e\u6709\u4e2a\u76f4\u89c2\u5370\u8c61<br \/>\nprint(df.head())<\/p>\n<p># 3. \u67e5\u770b\u5404\u5217\u7684\u6570\u636e\u7c7b\u578b\u548c\u975e\u7a7a\u503c\u6570\u91cf<br \/>\nprint(df.info())<\/p>\n<p>\u4ecedf.info()\u7684\u8f93\u51fa\u4e2d&#xff0c;\u6211\u4eec\u80fd\u7acb\u523b\u83b7\u5f97\u5927\u91cf\u4fe1\u606f&#xff1a;<\/p>\n<ul>\n<li>\u5171\u6709891\u4e2a\u6837\u672c&#xff08;\u884c&#xff09;&#xff0c;15\u4e2a\u7279\u5f81&#xff08;\u5217&#xff09;\u3002<\/li>\n<li>age&#xff08;\u5e74\u9f84&#xff09;\u3001deck&#xff08;\u7532\u677f\u53f7&#xff09;\u3001embarked&#xff08;\u767b\u8239\u6e2f\u53e3&#xff09;\u7b49\u5217\u5b58\u5728\u7f3a\u5931\u503c&#xff08;\u56e0\u4e3a\u5b83\u4eec\u7684\u975e\u7a7a\u8ba1\u6570\u5c11\u4e8e891&#xff09;\u3002<\/li>\n<li>survived,\u00a0pclass,\u00a0sex,\u00a0embarked\u00a0\u7b49\u662f\u7c7b\u522b\u578b\u7279\u5f81&#xff0c;\u800c\u00a0age,\u00a0fare\u00a0\u662f\u6570\u503c\u578b\u7279\u5f81\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u662f\u4e0e\u6570\u636e\u7684\u7b2c\u4e00\u8f6e\u201c\u5bf9\u8bdd\u201d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5bf9\u5b83\u7684\u201c\u5bb6\u5e95\u201d\u6709\u4e86\u5927\u81f4\u4e86\u89e3\u3002<\/p>\n<h5>3.1.2 \u63cf\u8ff0\u6027\u7edf\u8ba1\u4e0e\u5206\u5e03\u53ef\u89c6\u5316<\/h5>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u8981\u66f4\u6df1\u5165\u5730\u63a2\u67e5\u6570\u636e\u7684\u5185\u5728\u7279\u5f81\u3002<\/p>\n<p>1. \u63cf\u8ff0\u6027\u7edf\u8ba1<\/p>\n<p>\u5bf9\u4e8e\u6570\u503c\u578b\u7279\u5f81&#xff0c;describe()\u65b9\u6cd5\u662f\u6211\u4eec\u7684\u5f97\u529b\u52a9\u624b\u3002<\/p>\n<p>print(df.describe())<\/p>\n<p>\u8fd9\u4f1a\u8f93\u51fa\u6570\u503c\u5217\u7684\u8ba1\u6570\u3001\u5e73\u5747\u503c\u3001\u6807\u51c6\u5dee\u3001\u6700\u5c0f\u503c\u3001\u56db\u5206\u4f4d\u6570\u548c\u6700\u5927\u503c\u3002\u4ece\u4e2d\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u53d1\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u5e74\u9f84&#xff08;age&#xff09;&#xff1a;\u4e58\u5ba2\u5e73\u5747\u5e74\u9f84\u7ea629.7\u5c81&#xff0c;\u4f46\u5e74\u9f84\u8de8\u5ea6\u5f88\u5927&#xff08;\u4ece0.42\u5c81\u523080\u5c81&#xff09;&#xff0c;\u4e14\u5b58\u5728\u7f3a\u5931\u503c&#xff08;count\u4e3a714&#xff09;\u3002<\/li>\n<li>\u7968\u4ef7&#xff08;fare&#xff09;&#xff1a;\u7968\u4ef7\u5206\u5e03\u6781\u4e0d\u5747\u5300&#xff0c;75%\u7684\u4e58\u5ba2\u7968\u4ef7\u4f4e\u4e8e31\u7f8e\u5143&#xff0c;\u4f46\u6700\u9ad8\u7968\u4ef7\u7adf\u8fbe512\u7f8e\u5143&#xff0c;\u8fd9\u6697\u793a\u53ef\u80fd\u5b58\u5728\u6781\u7aef\u503c&#xff08;\u5f02\u5e38\u503c&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u7c7b\u522b\u578b\u7279\u5f81&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528value_counts()\u6765\u67e5\u770b\u5176\u53d6\u503c\u5206\u5e03\u3002<\/p>\n<p># \u67e5\u770b\u6027\u522b\u5206\u5e03<br \/>\nprint(df[&#039;sex&#039;].value_counts())<\/p>\n<p># \u67e5\u770b\u751f\u8fd8\u60c5\u51b5\u5206\u5e03<br \/>\nprint(df[&#039;survived&#039;].value_counts(normalize&#061;True)) # normalize&#061;True\u663e\u793a\u6bd4\u4f8b<\/p>\n<p>\u6211\u4eec\u53d1\u73b0&#xff0c;\u4e58\u5ba2\u4e2d\u7537\u6027\u8fdc\u591a\u4e8e\u5973\u6027&#xff0c;\u4e14\u603b\u4f53\u751f\u8fd8\u7387\u53ea\u6709\u7ea638.4%\u3002<\/p>\n<p>2. \u5206\u5e03\u53ef\u89c6\u5316<\/p>\n<p>\u6570\u5b57\u662f\u62bd\u8c61\u7684&#xff0c;\u56fe\u5f62\u662f\u76f4\u89c2\u7684\u3002\u6211\u4eec\u5c06\u4f7f\u7528Matplotlib\u548cSeaborn\u5c06\u7edf\u8ba1\u7ed3\u679c\u53ef\u89c6\u5316\u3002<\/p>\n<ul>\n<li>\n<p>\u89c2\u5bdf\u5355\u4e2a\u6570\u503c\u53d8\u91cf\u7684\u5206\u5e03&#xff08;\u76f4\u65b9\u56fe\/\u6838\u5bc6\u5ea6\u56fe&#xff09;<\/p>\n<p>sns.histplot(df[&#039;age&#039;].dropna(), kde&#061;True) # dropna()\u53bb\u6389\u7f3a\u5931\u503c<br \/>\nplt.title(&#039;\u4e58\u5ba2\u5e74\u9f84\u5206\u5e03&#039;)<br \/>\nplt.show()<\/p>\n<p>\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230&#xff0c;\u4e58\u5ba2\u4ee5\u5e74\u8f7b\u4eba\u4e3a\u4e3b&#xff0c;\u5448\u53f3\u504f\u6001\u5206\u5e03\u3002<\/p>\n<\/li>\n<li>\n<p>\u89c2\u5bdf\u5355\u4e2a\u7c7b\u522b\u53d8\u91cf\u7684\u5206\u5e03&#xff08;\u8ba1\u6570\u56fe\/\u67f1\u72b6\u56fe&#xff09;<\/p>\n<p>sns.countplot(x&#061;&#039;pclass&#039;, data&#061;df)<br \/>\nplt.title(&#039;\u5404\u8239\u8231\u7b49\u7ea7\u4eba\u6570&#039;)<br \/>\nplt.show()<\/p>\n<p>\u4e09\u7b49\u8231\u4e58\u5ba2\u6570\u91cf\u6700\u591a\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a2\u7d22\u7279\u5f81\u4e0e\u76ee\u6807\u53d8\u91cf\u7684\u5173\u7cfb\u00a0\u8fd9\u662fEDA\u7684\u6838\u5fc3\u76ee\u7684\u4e4b\u4e00\u3002\u4f8b\u5982&#xff0c;\u6211\u4eec\u60f3\u77e5\u9053\u201c\u8239\u8231\u7b49\u7ea7\u201d\u548c\u201c\u751f\u8fd8\u7387\u201d\u6709\u4f55\u5173\u7cfb\u3002<\/p>\n<p>sns.barplot(x&#061;&#039;pclass&#039;, y&#061;&#039;survived&#039;, data&#061;df)<br \/>\nplt.title(&#039;\u5404\u8239\u8231\u7b49\u7ea7\u7684\u751f\u8fd8\u7387&#039;)<br \/>\nplt.ylabel(&#039;\u751f\u8fd8\u7387&#039;)<br \/>\nplt.show()<\/p>\n<p>\u4e00\u76ee\u4e86\u7136&#xff0c;\u8239\u8231\u7b49\u7ea7\u8d8a\u9ad8&#xff08;1\u7b49\u8231&#xff09;&#xff0c;\u751f\u8fd8\u7387\u8d8a\u9ad8\u3002\u8fd9\u662f\u4e00\u4e2a\u6781\u5177\u4fe1\u606f\u91cf\u7684\u53d1\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a2\u7d22\u4e24\u4e2a\u6570\u503c\u53d8\u91cf\u7684\u5173\u7cfb&#xff08;\u6563\u70b9\u56fe&#xff09;<\/p>\n<p>sns.scatterplot(x&#061;&#039;age&#039;, y&#061;&#039;fare&#039;, data&#061;df)<br \/>\nplt.title(&#039;\u5e74\u9f84\u4e0e\u7968\u4ef7\u7684\u5173\u7cfb&#039;)<br \/>\nplt.show()<\/p>\n<\/li>\n<li>\n<p>\u63a2\u7d22\u591a\u4e2a\u53d8\u91cf\u95f4\u7684\u5173\u7cfb&#xff08;\u70ed\u529b\u56fe\/\u914d\u5bf9\u56fe&#xff09;<\/p>\n<p># \u8ba1\u7b97\u6570\u503c\u7279\u5f81\u7684\u76f8\u5173\u6027\u77e9\u9635<br \/>\ncorr &#061; df[[&#039;survived&#039;, &#039;pclass&#039;, &#039;age&#039;, &#039;sibsp&#039;, &#039;parch&#039;, &#039;fare&#039;]].corr()<br \/>\nsns.heatmap(corr, annot&#061;True, cmap&#061;&#039;coolwarm&#039;)<br \/>\nplt.title(&#039;\u7279\u5f81\u76f8\u5173\u6027\u70ed\u529b\u56fe&#039;)<br \/>\nplt.show()<br \/>\n&#096;&#096;&#096;    \u70ed\u529b\u56fe\u663e\u793a&#xff0c;&#096;pclass&#096;\u548c&#096;survived&#096;\u6709\u663e\u8457\u7684\u8d1f\u76f8\u5173&#xff08;-0.34&#xff09;&#xff0c;&#096;fare&#096;\u548c&#096;survived&#096;\u6709\u6b63\u76f8\u5173&#xff08;0.26&#xff09;&#xff0c;\u8fd9\u4e0e\u6211\u4eec\u4e4b\u524d\u7684\u53d1\u73b0\u4e00\u81f4\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8fd9\u4e00\u7cfb\u5217\u201c\u671b\u3001\u95fb\u3001\u95ee\u3001\u5207\u201d&#xff0c;\u6211\u4eec\u5bf9\u6570\u636e\u7684\u7279\u6027\u3001\u6f5c\u5728\u7684\u95ee\u9898&#xff08;\u7f3a\u5931\u503c\u3001\u5f02\u5e38\u503c&#xff09;\u4ee5\u53ca\u7279\u5f81\u95f4\u7684\u5173\u7cfb\u6709\u4e86\u6df1\u523b\u7684\u7406\u89e3\u3002\u8fd9\u4efd\u7406\u89e3&#xff0c;\u5c06\u6307\u5bfc\u6211\u4eec\u4e0b\u4e00\u6b65\u7684\u201c\u51c0\u6570\u636e\u201d\u548c\u201c\u70b9\u77f3\u6210\u91d1\u201d\u5de5\u4f5c\u3002<\/p>\n<hr \/>\n<h4>3.2 \u201c\u51c0\u6570\u636e\u201d&#xff1a;\u6570\u636e\u6e05\u6d17\u7684\u4fee\u884c<\/h4>\n<p>\u73b0\u5b9e\u4e16\u754c\u7684\u6570\u636e\u662f\u201c\u80ae\u810f\u201d\u7684\u3002\u6570\u636e\u5f55\u5165\u9519\u8bef\u3001\u4f20\u611f\u5668\u6545\u969c\u3001\u7528\u6237\u4e0d\u613f\u586b\u5199\u2026\u2026\u79cd\u79cd\u539f\u56e0\u5bfc\u81f4\u4e86\u6570\u636e\u4e2d\u5145\u6ee1\u4e86\u7f3a\u5931\u503c&#xff08;Missing Values&#xff09;\u548c\u5f02\u5e38\u503c&#xff08;Outliers&#xff09;\u3002\u6570\u636e\u6e05\u6d17&#xff0c;\u5c31\u662f\u5c06\u8fd9\u4e9b\u201c\u6742\u8d28\u201d\u5904\u7406\u6389\u7684\u8fc7\u7a0b&#xff0c;\u5b83\u662f\u4e00\u9879\u7ec6\u81f4\u4e14\u5173\u952e\u7684\u4fee\u884c\u3002<\/p>\n<h5>3.2.1 \u7f3a\u5931\u503c\u7684\u201c\u820d\u201d\u4e0e\u201c\u5f97\u201d&#xff1a;\u5220\u9664\u3001\u63d2\u8865\u4e0e\u9884\u6d4b<\/h5>\n<p>\u5904\u7406\u7f3a\u5931\u503c&#xff0c;\u6211\u4eec\u9700\u8981\u6743\u8861\u5229\u5f0a&#xff0c;\u505a\u51fa\u201c\u820d\u201d\u4e0e\u201c\u5f97\u201d\u7684\u51b3\u7b56\u3002<\/p>\n<p>1. \u8bc6\u522b\u7f3a\u5931\u503c<\/p>\n<p># \u67e5\u770b\u6bcf\u5217\u7684\u7f3a\u5931\u503c\u6570\u91cf<br \/>\nprint(df.isnull().sum())<\/p>\n<p># \u67e5\u770b\u7f3a\u5931\u503c\u6bd4\u4f8b<br \/>\nprint(df.isnull().sum() \/ len(df) * 100)<\/p>\n<p>\u5728\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u4e2d&#xff0c;age\u7f3a\u5931\u7ea619.8%&#xff0c;deck\u7f3a\u5931\u9ad8\u8fbe77.4%&#xff0c;embarked\u53ea\u7f3a\u59312\u4e2a\u3002<\/p>\n<p>2. \u5904\u7406\u7b56\u7565<\/p>\n<ul>\n<li>\n<p>\u5220\u9664&#xff08;Dropping&#xff09;&#xff1a;\u201c\u820d\u201d\u7684\u51b3\u65ad<\/p>\n<ul>\n<li>\u5220\u9664\u6574\u5217&#xff1a;\u5982\u679c\u4e00\u4e2a\u7279\u5f81\u7684\u7f3a\u5931\u6bd4\u4f8b\u8fc7\u9ad8&#xff08;\u5982deck\u768477%&#xff09;&#xff0c;\u5b83\u6240\u80fd\u63d0\u4f9b\u7684\u4fe1\u606f\u5df2\u7ecf\u975e\u5e38\u6709\u9650&#xff0c;\u5f3a\u884c\u586b\u5145\u53cd\u800c\u53ef\u80fd\u5f15\u5165\u566a\u58f0\u3002\u6b64\u65f6&#xff0c;\u53ef\u4ee5\u8003\u8651\u76f4\u63a5\u5220\u9664\u8be5\u5217\u3002\n<p>df_dropped_col &#061; df.drop(&#039;deck&#039;, axis&#061;1)<\/p>\n<\/li>\n<li>\u5220\u9664\u6574\u884c&#xff1a;\u5982\u679c\u67d0\u4e2a\u6837\u672c&#xff08;\u884c&#xff09;\u7f3a\u5931\u4e86\u591a\u4e2a\u5173\u952e\u7279\u5f81&#xff0c;\u6216\u8005\u6570\u636e\u96c6\u975e\u5e38\u5927\u800c\u7f3a\u5931\u7684\u884c\u6570\u5f88\u5c11&#xff08;\u5982embarked\u53ea\u7f3a\u59312\u884c&#xff09;&#xff0c;\u90a3\u4e48\u76f4\u63a5\u5220\u9664\u8fd9\u4e9b\u884c\u662f\u7b80\u5355\u6709\u6548\u7684\u505a\u6cd5\u3002\n<p>df_dropped_row &#061; df.dropna(subset&#061;[&#039;embarked&#039;])<\/p>\n<\/li>\n<\/ul>\n<p>\u4f18\u70b9&#xff1a;\u7b80\u5355\u76f4\u63a5&#xff0c;\u4e0d\u4f1a\u5f15\u5165\u504f\u8bef\u3002\u00a0\u7f3a\u70b9&#xff1a;\u4f1a\u635f\u5931\u6570\u636e&#xff0c;\u5982\u679c\u7f3a\u5931\u6570\u636e\u4e0d\u662f\u968f\u673a\u7684&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5206\u6790\u7ed3\u679c\u4ea7\u751f\u504f\u89c1\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d2\u8865&#xff08;Imputation&#xff09;&#xff1a;\u201c\u5f97\u201d\u7684\u667a\u6167\u00a0\u63d2\u8865\u662f\u7528\u4e00\u4e2a\u4f30\u7b97\u503c\u6765\u4ee3\u66ff\u7f3a\u5931\u503c\u3002\u8fd9\u662f\u66f4\u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<ul>\n<li>\u7528\u5747\u503c\/\u4e2d\u4f4d\u6570\/\u4f17\u6570\u586b\u5145&#xff1a;\u8fd9\u662f\u6700\u7b80\u5355\u7684\u63d2\u8865\u65b9\u6cd5\u3002\n<ul>\n<li>\u5bf9\u4e8e\u6570\u503c\u578b\u7279\u5f81&#xff0c;\u5982\u679c\u6570\u636e\u5206\u5e03\u6bd4\u8f83\u5bf9\u79f0&#xff0c;\u53ef\u4ee5\u7528**\u5747\u503c&#xff08;mean&#xff09;\u586b\u5145&#xff1b;\u5982\u679c\u6570\u636e\u5b58\u5728\u504f\u6001\u6216\u6709\u5f02\u5e38\u503c&#xff0c;\u7528\u4e2d\u4f4d\u6570&#xff08;median&#xff09;**\u66f4\u4e3a\u7a33\u5065\u3002<\/li>\n<li>\u5bf9\u4e8e\u7c7b\u522b\u578b\u7279\u5f81&#xff0c;\u53ef\u4ee5\u7528\u4f17\u6570&#xff08;mode&#xff09;&#xff08;\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u503c&#xff09;\u6765\u586b\u5145\u3002<\/li>\n<\/ul>\n<p># \u7528\u5e74\u9f84\u7684\u4e2d\u4f4d\u6570\u586b\u5145age\u5217\u7684\u7f3a\u5931\u503c<br \/>\nage_median &#061; df[&#039;age&#039;].median()<br \/>\ndf[&#039;age&#039;].fillna(age_median, inplace&#061;True) # inplace&#061;True\u76f4\u63a5\u5728\u539fDataFrame\u4e0a\u4fee\u6539<\/p>\n<p># \u7528\u767b\u8239\u6e2f\u53e3\u7684\u4f17\u6570\u586b\u5145embarked\u5217<br \/>\nembarked_mode &#061; df[&#039;embarked&#039;].mode()[0] # mode()\u8fd4\u56de\u4e00\u4e2aSeries&#xff0c;\u53d6\u7b2c\u4e00\u4e2a<br \/>\ndf[&#039;embarked&#039;].fillna(embarked_mode, inplace&#061;True)<\/p>\n<\/li>\n<li>\u5206\u7ec4\u63d2\u8865&#xff1a;\u7b80\u5355\u7684\u5168\u5c40\u5747\u503c\/\u4e2d\u4f4d\u6570\u5ffd\u7565\u4e86\u6570\u636e\u5185\u90e8\u7684\u7ed3\u6784\u3002\u6211\u4eec\u53ef\u4ee5\u505a\u5f97\u66f4\u7cbe\u7ec6\u3002\u4f8b\u5982&#xff0c;\u6211\u4eec\u77e5\u9053\u4e0d\u540c\u8239\u8231\u7b49\u7ea7\u7684\u4e58\u5ba2\u5e74\u9f84\u53ef\u80fd\u6709\u5dee\u5f02&#xff0c;\u53ef\u4ee5\u6309pclass\u5206\u7ec4&#xff0c;\u7528\u5404\u7ec4\u7684\u4e2d\u4f4d\u6570\u6765\u586b\u5145\u3002\n<p># \u4f2a\u4ee3\u7801\u6f14\u793a\u601d\u60f3<br \/>\n# df[&#039;age&#039;] &#061; df.groupby(&#039;pclass&#039;)[&#039;age&#039;].transform(lambda x: x.fillna(x.median()))<\/p>\n<\/li>\n<\/ul>\n<p>\u4f18\u70b9&#xff1a;\u4fdd\u7559\u4e86\u6837\u672c&#xff0c;\u5145\u5206\u5229\u7528\u4e86\u6570\u636e\u3002\u00a0\u7f3a\u70b9&#xff1a;\u53ef\u80fd\u4f1a\u4f4e\u4f30\u6570\u636e\u7684\u65b9\u5dee&#xff0c;\u5f15\u5165\u4e00\u5b9a\u504f\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u9884\u6d4b\u6a21\u578b\u63d2\u8865\u00a0\u8fd9\u662f\u4e00\u79cd\u66f4\u9ad8\u7ea7\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u542b\u6709\u7f3a\u5931\u503c\u7684\u5217\u4f5c\u4e3a\u76ee\u6807\u53d8\u91cf&#xff08;y&#xff09;&#xff0c;\u5176\u4ed6\u5217\u4f5c\u4e3a\u7279\u5f81&#xff08;X&#xff09;&#xff0c;\u8bad\u7ec3\u4e00\u4e2a\u673a\u5668\u5b66\u4e60\u6a21\u578b&#xff08;\u5982\u7ebf\u6027\u56de\u5f52\u3001K\u8fd1\u90bb&#xff09;\u6765\u9884\u6d4b\u7f3a\u5931\u503c\u3002\u00a0\u4f18\u70b9&#xff1a;\u901a\u5e38\u662f\u6700\u51c6\u786e\u7684\u63d2\u8865\u65b9\u6cd5\u3002\u00a0\u7f3a\u70b9&#xff1a;\u5b9e\u73b0\u590d\u6742&#xff0c;\u8ba1\u7b97\u6210\u672c\u9ad8\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5&#xff1f;\u00a0\u8fd9\u53d6\u51b3\u4e8e\u7f3a\u5931\u7684\u6bd4\u4f8b\u3001\u7279\u5f81\u7684\u91cd\u8981\u6027\u3001\u6570\u636e\u7684\u5185\u5728\u5173\u7cfb\u4ee5\u53ca\u4f60\u613f\u610f\u6295\u5165\u7684\u6210\u672c\u3002\u6ca1\u6709\u7edd\u5bf9\u7684\u201c\u6700\u4f18\u89e3\u201d&#xff0c;\u53ea\u6709\u201c\u6700\u5408\u9002\u201d\u7684\u89e3\u3002<\/p>\n<h5>3.2.2 \u5f02\u5e38\u503c\u7684\u201c\u8fa8\u201d\u4e0e\u201c\u878d\u201d&#xff1a;\u8bc6\u522b\u4e0e\u5904\u7406<\/h5>\n<p>\u5f02\u5e38\u503c&#xff08;Outliers&#xff09;\u662f\u6307\u90a3\u4e9b\u4e0e\u6570\u636e\u96c6\u4e2d\u5176\u4f59\u6570\u636e\u70b9\u663e\u8457\u4e0d\u540c\u7684\u6570\u636e\u70b9\u3002\u5b83\u4eec\u53ef\u80fd\u662f\u5f55\u5165\u9519\u8bef&#xff0c;\u4e5f\u53ef\u80fd\u662f\u771f\u5b9e\u4f46\u6781\u7aef\u7684\u60c5\u51b5\u3002<\/p>\n<p>1. \u8bc6\u522b\u5f02\u5e38\u503c&#xff08;\u201c\u8fa8\u201d&#xff09;<\/p>\n<ul>\n<li>\n<p>\u53ef\u89c6\u5316\u8bc6\u522b&#xff1a;**\u7bb1\u5f62\u56fe&#xff08;Box Plot&#xff09;**\u662f\u8bc6\u522b\u5f02\u5e38\u503c\u7684\u5229\u5668\u3002\u7bb1\u4f53\u5916\u7684\u70b9\u901a\u5e38\u88ab\u8ba4\u4e3a\u662f\u6f5c\u5728\u7684\u5f02\u5e38\u503c\u3002<\/p>\n<p>sns.boxplot(x&#061;df[&#039;fare&#039;])<br \/>\nplt.show()<\/p>\n<p>\u6cf0\u5766\u5c3c\u514b\u7968\u4ef7\u7684\u7bb1\u5f62\u56fe\u6e05\u695a\u5730\u663e\u793a\u4e86\u5927\u91cf\u7684\u9ad8\u4ef7\u5f02\u5e38\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u7edf\u8ba1\u65b9\u6cd5\u8bc6\u522b&#xff1a;<\/p>\n<ul>\n<li>3\u03c3\u6cd5\u5219&#xff08;3-Sigma Rule&#xff09;&#xff1a;\u5bf9\u4e8e\u8fd1\u4f3c\u6b63\u6001\u5206\u5e03\u7684\u6570\u636e&#xff0c;\u7ea699.7%\u7684\u6570\u636e\u70b9\u4f1a\u843d\u5728\u8ddd\u79bb\u5747\u503c3\u4e2a\u6807\u51c6\u5dee\u7684\u8303\u56f4\u5185\u3002\u8d85\u51fa\u8fd9\u4e2a\u8303\u56f4\u7684\u70b9\u53ef\u88ab\u89c6\u4e3a\u5f02\u5e38\u503c\u3002<\/li>\n<li>IQR\u6cd5\u5219&#xff08;Interquartile Range&#xff09;&#xff1a;\u8fd9\u662f\u7bb1\u5f62\u56fe\u80cc\u540e\u7684\u6570\u5b66\u539f\u7406\u3002IQR &#061; Q3&#xff08;\u4e0a\u56db\u5206\u4f4d\u6570&#xff09; &#8211; Q1&#xff08;\u4e0b\u56db\u5206\u4f4d\u6570&#xff09;\u3002\u901a\u5e38\u5c06\u5c0f\u4e8e\u00a0Q1 &#8211; 1.5 * IQR\u00a0\u6216\u5927\u4e8e\u00a0Q3 &#043; 1.5 * IQR\u00a0\u7684\u70b9\u5b9a\u4e49\u4e3a\u5f02\u5e38\u503c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>2. \u5904\u7406\u5f02\u5e38\u503c&#xff08;\u201c\u878d\u201d&#xff09;<\/p>\n<ul>\n<li>\u5220\u9664&#xff1a;\u5982\u679c\u786e\u5b9a\u5f02\u5e38\u503c\u662f\u7531\u4e8e\u9519\u8bef&#xff08;\u5982\u5e74\u9f84\u8f93\u5165\u4e3a200\u5c81&#xff09;&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u5220\u9664\u3002\u4f46\u5982\u679c\u5f02\u5e38\u503c\u662f\u771f\u5b9e\u7684&#xff08;\u5982CEO\u7684\u8d85\u9ad8\u85aa\u6c34&#xff09;&#xff0c;\u5220\u9664\u5b83\u4eec\u53ef\u80fd\u4f1a\u4e22\u5931\u91cd\u8981\u4fe1\u606f\u3002<\/li>\n<li>\u8f6c\u6362&#xff08;Transformation&#xff09;&#xff1a;\u5bf9\u6570\u636e\u8fdb\u884c\u6570\u5b66\u8f6c\u6362&#xff0c;\u5982\u5bf9\u6570\u8f6c\u6362&#xff08;log transform&#xff09;&#xff0c;\u53ef\u4ee5\u201c\u538b\u7f29\u201d\u6570\u636e\u7684\u5c3a\u5ea6&#xff0c;\u51cf\u5c0f\u5f02\u5e38\u503c\u7684\u5f71\u54cd\u3002\u8fd9\u5bf9\u4e8e\u5904\u7406\u53f3\u504f\u5206\u5e03&#xff08;\u5982\u6536\u5165\u3001\u7968\u4ef7&#xff09;\u7684\u6570\u636e\u7279\u522b\u6709\u6548\u3002\n<p>df[&#039;fare_log&#039;] &#061; np.log1p(df[&#039;fare&#039;]) # log1p(x) &#061; log(1&#043;x)&#xff0c;\u907f\u514dlog(0)<br \/>\nsns.histplot(df[&#039;fare_log&#039;], kde&#061;True)<br \/>\nplt.show()<\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u5bf9\u6570\u8f6c\u6362\u540e\u7684\u7968\u4ef7\u5206\u5e03\u66f4\u63a5\u8fd1\u6b63\u6001\u5206\u5e03\u3002<\/li>\n<li>\u76d6\u5e3d&#xff08;Capping\/Winsorization&#xff09;&#xff1a;\u5c06\u8d85\u51fa\u7279\u5b9a\u9608\u503c&#xff08;\u598299\u767e\u5206\u4f4d\u6570&#xff09;\u7684\u5f02\u5e38\u503c&#xff0c;\u66ff\u6362\u4e3a\u8be5\u9608\u503c\u3002\u8fd9\u65e2\u9650\u5236\u4e86\u5f02\u5e38\u503c\u7684\u6781\u7aef\u5f71\u54cd&#xff0c;\u53c8\u4fdd\u7559\u4e86\u5b83\u4eec\u4f5c\u4e3a\u201c\u9ad8\u503c\u201d\u7684\u4fe1\u606f\u3002\n<p>p99 &#061; df[&#039;fare&#039;].quantile(0.99)<br \/>\ndf_capped &#061; df.copy()<br \/>\ndf_capped.loc[df_capped[&#039;fare&#039;] &gt; p99, &#039;fare&#039;] &#061; p99<\/p>\n<\/li>\n<\/ul>\n<p>\u5904\u7406\u5f02\u5e38\u503c\u540c\u6837\u9700\u8981\u5ba1\u614e\u3002\u8981\u7ed3\u5408\u4e1a\u52a1\u7406\u89e3&#xff0c;\u5224\u65ad\u4e00\u4e2a\u201c\u5f02\u5e38\u201d\u70b9\u7a76\u7adf\u662f\u566a\u58f0\u8fd8\u662f\u6709\u4ef7\u503c\u7684\u4fe1\u53f7\u3002<\/p>\n<hr \/>\n<h4>3.3 \u201c\u70b9\u77f3\u6210\u91d1\u201d&#xff1a;\u7279\u5f81\u5de5\u7a0b\u7684\u79d1\u5b66\u4e0e\u827a\u672f<\/h4>\n<p>\u5982\u679c\u8bf4\u6570\u636e\u6e05\u6d17\u662f\u201c\u6253\u626b\u5c4b\u5b50\u201d&#xff0c;\u90a3\u4e48\u7279\u5f81\u5de5\u7a0b\u5c31\u662f\u201c\u7cbe\u5fc3\u88c5\u4fee\u201d\u3002\u7279\u5f81\u5de5\u7a0b\u662f\u6307\u5229\u7528\u9886\u57df\u77e5\u8bc6\u548c\u6280\u672f\u624b\u6bb5&#xff0c;\u4ece\u539f\u59cb\u6570\u636e\u4e2d\u63d0\u53d6\u3001\u521b\u9020\u51fa\u5bf9\u9884\u6d4b\u6a21\u578b\u66f4\u6709\u7528\u7684\u65b0\u7279\u5f81\u7684\u8fc7\u7a0b\u3002\u00a0\u5b83\u662f\u51b3\u5b9a\u673a\u5668\u5b66\u4e60\u9879\u76ee\u6210\u8d25\u7684\u6700\u5173\u952e\u56e0\u7d20\u3002<\/p>\n<h5>3.3.1 \u7279\u5f81\u63d0\u53d6\u4e0e\u521b\u9020&#xff1a;\u4ece\u539f\u59cb\u6570\u636e\u4e2d\u63d0\u70bc\u771f\u91d1<\/h5>\n<ul>\n<li>\n<p>\u4ece\u73b0\u6709\u7279\u5f81\u7ec4\u5408&#xff1a; \u5728\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u4e2d&#xff0c;\u6709sibsp&#xff08;\u5144\u5f1f\u59d0\u59b9\/\u914d\u5076\u6570&#xff09;\u548cparch&#xff08;\u7236\u6bcd\/\u5b50\u5973\u6570&#xff09;\u4e24\u4e2a\u7279\u5f81\u3002\u5b83\u4eec\u90fd\u4ee3\u8868\u4e86\u4eb2\u4eba\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u4eec\u7ec4\u5408\u6210\u4e00\u4e2a\u66f4\u6709\u610f\u4e49\u7684\u65b0\u7279\u5f81\u2014\u2014family_size&#xff08;\u5bb6\u5ead\u6210\u5458\u603b\u6570&#xff09;\u3002<\/p>\n<p>df[&#039;family_size&#039;] &#061; df[&#039;sibsp&#039;] &#043; df[&#039;parch&#039;] &#043; 1 # &#043;1\u662f\u52a0\u4e0a\u81ea\u5df1<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u6839\u636e\u5bb6\u5ead\u89c4\u6a21&#xff0c;\u521b\u9020\u4e00\u4e2a\u7c7b\u522b\u7279\u5f81&#xff0c;\u5982is_alone&#xff08;\u662f\u5426\u72ec\u81ea\u4e00\u4eba&#xff09;\u3002<\/p>\n<p>df[&#039;is_alone&#039;] &#061; (df[&#039;family_size&#039;] &#061;&#061; 1).astype(int) # astype(int)\u5c06\u5e03\u5c14\u503c\u8f6c\u4e3a0\/1<\/p>\n<\/li>\n<li>\n<p>\u4ece\u590d\u6742\u6570\u636e\u4e2d\u63d0\u53d6&#xff1a;<\/p>\n<ul>\n<li>\u65e5\u671f\u65f6\u95f4&#xff1a;\u4ece\u4e00\u4e2a\u65e5\u671f2025-07-18&#xff0c;\u53ef\u4ee5\u63d0\u53d6\u51fa\u5e74\u4efd\u3001\u6708\u4efd\u3001\u661f\u671f\u51e0\u3001\u662f\u5426\u4e3a\u5468\u672b\u7b49\u591a\u4e2a\u7279\u5f81\u3002<\/li>\n<li>\u6587\u672c\u6570\u636e&#xff1a;\u4ece\u4e00\u6bb5\u6587\u672c\u4e2d&#xff0c;\u53ef\u4ee5\u63d0\u53d6\u8bcd\u9891&#xff08;TF-IDF&#xff09;\u3001\u60c5\u611f\u503e\u5411\u3001\u5173\u952e\u8bcd\u7b49\u3002<\/li>\n<li>\u4e58\u5ba2\u59d3\u540d&#xff08;Name&#xff09;&#xff1a;\u770b\u4f3c\u65e0\u7528&#xff0c;\u4f46\u4ed4\u7ec6\u89c2\u5bdf&#xff0c;\u59d3\u540d\u4e2d\u5305\u542b\u4e86Mr.,\u00a0Mrs.,\u00a0Miss.,\u00a0Master.\u7b49\u79f0\u8c13&#xff08;Title&#xff09;\u3002\u8fd9\u4e9b\u79f0\u8c13\u53cd\u6620\u4e86\u4e58\u5ba2\u7684\u6027\u522b\u3001\u5e74\u9f84\u3001\u5a5a\u59fb\u72b6\u51b5\u548c\u793e\u4f1a\u5730\u4f4d&#xff0c;\u53ef\u80fd\u662f\u975e\u5e38\u6709\u7528\u7684\u7279\u5f81\u3002\n<p>df[&#039;title&#039;] &#061; df[&#039;name&#039;].str.extract(&#039; ([A-Za-z]&#043;)\\\\.&#039;, expand&#061;False)<br \/>\nprint(df[&#039;title&#039;].value_counts())<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>3.3.2 \u7279\u5f81\u7f29\u653e\u4e0e\u7f16\u7801&#xff1a;\u4e3a\u6a21\u578b\u51c6\u5907\u201c\u7d20\u98df\u201d<\/h5>\n<p>\u5927\u591a\u6570\u673a\u5668\u5b66\u4e60\u6a21\u578b\u90fd\u50cf\u201c\u6311\u98df\u7684\u5b69\u5b50\u201d&#xff0c;\u5b83\u4eec\u65e0\u6cd5\u76f4\u63a5\u201c\u5403\u201d\u4e0b\u539f\u59cb\u7684\u3001\u4e94\u82b1\u516b\u95e8\u7684\u6570\u636e\u3002\u6211\u4eec\u9700\u8981\u5c06\u6240\u6709\u7279\u5f81\u90fd\u5904\u7406\u6210\u5b83\u4eec\u559c\u6b22\u7684\u683c\u5f0f\u2014\u2014\u6570\u503c\u578b\u3002<\/p>\n<p>1. \u7c7b\u522b\u7279\u5f81\u7f16\u7801<\/p>\n<ul>\n<li>\n<p>\u72ec\u70ed\u7f16\u7801&#xff08;One-Hot Encoding&#xff09;&#xff1a;\u8fd9\u662f\u5904\u7406\u540d\u4e49\u7c7b\u522b\u7279\u5f81&#xff08;Nominal Feature&#xff09;&#xff08;\u7c7b\u522b\u95f4\u6ca1\u6709\u987a\u5e8f\u5173\u7cfb&#xff0c;\u5982\u201c\u989c\u8272\u201d&#xff1a;\u7ea2\u3001\u7eff\u3001\u84dd&#xff09;\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u5b83\u4f1a\u4e3a\u6bcf\u4e2a\u7c7b\u522b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8c\u8fdb\u5236&#xff08;0\/1&#xff09;\u7279\u5f81\u3002<\/p>\n<p># \u5bf9&#039;embarked&#039;\u5217\u8fdb\u884c\u72ec\u70ed\u7f16\u7801<br \/>\nembarked_dummies &#061; pd.get_dummies(df[&#039;embarked&#039;], prefix&#061;&#039;embarked&#039;)<br \/>\ndf &#061; pd.concat([df, embarked_dummies], axis&#061;1)<\/p>\n<p>pd.get_dummies\u662fPandas\u4e2d\u5b9e\u73b0\u72ec\u70ed\u7f16\u7801\u7684\u4fbf\u6377\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u6807\u7b7e\u7f16\u7801&#xff08;Label Encoding&#xff09;\/ \u5e8f\u6570\u7f16\u7801&#xff08;Ordinal Encoding&#xff09;&#xff1a;\u7528\u4e8e\u5904\u7406\u6709\u5e8f\u7c7b\u522b\u7279\u5f81&#xff08;Ordinal Feature&#xff09;&#xff08;\u7c7b\u522b\u95f4\u6709\u660e\u786e\u7684\u987a\u5e8f&#xff0c;\u5982\u201c\u5b66\u5386\u201d&#xff1a;\u5b66\u58eb\u3001\u7855\u58eb\u3001\u535a\u58eb&#xff09;\u3002\u5b83\u5c06\u6bcf\u4e2a\u7c7b\u522b\u6620\u5c04\u5230\u4e00\u4e2a\u6574\u6570\u3002<\/p>\n<p># \u5047\u8bbe\u6709\u5b66\u5386\u7279\u5f81<br \/>\n# mapping &#061; {&#039;\u5b66\u58eb&#039;: 1, &#039;\u7855\u58eb&#039;: 2, &#039;\u535a\u58eb&#039;: 3}<br \/>\n# df[&#039;education_encoded&#039;] &#061; df[&#039;education&#039;].map(mapping)<\/p>\n<p>\u6ce8\u610f&#xff1a;\u7edd\u5bf9\u4e0d\u80fd\u5bf9\u540d\u4e49\u7c7b\u522b\u7279\u5f81\u4f7f\u7528\u6807\u7b7e\u7f16\u7801&#xff0c;\u56e0\u4e3a\u8fd9\u4f1a\u9519\u8bef\u5730\u7ed9\u6a21\u578b\u5f15\u5165\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u987a\u5e8f\u5173\u7cfb&#xff08;\u4f8b\u5982&#xff0c;\u6a21\u578b\u4f1a\u8ba4\u4e3a\u201c\u84dd\u8272\u201d\u6bd4\u201c\u7ea2\u8272\u201d\u5927&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2. \u6570\u503c\u7279\u5f81\u7f29\u653e&#xff08;Scaling&#xff09;<\/p>\n<p>\u8bb8\u591a\u6a21\u578b&#xff08;\u5982\u7ebf\u6027\u56de\u5f52\u3001SVM\u3001\u795e\u7ecf\u7f51\u7edc&#xff09;\u5bf9\u7279\u5f81\u7684\u5c3a\u5ea6\u975e\u5e38\u654f\u611f\u3002\u5982\u679c\u4e00\u4e2a\u7279\u5f81\u7684\u8303\u56f4\u662f0-10000&#xff08;\u5982\u85aa\u6c34&#xff09;&#xff0c;\u53e6\u4e00\u4e2a\u662f0-100&#xff08;\u5982\u5e74\u9f84&#xff09;&#xff0c;\u6a21\u578b\u4f1a\u4e0d\u6210\u6bd4\u4f8b\u5730\u88ab\u85aa\u6c34\u8fd9\u4e2a\u7279\u5f81\u6240\u4e3b\u5bfc\u3002\u7279\u5f81\u7f29\u653e\u5c31\u662f\u5c06\u6240\u6709\u7279\u5f81\u8c03\u6574\u5230\u76f8\u4f3c\u7684\u5c3a\u5ea6\u3002<\/p>\n<ul>\n<li>\n<p>\u6807\u51c6\u5316&#xff08;Standardization \/ Z-score Normalization&#xff09;&#xff1a;\u5c06\u7279\u5f81\u7f29\u653e\u5230\u5747\u503c\u4e3a0&#xff0c;\u6807\u51c6\u5dee\u4e3a1\u7684\u5206\u5e03\u3002\u8ba1\u7b97\u516c\u5f0f\u4e3a\u00a0(x &#8211; mean) \/ std\u3002\u8fd9\u662f\u6700\u5e38\u7528\u3001\u6700\u901a\u7528\u7684\u7f29\u653e\u65b9\u6cd5\u3002<\/p>\n<p>from sklearn.preprocessing import StandardScaler<br \/>\nscaler &#061; StandardScaler()<br \/>\ndf[&#039;age_scaled&#039;] &#061; scaler.fit_transform(df[[&#039;age&#039;]])<\/p>\n<\/li>\n<li>\n<p>\u5f52\u4e00\u5316&#xff08;Normalization \/ Min-Max Scaling&#xff09;&#xff1a;\u5c06\u7279\u5f81\u7f29\u653e\u5230\u4e00\u4e2a\u56fa\u5b9a\u7684\u8303\u56f4&#xff0c;\u901a\u5e38\u662f****\u3002\u8ba1\u7b97\u516c\u5f0f\u4e3a\u00a0(x &#8211; min) \/ (max &#8211; min)\u3002\u5f53\u6570\u636e\u5206\u5e03\u4e0d\u7b26\u5408\u9ad8\u65af\u5206\u5e03&#xff0c;\u6216\u8005\u4f60\u60f3\u4fdd\u75590\u503c\u65f6\u6bd4\u8f83\u6709\u7528\u3002<\/p>\n<p>from sklearn.preprocessing import MinMaxScaler<br \/>\nscaler &#061; MinMaxScaler()<br \/>\ndf[&#039;fare_scaled&#039;] &#061; scaler.fit_transform(df[[&#039;fare&#039;]])<\/p>\n<\/li>\n<\/ul>\n<h5>3.3.3 \u7279\u5f81\u9009\u62e9\u4e0e\u964d\u7ef4&#xff1a;\u53bb\u829c\u5b58\u83c1&#xff0c;\u5927\u9053\u81f3\u7b80<\/h5>\n<p>\u5f53\u6211\u4eec\u521b\u9020\u4e86\u5927\u91cf\u7279\u5f81\u540e&#xff0c;\u53ef\u80fd\u4f1a\u5f15\u5165\u5197\u4f59\u6216\u4e0d\u76f8\u5173\u7684\u7279\u5f81&#xff0c;\u8fd9\u4f1a\u589e\u52a0\u6a21\u578b\u590d\u6742\u5ea6&#xff0c;\u964d\u4f4e\u6cdb\u5316\u80fd\u529b&#xff0c;\u751a\u81f3\u5bfc\u81f4\u201c\u7ef4\u5ea6\u707e\u96be\u201d\u3002\u56e0\u6b64&#xff0c;\u6211\u4eec\u9700\u8981\u201c\u53bb\u829c\u5b58\u83c1\u201d\u3002<\/p>\n<p>1. \u7279\u5f81\u9009\u62e9&#xff08;Feature Selection&#xff09;<\/p>\n<p>\u76ee\u6807\u662f\u4ece\u6240\u6709\u7279\u5f81\u4e2d&#xff0c;\u9009\u51fa\u4e00\u4e2a\u6700\u4f18\u7684\u5b50\u96c6\u3002<\/p>\n<ul>\n<li>\u8fc7\u6ee4\u6cd5&#xff08;Filter Methods&#xff09;&#xff1a;\u72ec\u7acb\u4e8e\u6a21\u578b&#xff0c;\u6839\u636e\u7279\u5f81\u672c\u8eab\u7684\u7edf\u8ba1\u7279\u6027&#xff08;\u5982\u76f8\u5173\u7cfb\u6570\u3001\u5361\u65b9\u68c0\u9a8c\u3001\u4fe1\u606f\u589e\u76ca&#xff09;\u6765\u6253\u5206\u548c\u6392\u5e8f&#xff0c;\u7136\u540e\u9009\u62e9\u5f97\u5206\u6700\u9ad8\u7684\u7279\u5f81\u3002\u901f\u5ea6\u5feb&#xff0c;\u4f46\u6ca1\u6709\u8003\u8651\u7279\u5f81\u95f4\u7684\u7ec4\u5408\u6548\u5e94\u3002<\/li>\n<li>\u5305\u88c5\u6cd5&#xff08;Wrapper Methods&#xff09;&#xff1a;\u5c06\u7279\u5f81\u9009\u62e9\u8fc7\u7a0b\u201c\u5305\u88c5\u201d\u5728\u6a21\u578b\u8bad\u7ec3\u4e2d\u3002\u5b83\u628a\u7279\u5f81\u5b50\u96c6\u7684\u9009\u62e9\u770b\u4f5c\u4e00\u4e2a\u641c\u7d22\u95ee\u9898&#xff0c;\u7528\u6a21\u578b\u7684\u6027\u80fd\u4f5c\u4e3a\u8bc4\u4f30\u6807\u51c6\u6765\u5bfb\u627e\u6700\u4f18\u5b50\u96c6\u3002\u4f8b\u5982&#xff0c;\u9012\u5f52\u7279\u5f81\u6d88\u9664&#xff08;Recursive Feature Elimination, RFE&#xff09;\u3002\u6548\u679c\u597d&#xff0c;\u4f46\u8ba1\u7b97\u6210\u672c\u9ad8\u3002<\/li>\n<li>\u5d4c\u5165\u6cd5&#xff08;Embedded Methods&#xff09;&#xff1a;\u5c06\u7279\u5f81\u9009\u62e9\u5d4c\u5165\u5230\u6a21\u578b\u6784\u5efa\u7684\u8fc7\u7a0b\u4e2d\u3002\u4f8b\u5982&#xff0c;**L1\u6b63\u5219\u5316&#xff08;\u5982Lasso\u56de\u5f52&#xff09;**\u5728\u8bad\u7ec3\u65f6\u4f1a\u81ea\u52a8\u5c06\u4e0d\u91cd\u8981\u7279\u5f81\u7684\u7cfb\u6570\u60e9\u7f5a\u4e3a0&#xff0c;\u4ece\u800c\u5b9e\u73b0\u4e86\u81ea\u52a8\u7684\u7279\u5f81\u9009\u62e9\u3002\u8fd9\u662f\u76ee\u524d\u975e\u5e38\u63a8\u5d07\u7684\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>2. \u964d\u7ef4&#xff08;Dimensionality Reduction&#xff09;<\/p>\n<p>\u964d\u7ef4\u4e0d\u662f\u7b80\u5355\u5730\u201c\u9009\u62e9\u201d\u7279\u5f81&#xff0c;\u800c\u662f\u901a\u8fc7\u7ebf\u6027\u6216\u975e\u7ebf\u6027\u53d8\u6362&#xff0c;\u5c06\u9ad8\u7ef4\u6570\u636e\u6295\u5f71\u5230\u4f4e\u7ef4\u7a7a\u95f4&#xff0c;\u540c\u65f6\u5c3d\u53ef\u80fd\u591a\u5730\u4fdd\u7559\u539f\u59cb\u6570\u636e\u7684\u4fe1\u606f&#xff0c;\u521b\u9020\u51fa\u5168\u65b0\u7684\u3001\u66f4\u5c11\u7684\u7279\u5f81\u3002<\/p>\n<ul>\n<li>\u4e3b\u6210\u5206\u5206\u6790&#xff08;Principal Component Analysis, PCA&#xff09;&#xff1a;\u8fd9\u662f\u6700\u7ecf\u5178\u7684\u7ebf\u6027\u964d\u7ef4\u65b9\u6cd5\u3002\u5b83\u7684\u601d\u60f3\u662f&#xff0c;\u5bfb\u627e\u4e00\u4e2a\u65b0\u7684\u5750\u6807\u7cfb&#xff0c;\u4f7f\u5f97\u6570\u636e\u5728\u7b2c\u4e00\u4e2a\u65b0\u5750\u6807\u8f74&#xff08;\u7b2c\u4e00\u4e3b\u6210\u5206&#xff09;\u4e0a\u7684\u65b9\u5dee\u6700\u5927&#xff0c;\u5728\u7b2c\u4e8c\u4e2a\u65b0\u5750\u6807\u8f74&#xff08;\u7b2c\u4e8c\u4e3b\u6210\u5206&#xff09;\u4e0a\u7684\u65b9\u5dee\u6b21\u4e4b&#xff0c;\u4e14\u4e0e\u7b2c\u4e00\u4e2a\u6b63\u4ea4&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002\u7136\u540e\u6211\u4eec\u53ea\u4fdd\u7559\u524dk\u4e2a\u65b9\u5dee\u6700\u5927\u7684\u4e3b\u6210\u5206&#xff0c;\u5c31\u5b9e\u73b0\u4e86\u964d\u7ef4\u3002 PCA\u5728\u6570\u636e\u53ef\u89c6\u5316&#xff08;\u5c06\u9ad8\u7ef4\u6570\u636e\u964d\u52302D\u62163D\u8fdb\u884c\u89c2\u5bdf&#xff09;\u548c\u6d88\u9664\u591a\u91cd\u5171\u7ebf\u6027\u65b9\u9762\u975e\u5e38\u6709\u7528\u3002\u6211\u4eec\u5c06\u5728\u540e\u7eed\u7ae0\u8282\u4e2d\u66f4\u8be6\u7ec6\u5730\u5b66\u4e60\u548c\u5b9e\u8df5\u5b83\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u4e00\u6b21\u4ece\u201c\u539f\u59cb\u6570\u636e\u201d\u5230\u201c\u7cbe\u70bc\u7279\u5f81\u201d\u7684\u5b8c\u6574\u4fee\u884c\u3002\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u4e0e\u6570\u636e\u5bf9\u8bdd&#xff08;EDA&#xff09;&#xff0c;\u5982\u4f55\u4e3a\u6570\u636e\u201c\u6c90\u6d74\u66f4\u8863\u201d&#xff08;\u6e05\u6d17&#xff09;&#xff0c;\u4ee5\u53ca\u5982\u4f55\u4e3a\u5176\u201c\u68b3\u5986\u6253\u626e\u201d&#xff08;\u7279\u5f81\u5de5\u7a0b&#xff09;\u3002<\/p>\n<p>\u8bf7\u7262\u8bb0&#xff0c;\u7279\u5f81\u5de5\u7a0b\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u521b\u9020\u529b\u548c\u9886\u57df\u77e5\u8bc6\u4ef7\u503c\u6700\u5927\u7684\u4f53\u73b0\u3002\u597d\u7684\u7279\u5f81&#xff0c;\u80fd\u8ba9\u7b80\u5355\u7684\u6a21\u578b\u5927\u653e\u5f02\u5f69&#xff1b;\u800c\u5dee\u7684\u7279\u5f81&#xff0c;\u5373\u4f7f\u662f\u518d\u5f3a\u5927\u7684\u6a21\u578b\u4e5f\u65e0\u529b\u56de\u5929\u3002<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u7684\u6570\u636e\u5df2\u7ecf\u51c6\u5907\u5c31\u7eea&#xff0c;\u53ef\u4ee5\u968f\u65f6\u201c\u5582\u201d\u7ed9\u6a21\u578b\u4e86\u3002\u4e0b\u4e00\u7ae0&#xff0c;\u6211\u4eec\u5c06\u6b63\u5f0f\u5f00\u542f\u5404\u7c7b\u4e3b\u6d41\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u5b66\u4e60\u4e4b\u65c5&#xff0c;\u5c06\u8fd9\u4e9b\u7cbe\u5fc3\u51c6\u5907\u7684\u201c\u98df\u6750\u201d&#xff0c;\u70f9\u996a\u6210\u4e00\u9053\u9053\u7f8e\u5473\u7684\u201c\u7b97\u6cd5\u5927\u9910\u201d\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u56db\u7ae0&#xff1a;\u6a21\u578b\u7684\u7f57\u76d8\u2014\u2014\u8bc4\u4f30\u4e0e\u9009\u62e9<\/h3>\n<ul>\n<li>4.1 \u201c\u5ea6\u91cf\u8861\u201d&#xff1a;\u5206\u7c7b\u3001\u56de\u5f52\u4e0e\u805a\u7c7b\u6a21\u578b\u7684\u8bc4\u4f30\u6307\u6807<\/li>\n<li>4.2 \u201c\u6267\u5176\u4e24\u7aef\u800c\u7528\u4e2d\u201d&#xff1a;\u504f\u5dee\u4e0e\u65b9\u5dee\u7684\u6743\u8861<\/li>\n<li>4.3 \u201c\u4ed6\u5c71\u4e4b\u77f3\u201d&#xff1a;\u4ea4\u53c9\u9a8c\u8bc1\u7684\u667a\u6167<\/li>\n<li>4.4 \u201c\u5bfb\u8def\u201d&#xff1a;\u7f51\u683c\u641c\u7d22\u4e0e\u8d85\u53c2\u6570\u8c03\u4f18<\/li>\n<\/ul>\n<p>\u7ecf\u8fc7\u524d\u4e09\u7ae0\u7684\u4fee\u70bc&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b66\u4f1a\u4e86\u642d\u5efa\u73af\u5883\u3001\u9a7e\u9a6d\u5de5\u5177&#xff0c;\u5e76\u638c\u63e1\u4e86\u6570\u636e\u7684\u201c\u5fc3\u6cd5\u201d\u3002\u6211\u4eec\u624b\u4e2d\u5df2\u7ecf\u6709\u4e86\u7ecf\u8fc7\u7cbe\u5fc3\u63d0\u70bc\u7684\u201c\u71c3\u6599\u201d\u2014\u2014\u5e72\u51c0\u3001\u89c4\u6574\u7684\u7279\u5f81\u3002\u73b0\u5728&#xff0c;\u662f\u65f6\u5019\u5c06\u8fd9\u4e9b\u71c3\u6599\u6ce8\u5165\u5404\u79cd\u5f3a\u5927\u7684\u201c\u5f15\u64ce\u201d\u2014\u2014\u673a\u5668\u5b66\u4e60\u6a21\u578b\u4e86\u3002<\/p>\n<p>\u4f46\u5728\u6211\u4eec\u4e00\u5934\u624e\u8fdb\u5f62\u5f62\u8272\u8272\u7684\u7b97\u6cd5\u6d77\u6d0b\u4e4b\u524d&#xff0c;\u4e00\u4e2a\u81f3\u5173\u91cd\u8981\u7684\u95ee\u9898\u6446\u5728\u9762\u524d&#xff1a;\u6211\u4eec\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u6a21\u578b\u662f\u597d\u662f\u574f&#xff1f;<\/p>\n<p>\u5728\u4e24\u4e2a\u6a21\u578b\u4e4b\u95f4&#xff0c;\u6211\u4eec\u5982\u4f55\u5ba2\u89c2\u5730\u9009\u62e9\u90a3\u4e2a\u66f4\u597d\u7684&#xff1f;\u4e00\u4e2a\u6a21\u578b\u5728\u8bad\u7ec3\u6570\u636e\u4e0a\u8868\u73b0\u5b8c\u7f8e&#xff0c;\u6211\u4eec\u5c31\u80fd\u76f8\u4fe1\u5b83\u5728\u672a\u6765\u7684\u65b0\u6570\u636e\u4e0a\u540c\u6837\u51fa\u8272\u5417&#xff1f;\u5982\u4f55\u4e3a\u6a21\u578b\u9009\u62e9\u6700\u4f73\u7684\u201c\u914d\u7f6e\u53c2\u6570\u201d&#xff0c;\u8ba9\u5176\u53d1\u6325\u6700\u5927\u6f5c\u80fd&#xff1f;<\/p>\n<p>\u672c\u7ae0&#xff0c;\u4fbf\u662f\u89e3\u7b54\u8fd9\u4e9b\u95ee\u9898\u7684\u201c\u7f57\u76d8\u201d\u3002\u6211\u4eec\u5c06\u7cfb\u7edf\u5730\u5b66\u4e60\u6a21\u578b\u8bc4\u4f30\u4e0e\u9009\u62e9\u7684\u5b8c\u6574\u6846\u67b6\u3002\u9996\u5148&#xff0c;\u6211\u4eec\u4f1a\u4e3a\u4e0d\u540c\u7c7b\u578b\u7684\u4efb\u52a1&#xff08;\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b&#xff09;\u5efa\u7acb\u4e00\u5957\u7cbe\u786e\u7684\u201c\u5ea6\u91cf\u8861\u201d&#xff0c;\u5373\u8bc4\u4f30\u6307\u6807\u3002\u63a5\u7740&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u6240\u6709\u6a21\u578b\u90fd\u65e0\u6cd5\u56de\u907f\u7684\u4e24\u4e2a\u6838\u5fc3\u77db\u76fe\u2014\u2014\u504f\u5dee\u4e0e\u65b9\u5dee&#xff0c;\u5e76\u5b66\u4e60\u5982\u4f55\u901a\u8fc7\u5b66\u4e60\u66f2\u7ebf\u6765\u8bca\u65ad\u5b83\u4eec\u3002\u968f\u540e&#xff0c;\u6211\u4eec\u5c06\u638c\u63e1\u4ea4\u53c9\u9a8c\u8bc1\u8fd9\u4e00\u5f3a\u5927\u7684\u6280\u672f&#xff0c;\u4ee5\u83b7\u5f97\u5bf9\u6a21\u578b\u6027\u80fd\u66f4\u7a33\u5b9a\u3001\u66f4\u53ef\u9760\u7684\u8bc4\u4f30\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u50cf\u4e00\u4f4d\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5de5\u7a0b\u5e08\u4e00\u6837&#xff0c;\u7cfb\u7edf\u5730\u4e3a\u6a21\u578b\u5bfb\u627e\u6700\u4f18\u7684\u8d85\u53c2\u6570\u3002<\/p>\n<p>\u638c\u63e1\u672c\u7ae0\u5185\u5bb9&#xff0c;\u60a8\u5c06\u62e5\u6709\u4e00\u53cc\u201c\u6167\u773c\u201d&#xff0c;\u80fd\u591f\u6d1e\u6089\u6a21\u578b\u7684\u5185\u5728\u72b6\u6001&#xff0c;\u79d1\u5b66\u5730\u8bc4\u4f30\u5176\u4f18\u52a3&#xff0c;\u5e76\u81ea\u4fe1\u5730\u505a\u51fa\u9009\u62e9\u3002\u8fd9\u662f\u4ece\u201c\u4f1a\u7528\u6a21\u578b\u201d\u5230\u201c\u7528\u597d\u6a21\u578b\u201d\u7684\u5173\u952e\u4e00\u6b65\u3002<\/p>\n<hr \/>\n<h4>4.1 \u201c\u5ea6\u91cf\u8861\u201d&#xff1a;\u5206\u7c7b\u3001\u56de\u5f52\u4e0e\u805a\u7c7b\u6a21\u578b\u7684\u8bc4\u4f30\u6307\u6807<\/h4>\n<p>\u6ca1\u6709\u5ea6\u91cf&#xff0c;\u5c31\u65e0\u6cd5\u4f18\u5316\u3002\u8bc4\u4f30\u6307\u6807&#xff0c;\u5c31\u662f\u6211\u4eec\u8861\u91cf\u6a21\u578b\u6027\u80fd\u7684\u5c3a\u5b50\u3002\u4e0d\u540c\u7684\u4efb\u52a1&#xff0c;\u9700\u8981\u7528\u4e0d\u540c\u7684\u5c3a\u5b50\u6765\u91cf\u3002\u6211\u4eec\u4e0d\u80fd\u7528\u91cf\u8eab\u9ad8\u7684\u5c3a\u5b50\u53bb\u91cf\u4f53\u91cd&#xff0c;\u540c\u6837&#xff0c;\u6211\u4eec\u4e5f\u4e0d\u80fd\u7528\u56de\u5f52\u7684\u6307\u6807\u53bb\u8bc4\u4f30\u5206\u7c7b\u6a21\u578b\u3002<\/p>\n<h5>4.1.1 \u5206\u7c7b\u4efb\u52a1\u7684\u201c\u662f\u975e\u9898\u201d&#xff1a;\u6df7\u6dc6\u77e9\u9635\u7684\u6df1\u5c42\u89e3\u8bfb<\/h5>\n<p>\u5206\u7c7b\u4efb\u52a1\u662f\u6700\u5e38\u89c1\u7684\u673a\u5668\u5b66\u4e60\u95ee\u9898\u4e4b\u4e00\u3002\u5176\u8f93\u51fa\u662f\u79bb\u6563\u7684\u7c7b\u522b&#xff0c;\u5982\u201c\u662f\/\u5426\u201d\u3001\u201c\u732b\/\u72d7\/\u9e1f\u201d\u3001\u201cA\/B\/C\u7c7b\u201d\u3002\u5bf9\u4e8e\u6700\u57fa\u7840\u7684\u4e8c\u5143\u5206\u7c7b\u95ee\u9898&#xff08;\u4f8b\u5982&#xff0c;\u5224\u65ad\u4e00\u5c01\u90ae\u4ef6\u662f\u5426\u4e3a\u5783\u573e\u90ae\u4ef6&#xff09;&#xff0c;\u6a21\u578b\u7684\u6240\u6709\u9884\u6d4b\u7ed3\u679c\u53ef\u4ee5\u5f52\u5165\u56db\u79cd\u60c5\u51b5\u3002\u8fd9\u56db\u79cd\u60c5\u51b5\u5171\u540c\u6784\u6210\u4e86\u4e00\u4e2a\u540d\u4e3a**\u6df7\u6dc6\u77e9\u9635&#xff08;Confusion Matrix&#xff09;**\u7684\u8868\u683c&#xff0c;\u5b83\u662f\u51e0\u4e4e\u6240\u6709\u5206\u7c7b\u8bc4\u4f30\u6307\u6807\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u57fa\u672c\u6982\u5ff5&#xff1a;\u771f\u6b63\u4f8b(TP)\u3001\u5047\u6b63\u4f8b(FP)\u3001\u771f\u8d1f\u4f8b(FN)\u3001\u5047\u8d1f\u4f8b(TN)<\/p>\n<p>\u6211\u4eec\u4ee5\u4e00\u4e2a\u201cAI\u533b\u751f\u201d\u5224\u65ad\u75c5\u4eba\u662f\u5426\u60a3\u6709\u67d0\u79cd\u75be\u75c5&#xff08;\u201c\u9633\u6027\u201d\u4e3a\u60a3\u75c5&#xff0c;\u201c\u9634\u6027\u201d\u4e3a\u5065\u5eb7&#xff09;\u7684\u573a\u666f\u4e3a\u4f8b\u6765\u7406\u89e3\u8fd9\u56db\u4e2a\u6982\u5ff5&#xff1a;<\/p>\n<ul>\n<li>\u771f\u6b63\u4f8b (True Positive, TP)&#xff1a;\u75c5\u4eba\u786e\u5b9e\u60a3\u75c5&#xff08;\u771f\u5b9e\u4e3a\u6b63&#xff09;&#xff0c;AI\u533b\u751f\u4e5f\u6b63\u786e\u5730\u9884\u6d4b\u5176\u4e3a\u9633\u6027&#xff08;\u9884\u6d4b\u4e3a\u6b63&#xff09;\u3002\u2014\u2014\u00a0\u5224\u65ad\u6b63\u786e<\/li>\n<li>\u5047\u6b63\u4f8b (False Positive, FP)&#xff1a;\u75c5\u4eba\u5176\u5b9e\u5f88\u5065\u5eb7&#xff08;\u771f\u5b9e\u4e3a\u8d1f&#xff09;&#xff0c;\u4f46AI\u533b\u751f\u5374\u9519\u8bef\u5730\u9884\u6d4b\u5176\u4e3a\u9633\u6027&#xff08;\u9884\u6d4b\u4e3a\u6b63&#xff09;\u3002\u8fd9\u662f\u201c\u8bef\u62a5\u201d&#xff0c;\u4e5f\u79f0\u4e3a\u7b2c\u4e00\u7c7b\u9519\u8bef (Type I Error)\u3002\u2014\u2014\u00a0\u5224\u65ad\u9519\u8bef<\/li>\n<li>\u771f\u8d1f\u4f8b (True Negative, TN)&#xff1a;\u75c5\u4eba\u786e\u5b9e\u5f88\u5065\u5eb7&#xff08;\u771f\u5b9e\u4e3a\u8d1f&#xff09;&#xff0c;AI\u533b\u751f\u4e5f\u6b63\u786e\u5730\u9884\u6d4b\u5176\u4e3a\u9634\u6027&#xff08;\u9884\u6d4b\u4e3a\u8d1f&#xff09;\u3002\u2014\u2014\u00a0\u5224\u65ad\u6b63\u786e<\/li>\n<li>\u5047\u8d1f\u4f8b (False Negative, FN)&#xff1a;\u75c5\u4eba\u5176\u5b9e\u60a3\u6709\u8be5\u75c5&#xff08;\u771f\u5b9e\u4e3a\u6b63&#xff09;&#xff0c;\u4f46AI\u533b\u751f\u5374\u9519\u8bef\u5730\u9884\u6d4b\u5176\u4e3a\u9634\u6027&#xff08;\u9884\u6d4b\u4e3a\u8d1f&#xff09;\u3002\u8fd9\u662f\u201c\u6f0f\u62a5\u201d&#xff0c;\u4e5f\u79f0\u4e3a\u7b2c\u4e8c\u7c7b\u9519\u8bef (Type II Error)\u3002\u2014\u2014\u00a0\u5224\u65ad\u9519\u8bef<\/li>\n<\/ul>\n<p>\u8fd9\u56db\u8005\u53ef\u4ee5\u7528\u4e00\u4e2a2&#215;2\u7684\u77e9\u9635\u6e05\u6670\u5730\u5c55\u793a\u51fa\u6765&#xff1a;<\/p>\n<table>\n<tr>\n<p>\u9884\u6d4b\u4e3a\u6b63 (Predicted: 1)<\/p>\n<p>\u9884\u6d4b\u4e3a\u8d1f (Predicted: 0)<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u771f\u5b9e\u4e3a\u6b63 (Actual: 1)<\/p>\n<\/td>\n<td>\n<p>TP (\u771f\u6b63\u4f8b)<\/p>\n<\/td>\n<td>\n<p>FN (\u5047\u8d1f\u4f8b)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u771f\u5b9e\u4e3a\u8d1f (Actual: 0)<\/p>\n<\/td>\n<td>\n<p>FP (\u5047\u6b63\u4f8b)<\/p>\n<\/td>\n<td>\n<p>TN (\u771f\u8d1f\u4f8b)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728Scikit-learn\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u6df7\u6dc6\u77e9\u9635&#xff1a;<\/p>\n<p>from sklearn.metrics import confusion_matrix<br \/>\nfrom sklearn.linear_model import LogisticRegression<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nimport pandas as pd<br \/>\nimport seaborn as sns<br \/>\nimport matplotlib.pyplot as plt<\/p>\n<p># \u4f7f\u7528\u4e0a\u4e00\u7ae0\u5904\u7406\u8fc7\u7684\u6cf0\u5766\u5c3c\u514b\u6570\u636e&#xff08;\u5047\u8bbe\u5df2\u5b8c\u6210\u7f3a\u5931\u503c\u586b\u5145\u548c\u7f16\u7801&#xff09;<br \/>\n# \u4e3a\u4e86\u6f14\u793a&#xff0c;\u6211\u4eec\u7b80\u5316\u4e00\u4e0b\u7279\u5f81<br \/>\ndf &#061; sns.load_dataset(&#039;titanic&#039;)<br \/>\n# &#8230; (\u6b64\u5904\u7701\u7565\u4e0a\u4e00\u7ae0\u7684\u6570\u636e\u6e05\u6d17\u548c\u7279\u5f81\u5de5\u7a0b\u4ee3\u7801) &#8230;<br \/>\n# \u5047\u8bbe\u6211\u4eec\u5f97\u5230\u4e86\u4e00\u4e2a\u53ef\u7528\u7684df_processed&#xff0c;\u5305\u542b\u7279\u5f81X\u548c\u76ee\u6807y<br \/>\n# X &#061; df_processed[[&#039;pclass&#039;, &#039;age_scaled&#039;, &#039;fare_scaled&#039;, &#039;is_alone&#039;, &#8230;]]<br \/>\n# y &#061; df_processed[&#039;survived&#039;]<\/p>\n<p># \u4f2a\u4ee3\u7801\u6f14\u793a\u6d41\u7a0b<br \/>\n# X_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.3, random_state&#061;42)<br \/>\n# model &#061; LogisticRegression()<br \/>\n# model.fit(X_train, y_train)<br \/>\n# y_pred &#061; model.predict(X_test)<\/p>\n<p># \u5047\u8bbe\u6211\u4eec\u6709\u771f\u5b9e\u503cy_test\u548c\u9884\u6d4b\u503cy_pred<br \/>\ny_test &#061; pd.Series([1, 0, 0, 1, 0, 1, 0, 1, 1, 0]) # \u771f\u5b9e\u6807\u7b7e<br \/>\ny_pred &#061; pd.Series([1, 0, 1, 1, 0, 0, 0, 1, 1, 0]) # \u6a21\u578b\u9884\u6d4b<\/p>\n<p>cm &#061; confusion_matrix(y_test, y_pred)<br \/>\nprint(&#034;\u6df7\u6dc6\u77e9\u9635:\\\\n&#034;, cm)<\/p>\n<p># \u53ef\u89c6\u5316\u6df7\u6dc6\u77e9\u9635<br \/>\nsns.heatmap(cm, annot&#061;True, fmt&#061;&#039;d&#039;, cmap&#061;&#039;Blues&#039;)<br \/>\nplt.xlabel(&#039;Predicted Label&#039;)<br \/>\nplt.ylabel(&#039;True Label&#039;)<br \/>\nplt.show()<\/p>\n<p>\u6df7\u6dc6\u77e9\u9635\u672c\u8eab\u4fe1\u606f\u91cf\u5de8\u5927&#xff0c;\u4f46\u4e0d\u591f\u76f4\u89c2&#xff0c;\u6211\u4eec\u9700\u8981\u4ece\u4e2d\u63d0\u70bc\u51fa\u66f4\u6613\u4e8e\u6bd4\u8f83\u7684\u5355\u4e00\u6570\u503c\u6307\u6807\u3002<\/p>\n<p>\u4ece\u6df7\u6dc6\u77e9\u9635\u5230\u6838\u5fc3\u6307\u6807&#xff1a;\u51c6\u786e\u7387\u3001\u7cbe\u786e\u7387\u3001\u53ec\u56de\u7387\u3001F1\u5206\u6570<\/p>\n<ul>\n<li>\n<p>\u51c6\u786e\u7387 (Accuracy)<\/p>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u9884\u6d4b\u6b63\u786e\u7684\u6837\u672c\u6570\u5360\u603b\u6837\u672c\u6570\u7684\u6bd4\u4f8b\u3002<\/li>\n<li>\u516c\u5f0f&#xff1a;(TP &#043; TN) \/ (TP &#043; TN &#043; FP &#043; FN)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u8fd9\u662f\u6700\u76f4\u89c2\u7684\u6307\u6807&#xff0c;\u8861\u91cf\u4e86\u6a21\u578b\u201c\u6574\u4f53\u4e0a\u505a\u5bf9\u4e86\u591a\u5c11\u201d\u3002<\/li>\n<li>\u9677\u9631&#xff1a;\u5728\u6570\u636e\u4e0d\u5e73\u8861\u7684\u573a\u666f\u4e0b&#xff0c;\u51c6\u786e\u7387\u5177\u6709\u6781\u5927\u7684\u8bef\u5bfc\u6027\u3002\u4f8b\u5982&#xff0c;\u5728\u4e00\u4e2a99%\u7684\u90ae\u4ef6\u90fd\u662f\u6b63\u5e38\u90ae\u4ef6\u7684\u6570\u636e\u96c6\u4e2d&#xff0c;\u4e00\u4e2a\u65e0\u8111\u5730\u5c06\u6240\u6709\u90ae\u4ef6\u90fd\u9884\u6d4b\u4e3a\u201c\u6b63\u5e38\u201d\u7684\u6a21\u578b&#xff0c;\u5176\u51c6\u786e\u7387\u9ad8\u8fbe99%&#xff0c;\u4f46\u5b83\u6beb\u65e0\u7528\u5904&#xff0c;\u56e0\u4e3a\u5b83\u4e00\u4e2a\u5783\u573e\u90ae\u4ef6\u90fd\u627e\u4e0d\u51fa\u6765\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7cbe\u786e\u7387 (Precision)<\/p>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u5728\u6240\u6709\u88ab\u9884\u6d4b\u4e3a\u6b63\u4f8b\u7684\u6837\u672c\u4e2d&#xff0c;\u6709\u591a\u5c11\u662f\u771f\u6b63\u7684\u6b63\u4f8b\u3002<\/li>\n<li>\u516c\u5f0f&#xff1a;TP \/ (TP &#043; FP)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u5b83\u8861\u91cf\u7684\u662f\u6a21\u578b\u7684\u201c\u67e5\u51c6\u7387\u201d\u3002\u9ad8\u7cbe\u786e\u7387\u610f\u5473\u7740\u201c\u6211\u9884\u6d4b\u4f60\u662f\u6b63\u4f8b&#xff0c;\u4f60\u5927\u6982\u7387\u771f\u7684\u662f\u6b63\u4f8b\u201d\u3002\u5b83\u5173\u5fc3\u7684\u662f\u9884\u6d4b\u7ed3\u679c\u7684\u8d28\u91cf\u3002<\/li>\n<li>\u5e94\u7528\u573a\u666f&#xff1a;\u5bf9\u201c\u8bef\u62a5\u201d\u60e9\u7f5a\u5f88\u9ad8\u7684\u573a\u666f\u3002\u4f8b\u5982&#xff0c;\u5783\u573e\u90ae\u4ef6\u8fc7\u6ee4&#xff0c;\u6211\u4eec\u4e0d\u5e0c\u671b\u628a\u91cd\u8981\u7684\u6b63\u5e38\u90ae\u4ef6&#xff08;\u5982\u9762\u8bd5\u901a\u77e5&#xff09;\u9519\u8bef\u5730\u5224\u4e3a\u5783\u573e\u90ae\u4ef6&#xff08;FP&#xff09;&#xff0c;\u6b64\u65f6\u7cbe\u786e\u7387\u6bd4\u53ec\u56de\u7387\u66f4\u91cd\u8981\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u53ec\u56de\u7387 (Recall \/ Sensitivity \/ True Positive Rate)<\/p>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u5728\u6240\u6709\u771f\u5b9e\u4e3a\u6b63\u4f8b\u7684\u6837\u672c\u4e2d&#xff0c;\u6709\u591a\u5c11\u88ab\u6a21\u578b\u6210\u529f\u5730\u9884\u6d4b\u4e86\u51fa\u6765\u3002<\/li>\n<li>\u516c\u5f0f&#xff1a;TP \/ (TP &#043; FN)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u5b83\u8861\u91cf\u7684\u662f\u6a21\u578b\u7684\u201c\u67e5\u5168\u7387\u201d\u3002\u9ad8\u53ec\u56de\u7387\u610f\u5473\u7740\u201c\u6240\u6709\u771f\u5b9e\u7684\u6b63\u4f8b&#xff0c;\u6211\u57fa\u672c\u90fd\u627e\u51fa\u6765\u4e86\u201d\u3002\u5b83\u5173\u5fc3\u7684\u662f\u5bf9\u771f\u5b9e\u6b63\u4f8b\u7684\u8986\u76d6\u80fd\u529b\u3002<\/li>\n<li>\u5e94\u7528\u573a\u666f&#xff1a;\u5bf9\u201c\u6f0f\u62a5\u201d\u60e9\u7f5a\u5f88\u9ad8\u7684\u573a\u666f\u3002\u4f8b\u5982&#xff0c;\u5728\u75be\u75c5\u8bca\u65ad\u6216\u91d1\u878d\u6b3a\u8bc8\u68c0\u6d4b\u4e2d&#xff0c;\u6211\u4eec\u5b81\u53ef\u201c\u8bef\u62a5\u201d\u4e00\u4e9b\u5065\u5eb7\u4eba\u6216\u6b63\u5e38\u4ea4\u6613&#xff08;FP\u8f83\u9ad8&#xff0c;\u7cbe\u786e\u7387\u4e0b\u964d&#xff09;&#xff0c;\u4e5f\u7edd\u4e0d\u5e0c\u671b\u201c\u6f0f\u6389\u201d\u4e00\u4e2a\u771f\u6b63\u7684\u75c5\u4eba\u6216\u6b3a\u8bc8\u884c\u4e3a&#xff08;FN\u5f88\u4f4e&#xff0c;\u53ec\u56de\u7387\u9ad8&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>F1\u5206\u6570 (F1-Score)<\/p>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u7684\u8c03\u548c\u5e73\u5747\u6570\u3002<\/li>\n<li>\u516c\u5f0f&#xff1a;2 * (Precision * Recall) \/ (Precision &#043; Recall)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u5b83\u662f\u4e00\u4e2a\u7efc\u5408\u6027\u6307\u6807&#xff0c;\u8bd5\u56fe\u5728\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u4e4b\u95f4\u627e\u5230\u4e00\u4e2a\u5e73\u8861\u3002\u53ea\u6709\u5f53\u4e24\u8005\u90fd\u6bd4\u8f83\u9ad8\u65f6&#xff0c;F1\u5206\u6570\u624d\u4f1a\u9ad8\u3002<\/li>\n<li>\u5e94\u7528\u573a\u666f&#xff1a;\u5f53\u4f60\u5e0c\u671b\u540c\u65f6\u5173\u6ce8\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387&#xff0c;\u6216\u8005\u5f53\u4e24\u8005\u5b58\u5728\u77db\u76fe\u65f6&#xff0c;F1\u5206\u6570\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u53c2\u8003\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5728Scikit-learn\u4e2d&#xff0c;\u8fd9\u4e9b\u6307\u6807\u90fd\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97&#xff1a;<\/p>\n<p>from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, classification_report<\/p>\n<p>print(&#034;Accuracy:&#034;, accuracy_score(y_test, y_pred))<br \/>\nprint(&#034;Precision:&#034;, precision_score(y_test, y_pred))<br \/>\nprint(&#034;Recall:&#034;, recall_score(y_test, y_pred))<br \/>\nprint(&#034;F1 Score:&#034;, f1_score(y_test, y_pred))<\/p>\n<p># \u6216\u8005\u4f7f\u7528classification_report\u4e00\u6b21\u6027\u8f93\u51fa\u6240\u6709\u6307\u6807<br \/>\nprint(&#034;\\\\nClassification Report:\\\\n&#034;, classification_report(y_test, y_pred))<\/p>\n<p>\u7cbe\u786e\u7387\u4e0e\u53ec\u56de\u7387\u7684\u6743\u8861&#xff1a;\u5728\u201c\u5b81\u53ef\u9519\u6740\u201d\u4e0e\u201c\u7edd\u4e0d\u653e\u8fc7\u201d\u4e4b\u95f4<\/p>\n<p>\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u901a\u5e38\u662f\u4e00\u5bf9\u201c\u77db\u76fe\u201d\u7684\u6307\u6807\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u6a21\u578b\u5728\u5185\u90e8\u5e76\u4e0d\u662f\u76f4\u63a5\u8f93\u51fa\u201c0\u201d\u6216\u201c1\u201d&#xff0c;\u800c\u662f\u8f93\u51fa\u4e00\u4e2a\u201c\u662f\u6b63\u4f8b\u7684\u6982\u7387\u201d&#xff08;0\u52301\u4e4b\u95f4&#xff09;\u3002\u6211\u4eec\u901a\u8fc7\u8bbe\u5b9a\u4e00\u4e2a**\u9608\u503c&#xff08;Threshold&#xff09;**\u6765\u505a\u51fa\u6700\u7ec8\u5224\u65ad&#xff0c;\u4f8b\u5982&#xff0c;\u9ed8\u8ba4\u9608\u503c\u662f0.5&#xff0c;\u6982\u7387&gt;0.5\u5c31\u5224\u4e3a1&#xff0c;\u5426\u5219\u4e3a0\u3002<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u6211\u4eec\u63d0\u9ad8\u9608\u503c&#xff08;\u4f8b\u5982&#xff0c;\u63d0\u9ad8\u52300.9&#xff09;&#xff0c;\u6a21\u578b\u4f1a\u53d8\u5f97\u975e\u5e38\u201c\u8c28\u614e\u201d\u3002\u53ea\u6709\u975e\u5e38\u6709\u628a\u63e1\u7684\u624d\u5224\u4e3a\u6b63\u4f8b\u3002\u8fd9\u6837&#xff0c;FP\u4f1a\u51cf\u5c11&#xff0c;\u7cbe\u786e\u7387\u4f1a\u63d0\u9ad8&#xff1b;\u4f46\u540c\u65f6&#xff0c;\u5f88\u591a\u201c\u6709\u70b9\u50cf\u4f46\u628a\u63e1\u4e0d\u5927\u201d\u7684\u6b63\u4f8b\u4f1a\u88ab\u6f0f\u6389&#xff08;FN\u589e\u52a0&#xff09;&#xff0c;\u5bfc\u81f4\u53ec\u56de\u7387\u4e0b\u964d\u3002\u8fd9\u5bf9\u5e94\u4e86\u201c\u5b81\u53ef\u9519\u6740\u4e00\u5343&#xff0c;\u7edd\u4e0d\u653e\u8fc7\u4e00\u4e2a&#xff08;\u654c\u4eba&#xff09;\u201d\u7684\u53cd\u9762&#xff0c;\u5373\u201c\u5b81\u53ef\u653e\u8fc7&#xff08;\u6f0f\u6389&#xff09;\u4e00\u4e9b\u53ef\u7591\u5206\u5b50&#xff0c;\u4e5f\u8981\u4fdd\u8bc1\u6293\u5230\u7684\u90fd\u662f\u94c1\u8bc1\u5982\u5c71\u7684\u771f\u51f6\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u6211\u4eec\u964d\u4f4e\u9608\u503c&#xff08;\u4f8b\u5982&#xff0c;\u964d\u4f4e\u52300.1&#xff09;&#xff0c;\u6a21\u578b\u4f1a\u53d8\u5f97\u975e\u5e38\u201c\u6fc0\u8fdb\u201d\u3002\u53ea\u8981\u6709\u4e00\u70b9\u70b9\u50cf\u6b63\u4f8b&#xff0c;\u5c31\u5224\u4e3a\u6b63\u4f8b\u3002\u8fd9\u6837&#xff0c;FN\u4f1a\u51cf\u5c11&#xff0c;\u53ec\u56de\u7387\u4f1a\u63d0\u9ad8&#xff1b;\u4f46\u540c\u65f6&#xff0c;\u5f88\u591a\u8d1f\u4f8b\u4f1a\u88ab\u8bef\u5224\u4e3a\u6b63\u4f8b&#xff08;FP\u589e\u52a0&#xff09;&#xff0c;\u5bfc\u81f4\u7cbe\u786e\u7387\u4e0b\u964d\u3002\u8fd9\u5bf9\u5e94\u4e86\u201c\u5b81\u53ef\u9519\u6740\u4e00\u5343&#xff0c;\u7edd\u4e0d\u653e\u8fc7\u4e00\u4e2a\u201d\u7684\u7b56\u7565\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u7406\u89e3\u8fd9\u79cd\u6743\u8861\u5173\u7cfb\u81f3\u5173\u91cd\u8981\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u6211\u4eec\u9700\u8981\u6839\u636e\u4e1a\u52a1\u9700\u6c42&#xff0c;\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u9608\u503c&#xff0c;\u6765\u5e73\u8861\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u3002\u800c**\u7cbe\u786e\u7387-\u53ec\u56de\u7387\u66f2\u7ebf&#xff08;P-R Curve&#xff09;**\u6b63\u662f\u53ef\u89c6\u5316\u8fd9\u79cd\u6743\u8861\u7684\u5de5\u5177\u3002<\/p>\n<hr \/>\n<p>\u7cbe\u786e\u7387\u4e0e\u53ec\u56de\u7387\u7684\u6743\u8861&#xff1a;\u5728\u201c\u5b81\u53ef\u9519\u6740\u201d\u4e0e\u201c\u7edd\u4e0d\u653e\u8fc7\u201d\u4e4b\u95f4<\/p>\n<p>\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u901a\u5e38\u662f\u4e00\u5bf9\u201c\u77db\u76fe\u201d\u7684\u6307\u6807&#xff0c;\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u4e00\u79cd\u6b64\u6d88\u5f7c\u957f\u7684\u6743\u8861\u5173\u7cfb\u3002\u7406\u89e3\u8fd9\u79cd\u6743\u8861&#xff0c;\u662f\u505a\u51fa\u6709\u6548\u4e1a\u52a1\u51b3\u7b56\u7684\u5173\u952e\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u5927\u591a\u6570\u5206\u7c7b\u6a21\u578b&#xff08;\u5982\u903b\u8f91\u56de\u5f52\u3001\u795e\u7ecf\u7f51\u7edc&#xff09;\u5728\u5185\u90e8\u5e76\u4e0d\u662f\u76f4\u63a5\u8f93\u51fa\u201c0\u201d\u6216\u201c1\u201d\u7684\u786c\u6027\u7c7b\u522b&#xff0c;\u800c\u662f\u8f93\u51fa\u4e00\u4e2a\u201c\u6837\u672c\u5c5e\u4e8e\u6b63\u4f8b\u7684\u6982\u7387\u201d&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\u7684\u8fde\u7eed\u503c\u3002\u6211\u4eec\u6700\u7ec8\u770b\u5230\u7684\u201c0\u201d\u6216\u201c1\u201d\u7684\u9884\u6d4b\u7ed3\u679c&#xff0c;\u662f\u8fd9\u4e2a\u6982\u7387\u503c\u4e0e\u4e00\u4e2a\u6211\u4eec\u8bbe\u5b9a\u7684**\u51b3\u7b56\u9608\u503c&#xff08;Decision Threshold&#xff09;**\u6bd4\u8f83\u5f97\u6765\u7684\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u8fd9\u4e2a\u9608\u503c\u901a\u5e38\u662f0.5\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u00a0\u6a21\u578b\u8f93\u51fa\u6982\u7387 &gt; \u9608\u503c&#xff0c;\u5219\u9884\u6d4b\u4e3a\u6b63\u4f8b&#xff08;1&#xff09;\u3002<\/li>\n<li>\u5982\u679c\u00a0\u6a21\u578b\u8f93\u51fa\u6982\u7387 &lt;&#061; \u9608\u503c&#xff0c;\u5219\u9884\u6d4b\u4e3a\u8d1f\u4f8b&#xff08;0&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u770b\u770b\u8c03\u6574\u8fd9\u4e2a\u9608\u503c\u4f1a\u53d1\u751f\u4ec0\u4e48&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u63d0\u9ad8\u51b3\u7b56\u9608\u503c&#xff08;\u4f8b\u5982&#xff0c;\u4ece0.5\u63d0\u9ad8\u52300.9&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5f71\u54cd&#xff1a;\u6a21\u578b\u4f1a\u53d8\u5f97\u975e\u5e38\u201c\u4fdd\u5b88\u201d\u6216\u201c\u6311\u5254\u201d\u3002\u53ea\u6709\u5f53\u5b83\u201c\u6781\u5ea6\u786e\u4fe1\u201d\u4e00\u4e2a\u6837\u672c\u662f\u6b63\u4f8b\u65f6&#xff08;\u6982\u7387\u9ad8\u8fbe90%\u4ee5\u4e0a&#xff09;&#xff0c;\u624d\u4f1a\u5c06\u5176\u9884\u6d4b\u4e3a\u6b63\u4f8b\u3002<\/li>\n<li>\u7ed3\u679c&#xff1a;\n<ul>\n<li>\u5927\u91cf\u7684\u201c\u7591\u4f3c\u201d\u6b63\u4f8b\u4f1a\u88ab\u5212\u4e3a\u8d1f\u4f8b&#xff0c;\u5bfc\u81f4\u5047\u8d1f\u4f8b&#xff08;FN&#xff09;\u589e\u52a0&#xff0c;\u4ece\u800c\u53ec\u56de\u7387&#xff08;Recall&#xff09;\u6025\u5267\u4e0b\u964d\u3002<\/li>\n<li>\u7531\u4e8e\u6807\u51c6\u4e25\u82db&#xff0c;\u88ab\u9884\u6d4b\u4e3a\u6b63\u4f8b\u7684\u6837\u672c&#xff0c;\u5176\u201c\u542b\u91d1\u91cf\u201d\u4f1a\u5f88\u9ad8&#xff0c;\u5047\u6b63\u4f8b&#xff08;FP&#xff09;\u4f1a\u51cf\u5c11&#xff0c;\u4ece\u800c\u7cbe\u786e\u7387&#xff08;Precision&#xff09;\u4f1a\u63d0\u9ad8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7c7b\u6bd4&#xff1a;\u201c\u5b81\u53ef\u653e\u8fc7\u4e00\u5343&#xff0c;\u4e0d\u53ef\u9519\u6740\u4e00\u4eba\u201d\u3002\u9002\u7528\u4e8e\u5bf9\u8bef\u62a5&#xff08;FP&#xff09;\u5bb9\u5fcd\u5ea6\u6781\u4f4e\u7684\u573a\u666f&#xff0c;\u5982\u5411\u7528\u6237\u63a8\u9001\u9ad8\u4ef7\u503c\u4f46\u6253\u6270\u6027\u5f3a\u7684\u5e7f\u544a\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u964d\u4f4e\u51b3\u7b56\u9608\u503c&#xff08;\u4f8b\u5982&#xff0c;\u4ece0.5\u964d\u4f4e\u52300.1&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5f71\u54cd&#xff1a;\u6a21\u578b\u4f1a\u53d8\u5f97\u975e\u5e38\u201c\u6fc0\u8fdb\u201d\u6216\u201c\u654f\u611f\u201d\u3002\u53ea\u8981\u6709\u4e00\u70b9\u70b9\u53ef\u80fd\u662f\u6b63\u4f8b\u7684\u8ff9\u8c61&#xff08;\u6982\u7387\u8d85\u8fc710%&#xff09;&#xff0c;\u5b83\u5c31\u4f1a\u5c06\u5176\u9884\u6d4b\u4e3a\u6b63\u4f8b\u3002<\/li>\n<li>\u7ed3\u679c&#xff1a;\n<ul>\n<li>\u5927\u91cf\u7684\u201c\u7591\u4f3c\u201d\u6b63\u4f8b\u4f1a\u88ab\u6210\u529f\u6355\u83b7&#xff0c;\u5047\u8d1f\u4f8b&#xff08;FN&#xff09;\u4f1a\u51cf\u5c11&#xff0c;\u4ece\u800c\u53ec\u56de\u7387&#xff08;Recall&#xff09;\u4f1a\u63d0\u9ad8\u3002<\/li>\n<li>\u7531\u4e8e\u6807\u51c6\u5bbd\u677e&#xff0c;\u5f88\u591a\u8d1f\u4f8b\u4f1a\u88ab\u9519\u8bef\u5730\u5212\u5165\u6b63\u4f8b&#xff0c;\u5047\u6b63\u4f8b&#xff08;FP&#xff09;\u4f1a\u589e\u52a0&#xff0c;\u4ece\u800c\u7cbe\u786e\u7387&#xff08;Precision&#xff09;\u4f1a\u4e0b\u964d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7c7b\u6bd4&#xff1a;\u201c\u5b81\u53ef\u9519\u6740\u4e00\u5343&#xff0c;\u4e0d\u53ef\u653e\u8fc7\u4e00\u4e2a\u201d\u3002\u9002\u7528\u4e8e\u5bf9\u6f0f\u62a5&#xff08;FN&#xff09;\u5bb9\u5fcd\u5ea6\u6781\u4f4e\u7684\u573a\u666f&#xff0c;\u5982\u764c\u75c7\u7b5b\u67e5\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u7cbe\u786e\u7387-\u53ec\u56de\u7387\u66f2\u7ebf&#xff08;Precision-Recall Curve, P-R Curve&#xff09;\u00a0\u4e3a\u4e86\u7cfb\u7edf\u5730\u89c2\u5bdf\u8fd9\u79cd\u6743\u8861\u5173\u7cfb&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7ed8\u5236P-R\u66f2\u7ebf\u3002\u8be5\u66f2\u7ebf\u7684\u6a2a\u5750\u6807\u662f\u53ec\u56de\u7387&#xff0c;\u7eb5\u5750\u6807\u662f\u7cbe\u786e\u7387\u3002\u5b83\u662f\u901a\u8fc7\u4ece\u9ad8\u5230\u4f4e\u79fb\u52a8\u51b3\u7b56\u9608\u503c&#xff0c;\u5728\u6bcf\u4e2a\u9608\u503c\u4e0b\u8ba1\u7b97\u4e00\u7ec4(Recall, Precision)\u503c&#xff0c;\u7136\u540e\u5c06\u8fd9\u4e9b\u70b9\u8fde\u63a5\u800c\u6210\u3002<\/p>\n<p>from sklearn.metrics import precision_recall_curve<\/p>\n<p># \u5047\u8bbemodel\u5df2\u7ecf\u8bad\u7ec3\u597d&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u8f93\u51fa\u6982\u7387<br \/>\n# y_scores &#061; model.predict_proba(X_test)[:, 1] # \u83b7\u53d6\u6b63\u4f8b\u7684\u6982\u7387<\/p>\n<p># \u4f2a\u4ee3\u7801\u6f14\u793a<br \/>\ny_test &#061; pd.Series([1, 0, 0, 1, 0, 1, 0, 1, 1, 0])<br \/>\ny_scores &#061; pd.Series([0.9, 0.4, 0.6, 0.8, 0.3, 0.45, 0.2, 0.85, 0.7, 0.1]) # \u6a21\u578b\u8f93\u51fa\u7684\u6982\u7387<\/p>\n<p>precisions, recalls, thresholds &#061; precision_recall_curve(y_test, y_scores)<\/p>\n<p>plt.figure(figsize&#061;(8, 6))<br \/>\nplt.plot(recalls, precisions, marker&#061;&#039;.&#039;)<br \/>\nplt.xlabel(&#039;Recall&#039;)<br \/>\nplt.ylabel(&#039;Precision&#039;)<br \/>\nplt.title(&#039;Precision-Recall Curve&#039;)<br \/>\nplt.grid(True)<br \/>\nplt.show()<\/p>\n<p>\u4e00\u6839\u7406\u60f3\u7684P-R\u66f2\u7ebf\u4f1a\u5c3d\u53ef\u80fd\u5730\u9760\u8fd1\u53f3\u4e0a\u89d2&#xff08;\u5373\u5728\u76f8\u540c\u7684\u53ec\u56de\u7387\u4e0b&#xff0c;\u7cbe\u786e\u7387\u5c3d\u53ef\u80fd\u9ad8&#xff09;\u3002\u66f2\u7ebf\u4e0b\u65b9\u7684\u9762\u79ef&#xff08;AUC-PR&#xff09;\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u7efc\u5408\u8bc4\u4f30\u6307\u6807&#xff0c;\u9762\u79ef\u8d8a\u5927&#xff0c;\u6a21\u578b\u6027\u80fd\u8d8a\u597d\u3002<\/p>\n<h5>4.1.2 \u8d85\u8d8a\u5355\u4e00\u9608\u503c&#xff1a;ROC\u66f2\u7ebf\u4e0eAUC\u503c\u7684\u201c\u5168\u5c40\u89c2\u201d<\/h5>\n<p>P-R\u66f2\u7ebf\u975e\u5e38\u9002\u5408\u8bc4\u4f30\u5728\u4e0d\u5e73\u8861\u6570\u636e\u96c6\u4e0a\u7684\u6a21\u578b\u6027\u80fd\u3002\u4f46\u8fd8\u6709\u4e00\u4e2a\u66f4\u5e38\u7528\u3001\u66f4\u901a\u7528\u7684\u8bc4\u4f30\u5de5\u5177\u2014\u2014ROC\u66f2\u7ebf&#xff08;Receiver Operating Characteristic Curve&#xff09;\u3002<\/p>\n<p>ROC\u66f2\u7ebf\u7684\u7ed8\u5236&#xff1a;\u771f\u6b63\u4f8b\u7387(TPR) vs. \u5047\u6b63\u4f8b\u7387(FPR)<\/p>\n<p>ROC\u66f2\u7ebf\u63cf\u7ed8\u4e86\u4e24\u4e2a\u5173\u952e\u6307\u6807\u4e4b\u95f4\u7684\u5173\u7cfb&#xff1a;<\/p>\n<ul>\n<li>\u771f\u6b63\u4f8b\u7387 (True Positive Rate, TPR)&#xff1a;\u8fd9\u5176\u5b9e\u5c31\u662f\u6211\u4eec\u5df2\u7ecf\u5b66\u8fc7\u7684\u53ec\u56de\u7387&#xff08;Recall&#xff09;\u3002\u5b83\u8861\u91cf\u6a21\u578b\u201c\u6293\u4f4f\u4e86\u591a\u5c11\u771f\u75c5\u4eba\u201d\u3002\n<ul>\n<li>TPR &#061; TP \/ (TP &#043; FN)<\/li>\n<\/ul>\n<\/li>\n<li>\u5047\u6b63\u4f8b\u7387 (False Positive Rate, FPR)&#xff1a;\u5b83\u8861\u91cf\u7684\u662f&#xff0c;\u5728\u6240\u6709\u771f\u5b9e\u7684\u8d1f\u4f8b\u4e2d&#xff0c;\u6709\u591a\u5c11\u88ab\u6a21\u578b\u9519\u8bef\u5730\u9884\u6d4b\u4e3a\u4e86\u6b63\u4f8b\u3002\n<ul>\n<li>FPR &#061; FP \/ (FP &#043; TN)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>ROC\u66f2\u7ebf\u7684\u7ed8\u5236\u8fc7\u7a0b\u4e0eP-R\u66f2\u7ebf\u7c7b\u4f3c&#xff0c;\u4e5f\u662f\u901a\u8fc7\u4e0d\u65ad\u79fb\u52a8\u51b3\u7b56\u9608\u503c&#xff0c;\u5728\u6bcf\u4e2a\u9608\u503c\u4e0b\u8ba1\u7b97\u4e00\u7ec4(FPR, TPR)\u503c&#xff0c;\u7136\u540e\u5c06\u8fd9\u4e9b\u70b9\u8fde\u63a5\u800c\u6210\u3002<\/p>\n<p>AUC\u7684\u542b\u4e49&#xff1a;\u6a21\u578b\u6574\u4f53\u6392\u5e8f\u80fd\u529b\u7684\u91cf\u5316<\/p>\n<ul>\n<li>\n<p>ROC\u66f2\u7ebf\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>\u66f2\u7ebf\u4e0a\u7684\u6bcf\u4e2a\u70b9\u4ee3\u8868\u4e00\u4e2a\u7279\u5b9a\u7684\u51b3\u7b56\u9608\u503c\u3002<\/li>\n<li>\u5de6\u4e0b\u89d2(0,0)\u70b9&#xff1a;\u9608\u503c\u8bbe\u4e3a1&#xff0c;\u6a21\u578b\u5c06\u6240\u6709\u6837\u672c\u90fd\u9884\u6d4b\u4e3a\u8d1f&#xff0c;TPR\u548cFPR\u90fd\u4e3a0\u3002<\/li>\n<li>\u53f3\u4e0a\u89d2(1,1)\u70b9&#xff1a;\u9608\u503c\u8bbe\u4e3a0&#xff0c;\u6a21\u578b\u5c06\u6240\u6709\u6837\u672c\u90fd\u9884\u6d4b\u4e3a\u6b63&#xff0c;TPR\u548cFPR\u90fd\u4e3a1\u3002<\/li>\n<li>\u5de6\u4e0a\u89d2(0,1)\u70b9&#xff1a;\u7406\u60f3\u7684\u5b8c\u7f8e\u6a21\u578b&#xff0c;FPR\u4e3a0&#xff08;\u6ca1\u6709\u8bef\u62a5&#xff09;&#xff0c;TPR\u4e3a1&#xff08;\u6ca1\u6709\u6f0f\u62a5&#xff09;\u3002<\/li>\n<li>\u5bf9\u89d2\u7ebf&#xff08;y&#061;x&#xff09;&#xff1a;\u4ee3\u8868\u4e00\u4e2a\u201c\u968f\u673a\u731c\u6d4b\u201d\u6a21\u578b\u3002\u4e00\u4e2a\u6709\u4ef7\u503c\u7684\u6a21\u578b&#xff0c;\u5176ROC\u66f2\u7ebf\u5fc5\u987b\u5728\u5bf9\u89d2\u7ebf\u4e0a\u65b9\u3002<\/li>\n<li>\u66f2\u7ebf\u8d8a\u9760\u8fd1\u5de6\u4e0a\u89d2&#xff0c;\u8bf4\u660e\u6a21\u578b\u5728\u76f8\u540c\u7684\u201c\u8bef\u62a5\u6210\u672c\u201d&#xff08;FPR&#xff09;\u4e0b&#xff0c;\u80fd\u83b7\u5f97\u66f4\u9ad8\u7684\u201c\u67e5\u5168\u7387\u201d&#xff08;TPR&#xff09;&#xff0c;\u6027\u80fd\u8d8a\u597d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>AUC (Area Under the Curve)&#xff1a; AUC\u503c\u5c31\u662fROC\u66f2\u7ebf\u4e0b\u65b9\u7684\u9762\u79ef\u3002\u5b83\u662f\u4e00\u4e2a\u4ecb\u4e8e0\u548c1\u4e4b\u95f4\u7684\u6570\u503c\u3002<\/p>\n<ul>\n<li>AUC &#061; 1&#xff1a;\u5b8c\u7f8e\u5206\u7c7b\u5668\u3002<\/li>\n<li>AUC &#061; 0.5&#xff1a;\u968f\u673a\u731c\u6d4b\u6a21\u578b\u3002<\/li>\n<li>AUC &lt; 0.5&#xff1a;\u6a21\u578b\u6027\u80fd\u5dee\u4e8e\u968f\u673a\u731c\u6d4b&#xff08;\u53ef\u80fd\u628a\u6807\u7b7e\u641e\u53cd\u4e86&#xff09;\u3002<\/li>\n<li>0.5 &lt; AUC &lt; 1&#xff1a;\u6a21\u578b\u5177\u6709\u4e00\u5b9a\u7684\u9884\u6d4b\u4ef7\u503c&#xff0c;\u503c\u8d8a\u5927\u8d8a\u597d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>AUC\u6709\u4e00\u4e2a\u975e\u5e38\u76f4\u89c2\u7684\u7edf\u8ba1\u5b66\u89e3\u91ca&#xff1a;\u5b83\u7b49\u4e8e\u4ece\u6240\u6709\u6b63\u4f8b\u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6837\u672c&#xff0c;\u518d\u4ece\u6240\u6709\u8d1f\u4f8b\u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6837\u672c&#xff0c;\u8be5\u6a21\u578b\u5c06\u6b63\u4f8b\u7684\u9884\u6d4b\u6982\u7387\u6392\u5728\u8d1f\u4f8b\u4e4b\u524d\u7684\u6982\u7387\u3002\u00a0\u56e0\u6b64&#xff0c;AUC\u8861\u91cf\u7684\u662f\u6a21\u578b\u6574\u4f53\u7684\u6392\u5e8f\u80fd\u529b&#xff0c;\u800c\u4e0d\u4f9d\u8d56\u4e8e\u67d0\u4e2a\u7279\u5b9a\u7684\u51b3\u7b56\u9608\u503c\u3002<\/p>\n<p>from sklearn.metrics import roc_curve, auc<\/p>\n<p># y_scores \u540c\u6837\u662f\u6a21\u578b\u8f93\u51fa\u7684\u6b63\u4f8b\u6982\u7387<br \/>\nfpr, tpr, thresholds &#061; roc_curve(y_test, y_scores)<br \/>\nroc_auc &#061; auc(fpr, tpr)<\/p>\n<p>plt.figure(figsize&#061;(8, 6))<br \/>\nplt.plot(fpr, tpr, color&#061;&#039;darkorange&#039;, lw&#061;2, label&#061;f&#039;ROC curve (area &#061; {roc_auc:.2f})&#039;)<br \/>\nplt.plot([0, 1], [0, 1], color&#061;&#039;navy&#039;, lw&#061;2, linestyle&#061;&#039;&#8211;&#039;) # \u7ed8\u5236\u5bf9\u89d2\u7ebf<br \/>\nplt.xlim([0.0, 1.0])<br \/>\nplt.ylim([0.0, 1.05])<br \/>\nplt.xlabel(&#039;False Positive Rate&#039;)<br \/>\nplt.ylabel(&#039;True Positive Rate&#039;)<br \/>\nplt.title(&#039;Receiver Operating Characteristic&#039;)<br \/>\nplt.legend(loc&#061;&#034;lower right&#034;)<br \/>\nplt.grid(True)<br \/>\nplt.show()<\/p>\n<p>\u4f55\u65f6\u5173\u6ce8ROC\/AUC&#xff0c;\u4f55\u65f6\u5173\u6ce8P-R\u66f2\u7ebf<\/p>\n<ul>\n<li>\u5f53\u6b63\u8d1f\u6837\u672c\u5206\u5e03\u76f8\u5bf9\u5747\u8861\u65f6&#xff0c;ROC\/AUC\u662f\u4e00\u4e2a\u975e\u5e38\u7a33\u5b9a\u4e14\u5168\u9762\u7684\u8bc4\u4f30\u6307\u6807\u3002<\/li>\n<li>\u5f53\u5904\u7406\u4e25\u91cd\u7684\u6570\u636e\u4e0d\u5e73\u8861\u95ee\u9898\u65f6&#xff0c;P-R\u66f2\u7ebf\u901a\u5e38\u80fd\u63d0\u4f9b\u66f4\u591a\u7684\u4fe1\u606f\u3002\u56e0\u4e3a\u5728\u6781\u4e0d\u5e73\u8861\u7684\u6570\u636e\u4e2d&#xff0c;FPR\u7684\u5206\u6bcd&#xff08;FP&#043;TN&#xff09;\u7531\u4e8eTN\u6570\u91cf\u5de8\u5927&#xff0c;\u5373\u4f7fFP\u663e\u8457\u589e\u52a0&#xff0c;FPR\u7684\u53d8\u5316\u4e5f\u53ef\u80fd\u4e0d\u660e\u663e&#xff0c;\u5bfc\u81f4ROC\u66f2\u7ebf\u5448\u73b0\u51fa\u8fc7\u4e8e\u201c\u4e50\u89c2\u201d\u7684\u7ed3\u679c\u3002\u800cP-R\u66f2\u7ebf\u7684\u4e24\u4e2a\u6307\u6807&#xff08;Precision\u548cRecall&#xff09;\u90fd\u805a\u7126\u4e8e\u6b63\u4f8b&#xff0c;\u5bf9\u6b63\u4f8b\u7684\u9884\u6d4b\u53d8\u5316\u66f4\u4e3a\u654f\u611f\u3002<\/li>\n<\/ul>\n<h5>4.1.3 \u56de\u5f52\u4efb\u52a1\u7684\u201c\u5ea6\u91cf\u5c3a\u201d&#xff1a;\u8861\u91cf\u9884\u6d4b\u7684\u201c\u8fdc\u8fd1\u201d<\/h5>\n<p>\u56de\u5f52\u4efb\u52a1\u7684\u76ee\u6807\u662f\u9884\u6d4b\u4e00\u4e2a\u8fde\u7eed\u503c&#xff0c;\u5982\u623f\u4ef7\u3001\u6c14\u6e29\u3002\u8bc4\u4f30\u56de\u5f52\u6a21\u578b&#xff0c;\u5c31\u662f\u8861\u91cf\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u201c\u8ddd\u79bb\u201d\u6216\u201c\u8bef\u5dee\u201d\u3002<\/p>\n<p>\u8bef\u5dee\u7684\u57fa\u672c\u5ea6\u91cf&#xff1a;MAE, MSE, RMSE<\/p>\n<p>\u5047\u8bbe\u771f\u5b9e\u503c\u4e3a\u00a0y&#xff0c;\u9884\u6d4b\u503c\u4e3a\u00a0\u0177\u3002<\/p>\n<ul>\n<li>\n<p>\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee (Mean Absolute Error, MAE)<\/p>\n<ul>\n<li>\u516c\u5f0f&#xff1a;1\/n * \u03a3|y &#8211; \u0177|<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u8ba1\u7b97\u6bcf\u4e2a\u6837\u672c\u7684\u9884\u6d4b\u8bef\u5dee\u7684\u7edd\u5bf9\u503c&#xff0c;\u7136\u540e\u53d6\u5e73\u5747\u3002\u5b83\u76f4\u63a5\u53cd\u6620\u4e86\u9884\u6d4b\u8bef\u5dee\u7684\u5e73\u5747\u5927\u5c0f&#xff0c;\u5355\u4f4d\u4e0e\u76ee\u6807\u53d8\u91cf\u76f8\u540c&#xff0c;\u6613\u4e8e\u7406\u89e3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5747\u65b9\u8bef\u5dee (Mean Squared Error, MSE)<\/p>\n<ul>\n<li>\u516c\u5f0f&#xff1a;1\/n * \u03a3(y &#8211; \u0177)\u00b2<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u8ba1\u7b97\u6bcf\u4e2a\u6837\u672c\u7684\u9884\u6d4b\u8bef\u5dee\u7684\u5e73\u65b9&#xff0c;\u7136\u540e\u53d6\u5e73\u5747\u3002\u7531\u4e8e\u5e73\u65b9\u7684\u5b58\u5728&#xff0c;MSE\u5bf9\u8f83\u5927\u7684\u8bef\u5dee&#xff08;\u79bb\u7fa4\u70b9&#xff09;\u7ed9\u4e88\u4e86\u66f4\u9ad8\u7684\u6743\u91cd\u3002\u5982\u679c\u4f60\u7684\u4e1a\u52a1\u573a\u666f\u4e2d&#xff0c;\u5927\u7684\u8bef\u5dee\u662f\u4e0d\u53ef\u63a5\u53d7\u7684&#xff0c;\u90a3\u4e48MSE\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u60e9\u7f5a\u6307\u6807\u3002\u4f46\u5176\u5355\u4f4d\u662f\u76ee\u6807\u53d8\u91cf\u5355\u4f4d\u7684\u5e73\u65b9&#xff0c;\u4e0d\u6613\u89e3\u91ca\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5747\u65b9\u6839\u8bef\u5dee (Root Mean Squared Error, RMSE)<\/p>\n<ul>\n<li>\u516c\u5f0f&#xff1a;sqrt(MSE)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u5b83\u5c31\u662fMSE\u5f00\u6839\u53f7\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f&#xff0c;\u5176\u5355\u4f4d\u4e0e\u76ee\u6807\u53d8\u91cf\u6062\u590d\u4e00\u81f4&#xff0c;\u540c\u65f6\u4fdd\u7559\u4e86MSE\u5bf9\u5927\u8bef\u5dee\u654f\u611f\u7684\u7279\u6027\u3002RMSE\u53ef\u80fd\u662f\u56de\u5f52\u4efb\u52a1\u4e2d\u6700\u5e38\u7528\u7684\u8bc4\u4f30\u6307\u6807\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>from sklearn.metrics import mean_absolute_error, mean_squared_error<\/p>\n<p>y_true_reg &#061; [3, -0.5, 2, 7]<br \/>\ny_pred_reg &#061; [2.5, 0.0, 2, 8]<\/p>\n<p>mae &#061; mean_absolute_error(y_true_reg, y_pred_reg)<br \/>\nmse &#061; mean_squared_error(y_true_reg, y_pred_reg)<br \/>\nrmse &#061; np.sqrt(mse)<\/p>\n<p>print(f&#034;MAE: {mae}&#034;)<br \/>\nprint(f&#034;MSE: {mse}&#034;)<br \/>\nprint(f&#034;RMSE: {rmse}&#034;)<\/p>\n<p>\u76f8\u5bf9\u5ea6\u91cf&#xff1a;R\u00b2 (\u51b3\u5b9a\u7cfb\u6570)\u7684\u89e3\u91ca\u4e0e\u8bef\u533a<\/p>\n<ul>\n<li>R\u00b2 (R-squared \/ Coefficient of Determination)\n<ul>\n<li>\u516c\u5f0f&#xff1a;1 &#8211; (\u03a3(y &#8211; \u0177)\u00b2) \/ (\u03a3(y &#8211; \u0233)\u00b2)\u00a0&#xff0c;\u5176\u4e2d\u00a0\u0233\u00a0\u662f\u771f\u5b9e\u503c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<li>\u89e3\u8bfb&#xff1a;R\u00b2\u8861\u91cf\u7684\u662f\u6a21\u578b\u6240\u89e3\u91ca\u7684\u56e0\u53d8\u91cf\u65b9\u5dee\u7684\u6bd4\u4f8b\u3002\u901a\u4fd7\u5730\u8bf4&#xff0c;\u5b83\u8868\u793a\u4f60\u7684\u6a21\u578b\u5728\u591a\u5927\u7a0b\u5ea6\u4e0a\u201c\u89e3\u91ca\u201d\u4e86\u6570\u636e\u7684\u53d8\u52a8\u3002\n<ul>\n<li>R\u00b2 &#061; 1&#xff1a;\u6a21\u578b\u5b8c\u7f8e\u9884\u6d4b\u4e86\u6240\u6709\u6570\u636e\u3002<\/li>\n<li>R\u00b2 &#061; 0&#xff1a;\u6a21\u578b\u7684\u8868\u73b0\u7b49\u540c\u4e8e\u4e00\u4e2a\u201c\u57fa\u51c6\u6a21\u578b\u201d&#xff0c;\u8fd9\u4e2a\u57fa\u51c6\u6a21\u578b\u603b\u662f\u9884\u6d4b\u6240\u6709\u6837\u672c\u7684\u503c\u4e3a\u771f\u5b9e\u503c\u7684\u5e73\u5747\u6570\u3002<\/li>\n<li>R\u00b2 &lt; 0&#xff1a;\u6a21\u578b\u8868\u73b0\u6bd4\u57fa\u51c6\u6a21\u578b\u8fd8\u5dee\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4f18\u70b9&#xff1a;\u63d0\u4f9b\u4e86\u4e00\u4e2a\u76f8\u5bf9\u7684\u6027\u80fd\u5ea6\u91cf&#xff08;0%\u5230100%&#xff09;&#xff0c;\u4e0d\u53d7\u76ee\u6807\u53d8\u91cf\u5c3a\u5ea6\u7684\u5f71\u54cd\u3002<\/li>\n<li>\u8bef\u533a&#xff1a;R\u00b2\u6709\u4e00\u4e2a\u81f4\u547d\u7f3a\u9677\u2014\u2014\u5f53\u4f60\u5411\u6a21\u578b\u4e2d\u6dfb\u52a0\u4efb\u4f55\u65b0\u7684\u7279\u5f81\u65f6&#xff0c;\u5373\u4f7f\u8fd9\u4e2a\u7279\u5f81\u6beb\u65e0\u7528\u5904&#xff0c;R\u00b2\u7684\u503c\u4e5f\u51e0\u4e4e\u603b\u662f\u4f1a\u589e\u52a0\u6216\u4fdd\u6301\u4e0d\u53d8&#xff0c;\u7edd\u4e0d\u4f1a\u4e0b\u964d\u3002\u8fd9\u4f7f\u5f97\u5b83\u5728\u6bd4\u8f83\u5305\u542b\u4e0d\u540c\u6570\u91cf\u7279\u5f81\u7684\u6a21\u578b\u65f6\u5177\u6709\u8bef\u5bfc\u6027\u3002\u4e3a\u6b64&#xff0c;**\u8c03\u6574R\u00b2 (Adjusted R-squared)**\u88ab\u63d0\u51fa&#xff0c;\u5b83\u5bf9\u7279\u5f81\u7684\u6570\u91cf\u8fdb\u884c\u4e86\u60e9\u7f5a&#xff0c;\u662f\u4e00\u4e2a\u66f4\u516c\u5141\u7684\u6307\u6807\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>4.1.4 \u65e0\u76d1\u7763\u4efb\u52a1\u7684\u201c\u5185\u7701\u201d&#xff1a;\u805a\u7c7b\u6548\u679c\u7684\u8bc4\u4f30<\/h5>\n<p>\u8bc4\u4f30\u805a\u7c7b&#xff08;Clustering&#xff09;\u8fd9\u7c7b\u65e0\u76d1\u7763\u4efb\u52a1\u6bd4\u76d1\u7763\u5b66\u4e60\u66f4\u5177\u6311\u6218\u6027&#xff0c;\u56e0\u4e3a\u6211\u4eec\u901a\u5e38\u6ca1\u6709\u201c\u6b63\u786e\u7b54\u6848\u201d&#xff08;\u771f\u5b9e\u6807\u7b7e&#xff09;\u3002\u8bc4\u4f30\u65b9\u6cd5\u5206\u4e3a\u4e24\u7c7b&#xff1a;<\/p>\n<p>\u6709\u771f\u5b9e\u6807\u7b7e\u65f6&#xff08;\u5916\u90e8\u8bc4\u4f30&#xff09;<\/p>\n<p>\u5728\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5&#xff08;\u5982\u5b66\u672f\u7814\u7a76\u6216\u9a8c\u8bc1\u7b97\u6cd5&#xff09;&#xff0c;\u6211\u4eec\u624b\u5934\u6709\u6570\u636e\u7684\u771f\u5b9e\u7c7b\u522b\u3002\u6b64\u65f6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u6bd4\u8f83\u805a\u7c7b\u7ed3\u679c\u548c\u771f\u5b9e\u6807\u7b7e\u7684\u543b\u5408\u7a0b\u5ea6\u3002<\/p>\n<ul>\n<li>\u5170\u5fb7\u6307\u6570 (Rand Index, RI)&#xff1a;\u8861\u91cf\u4e24\u7ec4\u805a\u7c7b&#xff08;\u9884\u6d4b\u7684\u548c\u771f\u5b9e\u7684&#xff09;\u4e2d&#xff0c;\u6240\u6709\u201c\u70b9\u5bf9\u201d\u5206\u7c7b\u4e00\u81f4\u6027\u7684\u6bd4\u4f8b\u3002<\/li>\n<li>\u4e92\u4fe1\u606f (Mutual Information, MI)&#xff1a;\u4ece\u4fe1\u606f\u8bba\u89d2\u5ea6\u8861\u91cf\u4e24\u7ec4\u805a\u7c7b\u5171\u4eab\u7684\u4fe1\u606f\u91cf\u3002<\/li>\n<\/ul>\n<p>\u65e0\u771f\u5b9e\u6807\u7b7e\u65f6&#xff08;\u5185\u90e8\u8bc4\u4f30&#xff09;<\/p>\n<p>\u8fd9\u662f\u66f4\u5e38\u89c1\u7684\u60c5\u51b5\u3002\u5185\u90e8\u8bc4\u4f30\u4ec5\u5229\u7528\u6570\u636e\u672c\u8eab\u548c\u805a\u7c7b\u7ed3\u679c\u6765\u8fdb\u884c\u3002<\/p>\n<ul>\n<li>\n<p>\u8f6e\u5ed3\u7cfb\u6570 (Silhouette Coefficient)&#xff1a;\u8fd9\u662f\u6700\u5e38\u7528\u3001\u6700\u76f4\u89c2\u7684\u5185\u90e8\u8bc4\u4f30\u6307\u6807\u3002\u5b83\u4e3a\u6bcf\u4e00\u4e2a\u6837\u672c\u8ba1\u7b97\u4e00\u4e2a\u8f6e\u5ed3\u5206\u6570&#xff0c;\u8be5\u5206\u6570\u8861\u91cf&#xff1a;<\/p>\n<ul>\n<li>a: \u8be5\u6837\u672c\u4e0e\u5176\u6240\u5728\u7c07\u5185\u5176\u4ed6\u6240\u6709\u70b9\u7684\u5e73\u5747\u8ddd\u79bb&#xff08;\u7c07\u5185\u51dd\u805a\u5ea6&#xff09;\u3002<\/li>\n<li>b: \u8be5\u6837\u672c\u4e0e\u8ddd\u79bb\u5b83\u6700\u8fd1\u7684\u4e0b\u4e00\u4e2a\u7c07\u5185\u6240\u6709\u70b9\u7684\u5e73\u5747\u8ddd\u79bb&#xff08;\u7c07\u95f4\u5206\u79bb\u5ea6&#xff09;\u3002<\/li>\n<li>\u8f6e\u5ed3\u5206\u6570 &#061;\u00a0(b &#8211; a) \/ max(a, b)<\/li>\n<li>\u89e3\u8bfb&#xff1a;\n<ul>\n<li>\u5206\u6570\u63a5\u8fd1\u00a0&#043;1&#xff1a;\u8bf4\u660e\u6837\u672c\u8fdc\u79bb\u76f8\u90bb\u7c07&#xff0c;\u5f88\u597d\u5730\u88ab\u5206\u914d\u5230\u4e86\u5f53\u524d\u7c07&#xff08;\u51dd\u805a\u5ea6\u548c\u5206\u79bb\u5ea6\u90fd\u597d&#xff09;\u3002<\/li>\n<li>\u5206\u6570\u63a5\u8fd1\u00a00&#xff1a;\u8bf4\u660e\u6837\u672c\u4f4d\u4e8e\u4e24\u4e2a\u7c07\u7684\u8fb9\u754c\u4e0a\u3002<\/li>\n<li>\u5206\u6570\u63a5\u8fd1\u00a0-1&#xff1a;\u8bf4\u660e\u6837\u672c\u53ef\u80fd\u88ab\u5206\u914d\u5230\u4e86\u9519\u8bef\u7684\u7c07\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6574\u4e2a\u6570\u636e\u96c6\u7684\u8f6e\u5ed3\u7cfb\u6570\u662f\u6240\u6709\u6837\u672c\u8f6e\u5ed3\u5206\u6570\u7684\u5e73\u5747\u503c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Calinski-Harabasz\u6307\u6570 (CH Index)&#xff1a;\u901a\u8fc7\u8ba1\u7b97\u7c07\u95f4\u6563\u5ea6\u4e0e\u7c07\u5185\u6563\u5ea6\u7684\u6bd4\u503c\u6765\u8bc4\u4f30\u3002\u6bd4\u503c\u8d8a\u5927&#xff0c;\u610f\u5473\u7740\u7c07\u95f4\u5206\u79bb\u5f97\u8d8a\u8fdc&#xff0c;\u7c07\u5185\u51dd\u805a\u5f97\u8d8a\u7d27&#xff0c;\u805a\u7c7b\u6548\u679c\u8d8a\u597d\u3002<\/p>\n<\/li>\n<\/ul>\n<p>from sklearn.metrics import silhouette_score<br \/>\nfrom sklearn.cluster import KMeans<\/p>\n<p># \u5047\u8bbeX_cluster\u662f\u5f85\u805a\u7c7b\u7684\u6570\u636e<br \/>\n# kmeans &#061; KMeans(n_clusters&#061;3, random_state&#061;42, n_init&#061;10)<br \/>\n# labels &#061; kmeans.fit_predict(X_cluster)<br \/>\n# score &#061; silhouette_score(X_cluster, labels)<br \/>\n# print(f&#034;Silhouette Score: {score}&#034;)<\/p>\n<hr \/>\n<h4>4.2 \u201c\u6267\u5176\u4e24\u7aef\u800c\u7528\u4e2d\u201d&#xff1a;\u504f\u5dee\u4e0e\u65b9\u5dee\u7684\u6743\u8861<\/h4>\n<p>\u638c\u63e1\u4e86\u8bc4\u4f30\u6307\u6807&#xff0c;\u6211\u4eec\u5c31\u6709\u4e86\u4e00\u628a\u5c3a\u5b50\u3002\u4f46\u6709\u65f6\u6211\u4eec\u4f1a\u53d1\u73b0&#xff0c;\u6a21\u578b\u5728\u4e00\u4e2a\u6570\u636e\u96c6\u4e0a\u8868\u73b0\u4f18\u5f02&#xff0c;\u6362\u4e2a\u6570\u636e\u96c6\u5c31\u4e00\u584c\u7cca\u6d82\u3002\u8fd9\u80cc\u540e&#xff0c;\u662f\u6240\u6709\u76d1\u7763\u5b66\u4e60\u6a21\u578b\u90fd\u5fc5\u987b\u9762\u5bf9\u7684\u4e00\u5bf9\u6838\u5fc3\u77db\u76fe\u2014\u2014\u504f\u5dee&#xff08;Bias&#xff09;\u4e0e\u65b9\u5dee&#xff08;Variance&#xff09;\u3002<\/p>\n<h5>4.2.1 \u6a21\u578b\u7684\u4e24\u79cd\u201c\u539f\u7f6a\u201d&#xff1a;\u504f\u5dee(Bias)\u4e0e\u65b9\u5dee(Variance)<\/h5>\n<p>\u60f3\u8c61\u6211\u4eec\u7528\u4e0d\u540c\u7684\u8bad\u7ec3\u6570\u636e\u96c6&#xff08;\u6765\u81ea\u540c\u4e00\u6570\u636e\u6e90&#xff09;\u591a\u6b21\u8bad\u7ec3\u540c\u4e00\u4e2a\u6a21\u578b&#xff0c;\u7136\u540e\u53bb\u9884\u6d4b\u540c\u4e00\u4e2a\u6d4b\u8bd5\u70b9\u3002<\/p>\n<ul>\n<li>\u504f\u5dee&#xff1a;\u63cf\u8ff0\u7684\u662f\u6a21\u578b\u6240\u6709\u9884\u6d4b\u503c\u7684\u5e73\u5747\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u5dee\u8ddd\u3002\u9ad8\u504f\u5dee\u610f\u5473\u7740\u6a21\u578b\u7cfb\u7edf\u6027\u5730\u504f\u79bb\u4e86\u771f\u76f8\u3002<\/li>\n<li>\u65b9\u5dee&#xff1a;\u63cf\u8ff0\u7684\u662f\u6a21\u578b\u4e0d\u540c\u6b21\u9884\u6d4b\u503c\u4e4b\u95f4\u7684\u79bb\u6563\u7a0b\u5ea6\u6216\u6563\u5e03\u8303\u56f4\u3002\u9ad8\u65b9\u5dee\u610f\u5473\u7740\u6a21\u578b\u5bf9\u8bad\u7ec3\u6570\u636e\u7684\u5fae\u5c0f\u53d8\u5316\u6781\u5176\u654f\u611f\u3002<\/li>\n<\/ul>\n<p>\u4e00\u4e2a\u597d\u7684\u6a21\u578b&#xff0c;\u5e94\u8be5\u65e2\u6ca1\u6709\u7cfb\u7edf\u6027\u7684\u504f\u79bb&#xff08;\u4f4e\u504f\u5dee&#xff09;&#xff0c;\u53c8\u5bf9\u6570\u636e\u7684\u6270\u52a8\u4e0d\u90a3\u4e48\u654f\u611f&#xff08;\u4f4e\u65b9\u5dee&#xff09;\u3002<\/p>\n<p>\u504f\u5dee&#xff1a;\u6a21\u578b\u5bf9\u771f\u76f8\u7684\u201c\u56fa\u6709\u504f\u89c1\u201d<\/p>\n<p>\u9ad8\u504f\u5dee\u7684\u6839\u672c\u539f\u56e0\u662f\u6a21\u578b\u8fc7\u4e8e\u7b80\u5355&#xff0c;\u65e0\u6cd5\u6355\u6349\u6570\u636e\u4e2d\u590d\u6742\u7684\u771f\u5b9e\u89c4\u5f8b\u3002\u5b83\u5c31\u50cf\u4e00\u4e2a\u56fa\u6267\u7684\u201c\u8001\u5b66\u7a76\u201d&#xff0c;\u8111\u5b50\u91cc\u53ea\u6709\u51e0\u6761\u7b80\u5355\u7684\u89c4\u5219&#xff08;\u5982\u4e00\u6761\u76f4\u7ebf&#xff09;&#xff0c;\u8bd5\u56fe\u7528\u5b83\u53bb\u89e3\u91ca\u4e00\u4e2a\u590d\u6742\u7684\u4e16\u754c&#xff08;\u5982\u4e00\u6761\u66f2\u7ebf&#xff09;\u3002\u65e0\u8bba\u7ed9\u4ed6\u591a\u5c11\u6570\u636e&#xff0c;\u4ed6\u90fd\u575a\u6301\u81ea\u5df1\u7684\u201c\u504f\u89c1\u201d\u3002<\/p>\n<p>\u65b9\u5dee&#xff1a;\u6a21\u578b\u5bf9\u6570\u636e\u7684\u201c\u8fc7\u5ea6\u654f\u611f\u201d<\/p>\n<p>\u9ad8\u65b9\u5dee\u7684\u6839\u672c\u539f\u56e0\u662f\u6a21\u578b\u8fc7\u4e8e\u590d\u6742&#xff0c;\u5b83\u4e0d\u4ec5\u5b66\u4e60\u4e86\u6570\u636e\u4e2d\u666e\u9002\u7684\u89c4\u5f8b&#xff0c;\u8fd8\u628a\u8bad\u7ec3\u6570\u636e\u4e2d\u7684\u566a\u58f0\u548c\u968f\u673a\u6027\u4e5f\u5f53\u4f5c\u4e86\u201c\u771f\u7406\u201d\u6765\u5b66\u4e60\u3002\u5b83\u5c31\u50cf\u4e00\u4e2a\u201c\u4e66\u5446\u5b50\u201d&#xff0c;\u628a\u8bad\u7ec3\u96c6\u8fd9\u672c\u201c\u6559\u79d1\u4e66\u201d\u80cc\u5f97\u6eda\u74dc\u70c2\u719f&#xff0c;\u6bcf\u4e00\u4e2a\u7ec6\u8282\u90fd\u8bb0\u5f97\u6e05\u6e05\u695a\u695a&#xff0c;\u4f46\u7f3a\u4e4f\u4e3e\u4e00\u53cd\u4e09\u7684\u80fd\u529b\u3002\u6362\u4e00\u672c\u201c\u6a21\u62df\u8bd5\u5377\u201d&#xff08;\u6d4b\u8bd5\u96c6&#xff09;&#xff0c;\u4ed6\u5c31\u50bb\u773c\u4e86\u3002<\/p>\n<h5>4.2.2 \u6b20\u62df\u5408\u4e0e\u8fc7\u62df\u5408&#xff1a;\u6a21\u578b\u5b66\u4e60\u7684\u201c\u6267\u5ff5\u201d\u4e0e\u201c\u5984\u5ff5\u201d<\/h5>\n<p>\u504f\u5dee\u548c\u65b9\u5dee\u7684\u6982\u5ff5&#xff0c;\u6700\u7ec8\u4f53\u73b0\u5728\u6a21\u578b\u7684\u4e24\u79cd\u5e38\u89c1\u72b6\u6001\u4e0a&#xff1a;<\/p>\n<p>\u6b20\u62df\u5408(Underfitting)&#xff1a;\u5b66\u5f97\u592a\u5c11&#xff0c;\u60f3\u5f97\u592a\u7b80\u5355&#xff08;\u9ad8\u504f\u5dee&#xff09;<\/p>\n<ul>\n<li>\u8868\u73b0&#xff1a;\u6a21\u578b\u5728\u8bad\u7ec3\u96c6\u4e0a\u7684\u8868\u73b0\u5c31\u5f88\u5dee&#xff0c;\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u8868\u73b0\u540c\u6837\u5f88\u5dee\u3002<\/li>\n<li>\u539f\u56e0&#xff1a;\u901a\u5e38\u662f\u6a21\u578b\u590d\u6742\u5ea6\u592a\u4f4e&#xff08;\u5982\u7528\u7ebf\u6027\u6a21\u578b\u53bb\u62df\u5408\u975e\u7ebf\u6027\u6570\u636e&#xff09;&#xff0c;\u6216\u8005\u7279\u5f81\u592a\u5c11\u3002<\/li>\n<\/ul>\n<p>\u8fc7\u62df\u5408(Overfitting)&#xff1a;\u5b66\u5f97\u592a\u7ec6&#xff0c;\u60f3\u5f97\u592a\u590d\u6742&#xff08;\u9ad8\u65b9\u5dee&#xff09;<\/p>\n<ul>\n<li>\u8868\u73b0&#xff1a;\u6a21\u578b\u5728\u8bad\u7ec3\u96c6\u4e0a\u8868\u73b0\u6781\u597d&#xff0c;\u751a\u81f3\u63a5\u8fd1\u5b8c\u7f8e&#xff0c;\u4f46\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u8868\u73b0\u5374\u5927\u5e45\u4e0b\u964d\u3002\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u6027\u80fd\u4e4b\u95f4\u5b58\u5728\u5de8\u5927\u9e3f\u6c9f\u3002<\/li>\n<li>\u539f\u56e0&#xff1a;\u901a\u5e38\u662f\u6a21\u578b\u590d\u6742\u5ea6\u8fc7\u9ad8&#xff08;\u5982\u4e00\u4e2a\u6df1\u5ea6\u5f88\u6df1\u7684\u51b3\u7b56\u6811&#xff09;&#xff0c;\u6216\u8005\u6570\u636e\u91cf\u76f8\u5bf9\u4e8e\u6a21\u578b\u590d\u6742\u5ea6\u6765\u8bf4\u592a\u5c11\u3002<\/li>\n<\/ul>\n<p>\u504f\u5dee-\u65b9\u5dee\u6743\u8861&#xff08;Bias-Variance Trade-off&#xff09;&#xff1a; \u6a21\u578b\u590d\u6742\u5ea6\u4e0e\u8fd9\u4e24\u8005\u4e4b\u95f4\u5b58\u5728\u4e00\u4e2aU\u578b\u5173\u7cfb\u3002<\/p>\n<ul>\n<li>\u975e\u5e38\u7b80\u5355\u7684\u6a21\u578b&#xff1a;\u9ad8\u504f\u5dee&#xff0c;\u4f4e\u65b9\u5dee\u3002<\/li>\n<li>\u975e\u5e38\u590d\u6742\u7684\u6a21\u578b&#xff1a;\u4f4e\u504f\u5dee&#xff0c;\u9ad8\u65b9\u5dee\u3002 \u6211\u4eec\u7684\u76ee\u6807&#xff0c;\u662f\u5728\u8fd9\u4e2aU\u578b\u66f2\u7ebf\u7684\u8c37\u5e95\u627e\u5230\u4e00\u4e2a\u5e73\u8861\u70b9&#xff0c;\u4f7f\u5f97\u603b\u8bef\u5dee&#xff08;\u7ea6\u7b49\u4e8e \u504f\u5dee\u00b2 &#043; \u65b9\u5dee&#xff09;\u6700\u5c0f\u3002<\/li>\n<\/ul>\n<h5>4.2.3 \u8bca\u65ad\u4e4b\u9053&#xff1a;\u5b66\u4e60\u66f2\u7ebf\u7684\u53ef\u89c6\u5316\u89e3\u8bfb<\/h5>\n<p>\u5982\u4f55\u5224\u65ad\u6211\u4eec\u7684\u6a21\u578b\u6b63\u5904\u4e8e\u6b20\u62df\u5408\u3001\u8fc7\u62df\u5408\u8fd8\u662f\u7406\u60f3\u72b6\u6001&#xff1f;**\u5b66\u4e60\u66f2\u7ebf&#xff08;Learning Curves&#xff09;**\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8bca\u65ad\u5de5\u5177\u3002<\/p>\n<p>\u5b66\u4e60\u66f2\u7ebf\u5c55\u793a\u7684\u662f&#xff0c;\u968f\u7740\u8bad\u7ec3\u6837\u672c\u6570\u91cf\u7684\u589e\u52a0&#xff0c;\u6a21\u578b\u7684\u8bad\u7ec3\u96c6\u5f97\u5206\u548c\u9a8c\u8bc1\u96c6\u5f97\u5206\u5982\u4f55\u53d8\u5316\u3002<\/p>\n<p>\u7ed8\u5236\u5b66\u4e60\u66f2\u7ebf&#xff1a;\u8bad\u7ec3\u96c6\u4e0e\u9a8c\u8bc1\u96c6\u5f97\u5206\u968f\u6837\u672c\u91cf\u53d8\u5316\u7684\u8f68\u8ff9<\/p>\n<p>from sklearn.model_selection import learning_curve<\/p>\n<p># model &#061; LogisticRegression() # \u6216\u5176\u4ed6\u4efb\u4f55\u6a21\u578b<br \/>\n# train_sizes, train_scores, validation_scores &#061; learning_curve(<br \/>\n#     estimator&#061;model,<br \/>\n#     X&#061;X, y&#061;y,<br \/>\n#     train_sizes&#061;np.linspace(0.1, 1.0, 10), # \u8bad\u7ec3\u6837\u672c\u7684\u6bd4\u4f8b<br \/>\n#     cv&#061;5, # \u4ea4\u53c9\u9a8c\u8bc1\u6298\u6570<br \/>\n#     scoring&#061;&#039;accuracy&#039; # \u8bc4\u4f30\u6307\u6807<br \/>\n# )<\/p>\n<p># # \u8ba1\u7b97\u5747\u503c\u548c\u6807\u51c6\u5dee<br \/>\n# train_scores_mean &#061; np.mean(train_scores, axis&#061;1)<br \/>\n# validation_scores_mean &#061; np.mean(validation_scores, axis&#061;1)<\/p>\n<p># # \u7ed8\u5236\u66f2\u7ebf<br \/>\n# plt.plot(train_sizes, train_scores_mean, &#039;o-&#039;, color&#061;&#034;r&#034;, label&#061;&#034;Training score&#034;)<br \/>\n# plt.plot(train_sizes, validation_scores_mean, &#039;o-&#039;, color&#061;&#034;g&#034;, label&#061;&#034;Cross-validation score&#034;)<br \/>\n# plt.title(&#034;Learning Curve&#034;)<br \/>\n# plt.xlabel(&#034;Training examples&#034;)<br \/>\n# plt.ylabel(&#034;Score&#034;)<br \/>\n# plt.legend(loc&#061;&#034;best&#034;)<br \/>\n# plt.grid()<br \/>\n# plt.show()<\/p>\n<p>\u4ece\u66f2\u7ebf\u5f62\u6001\u8bca\u65ad\u6a21\u578b\u662f\u201c\u6b20\u201d\u8fd8\u662f\u201c\u8fc7\u201d<\/p>\n<ul>\n<li>\n<p>\u7406\u60f3\u72b6\u6001&#xff1a;<\/p>\n<ul>\n<li>\u968f\u7740\u6837\u672c\u589e\u52a0&#xff0c;\u8bad\u7ec3\u5f97\u5206\u548c\u9a8c\u8bc1\u5f97\u5206\u90fd\u9010\u6e10\u5347\u9ad8\u5e76\u6700\u7ec8\u6536\u655b\u3002<\/li>\n<li>\u6536\u655b\u65f6&#xff0c;\u4e24\u6761\u66f2\u7ebf\u9760\u5f97\u5f88\u8fd1&#xff0c;\u4e14\u5f97\u5206\u90fd\u5f88\u9ad8\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9ad8\u504f\u5dee&#xff08;\u6b20\u62df\u5408&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u4e24\u6761\u66f2\u7ebf\u5f88\u65e9\u5c31\u6536\u655b\u4e86&#xff0c;\u4e14\u6536\u655b\u5230\u4e00\u4e2a\u6bd4\u8f83\u4f4e\u7684\u5f97\u5206\u6c34\u5e73\u3002<\/li>\n<li>\u4e24\u6761\u66f2\u7ebf\u9760\u5f97\u5f88\u8fd1\u3002<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u6a21\u578b\u592a\u7b80\u5355\u4e86&#xff0c;\u5373\u4f7f\u7ed9\u5b83\u518d\u591a\u7684\u6570\u636e&#xff0c;\u5b83\u4e5f\u5b66\u4e0d\u5230\u66f4\u591a\u4e1c\u897f\u4e86\u3002\u6027\u80fd\u7684\u74f6\u9888\u5728\u4e8e\u6a21\u578b\u672c\u8eab\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9ad8\u65b9\u5dee&#xff08;\u8fc7\u62df\u5408&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u8bad\u7ec3\u5f97\u5206\u4e00\u76f4\u5f88\u9ad8&#xff0c;\u800c\u9a8c\u8bc1\u5f97\u5206\u4e00\u76f4\u6bd4\u8f83\u4f4e\u3002<\/li>\n<li>\u4e24\u6761\u66f2\u7ebf\u4e4b\u95f4\u5b58\u5728\u660e\u663e\u7684\u3001\u6301\u7eed\u7684\u5dee\u8ddd&#xff08;Gap&#xff09;\u3002<\/li>\n<li>\u89e3\u8bfb&#xff1a;\u6a21\u578b\u5728\u8bad\u7ec3\u96c6\u4e0a\u201c\u6b7b\u8bb0\u786c\u80cc\u201d&#xff0c;\u4f46\u6cdb\u5316\u80fd\u529b\u5dee\u3002\u597d\u6d88\u606f\u662f&#xff0c;\u968f\u7740\u6837\u672c\u91cf\u7684\u589e\u52a0&#xff0c;\u8fd9\u4e2a\u5dee\u8ddd\u6709\u7f29\u5c0f\u7684\u8d8b\u52bf&#xff0c;\u8bf4\u660e\u589e\u52a0\u6570\u636e\u91cf\u53ef\u80fd\u6709\u52a9\u4e8e\u7f13\u89e3\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>4.2.4 \u5e94\u5bf9\u4e4b\u7b56&#xff1a;\u964d\u4f4e\u504f\u5dee\u4e0e\u65b9\u5dee\u7684\u5e38\u7528\u7b56\u7565<\/h5>\n<ul>\n<li>\n<p>\u89e3\u51b3\u9ad8\u504f\u5dee&#xff08;\u6b20\u62df\u5408&#xff09;&#xff1a;<\/p>\n<li>\u589e\u52a0\u6a21\u578b\u590d\u6742\u5ea6&#xff1a;\u6362\u7528\u66f4\u5f3a\u5927\u7684\u6a21\u578b&#xff08;\u5982\u4ece\u7ebf\u6027\u6a21\u578b\u6362\u5230\u68af\u5ea6\u63d0\u5347\u6811\u6216\u795e\u7ecf\u7f51\u7edc&#xff09;\u3002<\/li>\n<li>\u83b7\u53d6\u6216\u521b\u9020\u66f4\u591a\u7279\u5f81&#xff1a;\u8ba9\u6a21\u578b\u6709\u66f4\u591a\u7684\u4fe1\u606f\u6765\u6e90\u6765\u5b66\u4e60\u3002<\/li>\n<li>\u51cf\u5c11\u6b63\u5219\u5316&#xff1a;\u6b63\u5219\u5316\u662f\u7528\u6765\u5bf9\u6297\u8fc7\u62df\u5408\u7684&#xff0c;\u5982\u679c\u6a21\u578b\u5df2\u7ecf\u6b20\u62df\u5408&#xff0c;\u5e94\u51cf\u5c0f\u6b63\u5219\u5316\u5f3a\u5ea6\u3002<\/li>\n<\/li>\n<li>\n<p>\u89e3\u51b3\u9ad8\u65b9\u5dee&#xff08;\u8fc7\u62df\u5408&#xff09;&#xff1a;<\/p>\n<li>\u589e\u52a0\u6570\u636e\u91cf&#xff1a;\u8fd9\u662f\u6700\u6709\u6548\u4f46\u5f80\u5f80\u4e5f\u6700\u6602\u8d35\u7684\u65b9\u6cd5\u3002<\/li>\n<li>\u964d\u4f4e\u6a21\u578b\u590d\u6742\u5ea6&#xff1a;\u4f7f\u7528\u66f4\u7b80\u5355\u7684\u6a21\u578b&#xff0c;\u6216\u8005\u51cf\u5c11\u73b0\u6709\u6a21\u578b\u7684\u53c2\u6570&#xff08;\u5982\u964d\u4f4e\u51b3\u7b56\u6811\u7684\u6df1\u5ea6&#xff09;\u3002<\/li>\n<li>\u6b63\u5219\u5316&#xff08;Regularization&#xff09;&#xff1a;\u5728\u635f\u5931\u51fd\u6570\u4e2d\u52a0\u5165\u4e00\u4e2a\u60e9\u7f5a\u9879&#xff0c;\u5bf9\u6a21\u578b\u7684\u590d\u6742\u6027&#xff08;\u5982\u5927\u7684\u6743\u91cd&#xff09;\u8fdb\u884c\u60e9\u7f5a\u3002L1\u548cL2\u6b63\u5219\u5316\u662f\u7ecf\u5178\u65b9\u6cd5\u3002<\/li>\n<li>\u7279\u5f81\u9009\u62e9\/\u964d\u7ef4&#xff1a;\u79fb\u9664\u4e0d\u76f8\u5173\u6216\u5197\u4f59\u7684\u7279\u5f81\u3002<\/li>\n<li>\u96c6\u6210\u5b66\u4e60&#xff08;Ensemble Methods&#xff09;&#xff1a;\u5982Bagging&#xff08;\u968f\u673a\u68ee\u6797&#xff09;&#xff0c;\u901a\u8fc7\u5e73\u5747\u591a\u4e2a\u4e0d\u540c\u6a21\u578b\u7684\u7ed3\u679c\u6765\u964d\u4f4e\u65b9\u5dee\u3002<\/li>\n<li>Dropout&#xff08;\u4e3b\u8981\u7528\u4e8e\u795e\u7ecf\u7f51\u7edc&#xff09;&#xff1a;\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u968f\u673a\u201c\u4e22\u5f03\u201d\u4e00\u90e8\u5206\u795e\u7ecf\u5143&#xff0c;\u5f3a\u8feb\u7f51\u7edc\u5b66\u4e60\u66f4\u9c81\u68d2\u7684\u7279\u5f81\u3002<\/li>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>4.3 \u201c\u4ed6\u5c71\u4e4b\u77f3\u201d&#xff1a;\u4ea4\u53c9\u9a8c\u8bc1\u7684\u667a\u6167<\/h4>\n<p>\u5728\u8bca\u65ad\u6a21\u578b\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6211\u4eec\u53cd\u590d\u63d0\u5230\u4e86\u201c\u9a8c\u8bc1\u96c6\u201d\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u505a\u6cd5\u662f\u5c06\u6570\u636e\u4e00\u6b21\u6027\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002\u4f46\u8fd9\u79cd\u65b9\u6cd5\u5b58\u5728\u4e00\u4e2a\u4e25\u91cd\u95ee\u9898\u3002<\/p>\n<h5>4.3.1 \u4e3a\u4f55\u9700\u8981\u4ea4\u53c9\u9a8c\u8bc1&#xff1f;\u7b80\u5355\u201c\u8bad\u7ec3\/\u6d4b\u8bd5\u96c6\u201d\u5212\u5206\u7684\u9677\u9631<\/h5>\n<ul>\n<li>\u6570\u636e\u5212\u5206\u7684\u5076\u7136\u6027&#xff1a;\u4f60\u78b0\u5de7\u5206\u5230\u9a8c\u8bc1\u96c6\u91cc\u7684\u6570\u636e\u53ef\u80fd\u7279\u522b\u201c\u7b80\u5355\u201d\u6216\u7279\u522b\u201c\u56f0\u96be\u201d&#xff0c;\u5bfc\u81f4\u4f60\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u8bc4\u4f30\u8fc7\u4e8e\u4e50\u89c2\u6216\u60b2\u89c2\u3002\u6362\u4e00\u79cd\u968f\u673a\u5212\u5206\u65b9\u5f0f&#xff0c;\u7ed3\u679c\u53ef\u80fd\u622a\u7136\u4e0d\u540c\u3002<\/li>\n<li>\u8bc4\u4f30\u7ed3\u679c\u7684\u4e0d\u7a33\u5b9a&#xff1a;\u57fa\u4e8e\u4e00\u6b21\u5212\u5206\u7684\u8bc4\u4f30\u7ed3\u679c&#xff0c;\u5176\u968f\u673a\u6027\u592a\u5927&#xff0c;\u4e0d\u591f\u53ef\u9760\u3002<\/li>\n<li>\u6570\u636e\u6d6a\u8d39&#xff1a;\u5728\u6570\u636e\u91cf\u672c\u5c31\u4e0d\u591a\u7684\u60c5\u51b5\u4e0b&#xff0c;\u7559\u51fa\u4e00\u90e8\u5206\u6570\u636e\u53ea\u7528\u4e8e\u9a8c\u8bc1&#xff0c;\u662f\u4e00\u79cd\u6d6a\u8d39\u3002<\/li>\n<\/ul>\n<p>\u4ea4\u53c9\u9a8c\u8bc1&#xff08;Cross-Validation, CV&#xff09;\u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f\u7684\u667a\u6167\u3002<\/p>\n<h5>4.3.2 K-\u6298\u4ea4\u53c9\u9a8c\u8bc1&#xff08;K-Fold Cross-Validation&#xff09;&#xff1a;\u8ba9\u6bcf\u4e00\u4efd\u6570\u636e\u90fd\u53d1\u5149<\/h5>\n<p>K-\u6298\u4ea4\u53c9\u9a8c\u8bc1\u662f\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u4ea4\u53c9\u9a8c\u8bc1\u6280\u672f\u3002<\/p>\n<p>K-\u6298\u7684\u6267\u884c\u6d41\u7a0b&#xff1a;\u5206\u5272\u3001\u8bad\u7ec3\u3001\u9a8c\u8bc1\u3001\u53d6\u5e73\u5747<\/p>\n<li>\u5206\u5272&#xff1a;\u5c06\u6574\u4e2a\u8bad\u7ec3\u6570\u636e\u96c6\u968f\u673a\u5730\u3001\u4e0d\u91cd\u590d\u5730\u5212\u5206\u4e3aK\u4e2a\u5927\u5c0f\u76f8\u4f3c\u7684\u5b50\u96c6&#xff08;\u79f0\u4e3a\u201c\u6298\u201d&#xff0c;Fold&#xff09;\u3002<\/li>\n<li>\u5faa\u73af&#xff1a;\u8fdb\u884cK\u6b21\u5faa\u73af&#xff0c;\u5728\u6bcf\u4e00\u6b21\u5faa\u73af\u4e2d&#xff1a;\n<ul>\n<li>\u53d6\u5176\u4e2d1\u4e2a\u6298\u4f5c\u4e3a\u9a8c\u8bc1\u96c6\u3002<\/li>\n<li>\u53d6\u5176\u4f59\u7684K-1\u4e2a\u6298\u5408\u5e76\u4f5c\u4e3a\u8bad\u7ec3\u96c6\u3002<\/li>\n<li>\u5728\u8be5\u8bad\u7ec3\u96c6\u4e0a\u8bad\u7ec3\u6a21\u578b&#xff0c;\u5e76\u5728\u8be5\u9a8c\u8bc1\u96c6\u4e0a\u8fdb\u884c\u8bc4\u4f30&#xff0c;\u5f97\u5230\u4e00\u4e2a\u6027\u80fd\u5f97\u5206\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u53d6\u5e73\u5747&#xff1a;\u5c06K\u6b21\u5faa\u73af\u5f97\u5230\u7684K\u4e2a\u6027\u80fd\u5f97\u5206\u8fdb\u884c\u5e73\u5747&#xff0c;\u5f97\u5230\u6700\u7ec8\u7684\u3001\u66f4\u7a33\u5065\u7684\u4ea4\u53c9\u9a8c\u8bc1\u5f97\u5206\u3002<\/li>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"K-Fold Cross-Validation\" height=\"554\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260123042446-6972f80e4b1fc.png\" width=\"800\" \/><\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u6240\u6709\u6570\u636e\u90fd\u53c2\u4e0e\u4e86\u8bad\u7ec3\u548c\u9a8c\u8bc1&#xff0c;\u6570\u636e\u5229\u7528\u7387\u9ad8\u3002<\/li>\n<li>\u5f97\u5230\u7684\u8bc4\u4f30\u7ed3\u679c\u662fK\u6b21\u8bc4\u4f30\u7684\u5e73\u5747\u503c&#xff0c;\u5927\u5927\u964d\u4f4e\u4e86\u5076\u7136\u6027&#xff0c;\u66f4\u4e3a\u7a33\u5b9a\u548c\u53ef\u9760\u3002<\/li>\n<\/ul>\n<p>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684K\u503c&#xff1f;<\/p>\n<p>K\u7684\u5e38\u7528\u53d6\u503c\u662f5\u621610\u3002<\/p>\n<ul>\n<li>K\u503c\u8f83\u5c0f&#xff08;\u59823&#xff09;&#xff1a;\u6bcf\u6b21\u8bad\u7ec3\u7684\u6570\u636e\u91cf\u8f83\u5c11&#xff08;2\/3&#xff09;&#xff0c;\u9a8c\u8bc1\u96c6\u8f83\u5927&#xff08;1\/3&#xff09;\u3002\u504f\u5dee\u8f83\u9ad8&#xff0c;\u65b9\u5dee\u8f83\u4f4e&#xff0c;\u8ba1\u7b97\u6210\u672c\u4e5f\u4f4e\u3002<\/li>\n<li>K\u503c\u8f83\u5927&#xff08;\u598210&#xff09;&#xff1a;\u6bcf\u6b21\u8bad\u7ec3\u7684\u6570\u636e\u91cf\u8f83\u591a&#xff08;9\/10&#xff09;&#xff0c;\u66f4\u63a5\u8fd1\u4e8e\u5728\u5168\u90e8\u6570\u636e\u4e0a\u8bad\u7ec3\u3002\u504f\u5dee\u8f83\u4f4e&#xff0c;\u4f46\u7531\u4e8e\u4e0d\u540c\u6298\u7684\u8bad\u7ec3\u96c6\u91cd\u5408\u5ea6\u9ad8&#xff0c;K\u4e2a\u6a21\u578b\u4f1a\u6bd4\u8f83\u76f8\u4f3c&#xff0c;\u5bfc\u81f4\u6700\u7ec8\u8bc4\u4f30\u7ed3\u679c\u7684\u65b9\u5dee\u53ef\u80fd\u8f83\u9ad8\u3002\u8ba1\u7b97\u6210\u672c\u4e5f\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n<h5>4.3.3 \u7279\u6b8a\u573a\u666f\u4e0b\u7684\u53d8\u4f53&#xff1a;\u5206\u5c42K-\u6298\u4e0e\u7559\u4e00\u6cd5<\/h5>\n<p>\u5206\u5c42K-\u6298&#xff08;Stratified K-Fold&#xff09;&#xff1a;\u5904\u7406\u4e0d\u5e73\u8861\u5206\u7c7b\u95ee\u9898\u7684\u5229\u5668<\/p>\n<p>\u5728\u5206\u7c7b\u95ee\u9898\u4e2d&#xff0c;\u5982\u679c\u76f4\u63a5\u7528\u6807\u51c6K-Fold&#xff0c;\u53ef\u80fd\u4f1a\u51fa\u73b0\u67d0\u4e2a\u6298\u4e2d\u6b63\u4f8b\u6216\u8d1f\u4f8b\u7684\u6bd4\u4f8b\u4e0e\u6574\u4f53\u6570\u636e\u96c6\u5dee\u5f02\u5f88\u5927\u7684\u60c5\u51b5&#xff0c;\u751a\u81f3\u67d0\u4e2a\u6298\u4e2d\u5b8c\u5168\u6ca1\u6709\u67d0\u4e2a\u7c7b\u522b\u7684\u6837\u672c\u3002<\/p>\n<p>\u5206\u5c42K-\u6298\u5728\u8fdb\u884c\u6570\u636e\u5212\u5206\u65f6&#xff0c;\u4f1a\u786e\u4fdd\u6bcf\u4e00\u4e2a\u6298\u4e2d\u5404\u4e2a\u7c7b\u522b\u7684\u6837\u672c\u6bd4\u4f8b\u90fd\u4e0e\u539f\u59cb\u6570\u636e\u96c6\u4e2d\u76f8\u5e94\u7c7b\u522b\u7684\u6bd4\u4f8b\u5927\u81f4\u76f8\u540c\u3002\u5728\u5904\u7406\u4e0d\u5e73\u8861\u5206\u7c7b\u95ee\u9898\u65f6&#xff0c;\u8fd9\u51e0\u4e4e\u662f\u5fc5\u987b\u4f7f\u7528\u7684\u4ea4\u53c9\u9a8c\u8bc1\u65b9\u6cd5\u3002<\/p>\n<p>\u7559\u4e00\u6cd5&#xff08;Leave-One-Out, LOO&#xff09;&#xff1a;K-\u6298\u7684\u6781\u7aef\u5f62\u5f0f\u53ca\u5176\u4f18\u7f3a\u70b9<\/p>\n<p>\u7559\u4e00\u6cd5\u662fK-\u6298\u4ea4\u53c9\u9a8c\u8bc1\u7684\u4e00\u4e2a\u7279\u4f8b&#xff0c;\u5373K&#061;N&#xff08;N\u4e3a\u6837\u672c\u603b\u6570&#xff09;\u3002\u6bcf\u6b21\u53ea\u7559\u4e0b\u4e00\u4e2a\u6837\u672c\u4f5c\u4e3a\u9a8c\u8bc1\u96c6&#xff0c;\u5176\u4f59N-1\u4e2a\u6837\u672c\u90fd\u4f5c\u4e3a\u8bad\u7ec3\u96c6\u3002<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u6570\u636e\u5229\u7528\u7387\u6700\u9ad8&#xff0c;\u8bc4\u4f30\u7ed3\u679c\u7684\u504f\u5dee\u6700\u4f4e\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u8ba1\u7b97\u6210\u672c\u6781\u9ad8&#xff08;\u9700\u8981\u8bad\u7ec3N\u4e2a\u6a21\u578b&#xff09;&#xff0c;\u4e14\u8bc4\u4f30\u7ed3\u679c\u7684\u65b9\u5dee\u901a\u5e38\u4e5f\u8f83\u9ad8\u3002\u4e00\u822c\u53ea\u5728\u6570\u636e\u96c6\u975e\u5e38\u5c0f\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>4.4 \u201c\u5bfb\u8def\u201d&#xff1a;\u7f51\u683c\u641c\u7d22\u4e0e\u8d85\u53c2\u6570\u8c03\u4f18<\/h4>\n<p>\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u5982\u4f55\u53ef\u9760\u5730\u8bc4\u4f30\u4e00\u4e2a\u6a21\u578b\u4e86\u3002\u4f46\u4e00\u4e2a\u6a21\u578b\u7684\u6027\u80fd&#xff0c;\u8fd8\u53d7\u5230\u53e6\u4e00\u7c7b\u53c2\u6570\u7684\u6df1\u523b\u5f71\u54cd\u2014\u2014\u8d85\u53c2\u6570\u3002<\/p>\n<h5>4.4.1 \u53c2\u6570 vs. \u8d85\u53c2\u6570&#xff1a;\u6a21\u578b\u81ea\u8eab\u7684\u201c\u4fee\u884c\u201d\u4e0e\u6211\u4eec\u65bd\u52a0\u7684\u201c\u70b9\u5316\u201d<\/h5>\n<ul>\n<li>\u53c2\u6570 (Parameters)&#xff1a;\u6a21\u578b\u4ece\u6570\u636e\u4e2d\u5b66\u4e60\u5f97\u5230\u7684\u503c\u3002\u4f8b\u5982&#xff0c;\u7ebf\u6027\u56de\u5f52\u7684\u6743\u91cdw\u548c\u504f\u7f6eb\u3002\u6211\u4eec\u65e0\u6cd5\u624b\u52a8\u8bbe\u7f6e\u5b83\u4eec&#xff0c;\u5b83\u4eec\u662f\u8bad\u7ec3\u8fc7\u7a0b\u7684\u7ed3\u679c\u3002<\/li>\n<li>\u8d85\u53c2\u6570 (Hyperparameters)&#xff1a;\u6211\u4eec\u5728\u6a21\u578b\u8bad\u7ec3\u4e4b\u524d\u624b\u52a8\u8bbe\u7f6e\u7684\u53c2\u6570\u3002\u5b83\u4eec\u662f\u6a21\u578b\u7684\u201c\u914d\u7f6e\u9009\u9879\u201d&#xff0c;\u63a7\u5236\u7740\u5b66\u4e60\u8fc7\u7a0b\u7684\u884c\u4e3a\u3002\u4f8b\u5982&#xff1a;\n<ul>\n<li>K\u8fd1\u90bb\u7b97\u6cd5\u4e2d\u7684K\u503c\u3002<\/li>\n<li>\u51b3\u7b56\u6811\u7684max_depth&#xff08;\u6700\u5927\u6df1\u5ea6&#xff09;\u3002<\/li>\n<li>SVM\u4e2d\u7684\u60e9\u7f5a\u7cfb\u6570C\u548c\u6838\u51fd\u6570kernel\u3002<\/li>\n<li>\u795e\u7ecf\u7f51\u7edc\u7684\u5b66\u4e60\u7387learning_rate\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8d85\u53c2\u6570\u8c03\u4f18&#xff08;Hyperparameter Tuning&#xff09;\u7684\u76ee\u7684&#xff0c;\u5c31\u662f\u4e3a\u6211\u4eec\u7684\u6a21\u578b\u627e\u5230\u4e00\u7ec4\u80fd\u4f7f\u5176\u6027\u80fd\u6700\u4f73\u7684\u8d85\u53c2\u6570\u7ec4\u5408\u3002<\/p>\n<h5>4.4.2 \u4f20\u7edf\u7684\u5bfb\u8def\u8005&#xff1a;\u7f51\u683c\u641c\u7d22&#xff08;Grid Search&#xff09;<\/h5>\n<p>\u7f51\u683c\u641c\u7d22\u662f\u4e00\u79cd\u7b80\u5355\u7c97\u66b4\u4f46\u6709\u6548\u7684\u8d85\u53c2\u6570\u641c\u7d22\u65b9\u6cd5\u3002<\/p>\n<p>\u5b9a\u4e49\u53c2\u6570\u7f51\u683c\u4e0e\u66b4\u529b\u641c\u7d22<\/p>\n<li>\u5b9a\u4e49\u7f51\u683c&#xff1a;\u4e3a\u6bcf\u4e00\u4e2a\u4f60\u60f3\u8981\u8c03\u4f18\u7684\u8d85\u53c2\u6570&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u5019\u9009\u503c\u5217\u8868\u3002\u8fd9\u4e9b\u5217\u8868\u7ec4\u5408\u5728\u4e00\u8d77&#xff0c;\u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u591a\u7ef4\u7684\u201c\u7f51\u683c\u201d\u3002<\/li>\n<li>\u66b4\u529b\u641c\u7d22&#xff1a;\u904d\u5386\u7f51\u683c\u4e2d\u6bcf\u4e00\u4e2a\u53ef\u80fd\u7684\u8d85\u53c2\u6570\u7ec4\u5408\u3002\u5bf9\u6bcf\u4e00\u4e2a\u7ec4\u5408&#xff0c;\u4f7f\u7528\u4ea4\u53c9\u9a8c\u8bc1\u6765\u8bc4\u4f30\u5176\u6027\u80fd\u3002<\/li>\n<li>\u9009\u62e9\u6700\u4f18&#xff1a;\u9009\u62e9\u90a3\u4e2a\u5728\u4ea4\u53c9\u9a8c\u8bc1\u4e2d\u5e73\u5747\u5f97\u5206\u6700\u9ad8\u7684\u8d85\u53c2\u6570\u7ec4\u5408\u3002<\/li>\n<p>\u7f51\u683c\u641c\u7d22\u4e0e\u4ea4\u53c9\u9a8c\u8bc1\u7684\u7ed3\u5408&#xff08;GridSearchCV&#xff09;<\/p>\n<p>Scikit-learn\u63d0\u4f9b\u4e86GridSearchCV\u8fd9\u4e2a\u5f3a\u5927\u7684\u5de5\u5177&#xff0c;\u5c06\u7f51\u683c\u641c\u7d22\u548c\u4ea4\u53c9\u9a8c\u8bc1\u5b8c\u7f8e\u5730\u7ed3\u5408\u5728\u4e86\u4e00\u8d77\u3002<\/p>\n<p>from sklearn.model_selection import GridSearchCV<br \/>\nfrom sklearn.svm import SVC<\/p>\n<p># 1. \u5b9a\u4e49\u6a21\u578b<br \/>\nmodel &#061; SVC()<\/p>\n<p># 2. \u5b9a\u4e49\u8d85\u53c2\u6570\u7f51\u683c<br \/>\nparam_grid &#061; {<br \/>\n    &#039;C&#039;: [0.1, 1, 10, 100],<br \/>\n    &#039;gamma&#039;: [1, 0.1, 0.01, 0.001],<br \/>\n    &#039;kernel&#039;: [&#039;rbf&#039;, &#039;linear&#039;]<br \/>\n}<\/p>\n<p># 3. \u521b\u5efaGridSearchCV\u5bf9\u8c61<br \/>\n# cv&#061;5\u8868\u793a\u4f7f\u75285\u6298\u4ea4\u53c9\u9a8c\u8bc1<br \/>\ngrid_search &#061; GridSearchCV(estimator&#061;model, param_grid&#061;param_grid, cv&#061;5, scoring&#061;&#039;accuracy&#039;, verbose&#061;2)<\/p>\n<p># 4. \u6267\u884c\u641c\u7d22 (\u5728\u8bad\u7ec3\u6570\u636e\u4e0a)<br \/>\n# grid_search.fit(X_train, y_train)<\/p>\n<p># 5. \u67e5\u770b\u6700\u4f73\u53c2\u6570\u548c\u6700\u4f73\u5f97\u5206<br \/>\n# print(&#034;Best Parameters:&#034;, grid_search.best_params_)<br \/>\n# print(&#034;Best Score:&#034;, grid_search.best_score_)<\/p>\n<p># 6. \u83b7\u53d6\u6700\u4f73\u6a21\u578b<br \/>\n# best_model &#061; grid_search.best_estimator_<\/p>\n<p>\u7f51\u683c\u641c\u7d22\u7684\u201c\u7ef4\u5ea6\u8bc5\u5492\u201d<\/p>\n<p>\u7f51\u683c\u641c\u7d22\u7684\u4e3b\u8981\u7f3a\u70b9\u662f\u8ba1\u7b97\u6210\u672c\u9ad8\u3002\u5982\u679c\u8d85\u53c2\u6570\u6570\u91cf\u589e\u591a&#xff0c;\u6216\u8005\u6bcf\u4e2a\u8d85\u53c2\u6570\u7684\u5019\u9009\u503c\u589e\u591a&#xff0c;\u9700\u8981\u5c1d\u8bd5\u7684\u7ec4\u5408\u6570\u91cf\u4f1a\u5448\u6307\u6570\u7ea7\u589e\u957f&#xff0c;\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u201c\u7ef4\u5ea6\u8bc5\u5492\u201d\u3002<\/p>\n<h5>4.4.3 \u66f4\u806a\u660e\u7684\u63a2\u7d22\u8005&#xff1a;\u968f\u673a\u641c\u7d22&#xff08;Random Search&#xff09;<\/h5>\n<p>\u968f\u673a\u641c\u7d22\u662f\u5bf9\u7f51\u683c\u641c\u7d22\u7684\u4e00\u4e2a\u7b80\u5355\u800c\u53c8\u5e38\u5e38\u66f4\u9ad8\u6548\u7684\u66ff\u4ee3\u65b9\u6848\u3002<\/p>\n<p>\u4ece\u201c\u5730\u6bef\u5f0f\u201d\u5230\u201c\u6492\u80e1\u6912\u9762\u5f0f\u201d\u7684\u8f6c\u53d8<\/p>\n<p>\u968f\u673a\u641c\u7d22\u4e0d\u518d\u5c1d\u8bd5\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408&#xff0c;\u800c\u662f\u5728\u6307\u5b9a\u7684\u53c2\u6570\u5206\u5e03&#xff08;\u5982\u4e00\u4e2a\u5217\u8868\u6216\u4e00\u4e2a\u8fde\u7eed\u5206\u5e03&#xff09;\u4e2d&#xff0c;\u968f\u673a\u5730\u91c7\u6837\u56fa\u5b9a\u6570\u91cf&#xff08;\u7531n_iter\u53c2\u6570\u6307\u5b9a&#xff09;\u7684\u8d85\u53c2\u6570\u7ec4\u5408\u3002<\/p>\n<p>\u4e3a\u4f55\u968f\u673a\u641c\u7d22\u5e38\u5e38\u66f4\u9ad8\u6548&#xff1f;<\/p>\n<p>\u7814\u7a76\u8868\u660e&#xff0c;\u5bf9\u4e8e\u5f88\u591a\u6a21\u578b\u6765\u8bf4&#xff0c;\u5176\u6027\u80fd\u4e3b\u8981\u7531\u5c11\u6570\u51e0\u4e2a\u201c\u5173\u952e\u201d\u8d85\u53c2\u6570\u51b3\u5b9a\u3002<\/p>\n<ul>\n<li>\u7f51\u683c\u641c\u7d22\u53ef\u80fd\u4f1a\u5728\u90a3\u4e9b\u4e0d\u91cd\u8981\u7684\u8d85\u53c2\u6570\u4e0a\u6d6a\u8d39\u5927\u91cf\u65f6\u95f4\u8fdb\u884c\u7cbe\u7ec6\u7684\u3001\u4e0d\u5fc5\u8981\u7684\u5c1d\u8bd5\u3002<\/li>\n<li>\u968f\u673a\u641c\u7d22\u5219\u66f4\u6709\u53ef\u80fd\u5728\u76f8\u540c\u7684\u8ba1\u7b97\u9884\u7b97\u5185&#xff0c;\u5728\u90a3\u4e9b\u201c\u5173\u952e\u201d\u8d85\u53c2\u6570\u4e0a\u63a2\u7d22\u5230\u66f4\u591a\u6837\u5316\u7684\u503c&#xff0c;\u4ece\u800c\u6709\u66f4\u5927\u51e0\u7387\u627e\u5230\u4e00\u4e2a\u4f18\u79c0\u7684\u7ec4\u5408\u3002<\/li>\n<\/ul>\n<p>\u5728Scikit-learn\u4e2d&#xff0c;\u4f7f\u7528RandomizedSearchCV&#xff0c;\u5176\u7528\u6cd5\u4e0eGridSearchCV\u975e\u5e38\u76f8\u4f3c\u3002<\/p>\n<h5>4.4.4 \u524d\u6cbf\u7684\u5411\u5bfc&#xff1a;\u8d1d\u53f6\u65af\u4f18\u5316\u7b49\u9ad8\u7ea7\u65b9\u6cd5\u7b80\u4ecb<\/h5>\n<p>\u5f53\u8d85\u53c2\u6570\u641c\u7d22\u7684\u6210\u672c\u6781\u9ad8\u65f6&#xff08;\u4f8b\u5982&#xff0c;\u8bad\u7ec3\u4e00\u4e2a\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u53ef\u80fd\u9700\u8981\u6570\u5929&#xff09;&#xff0c;\u7f51\u683c\u641c\u7d22\u548c\u968f\u673a\u641c\u7d22\u8fd9\u79cd\u201c\u76f2\u76ee\u201d\u7684\u63a2\u7d22\u5c31\u663e\u5f97\u6548\u7387\u4f4e\u4e0b\u4e86\u3002<\/p>\n<p>\u8d1d\u53f6\u65af\u4f18\u5316\u7684\u601d\u60f3&#xff1a;\u5229\u7528\u5148\u9a8c\u4fe1\u606f\u6307\u5bfc\u4e0b\u4e00\u6b21\u5c1d\u8bd5<\/p>\n<p>\u8d1d\u53f6\u65af\u4f18\u5316\u662f\u4e00\u79cd\u66f4\u667a\u80fd\u7684\u641c\u7d22\u7b56\u7565\u3002\u5b83\u5c06\u8d85\u53c2\u6570\u4e0e\u6a21\u578b\u6027\u80fd\u7684\u5173\u7cfb\u770b\u4f5c\u4e00\u4e2a\u9700\u8981\u5b66\u4e60\u7684\u51fd\u6570\u3002<\/p>\n<li>\u5b83\u9996\u5148\u5c1d\u8bd5\u51e0\u4e2a\u968f\u673a\u70b9\u3002<\/li>\n<li>\u7136\u540e&#xff0c;\u5b83\u6839\u636e\u5df2\u6709\u7684&#xff08;\u8d85\u53c2\u6570\u7ec4\u5408&#xff0c;\u6027\u80fd\u5f97\u5206&#xff09;\u7ed3\u679c&#xff0c;\u5efa\u7acb\u4e00\u4e2a\u6982\u7387\u6a21\u578b&#xff08;\u4ee3\u7406\u6a21\u578b&#xff09;&#xff0c;\u6765\u201c\u731c\u6d4b\u201d\u8fd9\u4e2a\u672a\u77e5\u51fd\u6570\u7684\u6837\u5b50\u3002<\/li>\n<li>\u63a5\u7740&#xff0c;\u5b83\u5229\u7528\u8fd9\u4e2a\u4ee3\u7406\u6a21\u578b&#xff0c;\u53bb\u9009\u62e9\u4e0b\u4e00\u4e2a\u6700\u6709\u53ef\u80fd\u5e26\u6765\u6027\u80fd\u63d0\u5347\u7684\u8d85\u53c2\u6570\u7ec4\u5408\u8fdb\u884c\u5c1d\u8bd5&#xff08;\u800c\u4e0d\u662f\u968f\u673a\u9009&#xff09;\u3002<\/li>\n<li>\u4e0d\u65ad\u91cd\u590d2\u548c3&#xff0c;\u76f4\u5230\u8fbe\u5230\u9884\u8bbe\u7684\u8fed\u4ee3\u6b21\u6570\u3002<\/li>\n<p>\u5b83\u5c31\u50cf\u4e00\u4e2a\u806a\u660e\u7684\u63a2\u77ff\u8005&#xff0c;\u4f1a\u6839\u636e\u5df2\u7ecf\u6316\u5230\u7684\u77ff\u77f3\u4fe1\u606f&#xff0c;\u6765\u5224\u65ad\u4e0b\u4e00\u94f2\u5b50\u5e94\u8be5\u6316\u5728\u54ea\u91cc&#xff0c;\u800c\u4e0d\u662f\u5230\u5904\u4e71\u6316\u3002<\/p>\n<p>\u4f55\u65f6\u8003\u8651\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u8c03\u4f18\u65b9\u6cd5<\/p>\n<p>\u5f53\u5355\u6b21\u6a21\u578b\u8bc4\u4f30\u7684\u6210\u672c\u975e\u5e38\u9ad8\u6602&#xff0c;\u4e14\u8d85\u53c2\u6570\u7a7a\u95f4\u590d\u6742\u65f6&#xff0c;\u5c31\u5e94\u8be5\u8003\u8651\u4f7f\u7528\u8d1d\u53f6\u65af\u4f18\u5316&#xff08;\u5982hyperopt,\u00a0scikit-optimize\u7b49\u5e93&#xff09;\u6216\u5176\u66f4\u5148\u8fdb\u7684\u53d8\u4f53\u3002<\/p>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u6253\u9020\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u6a21\u578b\u8bc4\u4f30\u4e0e\u9009\u62e9\u7684\u201c\u7f57\u76d8\u201d\u3002\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u7528\u7cbe\u786e\u7684\u201c\u5ea6\u91cf\u8861\u201d\u6765\u8861\u91cf\u6a21\u578b&#xff0c;\u5982\u4f55\u6d1e\u5bdf\u201c\u504f\u5dee\u4e0e\u65b9\u5dee\u201d\u8fd9\u5bf9\u6838\u5fc3\u77db\u76fe&#xff0c;\u5982\u4f55\u7528\u201c\u4ea4\u53c9\u9a8c\u8bc1\u201d\u7684\u667a\u6167\u83b7\u5f97\u53ef\u9760\u7684\u8bc4\u4f30&#xff0c;\u4ee5\u53ca\u5982\u4f55\u7528\u201c\u7f51\u683c\/\u968f\u673a\u641c\u7d22\u201d\u7684\u7b56\u7565\u4e3a\u6a21\u578b\u627e\u5230\u6700\u4f73\u7684\u201c\u914d\u7f6e\u201d\u3002<\/p>\n<p>\u8fd9\u5957\u6846\u67b6\u662f\u72ec\u7acb\u4e8e\u4efb\u4f55\u5177\u4f53\u6a21\u578b\u7684\u901a\u7528\u65b9\u6cd5\u8bba\u3002\u638c\u63e1\u4e86\u5b83&#xff0c;\u60a8\u5c31\u62e5\u6709\u4e86\u5728\u7b97\u6cd5\u6d77\u6d0b\u4e2d\u81ea\u4fe1\u822a\u884c\u7684\u80fd\u529b\u3002\u4ece\u4e0b\u4e00\u7ae0\u5f00\u59cb&#xff0c;\u6211\u4eec\u5c06\u6b63\u5f0f\u626c\u5e06\u8d77\u822a&#xff0c;\u9010\u4e00\u63a2\u7d22\u90a3\u4e9b\u4e3b\u6d41\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002\u5c4a\u65f6&#xff0c;\u672c\u7ae0\u6240\u5b66\u7684\u4e00\u5207&#xff0c;\u90fd\u5c06\u6210\u4e3a\u6211\u4eec\u8bc4\u4f30\u3001\u8bca\u65ad\u548c\u4f18\u5316\u8fd9\u4e9b\u6a21\u578b\u7684\u5f3a\u5927\u6b66\u5668\u3002<\/p>\n<hr \/>\n<h2>\u7b2c\u4e8c\u90e8\u5206&#xff1a;\u672f\u6cd5\u4e07\u5343\u2014\u2014\u4e3b\u6d41\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8be6\u89e3<\/h2>\n<\/p>\n<p>\u6838\u5fc3\u76ee\u6807&#xff1a;\u00a0\u6df1\u5165\u5256\u6790\u5404\u7c7b\u4e3b\u6d41\u7b97\u6cd5\u7684\u539f\u7406\u3001\u6570\u5b66\u57fa\u7840\u548c\u4ee3\u7801\u5b9e\u73b0\u3002\u5f3a\u8c03\u6bcf\u4e2a\u6a21\u578b\u7684\u9002\u7528\u573a\u666f\u3001\u4f18\u7f3a\u70b9&#xff0c;\u5e76\u7ed3\u5408\u5b9e\u4f8b\u8fdb\u884c\u201c\u5e96\u4e01\u89e3\u725b\u201d\u5f0f\u7684\u8bb2\u89e3\u3002<\/p>\n<h3>\u7b2c\u4e94\u7ae0&#xff1a;\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u5224\u522b\u201d\u2014\u2014\u5206\u7c7b\u7b97\u6cd5<\/h3>\n<ul>\n<li>5.1 \u903b\u8f91\u56de\u5f52&#xff1a;\u770b\u4f3c\u56de\u5f52&#xff0c;\u5b9e\u4e3a\u5206\u7c7b\u7684\u667a\u6167<\/li>\n<li>5.2 K-\u8fd1\u90bb&#xff08;KNN&#xff09;&#xff1a;\u201c\u7269\u4ee5\u7c7b\u805a&#xff0c;\u4eba\u4ee5\u7fa4\u5206\u201d\u7684\u6734\u7d20\u54f2\u5b66<\/li>\n<li>5.3 \u652f\u6491\u5411\u91cf\u673a&#xff08;SVM&#xff09;&#xff1a;\u201c\u4e00\u5212\u5f00\u5929\u201d\u7684\u6570\u5b66\u4e4b\u7f8e<\/li>\n<li>5.4 \u51b3\u7b56\u6811\u4e0e\u968f\u673a\u68ee\u6797&#xff1a;\u201c\u96c6\u601d\u5e7f\u76ca\u201d\u7684\u96c6\u6210\u667a\u6167<\/li>\n<li>5.5 \u6734\u7d20\u8d1d\u53f6\u65af&#xff1a;\u201c\u6267\u679c\u7d22\u56e0\u201d\u7684\u6982\u7387\u601d\u7ef4<\/li>\n<\/ul>\n<p>\u6b22\u8fce\u6765\u5230\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u8179\u5730\u3002\u4ece\u672c\u7ae0\u5f00\u59cb&#xff0c;\u6211\u4eec\u5c06\u5b66\u4e60\u5177\u4f53\u7684\u7b97\u6cd5&#xff0c;\u5c06\u524d\u51e0\u7ae0\u7684\u7406\u8bba\u3001\u5de5\u5177\u4e0e\u65b9\u6cd5\u8bba\u4ed8\u8bf8\u5b9e\u8df5\u3002\u6211\u4eec\u5c06\u4ece\u76d1\u7763\u5b66\u4e60\u4e2d\u7684**\u5206\u7c7b&#xff08;Classification&#xff09;**\u4efb\u52a1\u5f00\u59cb\u3002\u5206\u7c7b&#xff0c;\u987e\u540d\u601d\u4e49&#xff0c;\u5c31\u662f\u8ba9\u673a\u5668\u5b66\u4f1a\u201c\u5206\u8fa8\u7c7b\u522b\u201d&#xff0c;\u5b83\u65e8\u5728\u9884\u6d4b\u4e00\u4e2a\u79bb\u6563\u7684\u76ee\u6807\u53d8\u91cf\u3002<\/p>\n<p>\u751f\u6d3b\u4e2d\u7684\u5206\u7c7b\u95ee\u9898\u65e0\u5904\u4e0d\u5728&#xff1a;\u5224\u65ad\u4e00\u5c01\u90ae\u4ef6\u662f\u5426\u4e3a\u5783\u573e\u90ae\u4ef6&#xff0c;\u8bc6\u522b\u4e00\u5f20\u56fe\u7247\u4e2d\u7684\u52a8\u7269\u662f\u732b\u8fd8\u662f\u72d7&#xff0c;\u8bc4\u4f30\u4e00\u7b14\u4ea4\u6613\u662f\u5426\u5b58\u5728\u6b3a\u8bc8\u98ce\u9669&#xff0c;\u6216\u8005\u9884\u6d4b\u4e00\u4f4d\u5ba2\u6237\u662f\u5426\u4f1a\u6d41\u5931\u3002\u8fd9\u4e9b\u90fd\u662f\u5206\u7c7b\u7b97\u6cd5\u5927\u663e\u8eab\u624b\u7684\u821e\u53f0\u3002<\/p>\n<p>\u672c\u7ae0\u5c06\u4ecb\u7ecd\u4e94\u79cd\u6700\u7ecf\u5178\u3001\u6700\u57fa\u7840\u3001\u4e5f\u662f\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u5206\u7c7b\u7b97\u6cd5\u3002\u5b83\u4eec\u5404\u81ea\u4ee3\u8868\u4e86\u4e00\u79cd\u72ec\u7279\u7684\u89e3\u51b3\u95ee\u9898\u7684\u54f2\u5b66&#xff1a;\u903b\u8f91\u56de\u5f52\u7684\u6982\u7387\u5efa\u6a21\u3001K-\u8fd1\u90bb\u7684\u7c7b\u6bd4\u63a8\u7406\u3001\u652f\u6491\u5411\u91cf\u673a\u7684\u51e0\u4f55\u95f4\u9694\u3001\u51b3\u7b56\u6811\u7684\u903b\u8f91\u89c4\u5219\u4ee5\u53ca\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u6982\u7387\u63a8\u65ad\u3002<\/p>\n<p>\u5b66\u4e60\u8fd9\u4e9b\u7b97\u6cd5\u65f6&#xff0c;\u8bf7\u91cd\u70b9\u5173\u6ce8&#xff1a;<\/p>\n<li>\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u5b83\u662f\u5982\u4f55\u5b66\u4e60\u548c\u9884\u6d4b\u7684&#xff1f;<\/li>\n<li>\u5b83\u7684\u5173\u952e\u8d85\u53c2\u6570\u6709\u54ea\u4e9b&#xff0c;\u5206\u522b\u63a7\u5236\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u5b83\u7684\u4f18\u7f3a\u70b9\u662f\u4ec0\u4e48&#xff0c;\u9002\u7528\u4e8e\u54ea\u4e9b\u573a\u666f&#xff1f;<\/li>\n<p>\u638c\u63e1\u4e86\u8fd9\u4e9b&#xff0c;\u60a8\u4fbf\u80fd\u50cf\u4e00\u4f4d\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5de5\u5320&#xff0c;\u4e3a\u4e0d\u540c\u7684\u4efb\u52a1\u9009\u62e9\u6700\u5408\u9002\u7684\u5de5\u5177\u3002<\/p>\n<hr \/>\n<h4>5.1 \u903b\u8f91\u56de\u5f52&#xff1a;\u770b\u4f3c\u56de\u5f52&#xff0c;\u5b9e\u4e3a\u5206\u7c7b\u7684\u667a\u6167<\/h4>\n<p>\u903b\u8f91\u56de\u5f52&#xff08;Logistic Regression&#xff09;\u662f\u60a8\u5728\u5206\u7c7b\u9886\u57df\u9047\u5230\u7684\u7b2c\u4e00\u4e2a&#xff0c;\u4e5f\u53ef\u80fd\u662f\u6700\u91cd\u8981\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002\u5b83\u7684\u540d\u5b57\u91cc\u867d\u7136\u5e26\u6709\u201c\u56de\u5f52\u201d&#xff0c;\u4f46\u8bf7\u4e0d\u8981\u88ab\u8bef\u5bfc&#xff0c;\u5b83\u662f\u4e00\u4e2a\u5730\u5730\u9053\u9053\u7684\u5206\u7c7b\u7b97\u6cd5\u3002\u5b83\u56e0\u5176\u7b80\u5355\u3001\u9ad8\u6548\u3001\u53ef\u89e3\u91ca\u6027\u5f3a\u4e14\u8f93\u51fa\u7ed3\u679c\u4e3a\u6982\u7387\u800c\u5907\u53d7\u9752\u7750&#xff0c;\u5e38\u5e38\u88ab\u7528\u4f5c\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u7684\u9996\u9009\u57fa\u7ebf\u6a21\u578b\u3002<\/p>\n<h5>5.1.1 \u4ece\u7ebf\u6027\u56de\u5f52\u5230\u903b\u8f91\u56de\u5f52&#xff1a;\u8de8\u8d8a\u201c\u9884\u6d4b\u503c\u201d\u5230\u201c\u9884\u6d4b\u6982\u7387\u201d\u7684\u9e3f\u6c9f<\/h5>\n<p>\u8981\u7406\u89e3\u903b\u8f91\u56de\u5f52&#xff0c;\u6700\u597d\u7684\u65b9\u5f0f\u662f\u4ece\u6211\u4eec\u719f\u6089\u7684\u7ebf\u6027\u56de\u5f52\u51fa\u53d1\u3002\u7ebf\u6027\u56de\u5f52\u7684\u76ee\u6807\u662f\u62df\u5408\u4e00\u6761\u76f4\u7ebf&#xff08;\u6216\u8d85\u5e73\u9762&#xff09;\u6765\u9884\u6d4b\u4e00\u4e2a\u8fde\u7eed\u503c&#xff0c;\u5176\u516c\u5f0f\u4e3a&#xff1a;\u00a0\u0177 &#061; w\u2080 &#043; w\u2081x\u2081 &#043; w\u2082x\u2082 &#043; &#8230; &#043; w\u2099x\u2099<\/p>\n<p>\u7ebf\u6027\u56de\u5f52\u7684\u5c40\u9650\u6027\u00a0\u90a3\u6211\u4eec\u80fd\u5426\u76f4\u63a5\u7528\u5b83\u6765\u505a\u5206\u7c7b\u5462&#xff1f;\u6bd4\u5982&#xff0c;\u6211\u4eec\u89c4\u5b9a\u00a0\u0177 &gt; 0.5\u00a0\u5c31\u5224\u4e3a\u7c7b\u522b1&#xff0c;\u5426\u5219\u4e3a\u7c7b\u522b0\u3002\u8fd9\u6837\u505a\u6709\u4e24\u4e2a\u81f4\u547d\u95ee\u9898&#xff1a;<\/p>\n<li>\u8f93\u51fa\u8303\u56f4\u4e0d\u5339\u914d&#xff1a;\u7ebf\u6027\u56de\u5f52\u7684\u8f93\u51fa\u00a0\u0177\u00a0\u662f\u4e00\u4e2a\u5b9e\u6570&#xff0c;\u8303\u56f4\u662f\u00a0(-\u221e, &#043;\u221e)\u3002\u800c\u6211\u4eec\u60f3\u8981\u7684\u5206\u7c7b\u7ed3\u679c&#xff0c;\u6700\u597d\u662f\u4e00\u4e2a\u8868\u793a\u201c\u6982\u7387\u201d\u7684\u3001\u5728\u00a0(0, 1)\u00a0\u533a\u95f4\u5185\u7684\u503c\u3002\u76f4\u63a5\u6bd4\u8f83\u00a0\u0177\u00a0\u548c0.5&#xff0c;\u7269\u7406\u610f\u4e49\u4e0d\u660e\u786e\u3002<\/li>\n<li>\u5bf9\u79bb\u7fa4\u70b9\u654f\u611f&#xff1a;\u5982\u679c\u5728\u6570\u636e\u4e2d\u52a0\u5165\u4e00\u4e2ax\u503c\u5f88\u5927\u7684\u79bb\u7fa4\u70b9&#xff0c;\u7ebf\u6027\u56de\u5f52\u7684\u62df\u5408\u76f4\u7ebf\u4f1a\u88ab\u4e25\u91cd\u201c\u62c9\u504f\u201d&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u539f\u672c\u6b63\u786e\u7684\u51b3\u7b56\u8fb9\u754c\u53d1\u751f\u5de8\u5927\u504f\u79fb&#xff0c;\u9020\u6210\u9519\u8bef\u7684\u5206\u7c7b\u3002<\/li>\n<p>\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u201c\u8f6c\u6362\u5668\u201d&#xff0c;\u80fd\u5c06\u7ebf\u6027\u56de\u5f52\u00a0(-\u221e, &#043;\u221e)\u00a0\u7684\u8f93\u51fa&#xff0c;\u4f18\u96c5\u5730\u201c\u538b\u7f29\u201d\u5230\u00a0(0, 1)\u00a0\u7684\u6982\u7387\u533a\u95f4\u5185\u3002<\/p>\n<p>Sigmoid\u51fd\u6570\u7684\u5f15\u5165\u00a0\u8fd9\u4e2a\u795e\u5947\u7684\u201c\u8f6c\u6362\u5668\u201d\u5c31\u662fSigmoid\u51fd\u6570&#xff08;\u4e5f\u79f0Logistic\u51fd\u6570&#xff09;&#xff0c;\u5b83\u7684\u6570\u5b66\u5f62\u5f0f\u5982\u4e0b&#xff1a;\u00a0\u03c3(z) &#061; 1 \/ (1 &#043; e\u207b\u1dbb)<\/p>\n<p>\u8fd9\u91cc\u7684\u00a0z\u00a0\u5c31\u662f\u6211\u4eec\u7ebf\u6027\u56de\u5f52\u7684\u8f93\u51fa\u00a0w\u2080 &#043; w\u2081x\u2081 &#043; &#8230;\u3002Sigmoid\u51fd\u6570\u5177\u6709\u975e\u5e38\u4f18\u7f8e\u7684S\u578b\u66f2\u7ebf\u5f62\u6001&#xff1a;<\/p>\n<ul>\n<li>\u65e0\u8bba\u8f93\u5165\u00a0z\u00a0\u591a\u5927\u6216\u591a\u5c0f&#xff0c;\u5176\u8f93\u51fa\u00a0\u03c3(z)\u00a0\u59cb\u7ec8\u5728\u00a0(0, 1)\u00a0\u533a\u95f4\u5185\u3002<\/li>\n<li>\u5f53\u00a0z &#061; 0\u00a0\u65f6&#xff0c;\u03c3(z) &#061; 0.5\u3002<\/li>\n<li>\u5f53\u00a0z -&gt; &#043;\u221e\u00a0\u65f6&#xff0c;\u03c3(z) -&gt; 1\u3002<\/li>\n<li>\u5f53\u00a0z -&gt; -\u221e\u00a0\u65f6&#xff0c;\u03c3(z) -&gt; 0\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u5c06\u7ebf\u6027\u56de\u5f52\u7684\u8f93\u51fa\u00a0z\u00a0\u4f5c\u4e3aSigmoid\u51fd\u6570\u7684\u8f93\u5165&#xff0c;\u6211\u4eec\u5c31\u6784\u5efa\u4e86\u903b\u8f91\u56de\u5f52\u7684\u6838\u5fc3\u6a21\u578b&#xff1a;\u00a0P(y&#061;1 | X) &#061; \u03c3(z) &#061; 1 \/ (1 &#043; e\u207b(w\u1d40X &#043; b))\u00a0\u8fd9\u4e2a\u516c\u5f0f\u7684\u542b\u4e49\u662f&#xff1a;\u5728\u7ed9\u5b9a\u7279\u5f81\u00a0X\u00a0\u7684\u6761\u4ef6\u4e0b&#xff0c;\u6837\u672c\u7c7b\u522b\u00a0y\u00a0\u4e3a1\u7684\u6982\u7387\u3002<\/p>\n<h5>5.1.2 \u6a21\u578b\u89e3\u8bfb&#xff1a;\u6982\u7387\u3001\u51b3\u7b56\u8fb9\u754c\u4e0e\u635f\u5931\u51fd\u6570<\/h5>\n<p>\u6982\u7387\u7684\u89e3\u91ca\u00a0\u903b\u8f91\u56de\u5f52\u7684\u8f93\u51fa\u00a0P(y&#061;1|X)\u00a0\u662f\u4e00\u4e2a\u771f\u6b63\u7684\u6982\u7387\u503c&#xff0c;\u8fd9\u6781\u5177\u4ef7\u503c\u3002\u4f8b\u5982&#xff0c;\u4e00\u4e2a\u764c\u75c7\u9884\u6d4b\u6a21\u578b\u8f93\u51fa0.9&#xff0c;\u610f\u5473\u7740\u5b83\u670990%\u7684\u628a\u63e1\u8ba4\u4e3a\u8be5\u75c5\u4eba\u60a3\u6709\u764c\u75c7\u3002\u8fd9\u4e2a\u6982\u7387\u503c\u672c\u8eab\u5c31\u53ef\u4ee5\u7528\u4e8e\u98ce\u9669\u6392\u5e8f\u3001\u8bbe\u5b9a\u4e0d\u540c\u7684\u544a\u8b66\u7ea7\u522b\u7b49\u3002 \u6709\u4e86\u6982\u7387&#xff0c;\u5206\u7c7b\u5c31\u53d8\u5f97\u987a\u7406\u6210\u7ae0&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u00a0P(y&#061;1|X) &gt; 0.5&#xff0c;\u5219\u9884\u6d4b\u4e3a\u7c7b\u522b1\u3002<\/li>\n<li>\u5982\u679c\u00a0P(y&#061;1|X) &lt;&#061; 0.5&#xff0c;\u5219\u9884\u6d4b\u4e3a\u7c7b\u522b0\u3002<\/li>\n<\/ul>\n<p>\u51b3\u7b56\u8fb9\u754c&#xff08;Decision Boundary&#xff09;\u00a0\u51b3\u7b56\u8fb9\u754c\u662f\u6a21\u578b\u5728\u7279\u5f81\u7a7a\u95f4\u4e2d\u5c06\u4e0d\u540c\u7c7b\u522b\u5206\u5f00\u7684\u90a3\u6761\u201c\u7ebf\u201d\u6216\u201c\u9762\u201d\u3002\u5bf9\u4e8e\u903b\u8f91\u56de\u5f52&#xff0c;\u5f53\u00a0P(y&#061;1|X) &#061; 0.5\u00a0\u65f6&#xff0c;\u5206\u7c7b\u7ed3\u679c\u5904\u4e8e\u4e34\u754c\u72b6\u6001\u3002\u8fd9\u5bf9\u5e94\u4e8e\u00a0\u03c3(z) &#061; 0.5&#xff0c;\u4e5f\u5c31\u662f\u00a0z &#061; w\u1d40X &#043; b &#061; 0\u3002 \u6240\u4ee5&#xff0c;\u903b\u8f91\u56de\u5f52\u7684\u51b3\u7b56\u8fb9\u754c\u5c31\u662f\u7531\u00a0w\u1d40X &#043; b &#061; 0\u00a0\u8fd9\u6761\u65b9\u7a0b\u6240\u5b9a\u4e49\u7684\u7ebf\u6027\u8fb9\u754c\u3002<\/p>\n<ul>\n<li>\u5728\u4e8c\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u5b83\u662f\u4e00\u6761\u76f4\u7ebf\u3002<\/li>\n<li>\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u5b83\u662f\u4e00\u4e2a\u5e73\u9762\u3002<\/li>\n<li>\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u5b83\u662f\u4e00\u4e2a\u8d85\u5e73\u9762\u3002<\/li>\n<\/ul>\n<p>\u91cd\u8981&#xff1a;\u903b\u8f91\u56de\u5f52\u672c\u8eab\u662f\u4e00\u4e2a\u7ebf\u6027\u5206\u7c7b\u5668&#xff0c;\u5b83\u7684\u51b3\u7b56\u8fb9\u754c\u662f\u7ebf\u6027\u7684\u3002\u5982\u679c\u6570\u636e\u7684\u771f\u5b9e\u8fb9\u754c\u662f\u975e\u7ebf\u6027\u7684&#xff0c;\u57fa\u7840\u7684\u903b\u8f91\u56de\u5f52\u6a21\u578b\u5c06\u8868\u73b0\u4e0d\u4f73\u3002&#xff08;\u5f53\u7136&#xff0c;\u901a\u8fc7\u7279\u5f81\u5de5\u7a0b&#xff0c;\u5982\u6dfb\u52a0\u591a\u9879\u5f0f\u7279\u5f81&#xff0c;\u53ef\u4ee5\u4f7f\u5176\u5b66\u4e60\u975e\u7ebf\u6027\u8fb9\u754c&#xff09;\u3002<\/p>\n<p>\u635f\u5931\u51fd\u6570\u00a0\u6a21\u578b\u5982\u4f55\u5b66\u4e60\u5230\u6700\u4f18\u7684\u6743\u91cd\u00a0w\u00a0\u548c\u504f\u7f6e\u00a0b\u00a0\u5462&#xff1f;\u5b83\u9700\u8981\u4e00\u4e2a**\u635f\u5931\u51fd\u6570&#xff08;Loss Function&#xff09;**\u6765\u8861\u91cf\u5f53\u524d\u6a21\u578b\u7684\u9884\u6d4b\u4e0e\u771f\u5b9e\u6807\u7b7e\u4e4b\u95f4\u7684\u201c\u5dee\u8ddd\u201d&#xff0c;\u7136\u540e\u901a\u8fc7\u4f18\u5316\u7b97\u6cd5&#xff08;\u5982\u68af\u5ea6\u4e0b\u964d&#xff09;\u6765\u6700\u5c0f\u5316\u8fd9\u4e2a\u635f\u5931\u3002<\/p>\n<p>\u5bf9\u4e8e\u903b\u8f91\u56de\u5f52&#xff0c;\u6211\u4eec\u4e0d\u80fd\u4f7f\u7528\u7ebf\u6027\u56de\u5f52\u7684\u5747\u65b9\u8bef\u5dee&#xff08;MSE&#xff09;&#xff0c;\u56e0\u4e3a\u5b83\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u975e\u51f8\u7684\u635f\u5931\u51fd\u6570&#xff0c;\u4f18\u5316\u8d77\u6765\u975e\u5e38\u56f0\u96be\u3002\u6211\u4eec\u4f7f\u7528\u7684\u662f\u5bf9\u6570\u635f\u5931&#xff08;Log Loss&#xff09;&#xff0c;\u4e5f\u79f0\u4e3a\u4e8c\u5143\u4ea4\u53c9\u71b5\u635f\u5931&#xff08;Binary Cross-Entropy Loss&#xff09;\u3002<\/p>\n<p>\u5bf9\u4e8e\u5355\u4e2a\u6837\u672c&#xff0c;\u5176\u635f\u5931\u5b9a\u4e49\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u771f\u5b9e\u6807\u7b7e\u00a0y &#061; 1&#xff1a;Loss &#061; -log(p)&#xff0c;\u5176\u4e2d\u00a0p\u00a0\u662f\u6a21\u578b\u9884\u6d4b\u4e3a1\u7684\u6982\u7387\u3002<\/li>\n<li>\u5982\u679c\u771f\u5b9e\u6807\u7b7e\u00a0y &#061; 0&#xff1a;Loss &#061; -log(1-p)\u3002<\/li>\n<\/ul>\n<p>\u76f4\u89c2\u7406\u89e3&#xff1a;<\/p>\n<ul>\n<li>\u5f53\u771f\u5b9e\u6807\u7b7e\u662f1\u65f6&#xff0c;\u6211\u4eec\u5e0c\u671b\u9884\u6d4b\u6982\u7387\u00a0p\u00a0\u8d8a\u63a5\u8fd11\u8d8a\u597d\u3002\u5982\u679c\u00a0p\u00a0\u8d8b\u8fd1\u4e8e1&#xff0c;-log(p)\u00a0\u5c31\u8d8b\u8fd1\u4e8e0&#xff0c;\u635f\u5931\u5f88\u5c0f\u3002\u5982\u679c\u6a21\u578b\u9519\u8bef\u5730\u9884\u6d4b\u00a0p\u00a0\u8d8b\u8fd1\u4e8e0&#xff0c;-log(p)\u00a0\u4f1a\u8d8b\u8fd1\u4e8e\u65e0\u7a77\u5927&#xff0c;\u7ed9\u4e88\u5de8\u5927\u7684\u60e9\u7f5a\u3002<\/li>\n<li>\u5f53\u771f\u5b9e\u6807\u7b7e\u662f0\u65f6&#xff0c;\u60c5\u51b5\u6b63\u597d\u76f8\u53cd\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u5206\u6bb5\u51fd\u6570\u53ef\u4ee5\u4f18\u96c5\u5730\u5199\u6210\u4e00\u4e2a\u7edf\u4e00\u7684\u5f0f\u5b50&#xff1a;\u00a0Loss &#061; -[y * log(p) &#043; (1 &#8211; y) * log(1 &#8211; p)]\u00a0\u6574\u4e2a\u8bad\u7ec3\u96c6\u7684\u603b\u635f\u5931\u5c31\u662f\u6240\u6709\u6837\u672c\u635f\u5931\u7684\u5e73\u5747\u503c\u3002\u6a21\u578b\u8bad\u7ec3\u7684\u76ee\u6807&#xff0c;\u5c31\u662f\u627e\u5230\u4e00\u7ec4\u00a0w\u00a0\u548c\u00a0b&#xff0c;\u4f7f\u5f97\u8fd9\u4e2a\u603b\u635f\u5931\u6700\u5c0f\u3002<\/p>\n<h5>5.1.3 Scikit-learn\u5b9e\u6218\u4e0e\u6b63\u5219\u5316<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0\u5728Scikit-learn\u4e2d&#xff0c;\u4f7f\u7528\u903b\u8f91\u56de\u5f52\u975e\u5e38\u7b80\u5355\u3002\u6211\u4eec\u5c06\u4ee5\u4e00\u4e2a\u6807\u51c6\u6d41\u7a0b\u6765\u5c55\u793a\u5176\u5e94\u7528&#xff0c;\u8fd9\u4e2a\u6d41\u7a0b\u4e5f\u9002\u7528\u4e8e\u540e\u7eed\u5c06\u8981\u5b66\u4e60\u7684\u5927\u591a\u6570\u6a21\u578b\u3002<\/p>\n<p># \u5bfc\u5165\u5fc5\u8981\u7684\u5e93<br \/>\nfrom sklearn.model_selection import train_test_split, GridSearchCV<br \/>\nfrom sklearn.linear_model import LogisticRegression<br \/>\nfrom sklearn.metrics import classification_report, confusion_matrix<br \/>\nfrom sklearn.preprocessing import StandardScaler<br \/>\nimport pandas as pd<br \/>\nimport seaborn as sns<br \/>\nimport numpy as np<\/p>\n<p># &#8212; \u51c6\u5907\u6570\u636e (\u5047\u8bbe\u4f7f\u7528\u6cf0\u5766\u5c3c\u514b\u6570\u636e\u96c6) &#8212;<br \/>\n# \u4e3a\u4e86\u4ee3\u7801\u80fd\u72ec\u7acb\u8fd0\u884c&#xff0c;\u6211\u4eec\u5feb\u901f\u8fdb\u884c\u4e00\u6b21\u6781\u7b80\u7684\u6570\u636e\u9884\u5904\u7406<br \/>\ndf &#061; sns.load_dataset(&#039;titanic&#039;)<br \/>\ndf.drop([&#039;deck&#039;, &#039;embark_town&#039;, &#039;alive&#039;, &#039;who&#039;, &#039;adult_male&#039;, &#039;class&#039;], axis&#061;1, inplace&#061;True)<br \/>\ndf[&#039;age&#039;].fillna(df[&#039;age&#039;].median(), inplace&#061;True)<br \/>\ndf[&#039;embarked&#039;].fillna(df[&#039;embarked&#039;].mode()[0], inplace&#061;True)<br \/>\ndf &#061; pd.get_dummies(df, columns&#061;[&#039;sex&#039;, &#039;embarked&#039;], drop_first&#061;True)<br \/>\ndf.drop(&#039;name&#039;, axis&#061;1, inplace&#061;True) # \u540d\u5b57\u6682\u65f6\u4e0d\u7528<br \/>\ndf.drop(&#039;ticket&#039;, axis&#061;1, inplace&#061;True) # \u7968\u53f7\u6682\u65f6\u4e0d\u7528<\/p>\n<p>X &#061; df.drop(&#039;survived&#039;, axis&#061;1)<br \/>\ny &#061; df[&#039;survived&#039;]<\/p>\n<p># 1. \u5212\u5206\u6570\u636e<br \/>\n# stratify&#061;y \u786e\u4fdd\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u4e2d&#xff0c;\u76ee\u6807\u53d8\u91cfy\u7684\u7c7b\u522b\u6bd4\u4f8b\u4e0e\u539f\u59cb\u6570\u636e\u4e00\u81f4&#xff0c;\u8fd9\u5728\u5206\u7c7b\u95ee\u9898\u4e2d\u5f88\u91cd\u8981<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.3, random_state&#061;42, stratify&#061;y)<\/p>\n<p># 2. \u7279\u5f81\u7f29\u653e (\u5bf9\u4e8e\u903b\u8f91\u56de\u5f52&#xff0c;\u7279\u522b\u662f\u5e26\u6b63\u5219\u5316\u7684&#xff0c;\u8fd9\u662f\u4e2a\u597d\u4e60\u60ef)<br \/>\nscaler &#061; StandardScaler()<br \/>\nX_train_scaled &#061; scaler.fit_transform(X_train)<br \/>\nX_test_scaled &#061; scaler.transform(X_test)<\/p>\n<p># 3. \u521d\u59cb\u5316\u5e76\u8bad\u7ec3\u6a21\u578b<br \/>\n# penalty&#061;&#039;l2&#039;\u8868\u793a\u4f7f\u7528L2\u6b63\u5219\u5316&#xff0c;C\u662f\u6b63\u5219\u5316\u5f3a\u5ea6\u7684\u5012\u6570<br \/>\n# solver&#061;&#039;liblinear&#039; \u662f\u4e00\u4e2a\u9002\u7528\u4e8e\u5c0f\u6570\u636e\u96c6\u7684\u4f18\u79c0\u6c42\u89e3\u5668<br \/>\nmodel &#061; LogisticRegression(penalty&#061;&#039;l2&#039;, C&#061;1.0, solver&#061;&#039;liblinear&#039;, random_state&#061;42)<br \/>\nmodel.fit(X_train_scaled, y_train)<\/p>\n<p># 4. \u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ny_pred &#061; model.predict(X_test_scaled)<br \/>\nprint(&#034;&#8212; \u903b\u8f91\u56de\u5f52\u57fa\u7840\u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(&#034;\u6df7\u6dc6\u77e9\u9635:\\\\n&#034;, confusion_matrix(y_test, y_pred))<br \/>\nprint(&#034;\\\\n\u5206\u7c7b\u62a5\u544a:\\\\n&#034;, classification_report(y_test, y_pred))<\/p>\n<p># \u67e5\u770b\u6a21\u578b\u5b66\u4e60\u5230\u7684\u7cfb\u6570<br \/>\n# feature_names &#061; X.columns<br \/>\n# coefs &#061; pd.Series(model.coef_[0], index&#061;feature_names).sort_values()<br \/>\n# print(&#034;\\\\n\u6a21\u578b\u7cfb\u6570:\\\\n&#034;, coefs)<\/p>\n<p>\u6b63\u5219\u5316\u53c2\u6570&#xff08;C&#xff09;\u00a0\u903b\u8f91\u56de\u5f52\u5f88\u5bb9\u6613\u8fc7\u62df\u5408&#xff0c;\u7279\u522b\u662f\u5f53\u7279\u5f81\u6570\u91cf\u5f88\u591a\u65f6\u3002\u4e3a\u4e86\u5bf9\u6297\u8fc7\u62df\u5408&#xff0c;\u6211\u4eec\u5f15\u5165\u6b63\u5219\u5316\u3002LogisticRegression\u7c7b\u4e2d\u6700\u5173\u952e\u7684\u8d85\u53c2\u6570\u5c31\u662fC\u548cpenalty\u3002<\/p>\n<ul>\n<li>penalty&#xff1a;\u6307\u5b9a\u4f7f\u7528\u54ea\u79cd\u6b63\u5219\u5316&#xff0c;\u901a\u5e38\u662f&#039;l1&#039;\u6216&#039;l2&#039;\u3002\n<ul>\n<li>L2\u6b63\u5219\u5316&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u60e9\u7f5a\u90a3\u4e9b\u503c\u5f88\u5927\u7684\u6743\u91cd&#xff0c;\u4f7f\u5f97\u6240\u6709\u6743\u91cd\u90fd\u8d8b\u5411\u4e8e\u53d8\u5c0f&#xff0c;\u4f46\u4e0d\u4f1a\u53d8\u4e3a0\u3002\u5b83\u8ba9\u6a21\u578b\u7684\u51b3\u7b56\u8fb9\u754c\u66f4\u5e73\u6ed1\u3002<\/li>\n<li>L1\u6b63\u5219\u5316&#xff1a;\u540c\u6837\u60e9\u7f5a\u5927\u6743\u91cd&#xff0c;\u4f46\u5b83\u6709\u4e00\u4e2a\u7279\u6027&#xff0c;\u5c31\u662f\u80fd\u5c06\u4e00\u4e9b\u4e0d\u91cd\u8981\u7684\u7279\u5f81\u7684\u6743\u91cd\u76f4\u63a5\u60e9\u7f5a\u4e3a0&#xff0c;\u4ece\u800c\u5b9e\u73b0\u7279\u5f81\u9009\u62e9\u3002<\/li>\n<\/ul>\n<\/li>\n<li>C&#xff1a;\u6b63\u5219\u5316\u5f3a\u5ea6\u7684\u5012\u6570\u3002\u5b83\u662f\u4e00\u4e2a\u6b63\u6d6e\u70b9\u6570\u3002\n<ul>\n<li>C\u503c\u8d8a\u5c0f&#xff0c;\u4ee3\u8868\u6b63\u5219\u5316\u60e9\u7f5a\u8d8a\u5f3a&#xff0c;\u6a21\u578b\u4f1a\u66f4\u7b80\u5355&#xff0c;\u6709\u52a9\u4e8e\u9632\u6b62\u8fc7\u62df\u5408&#xff08;\u589e\u52a0\u504f\u5dee&#xff0c;\u964d\u4f4e\u65b9\u5dee&#xff09;\u3002<\/li>\n<li>C\u503c\u8d8a\u5927&#xff0c;\u4ee3\u8868\u6b63\u5219\u5316\u60e9\u7f5a\u8d8a\u5f31&#xff0c;\u6a21\u578b\u4f1a\u66f4\u52aa\u529b\u5730\u53bb\u62df\u5408\u8bad\u7ec3\u6570\u636e&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u8fc7\u62df\u5408&#xff08;\u964d\u4f4e\u504f\u5dee&#xff0c;\u589e\u52a0\u65b9\u5dee&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>C\u662f\u6211\u4eec\u9700\u8981\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u6765\u8c03\u4f18\u7684\u6700\u91cd\u8981\u7684\u8d85\u53c2\u6570\u3002\u4e0b\u9762\u6211\u4eec\u4f7f\u7528GridSearchCV\u6765\u5bfb\u627e\u6700\u4f18\u7684C\u503c\u3002<\/p>\n<p># &#8212; \u4f7f\u7528GridSearchCV\u8fdb\u884c\u8d85\u53c2\u6570\u8c03\u4f18 &#8212;<br \/>\nparam_grid &#061; {&#039;C&#039;: [0.001, 0.01, 0.1, 1, 10, 100]}<br \/>\ngrid_search &#061; GridSearchCV(LogisticRegression(penalty&#061;&#039;l2&#039;, solver&#061;&#039;liblinear&#039;, random_state&#061;42),<br \/>\n                           param_grid, cv&#061;5, scoring&#061;&#039;accuracy&#039;)<br \/>\ngrid_search.fit(X_train_scaled, y_train)<\/p>\n<p>print(&#034;\\\\n&#8212; \u903b\u8f91\u56de\u5f52\u8d85\u53c2\u6570\u8c03\u4f18 &#8212;&#034;)<br \/>\nprint(&#034;\u6700\u4f73\u8d85\u53c2\u6570:&#034;, grid_search.best_params_)<br \/>\nprint(&#034;\u4ea4\u53c9\u9a8c\u8bc1\u6700\u4f73\u5f97\u5206:&#034;, grid_search.best_score_)<\/p>\n<p># \u4f7f\u7528\u6700\u4f73\u6a21\u578b\u8fdb\u884c\u6700\u7ec8\u8bc4\u4f30<br \/>\nbest_model &#061; grid_search.best_estimator_<br \/>\ny_pred_best &#061; best_model.predict(X_test_scaled)<br \/>\nprint(&#034;\\\\n\u6700\u4f73\u6a21\u578b\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u5206\u7c7b\u62a5\u544a:\\\\n&#034;, classification_report(y_test, y_pred_best))<\/p>\n<p>\u4f18\u7f3a\u70b9\u4e0e\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<li>\u7b80\u5355\u5feb\u901f&#xff1a;\u8bad\u7ec3\u901f\u5ea6\u5feb&#xff0c;\u8ba1\u7b97\u6210\u672c\u4f4e&#xff0c;\u6613\u4e8e\u5b9e\u73b0\u3002<\/li>\n<li>\u53ef\u89e3\u91ca\u6027\u5f3a&#xff1a;\u53ef\u4ee5\u67e5\u770b\u6bcf\u4e2a\u7279\u5f81\u7684\u6743\u91cdcoef_&#xff0c;\u7406\u89e3\u7279\u5f81\u5bf9\u7ed3\u679c\u7684\u5f71\u54cd\u65b9\u5411\u548c\u5927\u5c0f&#xff0c;\u4fbf\u4e8e\u5411\u4e1a\u52a1\u65b9\u89e3\u91ca\u3002<\/li>\n<li>\u8f93\u51fa\u6982\u7387&#xff1a;\u7ed3\u679c\u4e3a\u6982\u7387&#xff0c;\u800c\u4e0d\u4ec5\u4ec5\u662f\u7c7b\u522b&#xff0c;\u8fd9\u5728\u5f88\u591a\u573a\u666f\u4e0b&#xff08;\u5982\u98ce\u9669\u8bc4\u4f30&#xff09;\u975e\u5e38\u6709\u7528\u3002<\/li>\n<li>\u5e94\u7528\u5e7f\u6cdb&#xff1a;\u662f\u8bb8\u591a\u5de5\u4e1a\u754c\u5e94\u7528&#xff08;\u5982\u5e7f\u544a\u70b9\u51fb\u7387\u9884\u6d4b\u3001\u91d1\u878d\u98ce\u63a7&#xff09;\u7684\u57fa\u77f3\u548c\u9996\u9009\u57fa\u7ebf\u6a21\u578b\u3002<\/li>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<li>\u7ebf\u6027\u6a21\u578b&#xff1a;\u6a21\u578b\u5047\u8bbe\u662f\u7ebf\u6027\u7684&#xff0c;\u5bb9\u6613\u6b20\u62df\u5408&#xff0c;\u65e0\u6cd5\u76f4\u63a5\u6355\u6349\u6570\u636e\u4e2d\u7684\u975e\u7ebf\u6027\u5173\u7cfb\u3002<\/li>\n<li>\u5bf9\u7279\u5f81\u5de5\u7a0b\u4f9d\u8d56\u9ad8&#xff1a;\u9700\u8981\u624b\u52a8\u521b\u9020\u7279\u5f81&#xff08;\u5982\u591a\u9879\u5f0f\u7279\u5f81&#xff09;\u6765\u5e2e\u52a9\u6a21\u578b\u5b66\u4e60\u975e\u7ebf\u6027\u3002<\/li>\n<li>\u5bf9\u591a\u91cd\u5171\u7ebf\u6027\u654f\u611f&#xff1a;\u5982\u679c\u7279\u5f81\u4e4b\u95f4\u9ad8\u5ea6\u76f8\u5173&#xff0c;\u6a21\u578b\u6743\u91cd\u7684\u89e3\u91ca\u6027\u4f1a\u4e0b\u964d\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u4f5c\u4e3a\u4efb\u4f55\u5206\u7c7b\u95ee\u9898\u7684\u9996\u9009\u57fa\u7ebf\u6a21\u578b&#xff08;Baseline Model&#xff09;\u3002\u5728\u5c1d\u8bd5\u590d\u6742\u6a21\u578b\u524d&#xff0c;\u5148\u7528\u903b\u8f91\u56de\u5f52\u8dd1\u4e00\u4e2a\u7ed3\u679c&#xff0c;\u53ef\u4ee5\u5e2e\u4f60\u5224\u65ad\u95ee\u9898\u7684\u96be\u5ea6&#xff0c;\u5e76\u4e3a\u540e\u7eed\u4f18\u5316\u63d0\u4f9b\u4e00\u4e2a\u6bd4\u8f83\u7684\u57fa\u51c6\u3002<\/li>\n<li>\u5f53\u9700\u8981\u4e00\u4e2a\u53ef\u89e3\u91ca\u7684\u6a21\u578b\u65f6\u3002<\/li>\n<li>\u5f53\u9700\u8981\u9884\u6d4b\u6982\u7387\u65f6\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u89c4\u6a21\u7a00\u758f\u6570\u636e&#xff08;\u5982\u6587\u672c\u5206\u7c7b\u540e\u7684\u8bcd\u888b\u6a21\u578b&#xff09;&#xff0c;\u903b\u8f91\u56de\u5f52\u914d\u5408L1\u6b63\u5219\u5316\u5e38\u5e38\u8868\u73b0\u51fa\u8272\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>5.2 K-\u8fd1\u90bb&#xff08;KNN&#xff09;&#xff1a;\u201c\u7269\u4ee5\u7c7b\u805a&#xff0c;\u4eba\u4ee5\u7fa4\u5206\u201d\u7684\u6734\u7d20\u54f2\u5b66<\/h4>\n<p>K-\u8fd1\u90bb&#xff08;K-Nearest Neighbors, KNN&#xff09;\u7b97\u6cd5\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u6700\u7b80\u5355\u3001\u6700\u76f4\u89c2\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u5b8c\u7f8e\u5730\u8be0\u91ca\u4e86\u4e2d\u56fd\u7684\u4e00\u53e5\u53e4\u8bdd&#xff1a;\u201c\u7269\u4ee5\u7c7b\u805a&#xff0c;\u4eba\u4ee5\u7fa4\u5206\u201d\u3002\u8981\u5224\u65ad\u4e00\u4e2a\u672a\u77e5\u6837\u672c\u7684\u7c7b\u522b&#xff0c;\u53ea\u9700\u770b\u770b\u5b83\u5728\u7279\u5f81\u7a7a\u95f4\u4e2d\u7684\u201c\u90bb\u5c45\u201d\u4eec\u90fd\u5c5e\u4e8e\u54ea\u4e2a\u7c7b\u522b\u5373\u53ef\u3002<\/p>\n<h5>5.2.1 \u7b97\u6cd5\u6838\u5fc3\u601d\u60f3&#xff1a;\u8fd1\u6731\u8005\u8d64&#xff0c;\u8fd1\u58a8\u8005\u9ed1<\/h5>\n<p>\u201c\u61d2\u60f0\u5b66\u4e60\u201d\u7684\u4ee3\u8868\u00a0KNN\u662f\u4e00\u79cd**\u61d2\u60f0\u5b66\u4e60&#xff08;Lazy Learning&#xff09;\u6216\u79f0\u57fa\u4e8e\u5b9e\u4f8b\u7684\u5b66\u4e60&#xff08;Instance-based Learning&#xff09;**\u7b97\u6cd5\u3002\u5b83\u4e0e\u5176\u4ed6\u6211\u4eec\u5373\u5c06\u5b66\u4e60\u7684\u7b97\u6cd5&#xff08;\u5982\u903b\u8f91\u56de\u5f52\u3001SVM&#xff09;\u6709\u4e00\u4e2a\u6839\u672c\u533a\u522b&#xff1a;<\/p>\n<ul>\n<li>\u5b83\u6ca1\u6709\u4f20\u7edf\u610f\u4e49\u4e0a\u7684\u201c\u8bad\u7ec3\u201d\u8fc7\u7a0b\u3002\u6240\u8c13\u7684\u201c\u8bad\u7ec3\u201d&#xff0c;\u4ec5\u4ec5\u662f\u628a\u6240\u6709\u8bad\u7ec3\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u800c\u5df2\u3002\u5b83\u4e0d\u4f1a\u4ece\u6570\u636e\u4e2d\u5b66\u4e60\u4e00\u4e2a\u5224\u522b\u51fd\u6570\u6216\u6a21\u578b\u53c2\u6570\u3002<\/li>\n<li>\u771f\u6b63\u7684\u8ba1\u7b97\u53d1\u751f\u5728\u201c\u9884\u6d4b\u201d\u9636\u6bb5\u3002\u5f53\u4e00\u4e2a\u65b0\u6837\u672c\u9700\u8981\u88ab\u9884\u6d4b\u65f6&#xff0c;KNN\u624d\u4f1a\u5f00\u59cb\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u4e09\u4e2a\u6838\u5fc3\u8981\u7d20\u00a0KNN\u7684\u9884\u6d4b\u8fc7\u7a0b\u7531\u4e09\u4e2a\u6838\u5fc3\u8981\u7d20\u51b3\u5b9a&#xff1a;<\/p>\n<li>K\u503c\u7684\u9009\u62e9&#xff1a;\u6211\u4eec\u8981\u770b\u65b0\u6837\u672c\u5468\u56f4\u7684\u591a\u5c11\u4e2a\u201c\u90bb\u5c45\u201d\u3002K\u662f\u4e00\u4e2a\u6b63\u6574\u6570\u3002<\/li>\n<li>\u8ddd\u79bb\u5ea6\u91cf&#xff1a;\u6211\u4eec\u5982\u4f55\u5b9a\u4e49\u548c\u8ba1\u7b97\u6837\u672c\u4e4b\u95f4\u7684\u201c\u8fdc\u8fd1\u201d\u3002<\/li>\n<li>\u51b3\u7b56\u89c4\u5219&#xff1a;\u6839\u636eK\u4e2a\u90bb\u5c45\u7684\u7c7b\u522b&#xff0c;\u5982\u4f55\u505a\u51fa\u6700\u7ec8\u7684\u5224\u51b3\u3002\u6700\u5e38\u89c1\u7684\u662f\u591a\u6570\u8868\u51b3&#xff08;Majority Voting&#xff09;\u3002<\/li>\n<p>\u9884\u6d4b\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u8ba1\u7b97\u672a\u77e5\u6837\u672c\u4e0e\u8bad\u7ec3\u96c6\u4e2d\u6bcf\u4e00\u4e2a\u6837\u672c\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002<\/li>\n<li>\u627e\u51fa\u8ddd\u79bb\u6700\u8fd1\u7684K\u4e2a\u8bad\u7ec3\u6837\u672c&#xff08;\u5373K\u4e2a\u201c\u90bb\u5c45\u201d&#xff09;\u3002<\/li>\n<li>\u7edf\u8ba1\u8fd9K\u4e2a\u90bb\u5c45\u7684\u7c7b\u522b\u3002<\/li>\n<li>\u5c06\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u90a3\u4e2a\u7c7b\u522b&#xff0c;\u4f5c\u4e3a\u672a\u77e5\u6837\u672c\u7684\u9884\u6d4b\u7ed3\u679c\u3002<\/li>\n<h5>5.2.2 \u8ddd\u79bb\u7684\u5ea6\u91cf\u4e0eK\u503c\u7684\u9009\u62e9<\/h5>\n<p>\u5e38\u89c1\u7684\u8ddd\u79bb\u516c\u5f0f\u00a0\u8ddd\u79bb\u5ea6\u91cf\u662fKNN\u7684\u57fa\u77f3\u3002\u6700\u5e38\u7528\u7684\u8ddd\u79bb\u662f\u6b27\u6c0f\u8ddd\u79bb&#xff08;Euclidean Distance&#xff09;&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u521d\u4e2d\u5c31\u5b66\u8fc7\u7684\u4e24\u70b9\u95f4\u76f4\u7ebf\u8ddd\u79bb\u516c\u5f0f\u3002 \u5bf9\u4e8e\u4e24\u4e2an\u7ef4\u5411\u91cf\u00a0x\u00a0\u548c\u00a0y&#xff1a;\u00a0d(x, y) &#061; sqrt(\u03a3(x\u1d62 &#8211; y\u1d62)\u00b2)<\/p>\n<p>\u6b64\u5916&#xff0c;\u8fd8\u6709\u5176\u4ed6\u8ddd\u79bb\u5ea6\u91cf\u65b9\u5f0f&#xff0c;\u5982&#xff1a;<\/p>\n<ul>\n<li>\u66fc\u54c8\u987f\u8ddd\u79bb&#xff08;Manhattan Distance&#xff09;&#xff1a;d(x, y) &#061; \u03a3|x\u1d62 &#8211; y\u1d62|&#xff0c;\u60f3\u8c61\u5728\u57ce\u5e02\u8857\u533a\u4e2d\u53ea\u80fd\u6cbf\u683c\u7ebf\u884c\u8d70\u65f6\u7684\u8ddd\u79bb\u3002<\/li>\n<li>\u95f5\u53ef\u592b\u65af\u57fa\u8ddd\u79bb&#xff08;Minkowski Distance&#xff09;&#xff1a;\u662f\u6b27\u6c0f\u8ddd\u79bb\u548c\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u63a8\u5e7f\u3002<\/li>\n<\/ul>\n<p>K\u503c\u9009\u62e9\u7684\u827a\u672f\u00a0K\u503c\u7684\u9009\u62e9\u5bf9KNN\u7684\u6027\u80fd\u81f3\u5173\u91cd\u8981&#xff0c;\u5b83\u76f4\u63a5\u5f71\u54cd\u7740\u6a21\u578b\u7684\u504f\u5dee\u548c\u65b9\u5dee\u3002<\/p>\n<ul>\n<li>\u8f83\u5c0f\u7684K\u503c&#xff08;\u5982 K&#061;1&#xff09;&#xff1a;\n<ul>\n<li>\u6a21\u578b\u975e\u5e38\u201c\u654f\u611f\u201d&#xff0c;\u5bb9\u6613\u53d7\u5230\u566a\u58f0\u70b9\u7684\u5f71\u54cd\u3002<\/li>\n<li>\u51b3\u7b56\u8fb9\u754c\u4f1a\u53d8\u5f97\u975e\u5e38\u590d\u6742\u3001\u4e0d\u89c4\u5219\u3002<\/li>\n<li>\u8fd9\u4f1a\u5bfc\u81f4\u4f4e\u504f\u5dee&#xff0c;\u4f46\u9ad8\u65b9\u5dee&#xff0c;\u5bb9\u6613\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u8f83\u5927\u7684K\u503c&#xff08;\u5982 K&#061;N&#xff0c;N\u4e3a\u8bad\u7ec3\u6837\u672c\u603b\u6570&#xff09;&#xff1a;\n<ul>\n<li>\u6a21\u578b\u975e\u5e38\u201c\u8fdf\u949d\u201d&#xff0c;\u65e0\u8bba\u65b0\u6837\u672c\u5728\u54ea\u91cc&#xff0c;\u90fd\u4f1a\u88ab\u9884\u6d4b\u4e3a\u8bad\u7ec3\u96c6\u4e2d\u6570\u91cf\u6700\u591a\u7684\u90a3\u4e2a\u7c7b\u522b\u3002<\/li>\n<li>\u51b3\u7b56\u8fb9\u754c\u4f1a\u53d8\u5f97\u975e\u5e38\u5e73\u6ed1\u3002<\/li>\n<li>\u8fd9\u4f1a\u5bfc\u81f4\u9ad8\u504f\u5dee&#xff0c;\u4f46\u4f4e\u65b9\u5dee&#xff0c;\u5bb9\u6613\u6b20\u62df\u5408\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u56e0\u6b64&#xff0c;\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684K\u503c\u662f\u5728\u504f\u5dee\u548c\u65b9\u5dee\u4e4b\u95f4\u505a\u6743\u8861\u3002\u901a\u5e38&#xff0c;\u6211\u4eec\u4f1a\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u6765\u5bfb\u627e\u4e00\u4e2a\u6700\u4f18\u7684K\u503c\u3002\u4e00\u4e2a\u7ecf\u9a8c\u6cd5\u5219\u662f&#xff0c;K\u503c\u901a\u5e38\u9009\u62e9\u4e00\u4e2a\u8f83\u5c0f\u7684\u5947\u6570&#xff08;\u4ee5\u907f\u514d\u6295\u7968\u65f6\u51fa\u73b0\u5e73\u5c40&#xff09;\u3002<\/p>\n<h5>5.2.3 Scikit-learn\u5b9e\u6218\u4e0e\u6570\u636e\u6807\u51c6\u5316\u7684\u91cd\u8981\u6027<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.neighbors import KNeighborsClassifier<\/p>\n<p># \u5047\u8bbeX_train_scaled, X_test_scaled, y_train, y_test\u5df2\u51c6\u5907\u597d<\/p>\n<p># \u521d\u59cb\u5316\u5e76\u8bad\u7ec3\u6a21\u578b (fit\u53ea\u662f\u5b58\u50a8\u6570\u636e)<br \/>\nknn &#061; KNeighborsClassifier(n_neighbors&#061;5) # \u5148\u9009\u62e9\u4e00\u4e2a\u7ecf\u9a8c\u503cK&#061;5<br \/>\nknn.fit(X_train_scaled, y_train)<\/p>\n<p># \u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ny_pred_knn &#061; knn.predict(X_test_scaled)<br \/>\nprint(&#034;&#8212; KNN\u57fa\u7840\u6a21\u578b\u8bc4\u4f30 (K&#061;5) &#8212;&#034;)<br \/>\nprint(classification_report(y_test, y_pred_knn))<\/p>\n<p># \u4f7f\u7528GridSearchCV\u5bfb\u627e\u6700\u4f18K\u503c<br \/>\nparam_grid_knn &#061; {&#039;n_neighbors&#039;: np.arange(1, 31, 2)} # \u5c1d\u8bd51\u523030\u4e4b\u95f4\u7684\u6240\u6709\u5947\u6570<br \/>\ngrid_search_knn &#061; GridSearchCV(KNeighborsClassifier(), param_grid_knn, cv&#061;5, scoring&#061;&#039;accuracy&#039;)<br \/>\ngrid_search_knn.fit(X_train_scaled, y_train)<\/p>\n<p>print(&#034;\\\\n&#8212; KNN\u8d85\u53c2\u6570\u8c03\u4f18 &#8212;&#034;)<br \/>\nprint(&#034;\u6700\u4f73K\u503c:&#034;, grid_search_knn.best_params_)<br \/>\nprint(&#034;\u4ea4\u53c9\u9a8c\u8bc1\u6700\u4f73\u5f97\u5206:&#034;, grid_search_knn.best_score_)<\/p>\n<p>\u6570\u636e\u6807\u51c6\u5316\u7684\u5fc5\u8981\u6027\u00a0\u5bf9\u4e8eKNN\u8fd9\u7c7b\u57fa\u4e8e\u8ddd\u79bb\u5ea6\u91cf\u7684\u6a21\u578b&#xff0c;\u8fdb\u884c\u7279\u5f81\u7f29\u653e&#xff08;\u5982\u6807\u51c6\u5316&#xff09;\u662f\u81f3\u5173\u91cd\u8981\u7684&#xff0c;\u751a\u81f3\u662f\u5f3a\u5236\u6027\u7684\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e2a\u573a\u666f&#xff0c;\u6211\u4eec\u6709\u4e24\u4e2a\u7279\u5f81&#xff1a;\u5e74\u9f84&#xff08;\u8303\u56f420-80&#xff09;\u548c\u85aa\u6c34&#xff08;\u8303\u56f45000-50000&#xff09;\u3002\u5728\u8ba1\u7b97\u6b27\u6c0f\u8ddd\u79bb\u65f6&#xff0c;\u85aa\u6c34\u8fd9\u4e2a\u7279\u5f81\u7684\u6570\u503c\u5dee\u5f02\u4f1a\u8fdc\u8fdc\u5927\u4e8e\u5e74\u9f84\u7684\u5dee\u5f02&#xff0c;\u4ece\u800c\u5728\u8ddd\u79bb\u8ba1\u7b97\u4e2d\u5360\u636e\u7edd\u5bf9\u4e3b\u5bfc\u5730\u4f4d\u3002\u8fd9\u4f1a\u4f7f\u5f97\u5e74\u9f84\u8fd9\u4e2a\u7279\u5f81\u51e0\u4e4e\u4e0d\u8d77\u4f5c\u7528&#xff0c;\u8fd9\u663e\u7136\u662f\u4e0d\u5408\u7406\u7684\u3002<\/p>\n<p>\u901a\u8fc7\u6807\u51c6\u5316&#xff08;StandardScaler&#xff09;&#xff0c;\u6211\u4eec\u5c06\u6240\u6709\u7279\u5f81\u90fd\u8f6c\u6362\u5230\u540c\u4e00\u4e2a\u5c3a\u5ea6\u4e0b&#xff08;\u5747\u503c\u4e3a0&#xff0c;\u6807\u51c6\u5dee\u4e3a1&#xff09;&#xff0c;\u4f7f\u5f97\u6bcf\u4e2a\u7279\u5f81\u5728\u8ddd\u79bb\u8ba1\u7b97\u4e2d\u90fd\u6709\u5e73\u7b49\u201c\u8bdd\u8bed\u6743\u201d\u3002<\/p>\n<p>\u4f18\u7f3a\u70b9\u4e0e\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<li>\u601d\u60f3\u7b80\u5355&#xff0c;\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0\u3002<\/li>\n<li>\u6a21\u578b\u7075\u6d3b&#xff1a;\u53ef\u4ee5\u5b66\u4e60\u4efb\u610f\u590d\u6742\u7684\u51b3\u7b56\u8fb9\u754c\u3002<\/li>\n<li>\u65e0\u9700\u8bad\u7ec3&#xff1a;\u5bf9\u4e8e\u9700\u8981\u5feb\u901f\u4e0a\u7ebf\u3001\u6570\u636e\u4e0d\u65ad\u66f4\u65b0\u7684\u573a\u666f\u6709\u4f18\u52bf\u3002<\/li>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<li>\u8ba1\u7b97\u6210\u672c\u9ad8\u6602&#xff1a;\u9884\u6d4b\u4e00\u4e2a\u65b0\u6837\u672c\u9700\u8981\u4e0e\u6240\u6709\u8bad\u7ec3\u6837\u672c\u8ba1\u7b97\u8ddd\u79bb&#xff0c;\u5f53\u8bad\u7ec3\u96c6\u5f88\u5927\u65f6&#xff0c;\u975e\u5e38\u8017\u65f6\u3002<\/li>\n<li>\u5bf9\u5185\u5b58\u9700\u6c42\u5927&#xff1a;\u9700\u8981\u5b58\u50a8\u6574\u4e2a\u8bad\u7ec3\u96c6\u3002<\/li>\n<li>\u5bf9\u4e0d\u5e73\u8861\u6570\u636e\u654f\u611f&#xff1a;\u6570\u91cf\u591a\u7684\u7c7b\u522b\u5728\u6295\u7968\u4e2d\u5360\u4f18\u52bf\u3002<\/li>\n<li>\u5bf9\u7ef4\u5ea6\u8bc5\u5492\u654f\u611f&#xff1a;\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u6240\u6709\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u90fd\u8d8b\u5411\u4e8e\u53d8\u5f97\u9065\u8fdc\u4e14\u76f8\u8fd1&#xff0c;\u201c\u90bb\u5c45\u201d\u7684\u6982\u5ff5\u53d8\u5f97\u6a21\u7cca\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u5c0f\u5230\u4e2d\u7b49\u89c4\u6a21\u7684\u6570\u636e\u96c6\u3002<\/li>\n<li>\u5f53\u95ee\u9898\u7684\u51b3\u7b56\u8fb9\u754c\u9ad8\u5ea6\u975e\u7ebf\u6027\u65f6\u3002<\/li>\n<li>\u4f5c\u4e3a\u4e00\u79cd\u5feb\u901f\u7684\u57fa\u7ebf\u6a21\u578b\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>5.3 \u652f\u6491\u5411\u91cf\u673a&#xff08;SVM&#xff09;&#xff1a;\u201c\u4e00\u5212\u5f00\u5929\u201d\u7684\u6570\u5b66\u4e4b\u7f8e<\/h4>\n<p>\u652f\u6491\u5411\u91cf\u673a&#xff08;Support Vector Machine, SVM&#xff09;\u662f\u673a\u5668\u5b66\u4e60\u9886\u57df\u6700\u5f3a\u5927\u3001\u6700\u4f18\u96c5\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002\u5b83\u8bde\u751f\u4e8e\u4e0a\u4e16\u7eaa90\u5e74\u4ee3&#xff0c;\u5728\u6df1\u5ea6\u5b66\u4e60\u6d6a\u6f6e\u6765\u4e34\u4e4b\u524d&#xff0c;\u66fe\u4e00\u5ea6\u88ab\u8ba4\u4e3a\u662f\u76d1\u7763\u5b66\u4e60\u4e2d\u6548\u679c\u6700\u597d\u7684\u201c\u5927\u6740\u5668\u201d\u3002SVM\u7684\u6838\u5fc3\u601d\u60f3\u662f\u57fa\u4e8e\u51e0\u4f55\u95f4\u9694&#xff0c;\u5bfb\u627e\u4e00\u4e2a\u201c\u6700\u4f18\u201d\u7684\u51b3\u7b56\u8fb9\u754c\u3002<\/p>\n<h5>5.3.1 \u6838\u5fc3\u601d\u60f3&#xff1a;\u5bfb\u627e\u6700\u5927\u95f4\u9694\u7684\u201c\u6700\u4f18\u201d\u51b3\u7b56\u8fb9\u754c<\/h5>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u7ebf\u6027\u53ef\u5206\u7684\u4e8c\u5206\u7c7b\u95ee\u9898&#xff0c;\u80fd\u5c06\u4e24\u7c7b\u6837\u672c\u5206\u5f00\u7684\u76f4\u7ebf&#xff08;\u6216\u8d85\u5e73\u9762&#xff09;\u6709\u65e0\u6570\u6761\u3002\u903b\u8f91\u56de\u5f52\u4f1a\u627e\u5230\u5176\u4e2d\u4e00\u6761&#xff0c;\u4f46SVM\u8ffd\u6c42\u7684\u662f\u6700\u597d\u7684\u90a3\u4e00\u6761\u3002<\/p>\n<p>\u4ec0\u4e48\u662f\u201c\u6700\u597d\u201d&#xff1f;\u00a0SVM\u8ba4\u4e3a&#xff0c;\u6700\u597d\u7684\u51b3\u7b56\u8fb9\u754c\u5e94\u8be5\u662f\u90a3\u6761\u79bb\u4e24\u8fb9\u6700\u8fd1\u7684\u6837\u672c\u70b9\u6700\u8fdc\u7684\u8fb9\u754c\u3002\u8fd9\u6761\u8fb9\u754c\u5c31\u50cf\u5728\u4e24\u519b\u5bf9\u5792\u7684\u6218\u573a\u4e2d\u592e\u5212\u4e0b\u7684\u4e00\u9053\u201c\u505c\u706b\u7ebf\u201d&#xff0c;\u5b83\u4f7f\u5f97\u53cc\u65b9&#xff08;\u4e0d\u540c\u7c7b\u522b\u7684\u6837\u672c&#xff09;\u90fd\u79bb\u8fd9\u6761\u7ebf\u6709\u5c3d\u53ef\u80fd\u5927\u7684\u201c\u7f13\u51b2\u5730\u5e26\u201d\u3002<\/p>\n<p>\u95f4\u9694&#xff08;Margin&#xff09;\u4e0e\u652f\u6301\u5411\u91cf&#xff08;Support Vectors&#xff09;<\/p>\n<ul>\n<li>\u51b3\u7b56\u8fb9\u754c&#xff1a;\u5c31\u662f\u4e2d\u95f4\u90a3\u6761\u5b9e\u7ebf\u7684\u8d85\u5e73\u9762\u00a0w\u1d40x &#043; b &#061; 0\u3002<\/li>\n<li>\u95f4\u9694&#xff08;Margin&#xff09;&#xff1a;\u662f\u51b3\u7b56\u8fb9\u754c\u4e0e\u4e24\u4fa7\u8ddd\u79bb\u5b83\u6700\u8fd1\u7684\u6837\u672c\u70b9\u4e4b\u95f4\u7684\u5782\u76f4\u8ddd\u79bb\u3002SVM\u7684\u76ee\u6807\u5c31\u662f\u6700\u5927\u5316\u8fd9\u4e2a\u95f4\u9694\u3002<\/li>\n<li>\u652f\u6301\u5411\u91cf&#xff08;Support Vectors&#xff09;&#xff1a;\u90a3\u4e9b\u6070\u597d\u843d\u5728\u95f4\u9694\u8fb9\u754c\u4e0a\u7684\u6837\u672c\u70b9\u3002\u5b83\u4eec\u5c31\u50cf\u652f\u6491\u8d77\u6574\u4e2a\u95f4\u9694\u7684\u201c\u6869\u5b50\u201d\u3002\u4e00\u4e2a\u60ca\u4eba\u7684\u4e8b\u5b9e\u662f&#xff1a;\u6700\u7ec8\u7684\u51b3\u7b56\u8fb9\u754c\u5b8c\u5168\u7531\u8fd9\u4e9b\u652f\u6301\u5411\u91cf\u51b3\u5b9a&#xff0c;\u4e0e\u5176\u4ed6\u6837\u672c\u70b9\u65e0\u5173\u3002\u5373\u4f7f\u79fb\u52a8\u6216\u5220\u9664\u975e\u652f\u6301\u5411\u91cf\u7684\u6837\u672c\u70b9&#xff0c;\u51b3\u7b56\u8fb9\u754c\u4e5f\u4e0d\u4f1a\u6539\u53d8\u3002\u8fd9\u4f7f\u5f97SVM\u975e\u5e38\u9ad8\u6548\u4e14\u9c81\u68d2\u3002<\/li>\n<\/ul>\n<p>\u4ece\u7ebf\u6027\u53ef\u5206\u5230\u7ebf\u6027\u4e0d\u53ef\u5206&#xff1a;\u8f6f\u95f4\u9694&#xff08;Soft Margin&#xff09;\u00a0\u73b0\u5b9e\u4e16\u754c\u7684\u6570\u636e\u5f80\u5f80\u4e0d\u662f\u5b8c\u7f8e\u7ebf\u6027\u53ef\u5206\u7684&#xff0c;\u603b\u4f1a\u6709\u4e00\u4e9b\u566a\u58f0\u70b9\u6216\u201c\u8d8a\u754c\u201d\u7684\u6837\u672c\u3002\u4e3a\u4e86\u5904\u7406\u8fd9\u79cd\u60c5\u51b5&#xff0c;SVM\u5f15\u5165\u4e86**\u8f6f\u95f4\u9694&#xff08;Soft Margin&#xff09;**\u7684\u6982\u5ff5\u3002<\/p>\n<p>\u8f6f\u95f4\u9694\u5141\u8bb8\u4e00\u4e9b\u6837\u672c\u70b9\u201c\u72af\u89c4\u201d&#xff0c;\u5373\u53ef\u4ee5\u5904\u5728\u95f4\u9694\u4e4b\u5185&#xff0c;\u751a\u81f3\u53ef\u4ee5\u88ab\u9519\u8bef\u5206\u7c7b\u3002\u4f46\u8fd9\u79cd\u201c\u72af\u89c4\u201d\u662f\u8981\u4ed8\u51fa\u4ee3\u4ef7\u7684\u3002SVM\u5f15\u5165\u4e86\u4e00\u4e2a\u60e9\u7f5a\u7cfb\u6570\u8d85\u53c2\u6570\u00a0C&#xff1a;<\/p>\n<ul>\n<li>C\u00a0\u63a7\u5236\u4e86\u6211\u4eec\u5bf9\u201c\u72af\u89c4\u201d\u7684\u5bb9\u5fcd\u7a0b\u5ea6\u3002<\/li>\n<li>\u8f83\u5927\u7684C\u503c&#xff1a;\u4ee3\u8868\u5bf9\u72af\u89c4\u7684\u60e9\u7f5a\u5f88\u91cd&#xff0c;SVM\u4f1a\u52aa\u529b\u5c06\u6240\u6709\u6837\u672c\u90fd\u6b63\u786e\u5206\u7c7b&#xff0c;\u8fd9\u53ef\u80fd\u5bfc\u81f4\u95f4\u9694\u53d8\u7a84&#xff0c;\u6a21\u578b\u53d8\u5f97\u590d\u6742&#xff0c;\u5bb9\u6613\u8fc7\u62df\u5408\u3002<\/li>\n<li>\u8f83\u5c0f\u7684C\u503c&#xff1a;\u4ee3\u8868\u5bf9\u72af\u89c4\u6bd4\u8f83\u5bbd\u5bb9&#xff0c;\u5141\u8bb8\u4e00\u4e9b\u9519\u8bef\u5206\u7c7b&#xff0c;\u4ee5\u6362\u53d6\u4e00\u4e2a\u66f4\u5bbd\u7684\u95f4\u9694\u3002\u8fd9\u4f1a\u4f7f\u6a21\u578b\u66f4\u7b80\u5355&#xff0c;\u6cdb\u5316\u80fd\u529b\u53ef\u80fd\u66f4\u5f3a&#xff0c;\u4f46\u53ef\u80fd\u6b20\u62df\u5408\u3002<\/li>\n<\/ul>\n<p>C\u662f\u5728\u504f\u5dee\u548c\u65b9\u5dee\u4e4b\u95f4\u8fdb\u884c\u6743\u8861\u7684\u5173\u952e\u3002<\/p>\n<h5>5.3.2 \u6838\u6280\u5de7&#xff08;Kernel Trick&#xff09;&#xff1a;\u4f4e\u7ef4\u5230\u9ad8\u7ef4\u7684\u201c\u4e7e\u5764\u5927\u632a\u79fb\u201d<\/h5>\n<p>SVM\u6700\u5f3a\u5927\u7684\u6b66\u5668\u662f\u6838\u6280\u5de7&#xff08;Kernel Trick&#xff09;\u3002\u5bf9\u4e8e\u90a3\u4e9b\u5728\u539f\u59cb\u7279\u5f81\u7a7a\u95f4\u4e2d\u7ebf\u6027\u4e0d\u53ef\u5206\u7684\u6570\u636e&#xff08;\u4f8b\u5982&#xff0c;\u4e00\u4e2a\u73af\u5f62\u5206\u5e03&#xff09;&#xff0c;SVM\u53ef\u4ee5\u901a\u8fc7\u6838\u6280\u5de7&#xff0c;\u5de7\u5999\u5730\u5c06\u5176\u6620\u5c04\u5230\u4e00\u4e2a\u66f4\u9ad8\u7ef4\u5ea6\u7684\u7a7a\u95f4&#xff0c;\u4f7f\u5f97\u6570\u636e\u5728\u8fd9\u4e2a\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u53d8\u5f97\u7ebf\u6027\u53ef\u5206\u3002<\/p>\n<p>\u6838\u51fd\u6570\u7684\u9b54\u529b\u00a0\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u6211\u4eec\u628a\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7684\u4e00\u5f20\u7eb8&#xff08;\u6570\u636e&#xff09;&#xff0c;\u901a\u8fc7\u67d0\u79cd\u65b9\u5f0f\u5411\u4e0a\u201c\u5f2f\u66f2\u201d&#xff0c;\u53d8\u6210\u4e00\u4e2a\u4e09\u7ef4\u7684\u7897\u72b6\u3002\u539f\u672c\u5728\u7eb8\u4e0a\u65e0\u6cd5\u7528\u4e00\u6761\u76f4\u7ebf\u5206\u5f00\u7684\u540c\u5fc3\u5706&#xff0c;\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u5c31\u53ef\u4ee5\u7528\u4e00\u4e2a\u6c34\u5e73\u9762\u8f7b\u6613\u5730\u5206\u5f00\u4e86\u3002<\/p>\n<p>\u6838\u51fd\u6570\u7684\u795e\u5947\u4e4b\u5904\u5728\u4e8e&#xff1a;\u5b83\u8ba9\u6211\u4eec\u65e0\u9700\u771f\u6b63\u5730\u53bb\u8ba1\u7b97\u6570\u636e\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u7684\u5750\u6807&#xff0c;\u5c31\u80fd\u5f97\u5230\u6570\u636e\u70b9\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u7684\u5185\u79ef\u7ed3\u679c\u3002\u8fd9\u6781\u5927\u5730\u8282\u7701\u4e86\u8ba1\u7b97\u91cf&#xff0c;\u4f7f\u5f97\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u5bfb\u627e\u51b3\u7b56\u8fb9\u754c\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u6838\u51fd\u6570<\/p>\n<ul>\n<li>\u7ebf\u6027\u6838&#xff08;Linear Kernel&#xff09;&#xff1a;kernel&#061;&#039;linear&#039;\u3002\u5b9e\u9645\u4e0a\u5c31\u662f\u4e0d\u505a\u4efb\u4f55\u6620\u5c04&#xff0c;\u5728\u539f\u59cb\u7a7a\u95f4\u4e2d\u5bfb\u627e\u7ebf\u6027\u8fb9\u754c\u3002<\/li>\n<li>\u591a\u9879\u5f0f\u6838&#xff08;Polynomial Kernel&#xff09;&#xff1a;kernel&#061;&#039;poly&#039;\u3002\u53ef\u4ee5\u5c06\u6570\u636e\u6620\u5c04\u5230\u591a\u9879\u5f0f\u7a7a\u95f4\u3002<\/li>\n<li>\u9ad8\u65af\u5f84\u5411\u57fa\u6838&#xff08;Gaussian Radial Basis Function, RBF&#xff09;&#xff1a;kernel&#061;&#039;rbf&#039;\u3002\u8fd9\u662f\u6700\u5e38\u7528\u3001\u6700\u5f3a\u5927\u7684\u6838\u51fd\u6570\u3002\u5b83\u53ef\u4ee5\u5c06\u6570\u636e\u6620\u5c04\u5230\u65e0\u9650\u7ef4\u7a7a\u95f4&#xff0c;\u80fd\u591f\u5b66\u4e60\u4efb\u610f\u590d\u6742\u7684\u975e\u7ebf\u6027\u51b3\u7b56\u8fb9\u754c\u3002<\/li>\n<\/ul>\n<h5>5.3.3 Scikit-learn\u5b9e\u6218\u4e0e\u5173\u952e\u8d85\u53c2\u6570<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.svm import SVC<\/p>\n<p># \u5047\u8bbeX_train_scaled, X_test_scaled, y_train, y_test\u5df2\u51c6\u5907\u597d<\/p>\n<p># \u521d\u59cb\u5316\u5e76\u8bad\u7ec3\u6a21\u578b (\u4f7f\u7528RBF\u6838)<br \/>\nsvm_model &#061; SVC(kernel&#061;&#039;rbf&#039;, C&#061;1.0, gamma&#061;&#039;scale&#039;, random_state&#061;42)<br \/>\nsvm_model.fit(X_train_scaled, y_train)<\/p>\n<p># \u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ny_pred_svm &#061; svm_model.predict(X_test_scaled)<br \/>\nprint(&#034;&#8212; SVM\u57fa\u7840\u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(classification_report(y_test, y_pred_svm))<\/p>\n<p># \u4f7f\u7528GridSearchCV\u8fdb\u884c\u8d85\u53c2\u6570\u8c03\u4f18<br \/>\nparam_grid_svm &#061; {<br \/>\n    &#039;C&#039;: [0.1, 1, 10],<br \/>\n    &#039;gamma&#039;: [&#039;scale&#039;, 0.1, 0.01],<br \/>\n    &#039;kernel&#039;: [&#039;rbf&#039;, &#039;linear&#039;]<br \/>\n}<br \/>\ngrid_search_svm &#061; GridSearchCV(SVC(random_state&#061;42), param_grid_svm, cv&#061;3, scoring&#061;&#039;accuracy&#039;) # cv&#061;3\u4ee5\u52a0\u5feb\u901f\u5ea6<br \/>\ngrid_search_svm.fit(X_train_scaled, y_train)<\/p>\n<p>print(&#034;\\\\n&#8212; SVM\u8d85\u53c2\u6570\u8c03\u4f18 &#8212;&#034;)<br \/>\nprint(&#034;\u6700\u4f73\u8d85\u53c2\u6570:&#034;, grid_search_svm.best_params_)<br \/>\nprint(&#034;\u4ea4\u53c9\u9a8c\u8bc1\u6700\u4f73\u5f97\u5206:&#034;, grid_search_svm.best_score_)<\/p>\n<p>\u5173\u952e\u8d85\u53c2\u6570\u00a0\u5bf9\u4e8e\u4f7f\u7528RBF\u6838\u7684SVM&#xff0c;\u6709\u4e24\u4e2a\u81f3\u5173\u91cd\u8981\u7684\u8d85\u53c2\u6570\u9700\u8981\u8c03\u4f18&#xff1a;<\/p>\n<li>C\u00a0(\u60e9\u7f5a\u7cfb\u6570)&#xff1a;\u5982\u524d\u6240\u8ff0&#xff0c;\u63a7\u5236\u7740\u5bf9\u9519\u8bef\u5206\u7c7b\u7684\u60e9\u7f5a\u529b\u5ea6&#xff0c;\u6743\u8861\u7740\u95f4\u9694\u5bbd\u5ea6\u548c\u5206\u7c7b\u51c6\u786e\u6027\u3002<\/li>\n<li>gamma\u00a0(\u6838\u7cfb\u6570)&#xff1a;\u5b83\u5b9a\u4e49\u4e86\u5355\u4e2a\u8bad\u7ec3\u6837\u672c\u7684\u5f71\u54cd\u8303\u56f4\u3002\n<ul>\n<li>\u8f83\u5c0f\u7684gamma\u503c&#xff1a;\u610f\u5473\u7740\u5f71\u54cd\u8303\u56f4\u5927&#xff0c;\u51b3\u7b56\u8fb9\u754c\u4f1a\u975e\u5e38\u5e73\u6ed1&#xff0c;\u6a21\u578b\u8d8b\u5411\u4e8e\u6b20\u62df\u5408&#xff08;\u9ad8\u504f\u5dee&#xff09;\u3002<\/li>\n<li>\u8f83\u5927\u7684gamma\u503c&#xff1a;\u610f\u5473\u7740\u5f71\u54cd\u8303\u56f4\u5c0f&#xff0c;\u53ea\u6709\u9760\u8fd1\u7684\u6837\u672c\u70b9\u624d\u4f1a\u5bf9\u51b3\u7b56\u8fb9\u754c\u4ea7\u751f\u5f71\u54cd&#xff0c;\u8fd9\u4f1a\u5bfc\u81f4\u51b3\u7b56\u8fb9\u754c\u975e\u5e38\u66f2\u6298\u3001\u590d\u6742&#xff0c;\u6a21\u578b\u8d8b\u5411\u4e8e\u8fc7\u62df\u5408&#xff08;\u9ad8\u65b9\u5dee&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<p>C\u548cgamma\u901a\u5e38\u9700\u8981\u4e00\u8d77\u8fdb\u884c\u7f51\u683c\u641c\u7d22\u6765\u5bfb\u627e\u6700\u4f18\u7ec4\u5408\u3002<\/p>\n<p>\u4f18\u7f3a\u70b9\u4e0e\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<li>\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u975e\u5e38\u6709\u6548&#xff0c;\u751a\u81f3\u5f53\u7ef4\u5ea6\u6570\u5927\u4e8e\u6837\u672c\u6570\u65f6\u3002<\/li>\n<li>\u5185\u5b58\u6548\u7387\u9ad8&#xff0c;\u56e0\u4e3a\u5b83\u53ea\u4f7f\u7528\u4e00\u90e8\u5206\u8bad\u7ec3\u70b9&#xff08;\u652f\u6301\u5411\u91cf&#xff09;\u6765\u505a\u51b3\u7b56\u3002<\/li>\n<li>\u975e\u5e38\u901a\u7528&#xff0c;\u901a\u8fc7\u9009\u62e9\u4e0d\u540c\u7684\u6838\u51fd\u6570&#xff0c;\u53ef\u4ee5\u9002\u5e94\u5404\u79cd\u6570\u636e\u548c\u51b3\u7b56\u8fb9\u754c\u3002<\/li>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<li>\u5f53\u6837\u672c\u6570\u91cf\u8fdc\u5927\u4e8e\u7279\u5f81\u6570\u91cf\u65f6&#xff0c;\u6027\u80fd\u548c\u901f\u5ea6\u901a\u5e38\u4e0d\u5982\u4e00\u4e9b\u96c6\u6210\u6a21\u578b&#xff08;\u5982\u968f\u673a\u68ee\u6797&#xff09;\u3002<\/li>\n<li>\u5bf9\u7f3a\u5931\u6570\u636e\u654f\u611f\u3002<\/li>\n<li>\u7ed3\u679c\u4e0d\u6613\u89e3\u91ca&#xff0c;\u7279\u522b\u662f\u4f7f\u7528\u975e\u7ebf\u6027\u6838\u65f6&#xff0c;\u5b83\u4e0d\u50cf\u903b\u8f91\u56de\u5f52\u6216\u51b3\u7b56\u6811\u90a3\u6837\u76f4\u89c2\u3002<\/li>\n<li>\u6ca1\u6709\u76f4\u63a5\u7684\u6982\u7387\u8f93\u51fa&#xff08;\u867d\u7136\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u65b9\u6cd5\u95f4\u63a5\u8ba1\u7b97&#xff09;\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u590d\u6742\u4f46\u4e2d\u5c0f\u578b\u7684\u6570\u636e\u96c6\u3002<\/li>\n<li>\u9ad8\u7ef4\u6570\u636e&#xff0c;\u5982\u56fe\u50cf\u8bc6\u522b\u3001\u6587\u672c\u5206\u7c7b\u3002<\/li>\n<li>\u5f53\u9700\u8981\u4e00\u4e2a\u975e\u7ebf\u6027\u5206\u7c7b\u5668\u65f6&#xff0c;SVM&#xff08;\u7279\u522b\u662fRBF\u6838&#xff09;\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>5.4 \u51b3\u7b56\u6811\u4e0e\u968f\u673a\u68ee\u6797&#xff1a;\u201c\u96c6\u601d\u5e7f\u76ca\u201d\u7684\u96c6\u6210\u667a\u6167<\/h4>\n<p>\u51b3\u7b56\u6811&#xff08;Decision Tree&#xff09;\u662f\u4e00\u79cd\u975e\u5e38\u7b26\u5408\u4eba\u7c7b\u76f4\u89c9\u7684\u5206\u7c7b\u6a21\u578b\u3002\u5b83\u901a\u8fc7\u5b66\u4e60\u4e00\u7cfb\u5217\u201cif-then\u201d\u89c4\u5219&#xff0c;\u6765\u6784\u5efa\u4e00\u4e2a\u6811\u5f62\u7684\u51b3\u7b56\u7ed3\u6784\u3002\u800c\u968f\u673a\u68ee\u6797&#xff08;Random Forest&#xff09;\u5219\u662f\u901a\u8fc7\u201c\u96c6\u4f53\u667a\u6167\u201d&#xff0c;\u5c06\u8bb8\u591a\u68f5\u51b3\u7b56\u6811\u7ec4\u5408\u8d77\u6765&#xff0c;\u5f62\u6210\u4e00\u4e2a\u66f4\u5f3a\u5927\u3001\u66f4\u7a33\u5065\u7684\u6a21\u578b\u3002<\/p>\n<h5>5.4.1 \u51b3\u7b56\u6811&#xff1a;\u50cf\u4eba\u4e00\u6837\u601d\u8003\u7684\u6811\u5f62\u7ed3\u6784<\/h5>\n<p>\u6784\u5efa\u8fc7\u7a0b\u00a0\u51b3\u7b56\u6811\u7684\u6784\u5efa\u662f\u4e00\u4e2a\u9012\u5f52\u7684\u8fc7\u7a0b&#xff0c;\u76ee\u6807\u662f\u751f\u6210\u4e00\u68f5\u6cdb\u5316\u80fd\u529b\u5f3a\u3001\u4e0d\u7eaf\u5ea6\u4f4e\u7684\u6811\u3002<\/p>\n<li>\u9009\u62e9\u6839\u8282\u70b9&#xff1a;\u4ece\u6240\u6709\u7279\u5f81\u4e2d&#xff0c;\u9009\u62e9\u4e00\u4e2a\u201c\u6700\u597d\u201d\u7684\u7279\u5f81\u4f5c\u4e3a\u6811\u7684\u6839\u8282\u70b9\u3002<\/li>\n<li>\u5206\u88c2&#xff1a;\u6839\u636e\u8fd9\u4e2a\u6700\u4f18\u7279\u5f81\u7684\u53d6\u503c&#xff0c;\u5c06\u6570\u636e\u96c6\u5206\u88c2\u6210\u82e5\u5e72\u4e2a\u5b50\u96c6\u3002<\/li>\n<li>\u9012\u5f52&#xff1a;\u5bf9\u6bcf\u4e2a\u5b50\u96c6&#xff0c;\u91cd\u590d\u6b65\u9aa41\u548c2&#xff0c;\u5373\u9009\u62e9\u8be5\u5b50\u96c6\u4e0b\u7684\u6700\u4f18\u7279\u5f81\u8fdb\u884c\u5206\u88c2&#xff0c;\u751f\u6210\u65b0\u7684\u5b50\u8282\u70b9\u3002<\/li>\n<li>\u505c\u6b62&#xff1a;\u5f53\u6ee1\u8db3\u505c\u6b62\u6761\u4ef6\u65f6&#xff08;\u5982\u8282\u70b9\u4e0b\u7684\u6240\u6709\u6837\u672c\u90fd\u5c5e\u4e8e\u540c\u4e00\u7c7b\u522b&#xff0c;\u6216\u8fbe\u5230\u9884\u8bbe\u7684\u6811\u6df1&#xff09;&#xff0c;\u8be5\u8282\u70b9\u6210\u4e3a\u53f6\u5b50\u8282\u70b9&#xff0c;\u4e0d\u518d\u5206\u88c2\u3002<\/li>\n<p>\u5982\u4f55\u9009\u62e9\u6700\u4f18\u7279\u5f81\u8fdb\u884c\u5206\u88c2\u00a0\u201c\u6700\u597d\u201d\u7684\u7279\u5f81&#xff0c;\u662f\u6307\u90a3\u4e2a\u80fd\u8ba9\u5206\u88c2\u540e\u7684\u6570\u636e\u96c6**\u201c\u4e0d\u7eaf\u5ea6\u201d\u4e0b\u964d\u6700\u5927**\u7684\u7279\u5f81\u3002\u6211\u4eec\u5e0c\u671b\u6bcf\u6b21\u5206\u88c2\u540e&#xff0c;\u5404\u4e2a\u5b50\u96c6\u5185\u90e8\u7684\u7c7b\u522b\u5c3d\u53ef\u80fd\u5730\u201c\u7eaf\u7cb9\u201d&#xff08;\u5373\u5927\u90e8\u5206\u6837\u672c\u5c5e\u4e8e\u540c\u4e00\u4e2a\u7c7b\u522b&#xff09;\u3002 \u8861\u91cf\u4e0d\u7eaf\u5ea6\u7684\u5e38\u7528\u6307\u6807\u6709&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u5c3c\u4e0d\u7eaf\u5ea6&#xff08;Gini Impurity&#xff09;&#xff1a;Scikit-learn\u4e2d\u7684\u9ed8\u8ba4\u9009\u62e9\u3002\u5b83\u8861\u91cf\u7684\u662f\u4ece\u6570\u636e\u96c6\u4e2d\u968f\u673a\u62bd\u53d6\u4e24\u4e2a\u6837\u672c&#xff0c;\u5176\u7c7b\u522b\u6807\u7b7e\u4e0d\u4e00\u81f4\u7684\u6982\u7387\u3002\u57fa\u5c3c\u4e0d\u7eaf\u5ea6\u8d8a\u5c0f&#xff0c;\u6570\u636e\u96c6\u8d8a\u7eaf\u3002<\/li>\n<li>\u4fe1\u606f\u589e\u76ca&#xff08;Information Gain&#xff09;&#xff1a;\u57fa\u4e8e\u4fe1\u606f\u71b5&#xff08;Entropy&#xff09;\u7684\u6982\u5ff5\u3002\u4fe1\u606f\u71b5\u8861\u91cf\u7684\u662f\u6570\u636e\u7684\u4e0d\u786e\u5b9a\u6027\u3002\u4fe1\u606f\u589e\u76ca\u5c31\u662f\u7236\u8282\u70b9\u7684\u4fe1\u606f\u71b5\u51cf\u53bb\u6240\u6709\u5b50\u8282\u70b9\u4fe1\u606f\u71b5\u7684\u52a0\u6743\u5e73\u5747\u3002\u4fe1\u606f\u589e\u76ca\u8d8a\u5927&#xff0c;\u8bf4\u660e\u8fd9\u6b21\u5206\u88c2\u5e26\u6765\u7684\u201c\u786e\u5b9a\u6027\u201d\u63d0\u5347\u8d8a\u5927\u3002<\/li>\n<\/ul>\n<p>\u53ef\u89c6\u5316\u4e0e\u53ef\u89e3\u91ca\u6027\u00a0\u51b3\u7b56\u6811\u6700\u5927\u7684\u4f18\u70b9\u4e4b\u4e00\u5c31\u662f\u9ad8\u5ea6\u7684\u53ef\u89e3\u91ca\u6027\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u8bad\u7ec3\u597d\u7684\u51b3\u7b56\u6811\u53ef\u89c6\u5316\u51fa\u6765&#xff0c;\u6e05\u6670\u5730\u770b\u5230\u5b83\u7684\u6bcf\u4e00\u4e2a\u51b3\u7b56\u89c4\u5219\u3002\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e00\u4e2a\u201c\u767d\u76d2\u201d\u6a21\u578b&#xff0c;\u975e\u5e38\u4fbf\u4e8e\u5411\u975e\u6280\u672f\u4eba\u5458\u89e3\u91ca\u3002<\/p>\n<p>\u526a\u679d&#xff08;Pruning&#xff09;\u00a0\u5982\u679c\u4e0d\u52a0\u9650\u5236&#xff0c;\u51b3\u7b56\u6811\u4f1a\u4e00\u76f4\u751f\u957f&#xff0c;\u76f4\u5230\u6bcf\u4e2a\u53f6\u5b50\u8282\u70b9\u90fd\u53ea\u5305\u542b\u4e00\u4e2a\u6837\u672c&#xff0c;\u8fd9\u4f1a\u5bfc\u81f4\u4e25\u91cd\u7684\u8fc7\u62df\u5408\u3002\u4e3a\u4e86\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u6211\u4eec\u9700\u8981\u5bf9\u6811\u8fdb\u884c\u201c\u526a\u679d\u201d\u3002<\/p>\n<ul>\n<li>\u9884\u526a\u679d&#xff08;Pre-pruning&#xff09;&#xff1a;\u5728\u6811\u7684\u751f\u957f\u8fc7\u7a0b\u4e2d&#xff0c;\u901a\u8fc7\u8bbe\u5b9a\u4e00\u4e9b\u6761\u4ef6\u63d0\u524d\u505c\u6b62\u5206\u88c2\u3002\u5e38\u7528\u7684\u8d85\u53c2\u6570\u5305\u62ec&#xff1a;\n<ul>\n<li>max_depth&#xff1a;\u6811\u7684\u6700\u5927\u6df1\u5ea6\u3002<\/li>\n<li>min_samples_split&#xff1a;\u4e00\u4e2a\u8282\u70b9\u8981\u5206\u88c2&#xff0c;\u81f3\u5c11\u9700\u8981\u5305\u542b\u7684\u6837\u672c\u6570\u3002<\/li>\n<li>min_samples_leaf&#xff1a;\u4e00\u4e2a\u53f6\u5b50\u8282\u70b9\u81f3\u5c11\u9700\u8981\u5305\u542b\u7684\u6837\u672c\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u540e\u526a\u679d&#xff08;Post-pruning&#xff09;&#xff1a;\u5148\u751f\u6210\u4e00\u68f5\u5b8c\u6574\u7684\u51b3\u7b56\u6811&#xff0c;\u7136\u540e\u81ea\u5e95\u5411\u4e0a\u5730\u8003\u5bdf\u975e\u53f6\u5b50\u8282\u70b9&#xff0c;\u5982\u679c\u5c06\u8be5\u8282\u70b9\u66ff\u6362\u4e3a\u53f6\u5b50\u8282\u70b9\u80fd\u63d0\u5347\u6a21\u578b\u7684\u6cdb\u5316\u6027\u80fd&#xff0c;\u5219\u8fdb\u884c\u526a\u679d\u3002<\/li>\n<\/ul>\n<h5>5.4.2 \u96c6\u6210\u5b66\u4e60\u5165\u95e8&#xff1a;\u4ece\u201c\u4e00\u4e2a\u597d\u6c49\u201d\u5230\u201c\u4e09\u4e2a\u81ed\u76ae\u5320\u201d<\/h5>\n<p>\u96c6\u6210\u5b66\u4e60&#xff08;Ensemble Learning&#xff09;\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u673a\u5668\u5b66\u4e60\u8303\u5f0f&#xff0c;\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u5355\u4e2a\u6a21\u578b&#xff0c;\u800c\u662f\u5c06\u591a\u4e2a\u5f31\u5b66\u4e60\u5668&#xff08;weak learners&#xff09;\u7ec4\u5408\u8d77\u6765&#xff0c;\u5f62\u6210\u4e00\u4e2a\u5f3a\u5927\u7684\u5f3a\u5b66\u4e60\u5668\u3002\u4fd7\u8bdd\u8bf4\u201c\u4e09\u4e2a\u81ed\u76ae\u5320&#xff0c;\u9876\u4e2a\u8bf8\u845b\u4eae\u201d&#xff0c;\u8fd9\u5c31\u662f\u96c6\u6210\u5b66\u4e60\u7684\u6838\u5fc3\u601d\u60f3\u3002<\/p>\n<p>Bagging\u601d\u60f3\u00a0Bagging&#xff08;Bootstrap Aggregating\u7684\u7f29\u5199&#xff09;\u662f\u96c6\u6210\u5b66\u4e60\u4e2d\u6700\u57fa\u7840\u7684\u601d\u60f3\u4e4b\u4e00\u3002\u5b83\u7684\u76ee\u6807\u662f\u964d\u4f4e\u6a21\u578b\u7684\u65b9\u5dee\u3002<\/p>\n<li>\u81ea\u52a9\u91c7\u6837&#xff08;Bootstrap&#xff09;&#xff1a;\u4ece\u539f\u59cb\u8bad\u7ec3\u96c6\u4e2d&#xff0c;\u8fdb\u884c\u6709\u653e\u56de\u5730\u968f\u673a\u62bd\u6837&#xff0c;\u751f\u6210\u591a\u4e2a\u5927\u5c0f\u4e0e\u539f\u59cb\u6570\u636e\u96c6\u76f8\u540c\u7684\u81ea\u52a9\u6837\u672c\u96c6\u3002\u7531\u4e8e\u662f\u6709\u653e\u56de\u62bd\u6837&#xff0c;\u6bcf\u4e2a\u81ea\u52a9\u6837\u672c\u96c6\u4e2d\u4f1a\u5305\u542b\u4e00\u4e9b\u91cd\u590d\u6837\u672c&#xff0c;\u4e5f\u6709\u4e9b\u539f\u59cb\u6837\u672c\u672a\u88ab\u62bd\u5230\u3002<\/li>\n<li>\u72ec\u7acb\u8bad\u7ec3&#xff1a;\u5728\u6bcf\u4e2a\u81ea\u52a9\u6837\u672c\u96c6\u4e0a&#xff0c;\u72ec\u7acb\u5730\u8bad\u7ec3\u4e00\u4e2a\u57fa\u5b66\u4e60\u5668&#xff08;\u5982\u4e00\u68f5\u51b3\u7b56\u6811&#xff09;\u3002<\/li>\n<li>\u805a\u5408&#xff08;Aggregating&#xff09;&#xff1a;\u5bf9\u4e8e\u5206\u7c7b\u4efb\u52a1&#xff0c;\u4f7f\u7528\u591a\u6570\u8868\u51b3\u7684\u65b9\u5f0f&#xff0c;\u5c06\u6240\u6709\u57fa\u5b66\u4e60\u5668\u7684\u9884\u6d4b\u7ed3\u679c\u8fdb\u884c\u6295\u7968&#xff0c;\u5f97\u51fa\u6700\u7ec8\u7684\u96c6\u6210\u9884\u6d4b\u3002\u5bf9\u4e8e\u56de\u5f52\u4efb\u52a1&#xff0c;\u5219\u53d6\u6240\u6709\u57fa\u5b66\u4e60\u5668\u9884\u6d4b\u7ed3\u679c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<h5>5.4.3 \u968f\u673a\u68ee\u6797&#xff08;Random Forest&#xff09;&#xff1a;\u51b3\u7b56\u6811\u7684\u201c\u96c6\u4f53\u667a\u6167\u201d<\/h5>\n<p>\u968f\u673a\u68ee\u6797\u5c31\u662f\u4ee5\u51b3\u7b56\u6811\u4e3a\u57fa\u5b66\u4e60\u5668\u7684Bagging\u96c6\u6210\u6a21\u578b&#xff0c;\u5e76\u4e14\u5728Bagging\u7684\u57fa\u7840\u4e0a&#xff0c;\u5f15\u5165\u4e86\u8fdb\u4e00\u6b65\u7684\u201c\u968f\u673a\u6027\u201d\u3002<\/p>\n<p>\u201c\u53cc\u91cd\u968f\u673a\u201d\u7684\u6838\u5fc3<\/p>\n<li>\u6837\u672c\u968f\u673a&#xff08;\u884c\u62bd\u6837&#xff09;&#xff1a;\u7ee7\u627f\u81eaBagging&#xff0c;\u6bcf\u4e2a\u57fa\u51b3\u7b56\u6811\u90fd\u5728\u4e00\u4e2a\u81ea\u52a9\u6837\u672c\u96c6\u4e0a\u8bad\u7ec3\u3002<\/li>\n<li>\u7279\u5f81\u968f\u673a&#xff08;\u5217\u62bd\u6837&#xff09;&#xff1a;\u8fd9\u662f\u968f\u673a\u68ee\u6797\u7684\u72ec\u521b\u3002\u5728\u6bcf\u4e2a\u8282\u70b9\u8fdb\u884c\u5206\u88c2\u65f6&#xff0c;\u4e0d\u662f\u4ece\u6240\u6709\u7279\u5f81\u4e2d\u9009\u62e9\u6700\u4f18\u7279\u5f81&#xff0c;\u800c\u662f\u5148\u4ece\u6240\u6709\u7279\u5f81\u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u5b50\u96c6&#xff08;\u901a\u5e38\u662fsqrt(n_features)\u4e2a&#xff09;&#xff0c;\u7136\u540e\u518d\u4ece\u8fd9\u4e2a\u5b50\u96c6\u4e2d\u9009\u62e9\u6700\u4f18\u7279\u5f81\u8fdb\u884c\u5206\u88c2\u3002<\/li>\n<p>\u4e3a\u4f55\u968f\u673a\u68ee\u6797\u901a\u5e38\u4f18\u4e8e\u5355\u68f5\u51b3\u7b56\u6811<\/p>\n<ul>\n<li>\u964d\u4f4e\u65b9\u5dee&#xff1a;Bagging\u7684\u805a\u5408\u8fc7\u7a0b\u672c\u8eab\u5c31\u80fd\u6709\u6548\u964d\u4f4e\u65b9\u5dee\u3002<\/li>\n<li>\u589e\u52a0\u6a21\u578b\u591a\u6837\u6027&#xff1a;\u201c\u7279\u5f81\u968f\u673a\u201d\u8fd9\u4e00\u6b65&#xff0c;\u4f7f\u5f97\u68ee\u6797\u4e2d\u7684\u6bcf\u68f5\u6811\u90fd\u957f\u5f97\u201c\u5404\u4e0d\u76f8\u540c\u201d&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u770b\u5230\u7684\u201c\u4e16\u754c\u201d&#xff08;\u7279\u5f81\u5b50\u96c6&#xff09;\u90fd\u4e0d\u540c\u3002\u8fd9\u964d\u4f4e\u4e86\u6811\u4e0e\u6811\u4e4b\u95f4\u7684\u76f8\u5173\u6027&#xff0c;\u4f7f\u5f97\u6295\u7968\u7ed3\u679c\u66f4\u52a0\u7a33\u5065&#xff0c;\u8fdb\u4e00\u6b65\u964d\u4f4e\u4e86\u6574\u4f53\u6a21\u578b\u7684\u65b9\u5dee&#xff0c;\u6709\u6548\u9632\u6b62\u4e86\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n<h5>5.4.4 Scikit-learn\u5b9e\u6218\u4e0e\u7279\u5f81\u91cd\u8981\u6027<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.tree import DecisionTreeClassifier<br \/>\nfrom sklearn.ensemble import RandomForestClassifier<\/p>\n<p># &#8212; \u51b3\u7b56\u6811 &#8212;<br \/>\ndt_model &#061; DecisionTreeClassifier(max_depth&#061;5, random_state&#061;42)<br \/>\ndt_model.fit(X_train, y_train) # \u51b3\u7b56\u6811\u5bf9\u7f29\u653e\u4e0d\u654f\u611f&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u7528\u539f\u59cb\u6570\u636e<br \/>\ny_pred_dt &#061; dt_model.predict(X_test)<br \/>\nprint(&#034;&#8212; \u51b3\u7b56\u6811\u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(classification_report(y_test, y_pred_dt))<\/p>\n<p># &#8212; \u968f\u673a\u68ee\u6797 &#8212;<br \/>\nrf_model &#061; RandomForestClassifier(n_estimators&#061;100, max_depth&#061;5, random_state&#061;42, n_jobs&#061;-1)<br \/>\nrf_model.fit(X_train, y_train)<br \/>\ny_pred_rf &#061; rf_model.predict(X_test)<br \/>\nprint(&#034;\\\\n&#8212; \u968f\u673a\u68ee\u6797\u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(classification_report(y_test, y_pred_rf))<\/p>\n<p>n_estimators\u662f\u68ee\u6797\u4e2d\u6811\u7684\u6570\u91cf&#xff0c;n_jobs&#061;-1\u8868\u793a\u4f7f\u7528\u6240\u6709CPU\u6838\u5fc3\u5e76\u884c\u8ba1\u7b97\u3002<\/p>\n<p>\u7279\u5f81\u91cd\u8981\u6027&#xff08;Feature Importance&#xff09;\u00a0\u968f\u673a\u68ee\u6797\u8fd8\u6709\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u526f\u4ea7\u54c1\u2014\u2014\u7279\u5f81\u91cd\u8981\u6027\u3002\u6a21\u578b\u53ef\u4ee5\u8bc4\u4f30\u6bcf\u4e2a\u7279\u5f81\u5728\u6240\u6709\u6811\u7684\u51b3\u7b56\u4e2d\u6240\u505a\u7684\u8d21\u732e\u5927\u5c0f&#xff08;\u901a\u5e38\u662f\u57fa\u4e8e\u8be5\u7279\u5f81\u5e26\u6765\u7684\u4e0d\u7eaf\u5ea6\u4e0b\u964d\u603b\u91cf&#xff09;\u3002\u8fd9\u4e3a\u6211\u4eec\u7406\u89e3\u6570\u636e\u548c\u7b5b\u9009\u7279\u5f81\u63d0\u4f9b\u4e86\u6781\u4f73\u7684\u6d1e\u5bdf\u3002<\/p>\n<p>importances &#061; rf_model.feature_importances_<br \/>\nfeature_importances &#061; pd.Series(importances, index&#061;X.columns).sort_values(ascending&#061;False)<\/p>\n<p>plt.figure(figsize&#061;(10, 6))<br \/>\nsns.barplot(x&#061;feature_importances, y&#061;feature_importances.index)<br \/>\nplt.title(&#039;Feature Importances in Random Forest&#039;)<br \/>\nplt.show()<\/p>\n<p>\u4f18\u7f3a\u70b9\u4e0e\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<li>\u6027\u80fd\u5f3a\u5927&#xff1a;\u901a\u5e38\u80fd\u83b7\u5f97\u975e\u5e38\u9ad8\u7684\u51c6\u786e\u7387&#xff0c;\u662f\u8bb8\u591a\u7ade\u8d5b\u548c\u5de5\u4e1a\u5e94\u7528\u4e2d\u7684\u4e3b\u529b\u6a21\u578b\u3002<\/li>\n<li>\u6297\u8fc7\u62df\u5408\u80fd\u529b\u5f3a&#xff1a;\u53cc\u91cd\u968f\u673a\u6027\u4f7f\u5176\u975e\u5e38\u7a33\u5065\u3002<\/li>\n<li>\u5bf9\u7f3a\u5931\u503c\u548c\u5f02\u5e38\u503c\u4e0d\u654f\u611f\u3002<\/li>\n<li>\u65e0\u9700\u7279\u5f81\u7f29\u653e\u3002<\/li>\n<li>\u80fd\u5904\u7406\u9ad8\u7ef4\u6570\u636e&#xff0c;\u5e76\u80fd\u8f93\u51fa\u7279\u5f81\u91cd\u8981\u6027\u3002<\/li>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<li>\u53ef\u89e3\u91ca\u6027\u5dee&#xff1a;\u76f8\u6bd4\u5355\u68f5\u51b3\u7b56\u6811&#xff0c;\u968f\u673a\u68ee\u6797\u662f\u4e00\u4e2a\u201c\u9ed1\u76d2\u201d\u6a21\u578b&#xff0c;\u96be\u4ee5\u89e3\u91ca\u5176\u5185\u90e8\u51b3\u7b56\u903b\u8f91\u3002<\/li>\n<li>\u8ba1\u7b97\u548c\u5185\u5b58\u5f00\u9500\u5927&#xff1a;\u9700\u8981\u8bad\u7ec3\u548c\u5b58\u50a8\u6570\u767e\u68f5\u6811\u3002<\/li>\n<li>\u5728\u67d0\u4e9b\u566a\u58f0\u5f88\u5927\u7684\u6570\u636e\u96c6\u4e0a&#xff0c;\u53ef\u80fd\u4f1a\u8fc7\u62df\u5408\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u51e0\u4e4e\u9002\u7528\u4e8e\u4efb\u4f55\u5206\u7c7b&#xff08;\u6216\u56de\u5f52&#xff09;\u95ee\u9898&#xff0c;\u662f\u5de5\u5177\u7bb1\u4e2d\u5fc5\u5907\u7684\u201c\u745e\u58eb\u519b\u5200\u201d\u3002<\/li>\n<li>\u5f53\u9700\u8981\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u5f00\u7bb1\u5373\u7528\u7684\u6a21\u578b\u65f6\u3002<\/li>\n<li>\u7528\u4e8e\u7279\u5f81\u9009\u62e9\u548c\u6570\u636e\u63a2\u7d22\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>5.5 \u6734\u7d20\u8d1d\u53f6\u65af&#xff1a;\u201c\u6267\u679c\u7d22\u56e0\u201d\u7684\u6982\u7387\u601d\u7ef4<\/h4>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;Naive Bayes&#xff09;\u662f\u4e00\u7c7b\u57fa\u4e8e\u8d1d\u53f6\u65af\u5b9a\u7406\u548c\u7279\u5f81\u6761\u4ef6\u72ec\u7acb\u6027\u5047\u8bbe\u7684\u7b80\u5355\u6982\u7387\u5206\u7c7b\u5668\u3002\u5c3d\u7ba1\u5b83\u7684\u5047\u8bbe\u975e\u5e38\u201c\u6734\u7d20\u201d&#xff0c;\u4f46\u5728\u8bb8\u591a\u73b0\u5b9e\u573a\u666f&#xff0c;\u5c24\u5176\u662f\u6587\u672c\u5206\u7c7b\u4e2d&#xff0c;\u5176\u8868\u73b0\u5374\u51fa\u4eba\u610f\u6599\u5730\u597d\u3002<\/p>\n<h5>5.5.1 \u8d1d\u53f6\u65af\u5b9a\u7406&#xff1a;\u6982\u7387\u8bba\u7684\u57fa\u77f3<\/h5>\n<p>\u8d1d\u53f6\u65af\u5b9a\u7406\u63cf\u8ff0\u4e86\u4e24\u4e2a\u6761\u4ef6\u6982\u7387\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f\u6839\u636e\u201c\u7ed3\u679c\u201d\u6765\u53cd\u63a8\u201c\u539f\u56e0\u201d\u7684\u6982\u7387\u3002\u00a0P(A|B) &#061; [P(B|A) * P(A)] \/ P(B)<\/p>\n<p>\u5728\u5206\u7c7b\u4efb\u52a1\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u6539\u5199\u4e3a&#xff1a;\u00a0P(\u7c7b\u522b | \u7279\u5f81) &#061; [P(\u7279\u5f81 | \u7c7b\u522b) * P(\u7c7b\u522b)] \/ P(\u7279\u5f81)<\/p>\n<ul>\n<li>P(\u7c7b\u522b | \u7279\u5f81)&#xff1a;\u540e\u9a8c\u6982\u7387&#xff08;Posterior&#xff09;\u3002\u8fd9\u662f\u6211\u4eec\u60f3\u6c42\u7684&#xff0c;\u5373\u5728\u770b\u5230\u8fd9\u4e9b\u7279\u5f81\u540e&#xff0c;\u6837\u672c\u5c5e\u4e8e\u67d0\u4e2a\u7c7b\u522b\u7684\u6982\u7387\u3002<\/li>\n<li>P(\u7279\u5f81 | \u7c7b\u522b)&#xff1a;\u4f3c\u7136&#xff08;Likelihood&#xff09;\u3002\u5728\u67d0\u4e2a\u7c7b\u522b\u4e0b&#xff0c;\u51fa\u73b0\u8fd9\u4e9b\u7279\u5f81\u7684\u6982\u7387\u3002\u8fd9\u662f\u6a21\u578b\u9700\u8981\u4ece\u8bad\u7ec3\u6570\u636e\u4e2d\u5b66\u4e60\u7684\u3002<\/li>\n<li>P(\u7c7b\u522b)&#xff1a;\u5148\u9a8c\u6982\u7387&#xff08;Prior&#xff09;\u3002\u5728\u4e0d\u770b\u4efb\u4f55\u7279\u5f81\u7684\u60c5\u51b5\u4e0b&#xff0c;\u67d0\u4e2a\u7c7b\u522b\u672c\u8eab\u51fa\u73b0\u7684\u6982\u7387\u3002\u53ef\u4ee5\u4ece\u8bad\u7ec3\u6570\u636e\u4e2d\u76f4\u63a5\u7edf\u8ba1\u3002<\/li>\n<li>P(\u7279\u5f81)&#xff1a;\u8bc1\u636e&#xff08;Evidence&#xff09;\u3002\u8fd9\u4e9b\u7279\u5f81\u51fa\u73b0\u7684\u6982\u7387\u3002\u5728\u9884\u6d4b\u65f6&#xff0c;\u5bf9\u4e8e\u6240\u6709\u7c7b\u522b&#xff0c;\u5b83\u662f\u4e00\u4e2a\u5e38\u6570&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u5ffd\u7565\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5&#xff0c;\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u9884\u6d4b\u8fc7\u7a0b\u5c31\u662f&#xff1a;\u5bf9\u4e8e\u4e00\u4e2a\u65b0\u6837\u672c&#xff0c;\u8ba1\u7b97\u5b83\u5c5e\u4e8e\u6bcf\u4e2a\u7c7b\u522b\u7684\u540e\u9a8c\u6982\u7387&#xff0c;\u7136\u540e\u9009\u62e9\u540e\u9a8c\u6982\u7387\u6700\u5927\u7684\u90a3\u4e2a\u7c7b\u522b\u4f5c\u4e3a\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n<h5>5.5.2 \u201c\u6734\u7d20\u201d\u5728\u4f55\u5904&#xff1f;\u7279\u5f81\u6761\u4ef6\u72ec\u7acb\u6027\u5047\u8bbe<\/h5>\n<p>\u8ba1\u7b97P(\u7279\u5f81 | \u7c7b\u522b)&#xff0c;\u5373P(\u7279\u5f81\u2081, \u7279\u5f81\u2082, &#8230; | \u7c7b\u522b)&#xff0c;\u662f\u975e\u5e38\u56f0\u96be\u7684\u3002\u4e3a\u4e86\u7b80\u5316\u8ba1\u7b97&#xff0c;\u6734\u7d20\u8d1d\u53f6\u65af\u505a\u51fa\u4e86\u4e00\u4e2a\u975e\u5e38\u5f3a\u7684\u5047\u8bbe&#xff1a;<\/p>\n<p>\u7279\u5f81\u6761\u4ef6\u72ec\u7acb\u6027\u5047\u8bbe&#xff1a;\u5b83\u5047\u8bbe\u5728\u7ed9\u5b9a\u7c7b\u522b\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6240\u6709\u7279\u5f81\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\u3002\u00a0P(\u7279\u5f81\u2081, \u7279\u5f81\u2082, &#8230; | \u7c7b\u522b) &#061; P(\u7279\u5f81\u2081 | \u7c7b\u522b) * P(\u7279\u5f81\u2082 | \u7c7b\u522b) * &#8230;<\/p>\n<p>\u8fd9\u4e2a\u5047\u8bbe\u5c31\u662f\u201c\u6734\u7d20\u201d\u4e00\u8bcd\u7684\u6765\u6e90\u3002\u5728\u73b0\u5b9e\u4e2d&#xff0c;\u7279\u5f81\u4e4b\u95f4\u5f80\u5f80\u662f\u6709\u5173\u8054\u7684&#xff08;\u4f8b\u5982&#xff0c;\u5728\u6587\u672c\u4e2d&#xff0c;\u201c\u673a\u5668\u5b66\u4e60\u201d\u548c\u201c\u7b97\u6cd5\u201d\u8fd9\u4e24\u4e2a\u8bcd\u5c31\u7ecf\u5e38\u4e00\u8d77\u51fa\u73b0&#xff09;\u3002\u4f46\u8fd9\u4e2a\u770b\u4f3c\u4e0d\u5408\u7406\u7684\u5047\u8bbe&#xff0c;\u5374\u6781\u5927\u5730\u7b80\u5316\u4e86\u8ba1\u7b97&#xff0c;\u5e76\u4f7f\u5f97\u6734\u7d20\u8d1d\u53f6\u65af\u5728\u5b9e\u8df5\u4e2d\u4f9d\u7136\u8868\u73b0\u826f\u597d\u3002<\/p>\n<p>\u4e0d\u540c\u7c7b\u578b\u7684\u6734\u7d20\u8d1d\u53f6\u65af\u00a0\u6839\u636e\u7279\u5f81\u6570\u636e\u7684\u4e0d\u540c\u5206\u5e03&#xff0c;\u6734\u7d20\u8d1d\u53f6\u65af\u6709\u51e0\u79cd\u5e38\u89c1\u7684\u53d8\u4f53&#xff1a;<\/p>\n<ul>\n<li>\u9ad8\u65af\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;GaussianNB&#xff09;&#xff1a;\u5047\u8bbe\u8fde\u7eed\u578b\u7279\u5f81\u670d\u4ece\u9ad8\u65af\u5206\u5e03&#xff08;\u6b63\u6001\u5206\u5e03&#xff09;\u3002<\/li>\n<li>\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;MultinomialNB&#xff09;&#xff1a;\u9002\u7528\u4e8e\u79bb\u6563\u578b\u7279\u5f81&#xff0c;\u7279\u522b\u662f\u6587\u672c\u5206\u7c7b\u4e2d\u7684\u8bcd\u9891\u8ba1\u6570\u3002<\/li>\n<li>\u4f2f\u52aa\u5229\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;BernoulliNB&#xff09;&#xff1a;\u9002\u7528\u4e8e\u4e8c\u5143\u7279\u5f81&#xff08;\u7279\u5f81\u51fa\u73b0\u6216\u4e0d\u51fa\u73b0&#xff09;&#xff0c;\u4e5f\u662f\u6587\u672c\u5206\u7c7b\u7684\u5e38\u7528\u6a21\u578b\u3002<\/li>\n<\/ul>\n<h5>5.5.3 Scikit-learn\u5b9e\u6218\u4e0e\u6587\u672c\u5206\u7c7b\u5e94\u7528<\/h5>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u6700\u7ecf\u5178\u3001\u6700\u6210\u529f\u7684\u5e94\u7528\u9886\u57df\u83ab\u8fc7\u4e8e\u6587\u672c\u5206\u7c7b\u3002\u6211\u4eec\u5c06\u4ee5\u4e00\u4e2a\u7ecf\u5178\u7684\u5783\u573e\u90ae\u4ef6\u8fc7\u6ee4\u4e3a\u4f8b&#xff0c;\u5c55\u793a\u5176\u5de5\u4f5c\u6d41\u7a0b\u3002\u5728\u6587\u672c\u5904\u7406\u4e2d&#xff0c;\u6211\u4eec\u901a\u5e38\u4f7f\u7528MultinomialNB\u6216BernoulliNB\u3002<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0\u4e3a\u4e86\u5904\u7406\u6587\u672c&#xff0c;\u6211\u4eec\u9996\u5148\u9700\u8981\u5c06\u6587\u5b57\u8f6c\u6362\u6210\u673a\u5668\u53ef\u4ee5\u7406\u89e3\u7684\u6570\u503c\u5f62\u5f0f\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u8bcd\u888b\u6a21\u578b&#xff08;Bag-of-Words&#xff09;&#xff0c;\u5b83\u5c06\u6bcf\u7bc7\u6587\u6863\u8868\u793a\u4e3a\u4e00\u4e2a\u5411\u91cf&#xff0c;\u5411\u91cf\u7684\u6bcf\u4e2a\u7ef4\u5ea6\u4ee3\u8868\u4e00\u4e2a\u8bcd&#xff0c;\u503c\u53ef\u4ee5\u662f\u8be5\u8bcd\u5728\u6587\u6863\u4e2d\u51fa\u73b0\u7684\u6b21\u6570&#xff08;\u8bcd\u9891&#xff09;\u3002Scikit-learn\u7684CountVectorizer\u53ef\u4ee5\u5e2e\u6211\u4eec\u5b8c\u6210\u8fd9\u4e2a\u8f6c\u6362\u3002<\/p>\n<p>make_pipeline\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177&#xff0c;\u5b83\u53ef\u4ee5\u5c06\u201c\u7279\u5f81\u63d0\u53d6\u201d&#xff08;\u5982CountVectorizer&#xff09;\u548c\u201c\u6a21\u578b\u8bad\u7ec3\u201d&#xff08;\u5982MultinomialNB&#xff09;\u8fd9\u4e24\u4e2a\u6b65\u9aa4\u4e32\u8054\u6210\u4e00\u4e2a\u65e0\u7f1d\u7684\u5904\u7406\u6d41\u7a0b\u3002<\/p>\n<p>from sklearn.feature_extraction.text import CountVectorizer<br \/>\nfrom sklearn.naive_bayes import MultinomialNB<br \/>\nfrom sklearn.pipeline import make_pipeline<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.metrics import classification_report<br \/>\nimport pandas as pd<\/p>\n<p># \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5305\u542b\u90ae\u4ef6\u6587\u672c\u548c\u6807\u7b7e\u7684\u6570\u636e\u96c6<br \/>\n# \u4e3a\u4e86\u6f14\u793a&#xff0c;\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u6570\u636e\u96c6<br \/>\ndata &#061; {<br \/>\n    &#039;text&#039;: [<br \/>\n        &#034;SPECIAL OFFER! Buy now and get a 50% discount!&#034;,<br \/>\n        &#034;Hi Bob, can we schedule a meeting for tomorrow?&#034;,<br \/>\n        &#034;Congratulations! You&#039;ve won a free cruise trip!&#034;,<br \/>\n        &#034;Please find the attached document for your review.&#034;,<br \/>\n        &#034;Limited time offer: exclusive access to cheap viagra.&#034;,<br \/>\n        &#034;Project update and next steps for our meeting.&#034;,<br \/>\n        &#034;URGENT: Your account has been compromised! Click here to secure it.&#034;,<br \/>\n        &#034;Thanks for your email, I will look into the document.&#034;<br \/>\n    ],<br \/>\n    &#039;label&#039;: [&#039;spam&#039;, &#039;ham&#039;, &#039;spam&#039;, &#039;ham&#039;, &#039;spam&#039;, &#039;ham&#039;, &#039;spam&#039;, &#039;ham&#039;]<br \/>\n}<br \/>\ndf_mail &#061; pd.DataFrame(data)<\/p>\n<p>X_mail &#061; df_mail[&#039;text&#039;]<br \/>\ny_mail &#061; df_mail[&#039;label&#039;]<\/p>\n<p># \u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<br \/>\nX_train_mail, X_test_mail, y_train_mail, y_test_mail &#061; train_test_split(X_mail, y_mail, test_size&#061;0.25, random_state&#061;42)<\/p>\n<p># 1. \u521b\u5efa\u4e00\u4e2a\u5904\u7406\u6d41\u7a0b\u7ba1\u9053<br \/>\n# CountVectorizer: \u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u8bcd\u9891\u8ba1\u6570\u5411\u91cf\u3002<br \/>\n# MultinomialNB: \u4f7f\u7528\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af\u5206\u7c7b\u5668\u3002<br \/>\npipeline &#061; make_pipeline(CountVectorizer(), MultinomialNB())<\/p>\n<p># 2. \u8bad\u7ec3\u6a21\u578b (\u7ba1\u9053\u4f1a\u81ea\u52a8\u5148\u5bf9X_train_mail\u505atransform&#xff0c;\u7136\u540e\u7528\u8f6c\u6362\u540e\u7684\u6570\u636e\u8bad\u7ec3\u6a21\u578b)<br \/>\npipeline.fit(X_train_mail, y_train_mail)<\/p>\n<p># 3. \u9884\u6d4b\u4e0e\u8bc4\u4f30<br \/>\ny_pred_mail &#061; pipeline.predict(X_test_mail)<br \/>\nprint(&#034;&#8212; \u6734\u7d20\u8d1d\u53f6\u65af\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(classification_report(y_test_mail, y_pred_mail))<\/p>\n<p># 4. \u9884\u6d4b\u65b0\u90ae\u4ef6<br \/>\nprint(&#034;\\\\n&#8212; \u9884\u6d4b\u65b0\u90ae\u4ef6 &#8212;&#034;)<br \/>\nnew_emails &#061; [<br \/>\n    &#034;Dear customer, your invoice is attached.&#034;,<br \/>\n    &#034;Claim your free prize now!&#034;<br \/>\n]<br \/>\npredictions &#061; pipeline.predict(new_emails)<br \/>\nproba_predictions &#061; pipeline.predict_proba(new_emails)<\/p>\n<p>for email, pred, proba in zip(new_emails, predictions, proba_predictions):<br \/>\n    # pipeline.classes_ \u53ef\u4ee5\u67e5\u770b\u7c7b\u522b\u7684\u987a\u5e8f<br \/>\n    class_order &#061; pipeline.classes_<br \/>\n    print(f&#034;\u90ae\u4ef6: &#039;{email}&#039;&#034;)<br \/>\n    print(f&#034;\u9884\u6d4b\u7ed3\u679c: {pred}&#034;)<br \/>\n    print(f&#034;\u5c5e\u4e8e\u5404\u7c7b\u7684\u6982\u7387: {dict(zip(class_order, proba))}\\\\n&#034;)<\/p>\n<p>\u4f18\u7f3a\u70b9\u4e0e\u9002\u7528\u573a\u666f<\/p>\n<ul>\n<li>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<li>\u7b97\u6cd5\u7b80\u5355&#xff0c;\u8bad\u7ec3\u901f\u5ea6\u6781\u5feb&#xff1a;\u8ba1\u7b97\u5f00\u9500\u5c0f&#xff0c;\u56e0\u4e3a\u5b83\u53ea\u9700\u8981\u505a\u4e00\u4e9b\u8ba1\u6570\u548c\u6982\u7387\u8ba1\u7b97&#xff0c;\u6ca1\u6709\u590d\u6742\u7684\u8fed\u4ee3\u4f18\u5316\u8fc7\u7a0b\u3002<\/li>\n<li>\u5bf9\u5c0f\u89c4\u6a21\u6570\u636e\u8868\u73b0\u5f88\u597d&#xff1a;\u5728\u6570\u636e\u91cf\u4e0d\u5927\u7684\u60c5\u51b5\u4e0b&#xff0c;\u4f9d\u7136\u80fd\u83b7\u5f97\u4e0d\u9519\u7684\u6027\u80fd\u3002<\/li>\n<li>\u80fd\u5904\u7406\u591a\u5206\u7c7b\u95ee\u9898&#xff0c;\u4e14\u8868\u73b0\u7a33\u5b9a\u3002<\/li>\n<li>\u5728\u7279\u5f81\u6761\u4ef6\u72ec\u7acb\u6027\u5047\u8bbe\u6210\u7acb\u6216\u8fd1\u4f3c\u6210\u7acb\u65f6&#xff08;\u5982\u6587\u672c\u5206\u7c7b\u4e2d&#xff0c;\u8bcd\u4e0e\u8bcd\u7684\u5173\u8054\u6027\u88ab\u7b80\u5316&#xff09;&#xff0c;\u6548\u679c\u751a\u81f3\u53ef\u4ee5\u5ab2\u7f8e\u590d\u6742\u6a21\u578b\u3002<\/li>\n<\/li>\n<li>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<li>\u201c\u6734\u7d20\u201d\u7684\u5047\u8bbe\u5728\u73b0\u5b9e\u4e2d\u51e0\u4e4e\u4e0d\u6210\u7acb&#xff0c;\u8fd9\u9650\u5236\u4e86\u5176\u9884\u6d4b\u7cbe\u5ea6\u7684\u4e0a\u9650\u3002\u5982\u679c\u7279\u5f81\u4e4b\u95f4\u5b58\u5728\u5f88\u5f3a\u7684\u5173\u8054\u6027&#xff0c;\u6a21\u578b\u7684\u8868\u73b0\u4f1a\u5927\u6253\u6298\u6263\u3002<\/li>\n<li>\u5bf9\u8f93\u5165\u6570\u636e\u7684\u8868\u8fbe\u5f62\u5f0f\u5f88\u654f\u611f\u3002<\/li>\n<li>\u96f6\u6982\u7387\u95ee\u9898&#xff1a;\u7531\u4e8e\u6982\u7387\u662f\u8fde\u4e58\u7684&#xff0c;\u5982\u679c\u67d0\u4e2a\u7279\u5f81\u5728\u8bad\u7ec3\u96c6\u7684\u67d0\u4e2a\u7c7b\u522b\u4e2d\u4ece\u672a\u51fa\u73b0\u8fc7&#xff0c;\u4f1a\u5bfc\u81f4\u5176\u6761\u4ef6\u6982\u7387\u4e3a0&#xff0c;\u4ece\u800c\u4f7f\u5f97\u6574\u4e2a\u540e\u9a8c\u6982\u7387\u8ba1\u7b97\u7ed3\u679c\u4e3a0&#xff0c;\u65e0\u8bba\u5176\u4ed6\u7279\u5f81\u5982\u4f55\u3002\u8fd9\u4e2a\u95ee\u9898\u9700\u8981\u901a\u8fc7**\u62c9\u666e\u62c9\u65af\u5e73\u6ed1&#xff08;Laplace Smoothing&#xff09;**\u6765\u89e3\u51b3&#xff08;Scikit-learn\u4e2d\u7684\u5b9e\u73b0\u5df2\u9ed8\u8ba4\u5904\u7406&#xff09;\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u9002\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\u6587\u672c\u5206\u7c7b&#xff1a;\u8fd9\u662f\u6734\u7d20\u8d1d\u53f6\u65af\u6700\u7ecf\u5178\u3001\u6700\u6210\u529f\u7684\u5e94\u7528\u573a\u666f&#xff0c;\u5982\u5783\u573e\u90ae\u4ef6\u8fc7\u6ee4\u3001\u65b0\u95fb\u4e3b\u9898\u5206\u7c7b\u3001\u60c5\u611f\u5206\u6790\u7b49\u3002<\/li>\n<li>\u4f5c\u4e3a\u4e00\u79cd\u5feb\u901f\u3001\u7b80\u5355\u7684\u57fa\u7ebf\u6a21\u578b&#xff1a;\u4e0e\u903b\u8f91\u56de\u5f52\u7c7b\u4f3c&#xff0c;\u5b83\u53ef\u4ee5\u4e3a\u66f4\u590d\u6742\u7684\u6a21\u578b\u63d0\u4f9b\u4e00\u4e2a\u6027\u80fd\u53c2\u8003\u57fa\u51c6\u3002<\/li>\n<li>\u9002\u7528\u4e8e\u7279\u5f81\u4e4b\u95f4\u5173\u8054\u6027\u8f83\u5f31\u7684\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u7cfb\u7edf\u5730\u5b66\u4e60\u4e86\u4e94\u79cd\u4e3b\u6d41\u7684\u76d1\u7763\u5b66\u4e60\u5206\u7c7b\u7b97\u6cd5\u3002\u6211\u4eec\u4ece\u903b\u8f91\u56de\u5f52\u7684\u6982\u7387\u89c6\u89d2\u51fa\u53d1&#xff0c;\u611f\u53d7\u4e86\u5176\u4f5c\u4e3a\u57fa\u7ebf\u6a21\u578b\u7684\u7a33\u5065\u4e0e\u53ef\u89e3\u91ca\u6027&#xff1b;\u63a5\u7740&#xff0c;\u6211\u4eec\u4f53\u4f1a\u4e86K-\u8fd1\u90bb\u201c\u8fd1\u6731\u8005\u8d64\u201d\u7684\u6734\u7d20\u54f2\u5b66&#xff0c;\u5e76\u8ba4\u8bc6\u5230\u6570\u636e\u6807\u51c6\u5316\u7684\u91cd\u8981\u6027&#xff1b;\u7136\u540e&#xff0c;\u6211\u4eec\u9886\u7565\u4e86\u652f\u6491\u5411\u91cf\u673a\u5728\u7ebf\u6027\u4e0e\u975e\u7ebf\u6027\u4e16\u754c\u4e2d\u5bfb\u627e\u201c\u6700\u5927\u95f4\u9694\u201d\u7684\u6570\u5b66\u4e4b\u7f8e&#xff1b;\u968f\u540e&#xff0c;\u6211\u4eec\u6df1\u5165\u63a2\u7d22\u4e86\u51b3\u7b56\u6811\u4e0e\u968f\u673a\u68ee\u6797\u5982\u4f55\u4ece\u201c\u4e2a\u4f53\u667a\u6167\u201d\u8d70\u5411\u201c\u96c6\u4f53\u667a\u6167\u201d&#xff0c;\u5e76\u89c1\u8bc6\u4e86\u96c6\u6210\u5b66\u4e60\u7684\u5f3a\u5927\u5a01\u529b&#xff1b;\u6700\u540e&#xff0c;\u6211\u4eec\u56de\u5f52\u6982\u7387\u7684\u672c\u6e90&#xff0c;\u7406\u89e3\u4e86\u6734\u7d20\u8d1d\u53f6\u65af\u201c\u6267\u679c\u7d22\u56e0\u201d\u7684\u63a8\u65ad\u903b\u8f91\u53ca\u5176\u5728\u6587\u672c\u4e16\u754c\u7684\u5353\u8d8a\u8868\u73b0\u3002<\/p>\n<p>\u8fd9\u4e94\u79cd\u7b97\u6cd5&#xff0c;\u5982\u540c\u4e94\u4f4d\u6027\u683c\u8fe5\u5f02\u7684\u6b66\u6797\u9ad8\u624b&#xff0c;\u5404\u6709\u5176\u72ec\u95e8\u7edd\u6280\u548c\u9002\u7528\u4e4b\u5730\u3002\u6ca1\u6709\u54ea\u4e00\u4e2a\u7b97\u6cd5\u662f\u6c38\u8fdc\u7684\u201c\u5929\u4e0b\u7b2c\u4e00\u201d&#xff0c;\u771f\u6b63\u7684\u201c\u9ad8\u624b\u201d\u5728\u4e8e\u80fd\u591f\u6d1e\u6089\u95ee\u9898\u7684\u672c\u8d28&#xff0c;\u4e3a\u4e4b\u5339\u914d\u6700\u5408\u9002\u7684\u201c\u62db\u5f0f\u201d\u3002<\/p>\n<p>\u81f3\u6b64&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u5bf9\u201c\u5224\u522b\u201d\u7c7b\u4efb\u52a1\u7684\u63a2\u7d22\u3002\u5728\u4e0b\u4e00\u7ae0&#xff0c;\u6211\u4eec\u5c06\u8f6c\u5411\u76d1\u7763\u5b66\u4e60\u7684\u53e6\u4e00\u4e2a\u91cd\u8981\u5206\u652f\u2014\u2014\u201c\u9884\u6d4b\u201d\u7c7b\u4efb\u52a1&#xff0c;\u6df1\u5165\u5b66\u4e60\u5404\u7c7b\u56de\u5f52\u7b97\u6cd5&#xff0c;\u63a2\u7d22\u5982\u4f55\u7cbe\u51c6\u5730\u9884\u6d4b\u8fde\u7eed\u7684\u6570\u503c\u3002\u8bf7\u5e26\u7740\u672c\u7ae0\u7684\u6536\u83b7&#xff0c;\u51c6\u5907\u597d\u8fdb\u5165\u65b0\u7684\u667a\u6167\u4e4b\u5883\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u516d\u7ae0&#xff1a;\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u9884\u6d4b\u201d\u2014\u2014\u56de\u5f52\u7b97\u6cd5<\/h3>\n<ul>\n<li>6.1 \u7ebf\u6027\u56de\u5f52&#xff1a;\u4ece\u7b80\u5355\u5230\u591a\u5143&#xff0c;\u63a2\u5bfb\u53d8\u91cf\u95f4\u7684\u7ebf\u6027\u5173\u7cfb<\/li>\n<li>6.2 \u5cad\u56de\u5f52\u4e0eLasso\u56de\u5f52&#xff1a;\u6b63\u5219\u5316\u4e0b\u7684\u201c\u4e2d\u5eb8\u4e4b\u9053\u201d<\/li>\n<li>6.3 \u591a\u9879\u5f0f\u56de\u5f52&#xff1a;\u7528\u66f2\u7ebf\u62df\u5408\u590d\u6742\u4e16\u754c<\/li>\n<li>6.4 \u56de\u5f52\u6811\u4e0e\u96c6\u6210\u56de\u5f52\u6a21\u578b&#xff08;\u4f8b\u5982 GBDT, XGBoost&#xff09;<\/li>\n<\/ul>\n<p>\u5728\u524d\u4e00\u7ae0&#xff0c;\u6211\u4eec\u63a2\u7d22\u4e86\u5982\u4f55\u8ba9\u673a\u5668\u5b66\u4f1a\u201c\u5224\u522b\u201d\u4e8b\u7269\u7684\u7c7b\u522b\u3002\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u5f00\u542f\u76d1\u7763\u5b66\u4e60\u7684\u53e6\u4e00\u6247\u5927\u95e8\u2014\u2014\u56de\u5f52&#xff08;Regression&#xff09;\u3002\u56de\u5f52\u4efb\u52a1\u7684\u76ee\u6807\u662f\u9884\u6d4b\u4e00\u4e2a\u8fde\u7eed\u7684\u6570\u503c\u578b\u8f93\u51fa\u3002\u5b83\u6784\u6210\u4e86\u73b0\u4ee3\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u7684\u57fa\u77f3&#xff0c;\u5e94\u7528\u573a\u666f\u65e0\u5904\u4e0d\u5728&#xff1a;<\/p>\n<ul>\n<li>\u7ecf\u6d4e\u91d1\u878d&#xff1a;\u9884\u6d4b\u80a1\u7968\u4ef7\u683c\u3001GDP\u589e\u957f\u7387\u3001\u516c\u53f8\u8425\u6536\u3002<\/li>\n<li>\u623f\u5730\u4ea7&#xff1a;\u6839\u636e\u623f\u5c4b\u7279\u5f81&#xff08;\u9762\u79ef\u3001\u4f4d\u7f6e\u3001\u623f\u9f84&#xff09;\u9884\u6d4b\u5176\u552e\u4ef7\u3002<\/li>\n<li>\u6c14\u8c61\u5b66&#xff1a;\u9884\u6d4b\u660e\u5929\u7684\u6700\u9ad8\u6e29\u5ea6\u3001\u964d\u96e8\u91cf\u3002<\/li>\n<li>\u5546\u4e1a\u8fd0\u8425&#xff1a;\u9884\u6d4b\u7f51\u7ad9\u7684\u8bbf\u95ee\u91cf\u3001\u4ea7\u54c1\u7684\u9500\u91cf\u3001\u5e7f\u544a\u7684\u70b9\u51fb\u7387\u3002<\/li>\n<\/ul>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u4ece\u6700\u7ecf\u5178\u3001\u6700\u57fa\u7840\u7684\u7ebf\u6027\u56de\u5f52\u51fa\u53d1&#xff0c;\u7406\u89e3\u53d8\u91cf\u95f4\u7ebf\u6027\u5173\u7cfb\u7684\u5efa\u6a21\u65b9\u5f0f\u3002\u63a5\u7740&#xff0c;\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u901a\u8fc7\u6b63\u5219\u5316\u6280\u672f&#xff08;\u5cad\u56de\u5f52\u4e0eLasso\u56de\u5f52&#xff09;\u6765\u7ea6\u675f\u548c\u4f18\u5316\u7ebf\u6027\u6a21\u578b&#xff0c;\u4f7f\u5176\u66f4\u52a0\u7a33\u5065\u3002\u7136\u540e&#xff0c;\u6211\u4eec\u4f1a\u770b\u5230\u5982\u4f55\u5229\u7528\u591a\u9879\u5f0f\u7279\u5f81&#xff0c;\u8ba9\u7ebf\u6027\u6a21\u578b\u4e5f\u80fd\u62df\u5408\u590d\u6742\u7684\u975e\u7ebf\u6027\u5173\u7cfb\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u5c06\u8fc8\u5411\u5f53\u4eca\u6700\u5f3a\u5927\u7684\u4e00\u7c7b\u56de\u5f52\u5de5\u5177\u2014\u2014\u4ee5\u56de\u5f52\u6811\u4e3a\u57fa\u7840\u7684\u96c6\u6210\u6a21\u578b&#xff0c;\u5982\u968f\u673a\u68ee\u6797\u3001GBDT\u548cXGBoost&#xff0c;\u5b83\u4eec\u662f\u65e0\u6570\u6570\u636e\u79d1\u5b66\u7ade\u8d5b\u548c\u5de5\u4e1a\u5e94\u7528\u4e2d\u7684\u6027\u80fd\u738b\u8005\u3002<\/p>\n<p>\u51c6\u5907\u597d&#xff0c;\u8ba9\u6211\u4eec\u4e00\u8d77\u63a2\u5bfb\u9884\u6d4b\u8fde\u7eed\u53d8\u91cf\u7684\u5965\u79d8&#xff0c;\u5b66\u4e60\u5982\u4f55\u4e3a\u590d\u6742\u4e16\u754c\u5efa\u7acb\u7cbe\u51c6\u7684\u91cf\u5316\u6a21\u578b\u3002<\/p>\n<hr \/>\n<h4>6.1 \u7ebf\u6027\u56de\u5f52&#xff1a;\u4ece\u7b80\u5355\u5230\u591a\u5143&#xff0c;\u63a2\u5bfb\u53d8\u91cf\u95f4\u7684\u7ebf\u6027\u5173\u7cfb<\/h4>\n<p>\u7ebf\u6027\u56de\u5f52\u662f\u56de\u5f52\u7b97\u6cd5\u5bb6\u65cf\u7684\u201c\u5f00\u5c71\u9f3b\u7956\u201d\u3002\u5b83\u7684\u601d\u60f3\u7b80\u5355\u800c\u5f3a\u5927&#xff1a;\u5047\u8bbe\u76ee\u6807\u53d8\u91cf\u4e0e\u4e00\u4e2a\u6216\u591a\u4e2a\u7279\u5f81\u53d8\u91cf\u4e4b\u95f4\u5b58\u5728\u7ebf\u6027\u5173\u7cfb\u3002\u5c3d\u7ba1\u7b80\u5355&#xff0c;\u4f46\u5b83\u81f3\u4eca\u4ecd\u662f\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u6a21\u578b\u4e4b\u4e00&#xff0c;\u5e76\u4e14\u662f\u7406\u89e3\u66f4\u590d\u6742\u56de\u5f52\u7b97\u6cd5\u7684\u91cd\u8981\u57fa\u7840\u3002<\/p>\n<h5>6.1.1 \u7b80\u5355\u7ebf\u6027\u56de\u5f52&#xff1a;\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u7684\u201c\u673a\u5668\u5b66\u4e60\u201d\u89c6\u89d2<\/h5>\n<p>\u7b80\u5355\u7ebf\u6027\u56de\u5f52\u53ea\u6d89\u53ca\u4e00\u4e2a\u7279\u5f81\u53d8\u91cf&#xff08;\u81ea\u53d8\u91cf\u00a0x&#xff09;\u548c\u4e00\u4e2a\u76ee\u6807\u53d8\u91cf&#xff08;\u56e0\u53d8\u91cf\u00a0y&#xff09;\u3002<\/p>\n<p>\u6a21\u578b\u5f62\u5f0f\u00a0\u6211\u4eec\u8bd5\u56fe\u627e\u5230\u4e00\u6761\u76f4\u7ebf&#xff0c;\u6765\u6700\u597d\u5730\u62df\u5408\u6570\u636e\u70b9\u3002\u8fd9\u6761\u76f4\u7ebf\u7684\u65b9\u7a0b&#xff0c;\u5c31\u662f\u6211\u4eec\u521d\u4e2d\u6570\u5b66\u5b66\u8fc7\u7684\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b&#xff1a;\u00a0\u0177 &#061; wx &#043; b\u00a0\u5728\u673a\u5668\u5b66\u4e60\u8bed\u5883\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u0177\u00a0(y-hat) \u662f\u6a21\u578b\u7684\u9884\u6d4b\u503c\u3002<\/li>\n<li>x\u00a0\u662f\u8f93\u5165\u7684\u7279\u5f81\u503c\u3002<\/li>\n<li>w\u00a0(weight) \u662f\u6743\u91cd\u6216\u7cfb\u6570&#xff0c;\u4ee3\u8868\u7279\u5f81\u00a0x\u00a0\u7684\u91cd\u8981\u6027&#xff0c;\u51e0\u4f55\u4e0a\u662f\u76f4\u7ebf\u7684\u659c\u7387\u3002<\/li>\n<li>b\u00a0(bias) \u662f\u504f\u7f6e\u6216\u622a\u8ddd&#xff0c;\u4ee3\u8868\u5f53\u6240\u6709\u7279\u5f81\u4e3a0\u65f6\u6a21\u578b\u7684\u57fa\u51c6\u8f93\u51fa&#xff0c;\u51e0\u4f55\u4e0a\u662f\u76f4\u7ebf\u5728y\u8f74\u4e0a\u7684\u622a\u8ddd\u3002<\/li>\n<\/ul>\n<p>\u673a\u5668\u5b66\u4e60\u7684\u201c\u8bad\u7ec3\u201d\u8fc7\u7a0b&#xff0c;\u5c31\u662f\u8981\u6839\u636e\u5df2\u6709\u7684\u00a0(x, y)\u00a0\u6570\u636e\u70b9&#xff0c;\u81ea\u52a8\u5730\u627e\u5230\u6700\u4f18\u7684\u00a0w\u00a0\u548c\u00a0b\u3002<\/p>\n<p>\u635f\u5931\u51fd\u6570&#xff1a;\u6700\u5c0f\u4e8c\u4e58\u6cd5&#xff08;Least Squares&#xff09;\u00a0\u5982\u4f55\u8bc4\u5224\u4e00\u7ec4\u00a0w\u00a0\u548c\u00a0b\u00a0\u662f\u4e0d\u662f\u201c\u6700\u4f18\u201d\u7684&#xff1f;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u6807\u51c6\u6765\u8861\u91cf\u6a21\u578b\u7684\u201c\u597d\u574f\u201d\u3002\u5bf9\u4e8e\u56de\u5f52\u95ee\u9898&#xff0c;\u6700\u76f4\u89c2\u7684\u60f3\u6cd5\u662f\u770b\u771f\u5b9e\u503c\u00a0y\u00a0\u548c\u9884\u6d4b\u503c\u00a0\u0177\u00a0\u4e4b\u95f4\u7684\u5dee\u8ddd\u3002<\/p>\n<p>\u6700\u5c0f\u4e8c\u4e58\u6cd5\u5c31\u662f\u8fd9\u4e2a\u6807\u51c6\u3002\u5b83\u5b9a\u4e49\u4e86\u6a21\u578b\u7684\u635f\u5931\u51fd\u6570&#xff08;Loss Function&#xff09;\u6216\u6210\u672c\u51fd\u6570&#xff08;Cost Function&#xff09;\u4e3a\u6240\u6709\u6837\u672c\u7684\u9884\u6d4b\u8bef\u5dee\u7684\u5e73\u65b9\u548c\u3002\u8fd9\u4e2a\u503c\u901a\u5e38\u88ab\u79f0\u4e3a\u6b8b\u5dee\u5e73\u65b9\u548c&#xff08;Residual Sum of Squares, RSS&#xff09;\u3002\u00a0Loss(w, b) &#061; \u03a3(y\u1d62 &#8211; \u0177\u1d62)\u00b2 &#061; \u03a3(y\u1d62 &#8211; (wx\u1d62 &#043; b))\u00b2<\/p>\n<p>\u51e0\u4f55\u610f\u4e49&#xff1a;\u8fd9\u4e2a\u635f\u5931\u51fd\u6570\u4ee3\u8868\u4e86\u6240\u6709\u6570\u636e\u70b9\u5230\u62df\u5408\u76f4\u7ebf\u7684\u5782\u76f4\u8ddd\u79bb\u7684\u5e73\u65b9\u548c\u3002\u00a0\u4ee3\u6570\u610f\u4e49&#xff1a;\u6211\u4eec\u7684\u76ee\u6807\u662f\u627e\u5230\u4e00\u7ec4\u00a0w\u00a0\u548c\u00a0b&#xff0c;\u4f7f\u5f97\u8fd9\u4e2a\u00a0Loss\u00a0\u503c\u6700\u5c0f\u3002<\/p>\n<p>\u6c42\u89e3\u65b9\u6cd5\u7b80\u4ecb\u00a0\u5982\u4f55\u627e\u5230\u6700\u5c0f\u5316\u635f\u5931\u51fd\u6570\u7684\u00a0w\u00a0\u548c\u00a0b&#xff1f;\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u6cd5&#xff1a;<\/p>\n<li>\u6b63\u89c4\u65b9\u7a0b&#xff08;Normal Equation&#xff09;&#xff1a;\u4e00\u79cd\u7eaf\u6570\u5b66\u7684\u89e3\u6cd5\u3002\u901a\u8fc7\u5bf9\u635f\u5931\u51fd\u6570\u6c42\u504f\u5bfc\u5e76\u4ee4\u5176\u4e3a\u96f6&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u89e3\u51fa\u4e00\u4e2a\u5c01\u95ed\u5f62\u5f0f\u7684\u6570\u5b66\u516c\u5f0f&#xff0c;\u4e00\u6b21\u6027\u8ba1\u7b97\u51fa\u6700\u4f18\u7684\u00a0w\u00a0\u548c\u00a0b\u3002\u5b83\u7684\u4f18\u70b9\u662f\u7cbe\u786e&#xff0c;\u65e0\u9700\u8fed\u4ee3&#xff1b;\u7f3a\u70b9\u662f\u5f53\u7279\u5f81\u6570\u91cf\u975e\u5e38\u5927\u65f6&#xff0c;\u77e9\u9635\u6c42\u9006\u7684\u8ba1\u7b97\u6210\u672c\u6781\u9ad8\u3002<\/li>\n<li>\u68af\u5ea6\u4e0b\u964d&#xff08;Gradient Descent&#xff09;&#xff1a;\u4e00\u79cd\u8fed\u4ee3\u5f0f\u7684\u4f18\u5316\u7b97\u6cd5\u3002\u5b83\u5c31\u50cf\u4e00\u4e2a\u8499\u7740\u773c\u775b\u4e0b\u5c71\u7684\u4eba&#xff0c;\u4ece\u4e00\u4e2a\u968f\u673a\u7684\u00a0(w, b)\u00a0\u70b9\u51fa\u53d1&#xff0c;\u6bcf\u6b21\u90fd\u6cbf\u7740\u5f53\u524d\u4f4d\u7f6e**\u6700\u9661\u5ced\u7684\u4e0b\u5761\u65b9\u5411&#xff08;\u68af\u5ea6\u7684\u53cd\u65b9\u5411&#xff09;**\u8d70\u4e00\u5c0f\u6b65&#xff0c;\u4e0d\u65ad\u8fed\u4ee3&#xff0c;\u76f4\u5230\u8d70\u5230\u5c71\u8c37\u7684\u6700\u4f4e\u70b9&#xff08;\u635f\u5931\u51fd\u6570\u7684\u6700\u5c0f\u503c\u70b9&#xff09;\u3002\u5b83\u662f\u7edd\u5927\u591a\u6570\u673a\u5668\u5b66\u4e60\u6a21\u578b&#xff08;\u5305\u62ec\u6df1\u5ea6\u5b66\u4e60&#xff09;\u7684\u6838\u5fc3\u4f18\u5316\u7b97\u6cd5\u3002<\/li>\n<h5>6.1.2 \u591a\u5143\u7ebf\u6027\u56de\u5f52&#xff1a;\u4ece\u201c\u7ebf\u201d\u5230\u201c\u9762\u201d\u7684\u6269\u5c55<\/h5>\n<p>\u73b0\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u4e00\u4e2a\u7ed3\u679c\u5f80\u5f80\u7531\u591a\u4e2a\u56e0\u7d20\u5171\u540c\u51b3\u5b9a\u3002\u4f8b\u5982&#xff0c;\u623f\u4ef7\u4e0d\u4ec5\u4e0e\u9762\u79ef\u6709\u5173&#xff0c;\u8fd8\u4e0e\u5730\u6bb5\u3001\u623f\u9f84\u3001\u697c\u5c42\u7b49\u591a\u4e2a\u7279\u5f81\u6709\u5173\u3002\u8fd9\u65f6&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u4f7f\u7528\u591a\u5143\u7ebf\u6027\u56de\u5f52&#xff08;Multiple Linear Regression&#xff09;\u3002<\/p>\n<p>\u6a21\u578b\u5f62\u5f0f\u00a0\u5b83\u53ea\u662f\u7b80\u5355\u7ebf\u6027\u56de\u5f52\u7684\u76f4\u63a5\u6269\u5c55&#xff0c;\u4ece\u4e00\u4e2a\u7279\u5f81\u6269\u5c55\u5230\u00a0n\u00a0\u4e2a\u7279\u5f81&#xff1a;\u00a0\u0177 &#061; w\u2081x\u2081 &#043; w\u2082x\u2082 &#043; &#8230; &#043; w\u2099x\u2099 &#043; b\u6216\u8005\u7528\u66f4\u7b80\u6d01\u7684\u5411\u91cf\u5f62\u5f0f\u8868\u793a&#xff1a;\u00a0\u0177 &#061; w\u1d40X &#043; b\u00a0\u8fd9\u91cc\u7684\u00a0w\u00a0\u662f\u4e00\u4e2a\u6743\u91cd\u5411\u91cf&#xff0c;X\u00a0\u662f\u4e00\u4e2a\u7279\u5f81\u5411\u91cf\u3002\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u5b83\u62df\u5408\u7684\u662f\u4e00\u4e2a\u5e73\u9762&#xff1b;\u5728\u66f4\u9ad8\u7ef4\u7684\u7a7a\u95f4\u4e2d&#xff0c;\u5b83\u62df\u5408\u7684\u662f\u4e00\u4e2a\u8d85\u5e73\u9762\u3002<\/p>\n<p>\u6838\u5fc3\u5047\u8bbe\u00a0\u4e3a\u4e86\u8ba9\u591a\u5143\u7ebf\u6027\u56de\u5f52\u7684\u7ed3\u679c\u53ef\u9760\u4e14\u5177\u6709\u826f\u597d\u7684\u89e3\u91ca\u6027&#xff0c;\u5b83\u4f9d\u8d56\u4e8e\u51e0\u4e2a\u6838\u5fc3\u5047\u8bbe&#xff0c;\u5e38\u88ab\u603b\u7ed3\u4e3a**\u201cLINE\u201d**\u539f\u5219&#xff1a;<\/p>\n<li>\u7ebf\u6027&#xff08;Linearity&#xff09;&#xff1a;\u7279\u5f81\u548c\u76ee\u6807\u53d8\u91cf\u4e4b\u95f4\u5b58\u5728\u7ebf\u6027\u5173\u7cfb\u3002<\/li>\n<li>\u72ec\u7acb\u6027&#xff08;Independence&#xff09;&#xff1a;\u6837\u672c\u7684\u8bef\u5dee&#xff08;\u6b8b\u5dee&#xff09;\u4e4b\u95f4\u76f8\u4e92\u72ec\u7acb\u3002<\/li>\n<li>\u6b63\u6001\u6027&#xff08;Normality&#xff09;&#xff1a;\u8bef\u5dee\u670d\u4ece\u6b63\u6001\u5206\u5e03\u3002<\/li>\n<li>\u540c\u65b9\u5dee\u6027&#xff08;Equal variance \/ Homoscedasticity&#xff09;&#xff1a;\u8bef\u5dee\u7684\u65b9\u5dee\u5728\u6240\u6709\u9884\u6d4b\u503c\u6c34\u5e73\u4e0a\u662f\u6052\u5b9a\u7684\u3002<\/li>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u8fd9\u4e9b\u5047\u8bbe\u4e0d\u4e00\u5b9a\u80fd\u5b8c\u7f8e\u6ee1\u8db3&#xff0c;\u4f46\u4e86\u89e3\u5b83\u4eec\u6709\u52a9\u4e8e\u6211\u4eec\u8bca\u65ad\u6a21\u578b\u7684\u95ee\u9898\u3002<\/p>\n<h5>6.1.3 Scikit-learn\u5b9e\u6218\u4e0e\u6a21\u578b\u89e3\u8bfb<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0Scikit-learn\u8ba9\u4f7f\u7528\u7ebf\u6027\u56de\u5f52\u53d8\u5f97\u5f02\u5e38\u7b80\u5355\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u7ecf\u5178\u7684\u6ce2\u58eb\u987f\u623f\u4ef7\u6570\u636e\u96c6\u8fdb\u884c\u6f14\u793a\u3002\u8fd9\u4e2a\u6570\u636e\u96c6\u5305\u542b\u4e86\u5f71\u54cd\u623f\u4ef7\u7684\u591a\u79cd\u56e0\u7d20&#xff08;\u5982\u72af\u7f6a\u7387\u3001\u623f\u95f4\u6570\u3001\u5b66\u751f\u6559\u5e08\u6bd4\u7b49&#xff09;&#xff0c;\u6211\u4eec\u7684\u76ee\u6807\u662f\u5efa\u7acb\u4e00\u4e2a\u6a21\u578b\u6765\u9884\u6d4b\u623f\u4ef7\u3002<\/p>\n<p># \u5bfc\u5165\u5fc5\u8981\u7684\u5e93<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.linear_model import LinearRegression<br \/>\nfrom sklearn.metrics import mean_squared_error, r2_score<br \/>\nimport pandas as pd<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport seaborn as sns<\/p>\n<p># &#8212; \u6570\u636e\u51c6\u5907 &#8212;<br \/>\n# \u52a0\u8f7d\u6570\u636e (Scikit-learn 1.2\u540e&#xff0c;\u6ce2\u58eb\u987f\u623f\u4ef7\u6570\u636e\u96c6\u56e0\u4f26\u7406\u95ee\u9898\u88ab\u79fb\u9664&#xff0c;\u6211\u4eec\u4ece\u5176\u4ed6\u6e90\u52a0\u8f7d)<br \/>\ndata_url &#061; &#034;http:\/\/lib.stat.cmu.edu\/datasets\/boston&#034;<br \/>\nraw_df &#061; pd.read_csv(data_url, sep&#061;&#034;\\\\s&#043;&#034;, skiprows&#061;22, header&#061;None )<br \/>\ndata &#061; np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])<br \/>\ntarget &#061; raw_df.values[1::2, 2]<br \/>\nfeature_names &#061; [&#039;CRIM&#039;, &#039;ZN&#039;, &#039;INDUS&#039;, &#039;CHAS&#039;, &#039;NOX&#039;, &#039;RM&#039;, &#039;AGE&#039;, &#039;DIS&#039;, &#039;RAD&#039;, &#039;TAX&#039;, &#039;PTRATIO&#039;, &#039;B&#039;, &#039;LSTAT&#039;]<br \/>\nX &#061; pd.DataFrame(data, columns&#061;feature_names)<br \/>\ny &#061; pd.Series(target, name&#061;&#039;PRICE&#039;)<\/p>\n<p># 1. \u5212\u5206\u6570\u636e<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.2, random_state&#061;42)<\/p>\n<p># 2. \u521d\u59cb\u5316\u5e76\u8bad\u7ec3\u6a21\u578b<br \/>\n# Scikit-learn\u7684LinearRegression\u9ed8\u8ba4\u4f7f\u7528\u6b63\u89c4\u65b9\u7a0b\u6c42\u89e3<br \/>\nlr_model &#061; LinearRegression()<br \/>\nlr_model.fit(X_train, y_train)<\/p>\n<p># 3. \u9884\u6d4b<br \/>\ny_pred &#061; lr_model.predict(X_test)<\/p>\n<p># 4. \u8bc4\u4f30<br \/>\nmse &#061; mean_squared_error(y_test, y_pred)<br \/>\nrmse &#061; np.sqrt(mse)<br \/>\nr2 &#061; r2_score(y_test, y_pred)<\/p>\n<p>print(&#034;&#8212; \u7ebf\u6027\u56de\u5f52\u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\nprint(f&#034;\u5747\u65b9\u8bef\u5dee (MSE): {mse:.2f}&#034;)<br \/>\nprint(f&#034;\u5747\u65b9\u6839\u8bef\u5dee (RMSE): {rmse:.2f}&#034;)<br \/>\nprint(f&#034;R^2 \u5206\u6570: {r2:.2f}&#034;)<\/p>\n<p>\u7cfb\u6570\u89e3\u8bfb&#xff08;Coefficients&#xff09;\u00a0\u7ebf\u6027\u56de\u5f52\u7684\u4e00\u5927\u4f18\u70b9\u662f\u5176\u53ef\u89e3\u91ca\u6027\u3002\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u67e5\u770b\u6a21\u578b\u5b66\u4e60\u5230\u7684\u6743\u91cd&#xff08;\u7cfb\u6570&#xff09;&#xff0c;\u6765\u7406\u89e3\u6bcf\u4e2a\u7279\u5f81\u5bf9\u9884\u6d4b\u7ed3\u679c\u7684\u5f71\u54cd\u3002<\/p>\n<p># \u67e5\u770b\u622a\u8ddd\u548c\u7cfb\u6570<br \/>\nprint(f&#034;\\\\n\u622a\u8ddd (b): {lr_model.intercept_:.2f}&#034;)<br \/>\ncoefficients &#061; pd.Series(lr_model.coef_, index&#061;X.columns).sort_values()<br \/>\nprint(&#034;\u7cfb\u6570 (w):\\\\n&#034;, coefficients)<\/p>\n<p># \u53ef\u89c6\u5316\u7cfb\u6570<br \/>\nplt.figure(figsize&#061;(10, 6))<br \/>\ncoefficients.plot(kind&#061;&#039;bar&#039;)<br \/>\nplt.title(&#039;Coefficients of the Linear Regression Model&#039;)<br \/>\nplt.show()<\/p>\n<p>\u5982\u4f55\u89e3\u8bfb\u7cfb\u6570&#xff1f;\u00a0\u4ee5RM&#xff08;\u5e73\u5747\u6bcf\u6237\u4f4f\u5b85\u7684\u623f\u95f4\u6570&#xff09;\u4e3a\u4f8b&#xff0c;\u5176\u7cfb\u6570\u4e3a\u6b63\u6570&#xff08;\u7ea62.94&#xff09;&#xff0c;\u5219\u610f\u5473\u7740\u5728\u5176\u4ed6\u6240\u6709\u7279\u5f81\u4fdd\u6301\u4e0d\u53d8\u7684\u60c5\u51b5\u4e0b&#xff0c;\u623f\u95f4\u6570\u6bcf\u589e\u52a01\u4e2a\u5355\u4f4d&#xff0c;\u9884\u6d4b\u7684\u623f\u4ef7\u5e73\u5747\u4f1a\u589e\u52a0\u7ea62.94\u4e07\u7f8e\u5143\u3002\u53cd\u4e4b&#xff0c;LSTAT&#xff08;\u4f4e\u5730\u4f4d\u4eba\u53e3\u6bd4\u4f8b&#xff09;\u7684\u7cfb\u6570\u4e3a\u8d1f\u6570&#xff08;\u7ea6-0.55&#xff09;&#xff0c;\u5219\u8bf4\u660e\u8be5\u6bd4\u4f8b\u8d8a\u9ad8&#xff0c;\u9884\u6d4b\u7684\u623f\u4ef7\u8d8a\u4f4e\u3002<\/p>\n<p>\u91cd\u8981\u63d0\u793a&#xff1a;\u53ea\u6709\u5f53\u6240\u6709\u7279\u5f81\u5904\u4e8e\u76f8\u540c\u6216\u76f8\u4f3c\u7684\u5c3a\u5ea6\u65f6&#xff0c;\u6211\u4eec\u624d\u80fd\u76f4\u63a5\u6bd4\u8f83\u7cfb\u6570\u7684\u7edd\u5bf9\u503c\u5927\u5c0f\u6765\u5224\u65ad\u7279\u5f81\u7684\u76f8\u5bf9\u91cd\u8981\u6027\u3002\u5426\u5219&#xff0c;\u4e00\u4e2a\u5355\u4f4d\u53d8\u5316\u5f88\u5927\u7684\u7279\u5f81&#xff08;\u5982\u603b\u8d44\u4ea7&#xff09;\u5373\u4f7f\u7cfb\u6570\u5f88\u5c0f&#xff0c;\u5176\u5f71\u54cd\u529b\u4e5f\u53ef\u80fd\u8d85\u8fc7\u4e00\u4e2a\u5355\u4f4d\u53d8\u5316\u5f88\u5c0f\u7684\u7279\u5f81&#xff08;\u5982\u5e74\u9f84&#xff09;\u3002\u56e0\u6b64&#xff0c;\u5728\u89e3\u8bfb\u7cfb\u6570\u91cd\u8981\u6027\u4e4b\u524d&#xff0c;\u901a\u5e38\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u3002<\/p>\n<p>\u8bc4\u4f30\u6307\u6807\u00a0\u9664\u4e86\u5728\u7b2c\u56db\u7ae0\u5b66\u8fc7\u7684MAE, MSE, RMSE&#xff0c;\u56de\u5f52\u4efb\u52a1\u4e2d\u6700\u5e38\u7528\u7684\u76f8\u5bf9\u8bc4\u4f30\u6307\u6807\u662fR\u00b2 (R-squared)\u3002<\/p>\n<ul>\n<li>R\u00b2&#xff0c;\u5373\u51b3\u5b9a\u7cfb\u6570&#xff0c;\u8861\u91cf\u7684\u662f\u6a21\u578b\u80fd\u591f\u89e3\u91ca\u7684\u76ee\u6807\u53d8\u91cf\u65b9\u5dee\u7684\u767e\u5206\u6bd4\u3002R\u00b2\u8d8a\u63a5\u8fd11&#xff0c;\u8bf4\u660e\u6a21\u578b\u7684\u62df\u5408\u6548\u679c\u8d8a\u597d\u3002\u4e00\u4e2aR\u00b2\u4e3a0.67\u7684\u6a21\u578b&#xff0c;\u610f\u5473\u7740\u5b83\u80fd\u89e3\u91ca67%\u7684\u623f\u4ef7\u53d8\u52a8\u3002\u5269\u4e0b\u768433%\u5219\u662f\u7531\u6a21\u578b\u672a\u5305\u542b\u7684\u5176\u4ed6\u56e0\u7d20\u5f15\u8d77\u7684\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>6.2 \u5cad\u56de\u5f52\u4e0eLasso\u56de\u5f52&#xff1a;\u6b63\u5219\u5316\u4e0b\u7684\u201c\u4e2d\u5eb8\u4e4b\u9053\u201d<\/h4>\n<p>\u666e\u901a\u7ebf\u6027\u56de\u5f52&#xff08;\u4e5f\u79f0OLS&#xff0c;Ordinary Least Squares&#xff09;\u867d\u7136\u7b80\u5355&#xff0c;\u4f46\u5b83\u6709\u4e24\u4e2a\u4e3b\u8981\u7684\u201c\u70e6\u607c\u201d&#xff1a;\u8fc7\u62df\u5408\u548c\u591a\u91cd\u5171\u7ebf\u6027\u3002\u6b63\u5219\u5316\u56de\u5f52\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f\u7684\u3002<\/p>\n<h5>6.2.1 \u7ebf\u6027\u56de\u5f52\u7684\u201c\u70e6\u607c\u201d&#xff1a;\u8fc7\u62df\u5408\u4e0e\u591a\u91cd\u5171\u7ebf\u6027<\/h5>\n<ul>\n<li>\u8fc7\u62df\u5408\u73b0\u8c61&#xff1a;\u5f53\u7279\u5f81\u6570\u91cf\u5f88\u591a&#xff0c;\u7279\u522b\u662f\u76f8\u5bf9\u4e8e\u6837\u672c\u6570\u91cf\u800c\u8a00\u65f6&#xff0c;\u7ebf\u6027\u56de\u5f52\u6a21\u578b\u4f1a\u53d8\u5f97\u8fc7\u4e8e\u590d\u6742\u3002\u5b83\u4f1a\u8bd5\u56fe\u53bb\u5b8c\u7f8e\u62df\u5408\u8bad\u7ec3\u6570\u636e\u4e2d\u7684\u6bcf\u4e00\u4e2a\u70b9&#xff0c;\u5305\u62ec\u566a\u58f0\u3002\u8fd9\u4f1a\u5bfc\u81f4\u6a21\u578b\u7684\u7cfb\u6570&#xff08;\u6743\u91cd\u00a0w&#xff09;\u53d8\u5f97\u5f02\u5e38\u5927&#xff0c;\u6a21\u578b\u5728\u8bad\u7ec3\u96c6\u4e0a\u8868\u73b0\u5f88\u597d&#xff0c;\u4f46\u5728\u6d4b\u8bd5\u96c6\u4e0a\u8868\u73b0\u5f88\u5dee\u3002<\/li>\n<li>\u591a\u91cd\u5171\u7ebf\u6027&#xff08;Multicollinearity&#xff09;&#xff1a;\u5f53\u4e24\u4e2a\u6216\u591a\u4e2a\u7279\u5f81\u9ad8\u5ea6\u76f8\u5173\u65f6&#xff08;\u4f8b\u5982&#xff0c;\u201c\u623f\u5c4b\u9762\u79ef\u201d\u548c\u201c\u623f\u95f4\u6570\u201d&#xff09;&#xff0c;\u7ebf\u6027\u56de\u5f52\u7684\u7cfb\u6570\u4f1a\u53d8\u5f97\u975e\u5e38\u4e0d\u7a33\u5b9a\u3002\u7a0d\u5fae\u6539\u53d8\u4e00\u4e0b\u8bad\u7ec3\u6570\u636e&#xff0c;\u7cfb\u6570\u7684\u503c\u5c31\u53ef\u80fd\u53d1\u751f\u5267\u70c8\u53d8\u5316&#xff0c;\u751a\u81f3\u6b63\u8d1f\u98a0\u5012\u3002\u8fd9\u4f7f\u5f97\u6211\u4eec\u65e0\u6cd5\u518d\u4fe1\u4efb\u7cfb\u6570\u7684\u89e3\u91ca\u6027\u3002<\/li>\n<\/ul>\n<p>\u6b63\u5219\u5316\u901a\u8fc7\u5728\u635f\u5931\u51fd\u6570\u4e2d\u52a0\u5165\u4e00\u4e2a\u60e9\u7f5a\u9879&#xff0c;\u6765\u5bf9\u6a21\u578b\u7684\u590d\u6742\u5ea6&#xff08;\u5373\u7cfb\u6570\u7684\u5927\u5c0f&#xff09;\u8fdb\u884c\u7ea6\u675f&#xff0c;\u4ece\u800c\u7f13\u89e3\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<h5>6.2.2 \u5cad\u56de\u5f52&#xff08;Ridge Regression&#xff09;&#xff1a;\u5728\u201c\u5c71\u5cad\u201d\u4e0a\u4fdd\u6301\u5e73\u8861<\/h5>\n<p>\u5cad\u56de\u5f52\u5728\u7ebf\u6027\u56de\u5f52\u7684\u539f\u59cb\u635f\u5931\u51fd\u6570&#xff08;RSS&#xff09;\u7684\u57fa\u7840\u4e0a&#xff0c;\u589e\u52a0\u4e86\u4e00\u4e2aL2\u6b63\u5219\u5316\u9879\u3002<\/p>\n<p>L2\u6b63\u5219\u5316\u00a0Loss_Ridge &#061; \u03a3(y\u1d62 &#8211; \u0177\u1d62)\u00b2 &#043; \u03b1 * \u03a3(w\u2c7c)\u00b2<\/p>\n<ul>\n<li>\u03a3(w\u2c7c)\u00b2\u00a0\u662f\u6240\u6709\u7279\u5f81\u7cfb\u6570\u7684\u5e73\u65b9\u548c\u3002<\/li>\n<li>\u03b1\u00a0(alpha) \u662f\u4e00\u4e2a\u8d85\u53c2\u6570&#xff0c;\u7528\u4e8e\u63a7\u5236\u6b63\u5219\u5316\u7684\u5f3a\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u8d85\u53c2\u6570Alpha&#xff08;\u03b1&#xff09;<\/p>\n<ul>\n<li>\u5f53\u00a0\u03b1 &#061; 0\u00a0\u65f6&#xff0c;\u5cad\u56de\u5f52\u5c31\u9000\u5316\u4e3a\u666e\u901a\u7684\u7ebf\u6027\u56de\u5f52\u3002<\/li>\n<li>\u5f53\u00a0\u03b1\u00a0\u589e\u5927\u65f6&#xff0c;\u5bf9\u5927\u7cfb\u6570\u7684\u60e9\u7f5a\u5c31\u8d8a\u5f3a&#xff0c;\u6a21\u578b\u4f1a\u8feb\u4f7f\u6240\u6709\u7cfb\u6570\u90fd\u54110\u6536\u7f29&#xff0c;\u4f46\u4e0d\u4f1a\u5b8c\u5168\u7b49\u4e8e0\u3002<\/li>\n<li>\u5f53\u00a0\u03b1 -&gt; \u221e\u00a0\u65f6&#xff0c;\u6240\u6709\u7cfb\u6570\u90fd\u5c06\u65e0\u9650\u8d8b\u8fd1\u4e8e0&#xff0c;\u6a21\u578b\u53d8\u4e3a\u4e00\u6761\u6c34\u5e73\u7ebf&#xff08;\u53ea\u5269\u4e0b\u622a\u8ddd&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u6548\u679c\u00a0\u901a\u8fc7\u60e9\u7f5a\u5927\u7cfb\u6570&#xff0c;\u5cad\u56de\u5f52\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u6a21\u578b\u8fc7\u62df\u5408\u3002\u540c\u65f6&#xff0c;\u5728\u5904\u7406\u591a\u91cd\u5171\u7ebf\u6027\u95ee\u9898\u65f6&#xff0c;\u5b83\u503e\u5411\u4e8e\u5c06\u76f8\u5173\u7279\u5f81\u7684\u7cfb\u6570\u201c\u5747\u5206\u201d\u6743\u91cd&#xff0c;\u800c\u4e0d\u662f\u50cf\u666e\u901a\u7ebf\u6027\u56de\u5f52\u90a3\u6837\u968f\u610f\u5730\u7ed9\u4e00\u4e2a\u5f88\u5927\u7684\u6b63\u7cfb\u6570\u548c\u53e6\u4e00\u4e2a\u5f88\u5927\u7684\u8d1f\u7cfb\u6570&#xff0c;\u4ece\u800c\u4f7f\u6a21\u578b\u66f4\u52a0\u7a33\u5b9a\u3002<\/p>\n<h5>6.2.3 Lasso\u56de\u5f52&#xff08;Least Absolute Shrinkage and Selection Operator&#xff09;&#xff1a;\u7a00\u758f\u6027\u7684\u529b\u91cf<\/h5>\n<p>Lasso\u56de\u5f52\u4e0e\u5cad\u56de\u5f52\u975e\u5e38\u76f8\u4f3c&#xff0c;\u4f46\u5b83\u4f7f\u7528\u7684\u662fL1\u6b63\u5219\u5316\u9879\u3002<\/p>\n<p>L1\u6b63\u5219\u5316\u00a0Loss_Lasso &#061; \u03a3(y\u1d62 &#8211; \u0177\u1d62)\u00b2 &#043; \u03b1 * \u03a3|w\u2c7c|<\/p>\n<ul>\n<li>\u03a3|w\u2c7c|\u00a0\u662f\u6240\u6709\u7279\u5f81\u7cfb\u6570\u7684\u7edd\u5bf9\u503c\u4e4b\u548c\u3002<\/li>\n<\/ul>\n<p>\u7a00\u758f\u89e3\u4e0e\u7279\u5f81\u9009\u62e9\u00a0L1\u6b63\u5219\u5316\u4e0eL2\u6b63\u5219\u5316\u6709\u4e00\u4e2a\u5173\u952e\u7684\u533a\u522b&#xff1a;L1\u6b63\u5219\u5316\u80fd\u591f\u5c06\u4e00\u4e9b\u4e0d\u91cd\u8981\u7684\u7279\u5f81\u7684\u7cfb\u6570\u5b8c\u5168\u538b\u7f29\u52300\u3002<\/p>\n<ul>\n<li>\u51e0\u4f55\u4e0a&#xff0c;L2\u7684\u60e9\u7f5a\u9879\u662f\u5706\u5f62&#xff0c;\u800cL1\u662f\u83f1\u5f62\u3002\u635f\u5931\u51fd\u6570\u7684\u7b49\u9ad8\u7ebf\u5728\u4e0e\u83f1\u5f62\u7684\u9876\u70b9\u76f8\u4ea4\u65f6&#xff0c;\u66f4\u5bb9\u6613\u4f7f\u5f97\u67d0\u4e9b\u5750\u6807\u8f74\u4e0a\u7684\u7cfb\u6570\u4e3a0\u3002<\/li>\n<li>\u8fd9\u4e2a\u7279\u6027\u4f7f\u5f97Lasso\u56de\u5f52\u5177\u6709\u81ea\u52a8\u8fdb\u884c\u7279\u5f81\u9009\u62e9\u7684\u80fd\u529b\u3002\u8bad\u7ec3\u5b8c\u4e00\u4e2aLasso\u6a21\u578b\u540e&#xff0c;\u90a3\u4e9b\u7cfb\u6570\u4e0d\u4e3a0\u7684\u7279\u5f81&#xff0c;\u5c31\u662f\u6a21\u578b\u8ba4\u4e3a\u6bd4\u8f83\u91cd\u8981\u7684\u7279\u5f81\u3002\u8fd9\u79cd\u4ea7\u751f\u201c\u7a00\u758f\u89e3\u201d&#xff08;\u5927\u90e8\u5206\u7cfb\u6570\u4e3a0&#xff09;\u7684\u80fd\u529b\u5728\u7279\u5f81\u6570\u91cf\u5e9e\u5927\u7684\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/li>\n<\/ul>\n<h5>6.2.4 Scikit-learn\u5b9e\u6218\u4e0e\u5f39\u6027\u7f51\u7edc&#xff08;Elastic Net&#xff09;<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0\u4f7f\u7528\u6b63\u5219\u5316\u56de\u5f52\u65f6&#xff0c;\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316\u662f\u81f3\u5173\u91cd\u8981\u7684&#xff0c;\u56e0\u4e3a\u60e9\u7f5a\u9879\u662f\u57fa\u4e8e\u7cfb\u6570\u7684\u5927\u5c0f\u7684&#xff0c;\u5982\u679c\u7279\u5f81\u5c3a\u5ea6\u4e0d\u540c&#xff0c;\u60e9\u7f5a\u5c31\u4f1a\u4e0d\u516c\u5e73\u3002<\/p>\n<p>from sklearn.preprocessing import StandardScaler<br \/>\nfrom sklearn.linear_model import Ridge, Lasso, ElasticNet<br \/>\nfrom sklearn.model_selection import GridSearchCV<\/p>\n<p># \u6807\u51c6\u5316\u6570\u636e<br \/>\nscaler &#061; StandardScaler()<br \/>\nX_train_scaled &#061; scaler.fit_transform(X_train)<br \/>\nX_test_scaled &#061; scaler.transform(X_test)<\/p>\n<p># &#8212; \u5cad\u56de\u5f52 &#8212;<br \/>\nridge &#061; Ridge(alpha&#061;1.0)<br \/>\nridge.fit(X_train_scaled, y_train)<br \/>\nprint(f&#034;\u5cad\u56de\u5f52\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684R^2: {ridge.score(X_test_scaled, y_test):.2f}&#034;)<\/p>\n<p># &#8212; Lasso\u56de\u5f52 &#8212;<br \/>\nlasso &#061; Lasso(alpha&#061;0.1)<br \/>\nlasso.fit(X_train_scaled, y_train)<br \/>\nprint(f&#034;Lasso\u56de\u5f52\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684R^2: {lasso.score(X_test_scaled, y_test):.2f}&#034;)<br \/>\nprint(f&#034;Lasso\u9009\u51fa\u7684\u7279\u5f81\u6570\u91cf: {np.sum(lasso.coef_ !&#061; 0)}&#034;)<\/p>\n<p># &#8212; \u4f7f\u7528GridSearchCV\u5bfb\u627e\u6700\u4f18alpha &#8212;<br \/>\nparam_grid &#061; {&#039;alpha&#039;: [0.001, 0.01, 0.1, 1, 10, 100]}<br \/>\nridge_cv &#061; GridSearchCV(Ridge(), param_grid, cv&#061;5)<br \/>\nridge_cv.fit(X_train_scaled, y_train)<br \/>\nprint(f&#034;\\\\n\u5cad\u56de\u5f52\u6700\u4f18alpha: {ridge_cv.best_params_[&#039;alpha&#039;]}&#034;)<\/p>\n<p>\u5f39\u6027\u7f51\u7edc&#xff08;Elastic Net&#xff09;\u00a0\u5f39\u6027\u7f51\u7edc\u662f\u5cad\u56de\u5f52\u548cLasso\u56de\u5f52\u7684\u7ed3\u5408\u4f53&#xff0c;\u5b83\u540c\u65f6\u4f7f\u7528\u4e86L1\u548cL2\u4e24\u79cd\u6b63\u5219\u5316\u3002\u00a0Loss_ElasticNet &#061; RSS &#043; \u03b1 * [ l1_ratio * \u03a3|w\u2c7c| &#043; (1 &#8211; l1_ratio) * 0.5 * \u03a3(w\u2c7c)\u00b2 ]<\/p>\n<ul>\n<li>\u5b83\u6709\u4e24\u4e2a\u8d85\u53c2\u6570&#xff1a;alpha\u00a0\u63a7\u5236\u6574\u4f53\u6b63\u5219\u5316\u5f3a\u5ea6&#xff0c;l1_ratio\u00a0\u63a7\u5236L1\u548cL2\u60e9\u7f5a\u7684\u6bd4\u4f8b\u3002<\/li>\n<li>\u5f53\u00a0l1_ratio &#061; 1\u00a0\u65f6&#xff0c;\u5b83\u5c31\u662fLasso&#xff1b;\u5f53\u00a0l1_ratio &#061; 0\u00a0\u65f6&#xff0c;\u5b83\u5c31\u662fRidge\u3002<\/li>\n<\/ul>\n<p>\u4f55\u65f6\u9009\u62e9<\/p>\n<ul>\n<li>\u5cad\u56de\u5f52&#xff1a;\u662f\u9ed8\u8ba4\u7684\u9996\u9009\u3002\u5f53\u4f60\u77e5\u9053\u5927\u90e8\u5206\u7279\u5f81\u90fd\u6709\u7528\u65f6&#xff0c;\u5b83\u901a\u5e38\u8868\u73b0\u66f4\u597d\u3002<\/li>\n<li>Lasso\u56de\u5f52&#xff1a;\u5f53\u4f60\u6000\u7591\u5f88\u591a\u7279\u5f81\u662f\u65e0\u7528\u6216\u5197\u4f59\u7684&#xff0c;\u5e76\u5e0c\u671b\u6a21\u578b\u80fd\u5e2e\u4f60\u81ea\u52a8\u7b5b\u9009\u7279\u5f81\u65f6&#xff0c;Lasso\u662f\u7edd\u4f73\u9009\u62e9\u3002<\/li>\n<li>\u5f39\u6027\u7f51\u7edc&#xff1a;\u5f53\u5b58\u5728\u9ad8\u5ea6\u76f8\u5173\u7684\u7279\u5f81\u7fa4\u7ec4\u65f6&#xff0c;Lasso\u503e\u5411\u4e8e\u53ea\u968f\u673a\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u7279\u5f81&#xff0c;\u800c\u5f39\u6027\u7f51\u7edc\u5219\u80fd\u50cf\u5cad\u56de\u5f52\u4e00\u6837&#xff0c;\u5c06\u8fd9\u4e2a\u7fa4\u7ec4\u7684\u7279\u5f81\u90fd\u9009\u5165\u6a21\u578b\u3002\u56e0\u6b64&#xff0c;\u5728\u6709\u5171\u7ebf\u6027\u4e14\u9700\u8981\u7279\u5f81\u9009\u62e9\u65f6&#xff0c;\u5f39\u6027\u7f51\u7edc\u662f\u6700\u597d\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>6.3 \u591a\u9879\u5f0f\u56de\u5f52&#xff1a;\u7528\u66f2\u7ebf\u62df\u5408\u590d\u6742\u4e16\u754c<\/h4>\n<h5>6.3.1 \u8d85\u8d8a\u7ebf\u6027&#xff1a;\u5f53\u5173\u7cfb\u4e0d\u518d\u662f\u76f4\u7ebf<\/h5>\n<p>\u7ebf\u6027\u56de\u5f52\u6709\u4e00\u4e2a\u5f88\u5f3a\u7684\u5047\u8bbe&#xff1a;\u7279\u5f81\u548c\u76ee\u6807\u53d8\u91cf\u4e4b\u95f4\u662f\u7ebf\u6027\u5173\u7cfb\u3002\u4f46\u73b0\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u5f88\u591a\u5173\u7cfb\u662f\u66f2\u7ebf\u5f62\u7684\u3002\u4f8b\u5982&#xff0c;\u65bd\u80a5\u91cf\u4e0e\u4f5c\u7269\u4ea7\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb&#xff0c;\u53ef\u80fd\u4e00\u5f00\u59cb\u662f\u6b63\u76f8\u5173\u7684&#xff0c;\u4f46\u65bd\u80a5\u8fc7\u591a\u540e&#xff0c;\u4ea7\u91cf\u53cd\u800c\u4f1a\u4e0b\u964d&#xff0c;\u5f62\u6210\u4e00\u4e2a\u629b\u7269\u7ebf\u5173\u7cfb\u3002<\/p>\n<h5>6.3.2 \u201c\u4f2a\u88c5\u201d\u7684\u7ebf\u6027\u56de\u5f52&#xff1a;\u7279\u5f81\u5de5\u7a0b\u7684\u529b\u91cf<\/h5>\n<p>\u591a\u9879\u5f0f\u56de\u5f52\u5e76\u4e0d\u662f\u4e00\u79cd\u65b0\u7684\u56de\u5f52\u7b97\u6cd5&#xff0c;\u5b83\u672c\u8d28\u4e0a\u4ecd\u7136\u662f\u7ebf\u6027\u56de\u5f52\u3002\u5b83\u7684\u5de7\u5999\u4e4b\u5904\u5728\u4e8e&#xff0c;\u901a\u8fc7\u7279\u5f81\u5de5\u7a0b\u7684\u624b\u6bb5&#xff0c;\u5bf9\u539f\u59cb\u6570\u636e\u8fdb\u884c\u201c\u5347\u7ef4\u201d&#xff0c;\u4ece\u800c\u8ba9\u7ebf\u6027\u6a21\u578b\u80fd\u591f\u62df\u5408\u975e\u7ebf\u6027\u6570\u636e\u3002<\/p>\n<p>\u591a\u9879\u5f0f\u7279\u5f81\u751f\u6210\u00a0\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7279\u5f81\u00a0x\u3002\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u521b\u9020\u51fa\u5b83\u7684\u9ad8\u6b21\u9879&#xff0c;\u5982\u00a0x\u00b2,\u00a0x\u00b3\u00a0\u7b49&#xff0c;\u5e76\u5c06\u8fd9\u4e9b\u65b0\u7279\u5f81\u52a0\u5165\u5230\u6a21\u578b\u4e2d\u3002\u00a0y &#061; w\u2081x &#043; w\u2082x\u00b2 &#043; w\u2083x\u00b3 &#043; b\u00a0\u8fd9\u4e2a\u6a21\u578b\u5bf9\u4e8e\u00a0y\u00a0\u548c\u00a0x\u00a0\u6765\u8bf4\u662f\u975e\u7ebf\u6027\u7684&#xff0c;\u4f46\u5982\u679c\u6211\u4eec\u628a\u00a0x\u2081_new &#061; x,\u00a0x\u2082_new &#061; x\u00b2,\u00a0x\u2083_new &#061; x\u00b3\u00a0\u770b\u4f5c\u662f\u4e09\u4e2a\u65b0\u7684\u3001\u72ec\u7acb\u7684\u7279\u5f81&#xff0c;\u90a3\u4e48\u6a21\u578b\u5c31\u53d8\u6210\u4e86&#xff1a;\u00a0y &#061; w\u2081x\u2081_new &#043; w\u2082x\u2082_new &#043; w\u2083x\u2083_new &#043; b\u00a0\u8fd9\u53c8\u56de\u5230\u4e86\u6211\u4eec\u719f\u6089\u7684\u591a\u5143\u7ebf\u6027\u56de\u5f52\u7684\u5f62\u5f0f&#xff01;<\/p>\n<p>Scikit-learn\u7684PolynomialFeatures\u53ef\u4ee5\u81ea\u52a8\u5e2e\u6211\u4eec\u5b8c\u6210\u8fd9\u4e2a\u7279\u5f81\u751f\u6210\u7684\u8fc7\u7a0b\u3002<\/p>\n<h5>6.3.3 Scikit-learn\u5b9e\u6218\u4e0e\u8fc7\u62df\u5408\u7684\u98ce\u9669<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.preprocessing import PolynomialFeatures<br \/>\nfrom sklearn.pipeline import make_pipeline<\/p>\n<p># \u4e3a\u4e86\u53ef\u89c6\u5316&#xff0c;\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u975e\u7ebf\u6027\u6570\u636e\u96c6<br \/>\nnp.random.seed(42)<br \/>\nX_poly &#061; np.sort(5 * np.random.rand(80, 1), axis&#061;0)<br \/>\ny_poly &#061; np.sin(X_poly).ravel() &#043; np.random.randn(80) * 0.1<\/p>\n<p>plt.scatter(X_poly, y_poly)<br \/>\nplt.title(&#034;Simple Non-linear Data&#034;)<br \/>\nplt.show()<\/p>\n<p># \u4f7f\u7528\u4e0d\u540c\u9636\u6570\u7684\u591a\u9879\u5f0f\u56de\u5f52\u8fdb\u884c\u62df\u5408<br \/>\nplt.figure(figsize&#061;(12, 8))<br \/>\nfor degree in [1, 3, 10]:<br \/>\n    # \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u591a\u9879\u5f0f\u7279\u5f81\u751f\u6210\u548c\u7ebf\u6027\u56de\u5f52\u7684\u7ba1\u9053<br \/>\n    poly_reg &#061; make_pipeline(PolynomialFeatures(degree&#061;degree), LinearRegression())<br \/>\n    poly_reg.fit(X_poly, y_poly)<\/p>\n<p>    X_fit &#061; np.arange(0.0, 5.0, 0.01)[:, np.newaxis]<br \/>\n    y_fit &#061; poly_reg.predict(X_fit)<\/p>\n<p>    plt.plot(X_fit, y_fit, label&#061;f&#039;degree&#061;{degree}&#039;)<\/p>\n<p>plt.scatter(X_poly, y_poly, edgecolor&#061;&#039;b&#039;, s&#061;20, label&#061;&#039;data points&#039;)<br \/>\nplt.xlabel(&#039;x&#039;)<br \/>\nplt.ylabel(&#039;y&#039;)<br \/>\nplt.legend()<br \/>\nplt.show()<\/p>\n<p>\u9636\u6570&#xff08;Degree&#xff09;\u7684\u9009\u62e9<\/p>\n<ul>\n<li>degree&#061;1&#xff1a;\u5c31\u662f\u666e\u901a\u7684\u7ebf\u6027\u56de\u5f52&#xff0c;\u65e0\u6cd5\u62df\u5408\u66f2\u7ebf&#xff0c;\u51fa\u73b0\u6b20\u62df\u5408\u3002<\/li>\n<li>degree&#061;3&#xff1a;\u8f83\u597d\u5730\u62df\u5408\u4e86\u6570\u636e\u7684\u771f\u5b9e\u8d8b\u52bf\u3002<\/li>\n<li>degree&#061;10&#xff1a;\u6a21\u578b\u53d8\u5f97\u5f02\u5e38\u626d\u66f2&#xff0c;\u8bd5\u56fe\u7a7f\u8fc7\u6bcf\u4e00\u4e2a\u6570\u636e\u70b9&#xff0c;\u5305\u62ec\u566a\u58f0\u70b9\u3002\u8fd9\u5728\u8bad\u7ec3\u96c6\u4e0a\u8bef\u5dee\u4f1a\u5f88\u5c0f&#xff0c;\u4f46\u5728\u65b0\u6570\u636e\u4e0a\u8868\u73b0\u4f1a\u5f88\u5dee&#xff0c;\u662f\u5178\u578b\u7684\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n<p>\u9636\u6570\u662f\u591a\u9879\u5f0f\u56de\u5f52\u4e2d\u6700\u91cd\u8981\u7684\u8d85\u53c2\u6570&#xff0c;\u9700\u8981\u901a\u8fc7\u4ea4\u53c9\u9a8c\u8bc1\u6765\u9009\u62e9\u3002\u901a\u5e38&#xff0c;\u6211\u4eec\u5f88\u5c11\u4f7f\u7528\u8d85\u8fc74\u62165\u9636\u7684\u591a\u9879\u5f0f&#xff0c;\u56e0\u4e3a\u9ad8\u9636\u591a\u9879\u5f0f\u975e\u5e38\u5bb9\u6613\u8fc7\u62df\u5408&#xff0c;\u4e14\u6a21\u578b\u4f1a\u53d8\u5f97\u4e0d\u7a33\u5b9a\u3002<\/p>\n<hr \/>\n<h4>6.4 \u56de\u5f52\u6811\u4e0e\u96c6\u6210\u56de\u5f52\u6a21\u578b&#xff1a;\u4ece\u89c4\u5219\u5230\u667a\u6167\u7684\u5347\u534e<\/h4>\n<p>\u7ebf\u6027\u6a21\u578b\u5bb6\u65cf\u867d\u7136\u5f3a\u5927&#xff0c;\u4f46\u5b83\u4eec\u90fd\u57fa\u4e8e\u4e00\u4e2a\u56fa\u5b9a\u7684\u51fd\u6570\u5f62\u5f0f\u3002\u800c\u57fa\u4e8e\u6811\u7684\u6a21\u578b&#xff0c;\u5219\u63d0\u4f9b\u4e86\u4e00\u79cd\u5b8c\u5168\u4e0d\u540c\u7684\u3001\u975e\u53c2\u6570\u5316\u7684\u89e3\u51b3\u601d\u8def\u3002<\/p>\n<h5>6.4.1 \u56de\u5f52\u6811&#xff08;Regression Tree&#xff09;&#xff1a;\u7528\u6811\u5f62\u7ed3\u6784\u505a\u9884\u6d4b<\/h5>\n<p>\u56de\u5f52\u6811\u7684\u7ed3\u6784\u4e0e\u6211\u4eec\u5728\u5206\u7c7b\u4efb\u52a1\u4e2d\u5b66\u5230\u7684\u51b3\u7b56\u6811\u5b8c\u5168\u76f8\u540c&#xff0c;\u4f46\u5728\u4e24\u4e2a\u5173\u952e\u70b9\u4e0a\u6709\u6240\u533a\u522b&#xff1a;<\/p>\n<li>\u5206\u88c2\u51c6\u5219&#xff1a;\u5206\u7c7b\u6811\u4f7f\u7528\u57fa\u5c3c\u4e0d\u7eaf\u5ea6\u6216\u4fe1\u606f\u589e\u76ca\u6765\u9009\u62e9\u5206\u88c2\u70b9&#xff0c;\u76ee\u6807\u662f\u8ba9\u5206\u88c2\u540e\u7684\u8282\u70b9\u7c7b\u522b\u66f4\u201c\u7eaf\u7cb9\u201d\u3002\u800c\u56de\u5f52\u6811\u7684\u76ee\u6807\u662f\u8ba9\u5206\u88c2\u540e\u7684\u6bcf\u4e2a\u8282\u70b9\u5185\u7684\u9884\u6d4b\u8bef\u5dee\u6700\u5c0f\u5316\u3002\u6700\u5e38\u7528\u7684\u5206\u88c2\u51c6\u5219\u5c31\u662f\u5747\u65b9\u8bef\u5dee&#xff08;MSE&#xff09;\u3002\u5728\u6bcf\u4e2a\u8282\u70b9&#xff0c;\u6811\u4f1a\u904d\u5386\u6240\u6709\u7279\u5f81\u7684\u6240\u6709\u53ef\u80fd\u5206\u88c2\u70b9&#xff0c;\u9009\u62e9\u90a3\u4e2a\u80fd\u4f7f\u5206\u88c2\u540e\u7684\u4e24\u4e2a\u5b50\u8282\u70b9\u7684MSE\u4e4b\u548c\u6700\u5c0f\u7684\u5206\u88c2\u65b9\u5f0f\u3002<\/li>\n<li>\u53f6\u8282\u70b9\u8f93\u51fa&#xff1a;\u5206\u7c7b\u6811\u7684\u53f6\u8282\u70b9\u8f93\u51fa\u662f\u8be5\u8282\u70b9\u6837\u672c\u7684\u4f17\u6570\u7c7b\u522b\u3002\u800c\u56de\u5f52\u6811\u7684\u53f6\u8282\u70b9\u8f93\u51fa\u662f\u843d\u5728\u8be5\u53f6\u8282\u70b9\u6240\u6709\u8bad\u7ec3\u6837\u672c\u7684\u76ee\u6807\u503c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<p>\u6a21\u578b\u7279\u70b9\u00a0\u56de\u5f52\u6811\u7684\u9884\u6d4b\u51fd\u6570\u662f\u4e00\u4e2a\u5206\u6bb5\u5e38\u6570\u51fd\u6570\u3002\u5b83\u5c06\u7279\u5f81\u7a7a\u95f4\u5212\u5206\u4e3a\u82e5\u5e72\u4e2a\u77e9\u5f62\u533a\u57df&#xff0c;\u5728\u6bcf\u4e2a\u533a\u57df\u5185&#xff0c;\u9884\u6d4b\u503c\u90fd\u662f\u4e00\u4e2a\u56fa\u5b9a\u7684\u5e38\u6570\u3002<\/p>\n<h5>6.4.2 \u968f\u673a\u68ee\u6797\u56de\u5f52&#xff08;Random Forest Regressor&#xff09;<\/h5>\n<p>\u5355\u68f5\u56de\u5f52\u6811\u540c\u6837\u5b58\u5728\u5bb9\u6613\u8fc7\u62df\u5408\u7684\u95ee\u9898\u3002\u968f\u673a\u68ee\u6797\u901a\u8fc7Bagging\u7684\u601d\u60f3&#xff0c;\u5c06\u591a\u68f5\u56de\u5f52\u6811\u96c6\u6210\u8d77\u6765&#xff0c;\u6781\u5927\u5730\u63d0\u5347\u4e86\u6a21\u578b\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<ul>\n<li>\u5de5\u4f5c\u539f\u7406&#xff1a;\u4e0e\u5206\u7c7b\u968f\u673a\u68ee\u6797\u5b8c\u5168\u4e00\u81f4&#xff0c;\u901a\u8fc7\u201c\u6837\u672c\u968f\u673a\u201d\u548c\u201c\u7279\u5f81\u968f\u673a\u201d\u6784\u5efa\u4e00\u4e2a\u7531\u591a\u68f5\u201c\u5404\u4e0d\u76f8\u540c\u201d\u7684\u56de\u5f52\u6811\u7ec4\u6210\u7684\u68ee\u6797\u3002<\/li>\n<li>\u9884\u6d4b\u65b9\u5f0f&#xff1a;\u5bf9\u4e8e\u4e00\u4e2a\u65b0\u7684\u6837\u672c&#xff0c;\u68ee\u6797\u4e2d\u7684\u6bcf\u68f5\u6811\u90fd\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u9884\u6d4b\u503c\u3002\u968f\u673a\u68ee\u6797\u7684\u6700\u7ec8\u9884\u6d4b\u7ed3\u679c\u662f\u6240\u6709\u6811\u9884\u6d4b\u503c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<\/ul>\n<p>Scikit-learn\u5b9e\u6218<\/p>\n<p>from sklearn.ensemble import RandomForestRegressor<\/p>\n<p># \u4f7f\u7528\u6ce2\u58eb\u987f\u623f\u4ef7\u6570\u636e<br \/>\nrf_reg &#061; RandomForestRegressor(n_estimators&#061;100, random_state&#061;42, n_jobs&#061;-1)<br \/>\nrf_reg.fit(X_train, y_train) # \u6811\u6a21\u578b\u5bf9\u6570\u636e\u7f29\u653e\u4e0d\u654f\u611f<br \/>\nprint(f&#034;\\\\n\u968f\u673a\u68ee\u6797\u56de\u5f52\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684R^2: {rf_reg.score(X_test, y_test):.2f}&#034;)<\/p>\n<h5>6.4.3 \u68af\u5ea6\u63d0\u5347\u51b3\u7b56\u6811&#xff08;GBDT&#xff09;&#xff1a;\u5728\u201c\u9519\u8bef\u201d\u4e2d\u4e0d\u65ad\u8fdb\u6b65<\/h5>\n<p>\u68af\u5ea6\u63d0\u5347\u51b3\u7b56\u6811&#xff08;Gradient Boosting Decision Tree, GBDT&#xff09;\u662f\u53e6\u4e00\u79cd\u5f3a\u5927\u7684\u96c6\u6210\u65b9\u6cd5&#xff0c;\u5b83\u91c7\u7528\u7684\u662fBoosting\u601d\u60f3\u3002<\/p>\n<p>Boosting\u601d\u60f3\u00a0\u4e0eBagging\u5e76\u884c\u8bad\u7ec3\u4e0d\u540c&#xff0c;Boosting\u662f\u4e00\u79cd\u4e32\u884c\u7684\u3001\u5faa\u5e8f\u6e10\u8fdb\u7684\u96c6\u6210\u65b9\u5f0f\u3002<\/p>\n<li>\u9996\u5148&#xff0c;\u8bad\u7ec3\u4e00\u4e2a\u7b80\u5355\u7684\u57fa\u5b66\u4e60\u5668&#xff08;\u5982\u4e00\u68f5\u5f88\u6d45\u7684\u51b3\u7b56\u6811&#xff09;\u3002<\/li>\n<li>\u8ba1\u7b97\u5f53\u524d\u6a21\u578b\u5728\u6240\u6709\u6837\u672c\u4e0a\u7684\u6b8b\u5dee&#xff08;Residuals&#xff09;&#xff0c;\u5373\u00a0\u771f\u5b9e\u503c &#8211; \u9884\u6d4b\u503c\u3002\u8fd9\u4e9b\u6b8b\u5dee\u5c31\u662f\u6a21\u578b\u5c1a\u672a\u5b66\u597d\u7684\u201c\u9519\u8bef\u201d\u3002<\/li>\n<li>\u63a5\u4e0b\u6765&#xff0c;\u8bad\u7ec3\u7b2c\u4e8c\u68f5\u6811&#xff0c;\u4f46\u8fd9\u68f5\u6811\u7684\u5b66\u4e60\u76ee\u6807\u4e0d\u518d\u662f\u539f\u59cb\u7684\u00a0y&#xff0c;\u800c\u662f\u4e0a\u4e00\u8f6e\u7684\u6b8b\u5dee\u3002\u5b83\u4e13\u95e8\u5b66\u4e60\u5982\u4f55\u5f25\u8865\u7b2c\u4e00\u68f5\u6811\u7684\u4e0d\u8db3\u3002<\/li>\n<li>\u5c06\u7b2c\u4e8c\u68f5\u6811\u7684\u9884\u6d4b\u7ed3\u679c&#xff08;\u6309\u4e00\u5b9a\u6bd4\u4f8b&#xff0c;\u5373\u5b66\u4e60\u7387&#xff09;\u52a0\u5230\u7b2c\u4e00\u68f5\u6811\u7684\u9884\u6d4b\u7ed3\u679c\u4e0a&#xff0c;\u5f62\u6210\u4e00\u4e2a\u65b0\u7684\u96c6\u6210\u6a21\u578b\u3002<\/li>\n<li>\u4e0d\u65ad\u91cd\u590d\u6b65\u9aa42-4&#xff0c;\u6bcf\u4e00\u68f5\u65b0\u6811\u90fd\u5728\u5b66\u4e60\u524d\u9762\u6240\u6709\u6811\u96c6\u6210\u8d77\u6765\u7684\u6a21\u578b\u7684\u6b8b\u5dee\u3002<\/li>\n<p>\u6700\u7ec8&#xff0c;GBDT\u7684\u9884\u6d4b\u7ed3\u679c\u662f\u6240\u6709\u6811\u7684\u9884\u6d4b\u7ed3\u679c\u7684\u52a0\u6743\u548c\u3002\u5b83\u901a\u8fc7\u8fd9\u79cd\u201c\u5728\u9519\u8bef\u4e2d\u4e0d\u65ad\u8fdb\u6b65\u201d\u7684\u65b9\u5f0f&#xff0c;\u9010\u6b65\u6784\u5efa\u51fa\u4e00\u4e2a\u975e\u5e38\u7cbe\u51c6\u7684\u6a21\u578b\u3002<\/p>\n<p>Scikit-learn\u5b9e\u6218<\/p>\n<p>from sklearn.ensemble import GradientBoostingRegressor<\/p>\n<p>gbrt &#061; GradientBoostingRegressor(n_estimators&#061;100, learning_rate&#061;0.1, max_depth&#061;3, random_state&#061;42)<br \/>\ngbrt.fit(X_train, y_train)<br \/>\nprint(f&#034;GBDT\u56de\u5f52\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684R^2: {gbrt.score(X_test, y_test):.2f}&#034;)<\/p>\n<h5>6.4.4 XGBoost&#xff1a;\u6781\u81f4\u7684\u5de5\u7a0b\u5b9e\u73b0\u4e0e\u6027\u80fd\u738b\u8005<\/h5>\n<p>XGBoost&#xff08;eXtreme Gradient Boosting&#xff09;\u662fGBDT\u7684\u4e00\u79cd\u9ad8\u6548\u3001\u7075\u6d3b\u4e14\u53ef\u79fb\u690d\u7684\u5de5\u7a0b\u5b9e\u73b0\u3002\u5b83\u5728\u7b97\u6cd5\u548c\u5de5\u7a0b\u5c42\u9762\u90fd\u505a\u4e86\u5927\u91cf\u7684\u4f18\u5316&#xff0c;\u4f7f\u5176\u6210\u4e3a\u6570\u636e\u79d1\u5b66\u7ade\u8d5b\u548c\u5de5\u4e1a\u754c\u6700\u53d7\u6b22\u8fce\u7684\u6a21\u578b\u4e4b\u4e00\u3002<\/p>\n<p>\u6838\u5fc3\u4f18\u52bf<\/p>\n<ul>\n<li>\u6b63\u5219\u5316&#xff1a;XGBoost\u5728\u635f\u5931\u51fd\u6570\u4e2d\u76f4\u63a5\u52a0\u5165\u4e86\u5bf9\u6811\u7684\u590d\u6742\u5ea6\u7684\u6b63\u5219\u5316\u9879&#xff08;\u5982\u53f6\u5b50\u8282\u70b9\u7684\u6570\u91cf\u548c\u53f6\u5b50\u8282\u70b9\u8f93\u51fa\u503c\u7684L2\u8303\u6570&#xff09;&#xff0c;\u8fd9\u6bd4GBDT\u5355\u7eaf\u4f9d\u9760\u5b66\u4e60\u7387\u548c\u526a\u679d\u6765\u63a7\u5236\u8fc7\u62df\u5408\u8981\u66f4\u80dc\u4e00\u7b79\u3002<\/li>\n<li>\u9ad8\u6548\u7684\u5e76\u884c\u5904\u7406&#xff1a;\u867d\u7136\u6811\u7684\u751f\u6210\u662f\u4e32\u884c\u7684&#xff0c;\u4f46\u5728\u6bcf\u4e2a\u8282\u70b9\u5bfb\u627e\u6700\u4f73\u5206\u88c2\u70b9\u65f6&#xff0c;XGBoost\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\u3002<\/li>\n<li>\u5185\u7f6e\u4ea4\u53c9\u9a8c\u8bc1&#xff1a;\u53ef\u4ee5\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u76f4\u63a5\u8fdb\u884c\u4ea4\u53c9\u9a8c\u8bc1\u3002<\/li>\n<li>\u5904\u7406\u7a00\u758f\u6570\u636e\u548c\u7f3a\u5931\u503c&#xff1a;\u6709\u4e13\u95e8\u7684\u4f18\u5316\u7b97\u6cd5\u6765\u5904\u7406\u7a00\u758f\u6570\u636e\u548c\u81ea\u52a8\u5904\u7406\u7f3a\u5931\u503c\u3002<\/li>\n<li>\u7f13\u5b58\u611f\u77e5\u548c\u6838\u5916\u8ba1\u7b97&#xff1a;\u5728\u5de5\u7a0b\u4e0a\u505a\u4e86\u5f88\u591a\u4f18\u5316&#xff0c;\u4f7f\u5f97\u5b83\u80fd\u5904\u7406\u8d85\u51fa\u5185\u5b58\u7684\u5927\u89c4\u6a21\u6570\u636e\u96c6\u3002<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0XGBoost\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u5e93&#xff0c;\u9700\u8981\u5355\u72ec\u5b89\u88c5 (pip install xgboost)\u3002<\/p>\n<p>import xgboost as xgb<\/p>\n<p>xgb_reg &#061; xgb.XGBRegressor(n_estimators&#061;100, learning_rate&#061;0.1, max_depth&#061;3, random_state&#061;42,<br \/>\n                           objective&#061;&#039;reg:squarederror&#039;)<br \/>\nxgb_reg.fit(X_train, y_train)<br \/>\nprint(f&#034;XGBoost\u56de\u5f52\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684R^2: {xgb_reg.score(X_test, y_test):.2f}&#034;)<\/p>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u4ece\u6700\u57fa\u7840\u7684\u7ebf\u6027\u56de\u5f52\u51fa\u53d1&#xff0c;\u4e00\u8def\u63a2\u7d22\u4e86\u56de\u5f52\u7b97\u6cd5\u7684\u5e7f\u9614\u5929\u5730\u3002\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u7528\u6b63\u5219\u5316\u6765\u7ea6\u675f\u7ebf\u6027\u6a21\u578b&#xff0c;\u5982\u4f55\u7528\u591a\u9879\u5f0f\u7279\u5f81\u6765\u6355\u6349\u975e\u7ebf\u6027&#xff0c;\u6700\u7ec8\u767b\u4e0a\u4e86\u4ee5\u968f\u673a\u68ee\u6797\u3001GBDT\u548cXGBoost\u4e3a\u4ee3\u8868\u7684\u96c6\u6210\u6a21\u578b\u7684\u6027\u80fd\u9ad8\u5cf0\u3002<\/p>\n<p>\u60a8\u73b0\u5728\u5df2\u7ecf\u638c\u63e1\u4e86\u89e3\u51b3\u4e24\u7c7b\u6700\u6838\u5fc3\u7684\u76d1\u7763\u5b66\u4e60\u95ee\u9898\u2014\u2014\u5206\u7c7b\u4e0e\u56de\u5f52\u2014\u2014\u7684\u5f3a\u5927\u5de5\u5177\u96c6\u3002\u7ebf\u6027\u6a21\u578b\u5bb6\u65cf\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u826f\u597d\u7684\u53ef\u89e3\u91ca\u6027\u548c\u57fa\u51c6&#xff0c;\u800c\u6811\u7684\u96c6\u6210\u6a21\u578b\u5219\u4e3a\u6211\u4eec\u8ffd\u6c42\u6781\u81f4\u6027\u80fd\u63d0\u4f9b\u4e86\u4fdd\u969c\u3002<\/p>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62&#xff0c;\u6211\u4eec\u6240\u5b66\u7684\u90fd\u662f\u201c\u76d1\u7763\u5b66\u4e60\u201d&#xff0c;\u5373\u6570\u636e\u90fd\u5e26\u6709\u660e\u786e\u7684\u201c\u7b54\u6848\u201d&#xff08;\u6807\u7b7e&#xff09;\u3002\u5728\u4e0b\u4e00\u7ae0&#xff0c;\u6211\u4eec\u5c06\u8fdb\u5165\u4e00\u4e2a\u5168\u65b0\u7684\u3001\u66f4\u5177\u63a2\u7d22\u6027\u7684\u9886\u57df\u2014\u2014\u65e0\u76d1\u7763\u5b66\u4e60\u3002\u5728\u90a3\u91cc&#xff0c;\u6570\u636e\u6ca1\u6709\u6807\u7b7e&#xff0c;\u6211\u4eec\u7684\u4efb\u52a1\u662f\u4ece\u6570\u636e\u672c\u8eab\u53d1\u73b0\u9690\u85cf\u7684\u7ed3\u6784\u3001\u6a21\u5f0f\u548c\u7fa4\u4f53\u3002\u8fd9\u5c06\u662f\u4e00\u573a\u5168\u65b0\u7684\u667a\u6167\u63a2\u9669\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e03\u7ae0&#xff1a;\u65e0\u76d1\u7763\u5b66\u4e60\u4e4b\u201c\u5f52\u7eb3\u201d\u2014\u2014\u805a\u7c7b\u4e0e\u964d\u7ef4<\/h3>\n<ul>\n<li>7.1 K-\u5747\u503c\u805a\u7c7b&#xff08;K-Means&#xff09;&#xff1a;\u5bfb\u627e\u6570\u636e\u4e2d\u7684\u201c\u5f15\u529b\u4e2d\u5fc3\u201d<\/li>\n<li>7.2 \u5c42\u6b21\u805a\u7c7b&#xff1a;\u6784\u5efa\u6570\u636e\u7684\u201c\u5bb6\u65cf\u8c31\u7cfb\u201d<\/li>\n<li>7.3 DBSCAN&#xff1a;\u57fa\u4e8e\u5bc6\u5ea6\u7684\u201c\u793e\u533a\u53d1\u73b0\u201d<\/li>\n<li>7.4 \u4e3b\u6210\u5206\u5206\u6790&#xff08;PCA&#xff09;&#xff1a;\u5728\u7eb7\u7e41\u4e2d\u89c1\u672c\u8d28\u7684\u964d\u7ef4\u4e4b\u9053<\/li>\n<\/ul>\n<p>\u81f3\u6b64&#xff0c;\u6211\u4eec\u65c5\u7a0b\u7684\u524d\u534a\u6bb5\u59cb\u7ec8\u6709\u4e00\u4f4d\u201c\u5411\u5bfc\u201d\u2014\u2014\u6570\u636e\u6807\u7b7e\u3002\u5b83\u544a\u8bc9\u6211\u4eec\u4ec0\u4e48\u662f\u5bf9\u7684&#xff0c;\u4ec0\u4e48\u662f\u9519\u7684&#xff0c;\u6211\u4eec\u7684\u6a21\u578b\u5219\u52aa\u529b\u5b66\u4e60\u8fd9\u4f4d\u5411\u5bfc\u7684\u667a\u6167\u3002\u7136\u800c&#xff0c;\u5728\u6d69\u701a\u7684\u6570\u636e\u5b87\u5b99\u4e2d&#xff0c;\u7edd\u5927\u591a\u6570\u7684\u201c\u661f\u8fb0\u201d&#xff08;\u6570\u636e&#xff09;\u90fd\u662f\u672a\u7ecf\u6807\u6ce8\u7684\u3002\u5982\u4f55\u4ece\u8fd9\u4e9b\u770b\u4f3c\u6df7\u6c8c\u7684\u6570\u636e\u4e2d\u53d1\u73b0\u79e9\u5e8f\u3001\u5f52\u7eb3\u7ed3\u6784\u3001\u63d0\u70bc\u7cbe\u534e&#xff1f;\u8fd9\u4fbf\u662f\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u4f7f\u547d\u3002<\/p>\n<p>\u65e0\u76d1\u7763\u5b66\u4e60&#xff0c;\u662f\u4e00\u573a\u6ca1\u6709\u6807\u51c6\u7b54\u6848\u7684\u63a2\u7d22\u3002\u5b83\u8981\u6c42\u6211\u4eec\u653e\u5f03\u5bf9\u201c\u9884\u6d4b\u201d\u7684\u6267\u5ff5&#xff0c;\u8f6c\u800c\u62e5\u62b1\u5bf9\u201c\u53d1\u73b0\u201d\u7684\u70ed\u60c5\u3002\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u805a\u7126\u4e8e\u65e0\u65e5\u5fd7\u5b66\u4e60\u7684\u4e24\u5927\u6838\u5fc3\u4efb\u52a1&#xff1a;<\/p>\n<li>\u805a\u7c7b&#xff08;Clustering&#xff09;&#xff1a;\u65e8\u5728\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6837\u672c\u5212\u5206\u4e3a\u82e5\u5e72\u4e2a\u5185\u90e8\u76f8\u4f3c\u3001\u5916\u90e8\u76f8\u5f02\u7684\u201c\u7c07\u201d&#xff08;Cluster&#xff09;\u3002\u5b83\u5e2e\u52a9\u6211\u4eec\u56de\u7b54\u201c\u6570\u636e\u53ef\u4ee5\u88ab\u81ea\u7136\u5730\u5206\u6210\u54ea\u4e9b\u7fa4\u4f53&#xff1f;\u201d\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<li>\u964d\u7ef4&#xff08;Dimensionality Reduction&#xff09;&#xff1a;\u65e8\u5728\u7528\u4e00\u7ec4\u6570\u91cf\u66f4\u5c11\u7684\u53d8\u91cf\u6765\u6982\u62ec\u539f\u59cb\u6570\u636e\u4e2d\u7684\u4e3b\u8981\u4fe1\u606f\u3002\u5b83\u5e2e\u52a9\u6211\u4eec\u56de\u7b54\u201c\u6570\u636e\u7684\u6838\u5fc3\u672c\u8d28\u662f\u4ec0\u4e48&#xff1f;\u201d\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<p>\u638c\u63e1\u65e0\u76d1\u7763\u5b66\u4e60&#xff0c;\u610f\u5473\u7740\u60a8\u5c06\u62e5\u6709\u4e00\u53cc\u80fd\u591f\u7a7f\u900f\u6570\u636e\u8868\u8c61\u3001\u6d1e\u5bdf\u5176\u5185\u5728\u7ed3\u6784\u7684\u201c\u6167\u773c\u201d\u3002\u8fd9\u4e0d\u4ec5\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u5173\u952e\u6b65\u9aa4&#xff0c;\u5176\u672c\u8eab\u5c31\u80fd\u5e26\u6765\u6df1\u523b\u7684\u5546\u4e1a\u6d1e\u5bdf&#xff0c;\u5982\u5ba2\u6237\u5206\u7fa4\u3001\u5f02\u5e38\u68c0\u6d4b\u3001\u6587\u672c\u4e3b\u9898\u6316\u6398\u7b49\u3002<\/p>\n<hr \/>\n<h4>7.1 K-\u5747\u503c\u805a\u7c7b&#xff08;K-Means&#xff09;&#xff1a;\u5bfb\u627e\u6570\u636e\u4e2d\u7684\u201c\u5f15\u529b\u4e2d\u5fc3\u201d<\/h4>\n<p>K-\u5747\u503c&#xff08;K-Means&#xff09;\u662f\u805a\u7c7b\u7b97\u6cd5\u4e2d\u6700\u8457\u540d\u3001\u6700\u7b80\u5355\u3001\u4e5f\u662f\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002\u5b83\u662f\u4e00\u79cd\u57fa\u4e8e\u539f\u578b&#xff08;Prototype-based&#xff09;\u7684\u805a\u7c7b\u65b9\u6cd5&#xff0c;\u8bd5\u56fe\u627e\u5230\u6bcf\u4e2a\u7c07\u7684\u201c\u539f\u578b\u201d\u2014\u2014\u5373\u8d28\u5fc3&#xff08;Centroid&#xff09;&#xff0c;\u7136\u540e\u5c06\u6bcf\u4e2a\u6837\u672c\u5212\u5206\u7ed9\u79bb\u5b83\u6700\u8fd1\u7684\u8d28\u5fc3\u6240\u4ee3\u8868\u7684\u7c07\u3002<\/p>\n<h5>7.1.1 \u6838\u5fc3\u601d\u60f3&#xff1a;\u7269\u4ee5\u7c7b\u805a&#xff0c;\u8fed\u4ee3\u4e3a\u738b<\/h5>\n<p>\u7b97\u6cd5\u76ee\u6807\u00a0K-Means\u7684\u6700\u7ec8\u76ee\u6807&#xff0c;\u662f\u5c06\u00a0n\u00a0\u4e2a\u6837\u672c\u5212\u5206\u4e3a\u00a0K\u00a0\u4e2a\u7c07&#xff0c;\u5e76\u4f7f\u5f97\u6240\u6709\u7c07\u7684**\u7c07\u5185\u5e73\u65b9\u548c&#xff08;Within-Cluster Sum of Squares, WCSS&#xff09;**\u6700\u5c0f\u3002WCSS\u8861\u91cf\u7684\u662f\u6bcf\u4e2a\u7c07\u5185\u6240\u6709\u6837\u672c\u70b9\u5230\u5176\u8d28\u5fc3\u7684\u8ddd\u79bb\u5e73\u65b9\u4e4b\u548c\u3002\u8fd9\u4e2a\u503c\u8d8a\u5c0f&#xff0c;\u8bf4\u660e\u7c07\u5185\u7684\u6837\u672c\u8d8a\u7d27\u5bc6&#xff0c;\u805a\u7c7b\u6548\u679c\u8d8a\u597d\u3002<\/p>\n<p>\u8fed\u4ee3\u6b65\u9aa4\u00a0K-Means\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u800c\u4f18\u7f8e\u7684\u8fed\u4ee3\u8fc7\u7a0b\u6765\u903c\u8fd1\u8fd9\u4e2a\u76ee\u6807&#xff1a;<\/p>\n<li>\u521d\u59cb\u5316&#xff1a;\u968f\u673a\u9009\u62e9\u00a0K\u00a0\u4e2a\u6570\u636e\u70b9\u4f5c\u4e3a\u521d\u59cb\u7684\u8d28\u5fc3\u3002<\/li>\n<li>\u5206\u914d&#xff08;Assignment&#xff09;&#xff1a;\u904d\u5386\u6bcf\u4e00\u4e2a\u6570\u636e\u70b9&#xff0c;\u8ba1\u7b97\u5b83\u5230\u6240\u6709\u00a0K\u00a0\u4e2a\u8d28\u5fc3\u7684\u8ddd\u79bb&#xff0c;\u5e76\u5c06\u5176\u5206\u914d\u7ed9\u8ddd\u79bb\u6700\u8fd1\u7684\u90a3\u4e2a\u8d28\u5fc3\u6240\u4ee3\u8868\u7684\u7c07\u3002<\/li>\n<li>\u66f4\u65b0&#xff08;Update&#xff09;&#xff1a;\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u7c07&#xff0c;\u91cd\u65b0\u8ba1\u7b97\u5176\u8d28\u5fc3\u3002\u65b0\u7684\u8d28\u5fc3\u662f\u8be5\u7c07\u5185\u6240\u6709\u6570\u636e\u70b9\u7684\u5e73\u5747\u503c\u3002<\/li>\n<li>\u91cd\u590d&#xff1a;\u4e0d\u65ad\u91cd\u590d\u6b65\u9aa42\u548c\u6b65\u9aa43&#xff0c;\u76f4\u5230\u8d28\u5fc3\u7684\u4f4d\u7f6e\u4e0d\u518d\u53d1\u751f\u663e\u8457\u53d8\u5316&#xff08;\u6216\u8fbe\u5230\u9884\u8bbe\u7684\u8fed\u4ee3\u6b21\u6570&#xff09;&#xff0c;\u7b97\u6cd5\u6536\u655b\u3002<\/li>\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u50cf\u5728\u6570\u636e\u5e73\u539f\u4e0a\u5bfb\u627e\u00a0K\u00a0\u4e2a\u201c\u5f15\u529b\u4e2d\u5fc3\u201d&#xff0c;\u6570\u636e\u70b9\u4e0d\u65ad\u88ab\u6700\u8fd1\u7684\u4e2d\u5fc3\u5438\u5f15&#xff0c;\u800c\u4e2d\u5fc3\u7684\u4f4d\u7f6e\u53c8\u6839\u636e\u88ab\u5438\u5f15\u6765\u7684\u70b9\u7684\u5206\u5e03\u800c\u8c03\u6574&#xff0c;\u6700\u7ec8\u8fbe\u5230\u4e00\u4e2a\u7a33\u5b9a\u7684\u5e73\u8861\u72b6\u6001\u3002<\/p>\n<h5>7.1.2 \u7b97\u6cd5\u7684\u201c\u963f\u5580\u7409\u65af\u4e4b\u8e35\u201d&#xff1a;K\u503c\u9009\u62e9\u4e0e\u521d\u59cb\u70b9\u654f\u611f\u6027<\/h5>\n<p>K-Means\u867d\u7136\u5f3a\u5927&#xff0c;\u4f46\u5b83\u6709\u4e24\u4e2a\u8457\u540d\u7684\u201c\u8f6f\u808b\u201d\u3002<\/p>\n<p>K\u503c\u7684\u786e\u5b9a\u00a0\u7b97\u6cd5\u5f00\u59cb\u524d&#xff0c;\u6211\u4eec\u5fc5\u987b\u624b\u52a8\u6307\u5b9a\u7c07\u7684\u6570\u91cf\u00a0K\u3002\u8fd9\u4e2a\u00a0K\u00a0\u503c\u5e94\u8be5\u5982\u4f55\u786e\u5b9a&#xff1f;<\/p>\n<ul>\n<li>\u8098\u90e8\u6cd5\u5219&#xff08;Elbow Method&#xff09;&#xff1a;\u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u591a\u4e2a\u4e0d\u540c\u7684\u00a0K\u00a0\u503c&#xff08;\u4f8b\u5982\u4ece2\u523010&#xff09;&#xff0c;\u5e76\u8ba1\u7b97\u6bcf\u4e2a\u00a0K\u00a0\u503c\u4e0b\u6700\u7ec8\u7684WCSS\u3002\u7136\u540e&#xff0c;\u5c06\u00a0K\u00a0\u503c\u4f5c\u4e3a\u6a2a\u5750\u6807&#xff0c;WCSS\u4f5c\u4e3a\u7eb5\u5750\u6807&#xff0c;\u7ed8\u5236\u4e00\u6761\u66f2\u7ebf\u3002\u901a\u5e38&#xff0c;\u8fd9\u6761\u66f2\u7ebf\u4f1a\u50cf\u4e00\u4e2a\u624b\u81c2&#xff0c;\u968f\u7740\u00a0K\u00a0\u7684\u589e\u52a0&#xff0c;WCSS\u4f1a\u8fc5\u901f\u4e0b\u964d&#xff0c;\u4f46\u5230\u67d0\u4e2a\u70b9\u540e&#xff0c;\u4e0b\u964d\u901f\u5ea6\u4f1a\u53d8\u5f97\u975e\u5e38\u5e73\u7f13\u3002\u8fd9\u4e2a\u201c\u62d0\u70b9\u201d&#xff0c;\u5373\u201c\u8098\u90e8\u201d&#xff0c;\u901a\u5e38\u88ab\u8ba4\u4e3a\u662f\u6bd4\u8f83\u5408\u9002\u7684\u00a0K\u00a0\u503c\u3002<\/li>\n<li>\u8f6e\u5ed3\u7cfb\u6570&#xff08;Silhouette Score&#xff09;&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u66f4\u4e25\u8c28\u7684\u6307\u6807&#xff08;\u6211\u4eec\u5728\u7b2c\u56db\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u8fc7&#xff09;\u3002\u5b83\u540c\u65f6\u8861\u91cf\u4e86\u7c07\u7684\u5185\u805a\u5ea6\u548c\u5206\u79bb\u5ea6\u3002\u6211\u4eec\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u00a0K\u00a0\u503c\u8ba1\u7b97\u5176\u8f6e\u5ed3\u7cfb\u6570\u7684\u5e73\u5747\u503c&#xff0c;\u7136\u540e\u9009\u62e9\u90a3\u4e2a\u4f7f\u5f97\u8f6e\u5ed3\u7cfb\u6570\u6700\u5927\u7684\u00a0K\u00a0\u503c\u3002<\/li>\n<\/ul>\n<p>\u521d\u59cb\u70b9\u654f\u611f\u6027\u00a0K-Means\u7684\u6700\u7ec8\u7ed3\u679c\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u4f9d\u8d56\u4e8e\u521d\u59cb\u8d28\u5fc3\u7684\u9009\u62e9\u3002\u4e0d\u540c\u7684\u968f\u673a\u521d\u59cb\u5316\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5b8c\u5168\u4e0d\u540c\u7684\u805a\u7c7b\u7ed3\u679c&#xff0c;\u751a\u81f3\u9677\u5165\u4e00\u4e2a\u5c40\u90e8\u6700\u4f18\u89e3\u3002<\/p>\n<p>K-Means&#043;&#043;\u00a0\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;**K-Means&#043;&#043;**\u88ab\u63d0\u4e86\u51fa\u6765\u3002\u5b83\u662f\u4e00\u79cd\u66f4\u667a\u80fd\u7684\u521d\u59cb\u5316\u7b56\u7565&#xff0c;\u5176\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u521d\u59cb\u7684\u00a0K\u00a0\u4e2a\u8d28\u5fc3\u5e94\u8be5\u5c3d\u53ef\u80fd\u5730\u76f8\u4e92\u8fdc\u79bb\u3002Scikit-learn\u4e2d\u7684KMeans\u9ed8\u8ba4\u4f7f\u7528\u7684\u5c31\u662fK-Means&#043;&#043;\u521d\u59cb\u5316&#xff08;init&#061;&#039;k-means&#043;&#043;&#039;&#xff09;&#xff0c;\u8fd9\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u7f13\u89e3\u4e86\u521d\u59cb\u70b9\u654f\u611f\u6027\u7684\u95ee\u9898\u3002<\/p>\n<h5>7.1.3 Scikit-learn\u5b9e\u6218\u4e0e\u6a21\u578b\u5047\u8bbe<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0\u5728Scikit-learn\u4e2d&#xff0c;\u5b9e\u73b0K-Means\u805a\u7c7b\u975e\u5e38\u76f4\u89c2\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u6d41\u7a0b&#xff0c;\u5305\u62ec\u5bfb\u627e\u6700\u4f18K\u503c\u3001\u8bad\u7ec3\u6a21\u578b\u548c\u53ef\u89c6\u5316\u7ed3\u679c&#xff0c;\u6765\u5c55\u793a\u5176\u5e94\u7528\u3002<\/p>\n<p># \u5bfc\u5165\u5fc5\u8981\u7684\u5e93<br \/>\nfrom sklearn.cluster import KMeans<br \/>\nfrom sklearn.datasets import make_blobs<br \/>\nimport matplotlib.pyplot as plt<br \/>\nfrom sklearn.metrics import silhouette_score<br \/>\nimport numpy as np<\/p>\n<p># 1. \u751f\u6210\u6a21\u62df\u6570\u636e<br \/>\n# \u6211\u4eec\u521b\u5efa\u4e00\u4e9b\u7b26\u5408K-Means\u5047\u8bbe\u7684\u6570\u636e&#xff0c;\u5373\u7403\u72b6\u3001\u5927\u5c0f\u76f8\u4f3c\u7684\u7c07<br \/>\nX, y_true &#061; make_blobs(n_samples&#061;300, centers&#061;4, cluster_std&#061;0.8, random_state&#061;42)<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.scatter(X[:, 0], X[:, 1], s&#061;50)<br \/>\nplt.title(&#034;Simulated Data for Clustering&#034;)<br \/>\nplt.show()<\/p>\n<p># 2. \u4f7f\u7528\u8098\u90e8\u6cd5\u5219\u548c\u8f6e\u5ed3\u7cfb\u6570\u5bfb\u627e\u6700\u4f18K<br \/>\nwcss &#061; []<br \/>\nsilhouette_scores &#061; []<br \/>\nk_range &#061; range(2, 11) # K\u503c\u81f3\u5c11\u4e3a2\u624d\u6709\u610f\u4e49<\/p>\n<p>for k in k_range:<br \/>\n    # n_init&#061;10 \u8868\u793a\u7b97\u6cd5\u4f1a\u752810\u4e2a\u4e0d\u540c\u7684\u521d\u59cb\u8d28\u5fc3\u8fd0\u884c10\u6b21&#xff0c;\u5e76\u9009\u62e9WCSS\u6700\u5c0f\u7684\u7ed3\u679c<br \/>\n    kmeans &#061; KMeans(n_clusters&#061;k, init&#061;&#039;k-means&#043;&#043;&#039;, random_state&#061;42, n_init&#061;10)<br \/>\n    kmeans.fit(X)<br \/>\n    wcss.append(kmeans.inertia_) # inertia_ \u5c5e\u6027\u5c31\u662fWCSS<\/p>\n<p>    # \u8ba1\u7b97\u8f6e\u5ed3\u7cfb\u6570<br \/>\n    score &#061; silhouette_score(X, kmeans.labels_)<br \/>\n    silhouette_scores.append(score)<\/p>\n<p># \u7ed8\u5236\u8098\u90e8\u6cd5\u5219\u56fe<br \/>\nplt.figure(figsize&#061;(12, 5))<br \/>\nplt.subplot(1, 2, 1)<br \/>\nplt.plot(k_range, wcss, marker&#061;&#039;o&#039;)<br \/>\nplt.title(&#039;Elbow Method&#039;)<br \/>\nplt.xlabel(&#039;Number of clusters (K)&#039;)<br \/>\nplt.ylabel(&#039;WCSS&#039;)<\/p>\n<p># \u7ed8\u5236\u8f6e\u5ed3\u7cfb\u6570\u56fe<br \/>\nplt.subplot(1, 2, 2)<br \/>\nplt.plot(k_range, silhouette_scores, marker&#061;&#039;o&#039;)<br \/>\nplt.title(&#039;Silhouette Score for each K&#039;)<br \/>\nplt.xlabel(&#039;Number of clusters (K)&#039;)<br \/>\nplt.ylabel(&#039;Silhouette Score&#039;)<br \/>\nplt.tight_layout()<br \/>\nplt.show()<\/p>\n<p># \u4ece\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u6e05\u6670\u5730\u770b\u5230&#xff0c;K&#061;4\u662f\u6700\u4f73\u9009\u62e9&#xff08;\u8098\u90e8\u70b9&#xff0c;\u8f6e\u5ed3\u7cfb\u6570\u6700\u9ad8&#xff09;<\/p>\n<p># 3. \u8bad\u7ec3\u6700\u7ec8\u7684K-Means\u6a21\u578b<br \/>\nbest_k &#061; 4<br \/>\nkmeans_final &#061; KMeans(n_clusters&#061;best_k, init&#061;&#039;k-means&#043;&#043;&#039;, random_state&#061;42, n_init&#061;10)<br \/>\ny_kmeans &#061; kmeans_final.fit_predict(X)<\/p>\n<p># 4. \u7ed3\u679c\u53ef\u89c6\u5316<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.scatter(X[:, 0], X[:, 1], c&#061;y_kmeans, s&#061;50, cmap&#061;&#039;viridis&#039;)<br \/>\ncenters &#061; kmeans_final.cluster_centers_<br \/>\nplt.scatter(centers[:, 0], centers[:, 1], c&#061;&#039;red&#039;, s&#061;200, alpha&#061;0.75, marker&#061;&#039;X&#039;, label&#061;&#039;Centroids&#039;)<br \/>\nplt.title(f&#039;K-Means Clustering Result (K&#061;{best_k})&#039;)<br \/>\nplt.legend()<br \/>\nplt.show()<\/p>\n<p># 5. \u6253\u5370\u6700\u7ec8\u7684\u8f6e\u5ed3\u7cfb\u6570<br \/>\nfinal_score &#061; silhouette_score(X, y_kmeans)<br \/>\nprint(f&#034;Final Silhouette Score for K&#061;{best_k}: {final_score:.3f}&#034;)<\/p>\n<p>\u6a21\u578b\u5047\u8bbe\u00a0\u7406\u89e3K-Means\u7684\u9690\u542b\u5047\u8bbe\u81f3\u5173\u91cd\u8981&#xff0c;\u56e0\u4e3a\u5b83\u51b3\u5b9a\u4e86\u7b97\u6cd5\u7684\u9002\u7528\u8303\u56f4&#xff1a;<\/p>\n<li>\u7c07\u662f\u51f8\u5f62\u7684\u3001\u7403\u72b6\u7684&#xff08;Isotropic&#xff09;&#xff1a;\u7531\u4e8eK-Means\u4f7f\u7528\u57fa\u4e8e\u6b27\u6c0f\u8ddd\u79bb\u7684\u8d28\u5fc3\u6765\u5b9a\u4e49\u7c07&#xff0c;\u5b83\u5929\u7136\u5730\u503e\u5411\u4e8e\u53d1\u73b0\u7403\u72b6\u7684\u7c07\u3002<\/li>\n<li>\u6240\u6709\u7c07\u7684\u5927\u5c0f&#xff08;\u6837\u672c\u91cf&#xff09;\u548c\u5bc6\u5ea6\u5927\u81f4\u76f8\u540c\u3002<\/li>\n<li>\u6bcf\u4e2a\u6837\u672c\u90fd\u5c5e\u4e8e\u67d0\u4e2a\u7c07&#xff1a;K-Means\u4f1a\u5c06\u6240\u6709\u70b9\u90fd\u5206\u914d\u7ed9\u4e00\u4e2a\u7c07&#xff0c;\u5b83\u65e0\u6cd5\u8bc6\u522b\u79bb\u7fa4\u70b9\u6216\u566a\u58f0\u3002<\/li>\n<p>\u5982\u679c\u6570\u636e\u7684\u771f\u5b9e\u7c07\u7ed3\u6784\u662f\u7ec6\u957f\u7684\u3001\u73af\u5f62\u7684&#xff0c;\u6216\u8005\u5927\u5c0f\u3001\u5bc6\u5ea6\u5dee\u5f02\u5de8\u5927&#xff0c;K-Means\u7684\u8868\u73b0\u5c31\u4f1a\u5f88\u5dee\u3002\u8fd9\u65f6&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u6c42\u52a9\u4e8e\u4e0b\u9762\u5c06\u8981\u4ecb\u7ecd\u7684\u5176\u4ed6\u805a\u7c7b\u7b97\u6cd5\u3002<\/p>\n<hr \/>\n<h4>7.2 \u5c42\u6b21\u805a\u7c7b&#xff1a;\u6784\u5efa\u6570\u636e\u7684\u201c\u5bb6\u65cf\u8c31\u7cfb\u201d<\/h4>\n<p>\u5c42\u6b21\u805a\u7c7b&#xff08;Hierarchical Clustering&#xff09;\u63d0\u4f9b\u4e86\u4e00\u79cd\u4e0eK-Means\u5b8c\u5168\u4e0d\u540c\u7684\u89c6\u89d2\u3002\u5b83\u4e0d\u8981\u6c42\u6211\u4eec\u9884\u5148\u6307\u5b9a\u7c07\u7684\u6570\u91cf&#xff0c;\u800c\u662f\u901a\u8fc7\u6784\u5efa\u4e00\u4e2a\u5d4c\u5957\u7684\u7c07\u7684\u5c42\u6b21\u7ed3\u6784&#xff0c;\u6765\u5c55\u73b0\u6570\u636e\u70b9\u4e4b\u95f4\u7684\u4eb2\u758f\u5173\u7cfb&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u5bb6\u65cf\u7684\u65cf\u8c31\u4e00\u6837\u3002<\/p>\n<h5>7.2.1 \u4e24\u79cd\u7b56\u7565&#xff1a;\u81ea\u5e95\u5411\u4e0a&#xff08;\u51dd\u805a&#xff09;\u4e0e\u81ea\u9876\u5411\u4e0b&#xff08;\u5206\u88c2&#xff09;<\/h5>\n<ul>\n<li>\u51dd\u805a\u578b\u5c42\u6b21\u805a\u7c7b&#xff08;Agglomerative Clustering&#xff09;&#xff1a;\u8fd9\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\n<li>\u5f00\u59cb&#xff1a;\u5c06\u6bcf\u4e00\u4e2a\u6570\u636e\u70b9\u90fd\u89c6\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u7c07\u3002<\/li>\n<li>\u5408\u5e76&#xff1a;\u627e\u5230\u6700\u63a5\u8fd1\u7684\u4e24\u4e2a\u7c07&#xff0c;\u5c06\u5b83\u4eec\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u7c07\u3002<\/li>\n<li>\u91cd\u590d&#xff1a;\u4e0d\u65ad\u91cd\u590d\u5408\u5e76\u6b65\u9aa4&#xff0c;\u76f4\u5230\u6240\u6709\u6570\u636e\u70b9\u90fd\u5408\u5e76\u6210\u4e00\u4e2a\u552f\u4e00\u7684\u3001\u5de8\u5927\u7684\u7c07\u3002<\/li>\n<\/li>\n<li>\u5206\u88c2\u578b\u5c42\u6b21\u805a\u7c7b&#xff08;Divisive Clustering&#xff09;&#xff1a;\u8fc7\u7a0b\u6b63\u597d\u76f8\u53cd\u3002\n<li>\u5f00\u59cb&#xff1a;\u6240\u6709\u6570\u636e\u70b9\u90fd\u5728\u4e00\u4e2a\u5927\u7c07\u91cc\u3002<\/li>\n<li>\u5206\u88c2&#xff1a;\u4ee5\u67d0\u79cd\u65b9\u5f0f\u5c06\u5f53\u524d\u6700\u201c\u4e0d\u534f\u8c03\u201d\u7684\u7c07\u5206\u88c2\u6210\u4e24\u4e2a\u5b50\u7c07\u3002<\/li>\n<li>\u91cd\u590d&#xff1a;\u4e0d\u65ad\u91cd\u590d\u5206\u88c2\u6b65\u9aa4&#xff0c;\u76f4\u5230\u6bcf\u4e2a\u6570\u636e\u70b9\u90fd\u81ea\u6210\u4e00\u7c07\u3002<\/li>\n<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5c06\u91cd\u70b9\u5173\u6ce8\u66f4\u4e3b\u6d41\u7684\u51dd\u805a\u578b\u65b9\u6cd5\u3002<\/p>\n<h5>7.2.2 \u6838\u5fc3\u8981\u7d20&#xff1a;\u94fe\u63a5\u6807\u51c6&#xff08;Linkage Criteria&#xff09;<\/h5>\n<p>\u5728\u51dd\u805a\u578b\u805a\u7c7b\u7684\u5408\u5e76\u6b65\u9aa4\u4e2d&#xff0c;\u6211\u4eec\u5982\u4f55\u5b9a\u4e49\u4e24\u4e2a\u7c07\u4e4b\u95f4\u7684\u201c\u8ddd\u79bb\u201d&#xff1f;\u8fd9\u5c31\u662f\u94fe\u63a5\u6807\u51c6\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<ul>\n<li>Ward\u94fe\u63a5&#xff08;Ward&#039;s Linkage&#xff09;&#xff1a;Scikit-learn\u4e2d\u7684\u9ed8\u8ba4\u9009\u9879\u3002\u5b83\u4f1a\u5408\u5e76\u90a3\u4e24\u4e2a\u80fd\u4f7f\u603b\u7684\u7c07\u5185\u65b9\u5dee\u589e\u52a0\u6700\u5c0f\u7684\u7c07\u3002\u5b83\u503e\u5411\u4e8e\u4ea7\u751f\u5927\u5c0f\u76f8\u4f3c\u7684\u7403\u72b6\u7c07&#xff0c;\u901a\u5e38\u8868\u73b0\u975e\u5e38\u7a33\u5065\u3002<\/li>\n<li>\u5b8c\u5168\u94fe\u63a5&#xff08;Complete Linkage&#xff09;&#xff1a;\u7c07\u95f4\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u7c07\u4e2d\u6700\u8fdc\u7684\u4e24\u4e2a\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u5b83\u503e\u5411\u4e8e\u4ea7\u751f\u7d27\u51d1\u7684\u7403\u72b6\u7c07\u3002<\/li>\n<li>\u5e73\u5747\u94fe\u63a5&#xff08;Average Linkage&#xff09;&#xff1a;\u7c07\u95f4\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u7c07\u4e2d\u6240\u6709\u70b9\u5bf9\u4e4b\u95f4\u8ddd\u79bb\u7684\u5e73\u5747\u503c\u3002<\/li>\n<li>\u5355\u4e00\u94fe\u63a5&#xff08;Single Linkage&#xff09;&#xff1a;\u7c07\u95f4\u8ddd\u79bb\u5b9a\u4e49\u4e3a\u4e24\u4e2a\u7c07\u4e2d\u6700\u8fd1\u7684\u4e24\u4e2a\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u5b83\u53ef\u4ee5\u5904\u7406\u975e\u7403\u72b6\u7684\u7c07&#xff0c;\u4f46\u5bf9\u566a\u58f0\u975e\u5e38\u654f\u611f\u3002<\/li>\n<\/ul>\n<h5>7.2.3 Scikit-learn\u5b9e\u6218\u4e0e\u6811\u72b6\u56fe&#xff08;Dendrogram&#xff09;\u89e3\u8bfb<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0\u5c42\u6b21\u805a\u7c7b\u7684\u7f8e\u5999\u4e4b\u5904\u5728\u4e8e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6811\u72b6\u56fe&#xff08;Dendrogram&#xff09;\u6765\u53ef\u89c6\u5316\u6574\u4e2a\u5408\u5e76\u8fc7\u7a0b\u3002<\/p>\n<p>from sklearn.cluster import AgglomerativeClustering<br \/>\nfrom scipy.cluster.hierarchy import dendrogram, linkage<\/p>\n<p># \u4f7f\u7528\u4e4b\u524d\u7684\u6570\u636eX<\/p>\n<p># 1. \u751f\u6210\u94fe\u63a5\u77e9\u9635<br \/>\n# &#039;ward&#039;\u94fe\u63a5\u65b9\u6cd5\u8ba1\u7b97\u7684\u662f\u7c07\u95f4\u65b9\u5dee&#xff0c;\u800c\u4e0d\u662f\u8ddd\u79bb&#xff0c;\u6240\u4ee5\u5b83\u901a\u5e38\u4e0e\u6b27\u6c0f\u8ddd\u79bb\u914d\u5408\u4f7f\u7528<br \/>\nlinked &#061; linkage(X, method&#061;&#039;ward&#039;)<\/p>\n<p># 2. \u7ed8\u5236\u6811\u72b6\u56fe<br \/>\nplt.figure(figsize&#061;(12, 7))<br \/>\ndendrogram(linked,<br \/>\n           orientation&#061;&#039;top&#039;,<br \/>\n           labels&#061;None, # \u5982\u679c\u6837\u672c\u5c11&#xff0c;\u53ef\u4ee5\u4f20\u5165\u6807\u7b7e<br \/>\n           distance_sort&#061;&#039;descending&#039;,<br \/>\n           show_leaf_counts&#061;True)<br \/>\nplt.title(&#039;Hierarchical Clustering Dendrogram (Ward Linkage)&#039;)<br \/>\nplt.xlabel(&#039;Sample index&#039;)<br \/>\nplt.ylabel(&#039;Distance (Ward)&#039;)<br \/>\nplt.show()<\/p>\n<p>\u6811\u72b6\u56fe\u89e3\u8bfb<\/p>\n<ul>\n<li>\u6a2a\u8f74\u4ee3\u8868\u6570\u636e\u6837\u672c\u3002<\/li>\n<li>\u7eb5\u8f74\u4ee3\u8868\u7c07\u4e4b\u95f4\u7684\u8ddd\u79bb\u6216\u4e0d\u76f8\u4f3c\u5ea6\u3002<\/li>\n<li>\u6bcf\u4e00\u6761\u7ad6\u7ebf\u4ee3\u8868\u4e00\u4e2a\u7c07\u3002<\/li>\n<li>\u8fde\u63a5\u4e24\u6761\u7ad6\u7ebf\u7684\u6a2a\u7ebf\u8868\u793a\u4e00\u6b21\u5408\u5e76&#xff0c;\u6a2a\u7ebf\u7684\u9ad8\u5ea6\u5c31\u662f\u8fd9\u6b21\u5408\u5e76\u65f6\u4e24\u4e2a\u7c07\u7684\u8ddd\u79bb\u3002<\/li>\n<\/ul>\n<p>\u5982\u4f55\u6839\u636e\u6811\u72b6\u56fe\u51b3\u5b9a\u7c07\u7684\u6570\u91cf&#xff1f;\u00a0\u6211\u4eec\u53ef\u4ee5\u753b\u4e00\u6761\u6c34\u5e73\u7ebf\u6a2a\u5207\u6574\u4e2a\u6811\u72b6\u56fe\u3002\u8fd9\u6761\u6c34\u5e73\u7ebf\u4e0e\u591a\u5c11\u6761\u7ad6\u7ebf\u76f8\u4ea4&#xff0c;\u5c31\u610f\u5473\u7740\u6211\u4eec\u5c06\u6570\u636e\u5206\u6210\u4e86\u591a\u5c11\u4e2a\u7c07\u3002\u4e00\u4e2a\u5e38\u7528\u7684\u65b9\u6cd5\u662f&#xff0c;\u5bfb\u627e\u90a3\u6bb5\u6700\u957f\u7684\u3001\u6ca1\u6709\u88ab\u6a2a\u7ebf\u7a7f\u8fc7\u7684\u7ad6\u7ebf&#xff0c;\u7136\u540e\u5728\u8fd9\u6bb5\u4e2d\u95f4\u753b\u4e00\u6761\u6c34\u5e73\u7ebf\u3002<\/p>\n<p># 3. \u8bad\u7ec3AgglomerativeClustering\u6a21\u578b<br \/>\n# \u5047\u8bbe\u6211\u4eec\u4ece\u6811\u72b6\u56fe\u4e2d\u51b3\u5b9an_clusters&#061;4<br \/>\nagg_cluster &#061; AgglomerativeClustering(n_clusters&#061;4, linkage&#061;&#039;ward&#039;)<br \/>\ny_agg &#061; agg_cluster.fit_predict(X)<\/p>\n<p># 4. \u7ed3\u679c\u53ef\u89c6\u5316<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.scatter(X[:, 0], X[:, 1], c&#061;y_agg, s&#061;50, cmap&#061;&#039;viridis&#039;)<br \/>\nplt.title(&#039;Agglomerative Clustering Result (K&#061;4)&#039;)<br \/>\nplt.show()<\/p>\n<hr \/>\n<h4>7.3 DBSCAN&#xff1a;\u57fa\u4e8e\u5bc6\u5ea6\u7684\u201c\u793e\u533a\u53d1\u73b0\u201d<\/h4>\n<p>DBSCAN&#xff08;Density-Based Spatial Clustering of Applications with Noise&#xff09;\u662f\u4e00\u79cd\u5b8c\u5168\u4e0d\u540c\u7684\u805a\u7c7b\u8303\u5f0f\u3002\u5b83\u4e0d\u57fa\u4e8e\u8ddd\u79bb\u4e2d\u5fc3\u6216\u5c42\u6b21\u5173\u7cfb&#xff0c;\u800c\u662f\u57fa\u4e8e\u5bc6\u5ea6\u3002<\/p>\n<h5>7.3.1 \u8d85\u8d8a\u51e0\u4f55\u4e2d\u5fc3&#xff1a;\u4ece\u201c\u5bc6\u5ea6\u201d\u51fa\u53d1\u770b\u4e16\u754c<\/h5>\n<p>\u6838\u5fc3\u601d\u60f3\u00a0DBSCAN\u8ba4\u4e3a&#xff0c;\u4e00\u4e2a\u7c07\u662f\u7531\u5bc6\u5ea6\u53ef\u8fbe&#xff08;density-reachable&#xff09;\u7684\u70b9\u7684\u96c6\u5408\u3002\u901a\u4fd7\u5730\u8bf4&#xff0c;\u4e00\u4e2a\u70b9\u5c5e\u4e8e\u67d0\u4e2a\u7c07&#xff0c;\u662f\u56e0\u4e3a\u5b83\u5468\u56f4\u201c\u8db3\u591f\u7a20\u5bc6\u201d\u3002<\/p>\n<p>\u4e24\u4e2a\u5173\u952e\u53c2\u6570<\/p>\n<li>\u90bb\u57df\u534a\u5f84 (eps)&#xff1a;\u5b9a\u4e49\u4e86\u4e00\u4e2a\u70b9\u7684\u201c\u90bb\u57df\u201d\u8303\u56f4\u3002\u5b83\u662f\u4e00\u4e2a\u8ddd\u79bb\u503c\u3002<\/li>\n<li>\u6700\u5c0f\u70b9\u6570 (min_samples)&#xff1a;\u8981\u6210\u4e3a\u4e00\u4e2a\u201c\u7a20\u5bc6\u201d\u533a\u57df&#xff0c;\u4e00\u4e2a\u70b9\u7684\u90bb\u57df\u5185\u81f3\u5c11\u9700\u8981\u5305\u542b\u591a\u5c11\u4e2a\u5176\u4ed6\u70b9&#xff08;\u5305\u62ec\u5b83\u81ea\u5df1&#xff09;\u3002<\/li>\n<p>\u70b9\u7684\u5206\u7c7b\u00a0\u6839\u636e\u8fd9\u4e24\u4e2a\u53c2\u6570&#xff0c;DBSCAN\u5c06\u6240\u6709\u70b9\u5206\u4e3a\u4e09\u7c7b&#xff1a;<\/p>\n<ul>\n<li>\u6838\u5fc3\u70b9&#xff08;Core Point&#xff09;&#xff1a;\u5728\u5176eps\u90bb\u57df\u5185&#xff0c;\u81f3\u5c11\u6709min_samples\u4e2a\u70b9\u7684\u70b9\u3002\u5b83\u4eec\u662f\u7c07\u7684\u201c\u5fc3\u810f\u201d\u3002<\/li>\n<li>\u8fb9\u754c\u70b9&#xff08;Border Point&#xff09;&#xff1a;\u5b83\u4e0d\u662f\u6838\u5fc3\u70b9&#xff0c;\u4f46\u5b83\u843d\u5728\u4e86\u67d0\u4e2a\u6838\u5fc3\u70b9\u7684eps\u90bb\u57df\u5185\u3002\u5b83\u4eec\u662f\u7c07\u7684\u201c\u8fb9\u7f18\u201d\u3002<\/li>\n<li>\u566a\u58f0\u70b9&#xff08;Noise Point \/ Outlier&#xff09;&#xff1a;\u65e2\u4e0d\u662f\u6838\u5fc3\u70b9&#xff0c;\u4e5f\u4e0d\u662f\u8fb9\u754c\u70b9\u3002\u5b83\u4eec\u662f\u79bb\u7fa4\u7684\u3001\u5b64\u72ec\u7684\u70b9\u3002<\/li>\n<\/ul>\n<p>\u7b97\u6cd5\u6d41\u7a0b&#xff1a;\u4ece\u4e00\u4e2a\u4efb\u610f\u70b9\u5f00\u59cb&#xff0c;\u5982\u679c\u5b83\u662f\u6838\u5fc3\u70b9&#xff0c;\u5c31\u4ee5\u5b83\u4e3a\u4e2d\u5fc3&#xff0c;\u901a\u8fc7\u5bc6\u5ea6\u53ef\u8fbe\u5173\u7cfb\u4e0d\u65ad\u6269\u5f20&#xff0c;\u5f62\u6210\u4e00\u4e2a\u7c07\u3002\u7136\u540e\u7ee7\u7eed\u5904\u7406\u4e0b\u4e00\u4e2a\u672a\u88ab\u8bbf\u95ee\u7684\u70b9\u3002<\/p>\n<h5>7.3.2 DBSCAN\u7684\u72ec\u7279\u4f18\u52bf&#xff1a;\u53d1\u73b0\u4efb\u610f\u5f62\u72b6\u7684\u7c07\u4e0e\u8bc6\u522b\u566a\u58f0<\/h5>\n<ul>\n<li>\u5904\u7406\u975e\u7403\u5f62\u7c07&#xff1a;\u7531\u4e8eDBSCAN\u4e0d\u5173\u5fc3\u70b9\u5230\u4e2d\u5fc3\u7684\u8ddd\u79bb&#xff0c;\u53ea\u5173\u5fc3\u5bc6\u5ea6&#xff0c;\u56e0\u6b64\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u53d1\u73b0\u4efb\u610f\u5f62\u72b6\u7684\u7c07&#xff0c;\u5982\u73af\u5f62\u3001\u6708\u7259\u5f62\u3001\u86c7\u5f62\u7b49&#xff0c;\u8fd9\u662fK-Means\u548c\u5c42\u6b21\u805a\u7c7b\u96be\u4ee5\u505a\u5230\u7684\u3002<\/li>\n<li>\u81ea\u52a8\u8bc6\u522b\u79bb\u7fa4\u70b9&#xff1a;DBSCAN\u4e0d\u9700\u8981\u9884\u5148\u6307\u5b9a\u7c07\u7684\u6570\u91cf\u3002\u5b83\u4f1a\u6839\u636e\u5bc6\u5ea6\u81ea\u52a8\u786e\u5b9a\u7c07\u7684\u6570\u91cf&#xff0c;\u5e76\u5c06\u4efb\u4f55\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u7c07\u7684\u70b9\u6807\u8bb0\u4e3a\u566a\u58f0&#xff08;\u901a\u5e38\u6807\u7b7e\u4e3a-1&#xff09;\u3002<\/li>\n<\/ul>\n<h5>7.3.3 Scikit-learn\u5b9e\u6218\u4e0e\u53c2\u6570\u9009\u62e9\u7684\u6311\u6218<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.cluster import DBSCAN<br \/>\nfrom sklearn.datasets import make_moons<\/p>\n<p># \u751f\u6210\u6708\u7259\u5f62\u6570\u636e<br \/>\nX_moon, y_moon &#061; make_moons(n_samples&#061;200, noise&#061;0.05, random_state&#061;42)<\/p>\n<p># \u8bad\u7ec3DBSCAN\u6a21\u578b<br \/>\n# eps\u548cmin_samples\u7684\u9009\u62e9\u975e\u5e38\u5173\u952e&#xff0c;\u9700\u8981\u8c03\u8bd5<br \/>\ndbscan &#061; DBSCAN(eps&#061;0.3, min_samples&#061;5)<br \/>\ny_db &#061; dbscan.fit_predict(X_moon)<\/p>\n<p># \u7ed3\u679c\u53ef\u89c6\u5316<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.scatter(X_moon[:, 0], X_moon[:, 1], c&#061;y_db, s&#061;50, cmap&#061;&#039;viridis&#039;)<br \/>\nplt.title(&#039;DBSCAN Clustering on Moons Dataset&#039;)<br \/>\nplt.show()<\/p>\n<p>\u53c2\u6570\u9009\u62e9\u7684\u6311\u6218\u00a0DBSCAN\u7684\u6027\u80fd\u9ad8\u5ea6\u4f9d\u8d56\u4e8eeps\u548cmin_samples\u7684\u9009\u62e9\u3002<\/p>\n<ul>\n<li>min_samples\u901a\u5e38\u6839\u636e\u9886\u57df\u77e5\u8bc6\u8bbe\u5b9a&#xff0c;\u4e00\u4e2a\u7ecf\u9a8c\u6cd5\u5219\u662f\u5c06\u5176\u8bbe\u4e3a2 * D&#xff0c;\u5176\u4e2dD\u662f\u6570\u636e\u7684\u7ef4\u5ea6\u3002<\/li>\n<li>eps\u7684\u9009\u62e9\u66f4\u5177\u6311\u6218\u6027\u3002\u4e00\u4e2a\u5e38\u7528\u7684\u8f85\u52a9\u65b9\u6cd5\u662fK-\u8ddd\u79bb\u56fe&#xff08;K-distance plot&#xff09;&#xff1a;\n<li>\u8ba1\u7b97\u6bcf\u4e2a\u70b9\u5230\u5176\u7b2ck\u4e2a\u6700\u8fd1\u90bb\u7684\u8ddd\u79bb&#xff08;\u8fd9\u91cc\u7684k\u5c31\u662fmin_samples-1&#xff09;\u3002<\/li>\n<li>\u5c06\u8fd9\u4e9b\u8ddd\u79bb\u4ece\u5927\u5230\u5c0f\u6392\u5e8f&#xff0c;\u5e76\u7ed8\u5236\u51fa\u6765\u3002<\/li>\n<li>\u56fe\u5f62\u4e2d\u540c\u6837\u4f1a\u51fa\u73b0\u4e00\u4e2a\u201c\u8098\u90e8\u201d&#xff0c;\u8fd9\u4e2a\u8098\u90e8\u5bf9\u5e94\u7684\u8ddd\u79bb\u503c&#xff0c;\u5c31\u662f\u4e00\u4e2a\u5f88\u597d\u7684eps\u5019\u9009\u503c\u3002<\/li>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>7.4 \u4e3b\u6210\u5206\u5206\u6790&#xff08;PCA&#xff09;&#xff1a;\u5728\u7eb7\u7e41\u4e2d\u89c1\u672c\u8d28\u7684\u964d\u7ef4\u4e4b\u9053<\/h4>\n<p>\u4e3b\u6210\u5206\u5206\u6790&#xff08;Principal Component Analysis, PCA&#xff09;\u662f\u65e0\u76d1\u7763\u5b66\u4e60\u4e2d\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u964d\u7ef4\u6280\u672f\u3002\u5b83\u65e8\u5728\u5c06\u9ad8\u7ef4\u6570\u636e\u6295\u5f71\u5230\u4e00\u4e2a\u4f4e\u7ef4\u7a7a\u95f4\u4e2d&#xff0c;\u540c\u65f6\u5c3d\u53ef\u80fd\u591a\u5730\u4fdd\u7559\u539f\u59cb\u6570\u636e\u7684\u65b9\u5dee&#xff08;\u4fe1\u606f&#xff09;\u3002<\/p>\n<h5>7.4.1 \u964d\u7ef4\u7684\u610f\u4e49&#xff1a;\u4e3a\u4f55\u6211\u4eec\u9700\u8981\u201c\u5316\u7e41\u4e3a\u7b80\u201d<\/h5>\n<ul>\n<li>\u514b\u670d\u7ef4\u5ea6\u8bc5\u5492&#xff1a;\u5f53\u7279\u5f81\u7ef4\u5ea6\u975e\u5e38\u9ad8\u65f6&#xff0c;\u6570\u636e\u4f1a\u53d8\u5f97\u5f02\u5e38\u7a00\u758f&#xff0c;\u6a21\u578b\u6027\u80fd\u4e0b\u964d&#xff0c;\u8ba1\u7b97\u6210\u672c\u5267\u589e\u3002\u964d\u7ef4\u53ef\u4ee5\u6709\u6548\u7f13\u89e3\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<li>\u6570\u636e\u53ef\u89c6\u5316&#xff1a;\u6211\u4eec\u7684\u8089\u773c\u53ea\u80fd\u611f\u77e5\u4e8c\u7ef4\u6216\u4e09\u7ef4\u7a7a\u95f4\u3002PCA\u53ef\u4ee5\u5c06\u4e0a\u767e\u7ef4\u7684\u6570\u636e\u964d\u52302D\u62163D&#xff0c;\u8ba9\u6211\u4eec\u80fd\u591f\u76f4\u89c2\u5730\u89c2\u5bdf\u6570\u636e\u7684\u5206\u5e03\u3001\u7ed3\u6784\u548c\u805a\u7c7b\u8d8b\u52bf\u3002<\/li>\n<li>\u964d\u4f4e\u8ba1\u7b97\u6210\u672c\u4e0e\u566a\u58f0&#xff1a;\u53bb\u9664\u5197\u4f59\u548c\u6b21\u8981\u7684\u7279\u5f81&#xff0c;\u53ef\u4ee5\u52a0\u5feb\u6a21\u578b\u8bad\u7ec3\u901f\u5ea6&#xff0c;\u5e76\u53ef\u80fd\u901a\u8fc7\u6ee4\u9664\u566a\u58f0\u6765\u63d0\u5347\u6a21\u578b\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h5>7.4.2 PCA\u7684\u6838\u5fc3\u601d\u60f3&#xff1a;\u5bfb\u627e\u6700\u5927\u65b9\u5dee\u7684\u65b9\u5411<\/h5>\n<p>PCA\u7684\u672c\u8d28\u662f\u8fdb\u884c\u4e00\u6b21\u5750\u6807\u7cfb\u7684\u65cb\u8f6c\u3002\u5b83\u8981\u627e\u5230\u4e00\u4e2a\u65b0\u7684\u5750\u6807\u7cfb&#xff0c;\u4f7f\u5f97\u6570\u636e\u5728\u8fd9\u4e2a\u65b0\u5750\u6807\u7cfb\u4e0b\u7684\u8868\u793a\u5177\u6709\u4e24\u4e2a\u7279\u70b9&#xff1a;<\/p>\n<li>\u65b9\u5dee\u6700\u5927\u5316&#xff1a;\u7b2c\u4e00\u4e2a\u65b0\u5750\u6807\u8f74&#xff08;\u5373\u7b2c\u4e00\u4e3b\u6210\u5206&#xff09;\u7684\u65b9\u5411&#xff0c;\u5fc5\u987b\u662f\u539f\u59cb\u6570\u636e\u65b9\u5dee\u6700\u5927\u7684\u65b9\u5411\u3002\u56e0\u4e3a\u65b9\u5dee\u8d8a\u5927&#xff0c;\u4ee3\u8868\u6570\u636e\u5728\u8be5\u65b9\u5411\u4e0a\u643a\u5e26\u7684\u4fe1\u606f\u8d8a\u591a\u3002\u7b2c\u4e8c\u4e2a\u65b0\u5750\u6807\u8f74&#xff08;\u7b2c\u4e8c\u4e3b\u6210\u5206&#xff09;\u5219\u662f\u5728\u4e0e\u7b2c\u4e00\u4e2a\u8f74\u6b63\u4ea4&#xff08;\u5782\u76f4&#xff09;\u7684\u524d\u63d0\u4e0b&#xff0c;\u65b9\u5dee\u6b21\u5927\u7684\u65b9\u5411&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002<\/li>\n<li>\u4e0d\u76f8\u5173\u6027&#xff1a;\u6240\u6709\u65b0\u7684\u5750\u6807\u8f74&#xff08;\u4e3b\u6210\u5206&#xff09;\u4e4b\u95f4\u90fd\u662f\u7ebf\u6027\u65e0\u5173&#xff08;\u6b63\u4ea4&#xff09;\u7684\u3002<\/li>\n<p>\u4e3b\u6210\u5206&#xff08;Principal Components&#xff09;\u5c31\u662f\u8fd9\u4e9b\u65b0\u7684\u5750\u6807\u8f74\u3002\u5b83\u4eec\u662f\u539f\u59cb\u7279\u5f81\u7684\u7ebf\u6027\u7ec4\u5408\u3002<\/p>\n<p>\u53ef\u89e3\u91ca\u65b9\u5dee\u6bd4&#xff08;Explained Variance Ratio&#xff09;\u00a0PCA\u5b8c\u6210\u540e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97\u6bcf\u4e2a\u4e3b\u6210\u5206\u201c\u89e3\u91ca\u201d\u4e86\u591a\u5c11\u539f\u59cb\u6570\u636e\u7684\u65b9\u5dee\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u524d\u4e24\u4e2a\u4e3b\u6210\u5206\u7684\u7d2f\u8ba1\u53ef\u89e3\u91ca\u65b9\u5dee\u6bd4\u4e3a0.95&#xff0c;\u5c31\u610f\u5473\u7740\u6211\u4eec\u7528\u8fd9\u4e24\u4e2a\u65b0\u7684\u7279\u5f81&#xff0c;\u4fdd\u7559\u4e86\u539f\u59cb\u6570\u636e95%\u7684\u4fe1\u606f\u3002<\/p>\n<h5>7.4.3 Scikit-learn\u5b9e\u6218\u4e0e\u5e94\u7528<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0PCA\u5bf9\u7279\u5f81\u7684\u5c3a\u5ea6\u975e\u5e38\u654f\u611f\u3002\u5982\u679c\u4e00\u4e2a\u7279\u5f81\u7684\u65b9\u5dee\u8fdc\u5927\u4e8e\u5176\u4ed6\u7279\u5f81&#xff0c;\u90a3\u4e48PCA\u4f1a\u4e3b\u8981\u88ab\u8fd9\u4e2a\u7279\u5f81\u6240\u4e3b\u5bfc\u3002\u56e0\u6b64&#xff0c;\u5728\u4f7f\u7528PCA\u4e4b\u524d&#xff0c;\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316&#xff08;StandardScaler&#xff09;\u662f\u4e00\u4e2a\u81f3\u5173\u91cd\u8981\u7684\u9884\u5904\u7406\u6b65\u9aa4\u3002Scikit-learn\u7684PCA\u5b9e\u73b0\u4f1a\u81ea\u52a8\u5bf9\u6570\u636e\u8fdb\u884c\u4e2d\u5fc3\u5316&#xff08;\u51cf\u53bb\u5747\u503c&#xff09;&#xff0c;\u4f46\u6807\u51c6\u5316\u7684\u6b65\u9aa4\u9700\u8981\u6211\u4eec\u81ea\u5df1\u5b8c\u6210\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u7ecf\u5178\u7684\u624b\u5199\u6570\u5b57\u6570\u636e\u96c6&#xff08;Digits&#xff09;\u6765\u6f14\u793aPCA\u7684\u5e94\u7528\u3002\u8fd9\u4e2a\u6570\u636e\u96c6\u7684\u6bcf\u4e2a\u6837\u672c\u670964\u4e2a\u7279\u5f81&#xff08;\u4e00\u4e2a8&#215;8\u50cf\u7d20\u7684\u56fe\u50cf&#xff09;&#xff0c;\u6211\u4eec\u7684\u76ee\u6807\u662f\u5c06\u5176\u964d\u7ef4\u4ee5\u4fbf\u4e8e\u53ef\u89c6\u5316\u3002<\/p>\n<p># \u5bfc\u5165\u5fc5\u8981\u7684\u5e93<br \/>\nfrom sklearn.decomposition import PCA<br \/>\nfrom sklearn.preprocessing import StandardScaler<br \/>\nfrom sklearn.datasets import load_digits<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport numpy as np<\/p>\n<p># 1. \u52a0\u8f7d\u6570\u636e<br \/>\n# Digits\u6570\u636e\u96c6&#xff0c;\u6bcf\u4e2a\u6837\u672c\u662f64\u7ef4\u7684\u5411\u91cf<br \/>\ndigits &#061; load_digits()<br \/>\nX_digits &#061; digits.data<br \/>\ny_digits &#061; digits.target<\/p>\n<p>print(f&#034;Original data shape: {X_digits.shape}&#034;)<\/p>\n<p># 2. \u6570\u636e\u6807\u51c6\u5316<br \/>\nscaler &#061; StandardScaler()<br \/>\nX_scaled &#061; scaler.fit_transform(X_digits)<\/p>\n<p># 3. \u5e94\u7528PCA\u8fdb\u884c\u964d\u7ef4 (\u76ee\u6807\u662f\u964d\u52302\u7ef4\u4ee5\u4fbf\u53ef\u89c6\u5316)<br \/>\n# n_components\u53ef\u4ee5\u662f\u4e00\u4e2a\u6574\u6570&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a(0,1)\u4e4b\u95f4\u7684\u6d6e\u70b9\u6570<br \/>\npca &#061; PCA(n_components&#061;2)<br \/>\nX_pca &#061; pca.fit_transform(X_scaled)<\/p>\n<p>print(f&#034;Data shape after PCA: {X_pca.shape}&#034;)<\/p>\n<p># 4. \u67e5\u770b\u53ef\u89e3\u91ca\u65b9\u5dee\u6bd4<br \/>\n# explained_variance_ratio_ \u5c5e\u6027\u662f\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u5305\u542b\u4e86\u6bcf\u4e2a\u4e3b\u6210\u5206\u89e3\u91ca\u7684\u65b9\u5dee\u6bd4\u4f8b<br \/>\nprint(f&#034;\\\\nExplained variance ratio of the first component: {pca.explained_variance_ratio_[0]:.3f}&#034;)<br \/>\nprint(f&#034;Explained variance ratio of the second component: {pca.explained_variance_ratio_[1]:.3f}&#034;)<br \/>\nprint(f&#034;Total explained variance by 2 components: {np.sum(pca.explained_variance_ratio_):.3f}&#034;)<br \/>\n# \u8fd9\u4e2a\u7ed3\u679c\u544a\u8bc9\u6211\u4eec&#xff0c;\u4ec5\u75282\u4e2a\u4e3b\u6210\u5206&#xff0c;\u5c31\u4fdd\u7559\u4e86\u539f\u59cb64\u7ef4\u6570\u636e\u7ea628.7%\u7684\u65b9\u5dee&#xff08;\u4fe1\u606f&#xff09;\u3002<\/p>\n<p># 5. \u53ef\u89c6\u5316\u964d\u7ef4\u540e\u7684\u6570\u636e<br \/>\nplt.figure(figsize&#061;(10, 8))<br \/>\nscatter &#061; plt.scatter(X_pca[:, 0], X_pca[:, 1], c&#061;y_digits, cmap&#061;&#039;jet&#039;, alpha&#061;0.7, s&#061;40)<br \/>\nplt.xlabel(&#039;First Principal Component&#039;)<br \/>\nplt.ylabel(&#039;Second Principal Component&#039;)<br \/>\nplt.title(&#039;PCA of Digits Dataset (64D -&gt; 2D)&#039;)<br \/>\nplt.legend(handles&#061;scatter.legend_elements()[0], labels&#061;digits.target_names)<br \/>\nplt.colorbar(label&#061;&#039;Digit Label&#039;)<br \/>\nplt.grid(True)<br \/>\nplt.show()<\/p>\n<p>\u4ece\u53ef\u89c6\u5316\u7ed3\u679c\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u6e05\u6670\u5730\u770b\u5230&#xff0c;\u5373\u4f7f\u53ea\u7528\u4e86\u4e24\u4e2a\u4e3b\u6210\u5206&#xff0c;\u4e0d\u540c\u6570\u5b57\u7684\u7c7b\u522b\u4e5f\u5df2\u7ecf\u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\u5448\u73b0\u51fa\u4e86\u660e\u663e\u7684\u5206\u79bb\u8d8b\u52bf\u3002\u8fd9\u5c31\u662fPCA\u5728\u6570\u636e\u63a2\u7d22\u548c\u53ef\u89c6\u5316\u65b9\u9762\u7684\u5f3a\u5927\u5a01\u529b\u3002<\/p>\n<p>\u9009\u62e9\u4e3b\u6210\u5206\u6570\u91cf\u00a0\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u6211\u4eec\u4e0d\u4e00\u5b9a\u603b\u60f3\u964d\u52302\u7ef4\u3002\u5982\u4f55\u9009\u62e9\u4e00\u4e2a\u65e2\u80fd\u663e\u8457\u964d\u7ef4\u3001\u53c8\u80fd\u4fdd\u7559\u8db3\u591f\u4fe1\u606f\u7684\u7ef4\u5ea6\u00a0k&#xff1f;<\/p>\n<ul>\n<li>\u6839\u636e\u7d2f\u8ba1\u53ef\u89e3\u91ca\u65b9\u5dee\u6bd4&#xff1a;\u8fd9\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u9608\u503c&#xff08;\u4f8b\u5982&#xff0c;\u5e0c\u671b\u4fdd\u755995%\u7684\u65b9\u5dee&#xff09;&#xff0c;\u7136\u540e\u8fd0\u884cPCA&#xff0c;\u8ba9\u5b83\u81ea\u52a8\u9009\u62e9\u80fd\u8fbe\u5230\u8fd9\u4e2a\u9608\u503c\u7684\u6700\u5c0f\u7ec4\u4ef6\u6570\u3002<\/li>\n<li>\u788e\u77f3\u56fe&#xff08;Scree Plot&#xff09;&#xff1a;\u5c06\u6240\u6709\u4e3b\u6210\u5206\u6309\u5176\u89e3\u91ca\u7684\u65b9\u5dee\u5927\u5c0f\u6392\u5e8f\u5e76\u7ed8\u5236\u51fa\u6765\u3002\u56fe\u5f62\u4e2d\u901a\u5e38\u4e5f\u4f1a\u51fa\u73b0\u4e00\u4e2a\u201c\u8098\u90e8\u201d&#xff0c;\u8098\u90e8\u4e4b\u524d\u7684\u4e3b\u6210\u5206\u901a\u5e38\u88ab\u8ba4\u4e3a\u662f\u91cd\u8981\u7684&#xff0c;\u53ef\u4ee5\u4fdd\u7559\u3002<\/li>\n<\/ul>\n<p># \u65b9\u6cd5\u4e00&#xff1a;\u8bbe\u5b9a\u53ef\u89e3\u91ca\u65b9\u5dee\u6bd4\u9608\u503c<br \/>\n# n_components&#061;0.95 \u8868\u793a\u9009\u62e9\u80fd\u4fdd\u755995%\u65b9\u5dee\u7684\u6700\u5c11\u6570\u91cf\u7684\u4e3b\u6210\u5206<br \/>\npca_95 &#061; PCA(n_components&#061;0.95)<br \/>\nX_pca_95 &#061; pca_95.fit_transform(X_scaled)<br \/>\nprint(f&#034;\\\\nNumber of components to explain 95% variance: {pca_95.n_components_}&#034;)<\/p>\n<p># \u65b9\u6cd5\u4e8c&#xff1a;\u7ed8\u5236\u788e\u77f3\u56fe\u6765\u8f85\u52a9\u51b3\u7b56<br \/>\npca_full &#061; PCA().fit(X_scaled) # \u4e0d\u6307\u5b9an_components&#xff0c;\u8ba1\u7b97\u6240\u6709\u4e3b\u6210\u5206<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.plot(np.cumsum(pca_full.explained_variance_ratio_), marker&#061;&#039;o&#039;, linestyle&#061;&#039;&#8211;&#039;)<br \/>\nplt.xlabel(&#039;Number of Components&#039;)<br \/>\nplt.ylabel(&#039;Cumulative Explained Variance Ratio&#039;)<br \/>\nplt.title(&#039;Scree Plot for PCA&#039;)<br \/>\nplt.axhline(y&#061;0.95, color&#061;&#039;r&#039;, linestyle&#061;&#039;-&#039;, label&#061;&#039;95% threshold&#039;)<br \/>\nplt.legend()<br \/>\nplt.grid(True)<br \/>\nplt.show()<\/p>\n<p>\u4ece\u788e\u77f3\u56fe\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u770b\u5230&#xff0c;\u5927\u7ea6\u9700\u898128\u4e2a\u4e3b\u6210\u5206\u624d\u80fd\u4fdd\u755995%\u7684\u65b9\u5dee&#xff0c;\u8fd9\u4f9d\u7136\u5b9e\u73b0\u4e86\u8d85\u8fc7\u4e00\u534a\u7684\u7ef4\u5ea6\u7ea6\u51cf\u3002<\/p>\n<p>\u5e94\u7528\u6848\u4f8b<\/p>\n<ul>\n<li>\u6570\u636e\u53ef\u89c6\u5316&#xff1a;\u5982\u4e0a\u4f8b\u6240\u793a&#xff0c;\u5c06\u9ad8\u7ef4\u6570\u636e\u6295\u5f71\u52302D\u62163D\u7a7a\u95f4&#xff0c;\u4ee5\u6d1e\u5bdf\u5176\u5185\u5728\u7ed3\u6784\u3002<\/li>\n<li>\u4f5c\u4e3a\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u9884\u5904\u7406\u6b65\u9aa4&#xff1a;\u5148\u7528PCA\u5bf9\u6570\u636e\u964d\u7ef4&#xff0c;\u518d\u5c06\u964d\u7ef4\u540e\u7684\u6570\u636e\u8f93\u5165\u5230\u5206\u7c7b\u6216\u56de\u5f52\u6a21\u578b\u4e2d\u3002\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u53ef\u4ee5\u663e\u8457\u52a0\u5feb\u6a21\u578b\u8bad\u7ec3\u901f\u5ea6&#xff0c;\u5e76\u53ef\u80fd\u901a\u8fc7\u6ee4\u9664\u566a\u58f0\u548c\u5171\u7ebf\u6027\u6765\u63d0\u5347\u6a21\u578b\u6027\u80fd\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u964d\u7ef4\u540e\u7684\u65b0\u7279\u5f81\u662f\u539f\u59cb\u7279\u5f81\u7684\u7ebf\u6027\u7ec4\u5408&#xff0c;\u5931\u53bb\u4e86\u539f\u6709\u7684\u7269\u7406\u610f\u4e49&#xff0c;\u5bfc\u81f4\u6a21\u578b\u7684\u53ef\u89e3\u91ca\u6027\u4e0b\u964d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u8e0f\u5165\u4e86\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u5947\u5999\u4e16\u754c\u3002\u8fd9\u662f\u4e00\u7247\u5145\u6ee1\u672a\u77e5\u4e0e\u60ca\u559c\u7684\u571f\u5730&#xff0c;\u5728\u8fd9\u91cc&#xff0c;\u6211\u4eec\u4e0d\u518d\u662f\u8ddf\u968f\u201c\u6807\u7b7e\u201d\u7684\u5b66\u5f92&#xff0c;\u800c\u662f\u6210\u4e3a\u4e86\u4e3b\u52a8\u53d1\u73b0\u6570\u636e\u5965\u79d8\u7684\u201c\u63a2\u9669\u5bb6\u201d\u3002<\/p>\n<p>\u6211\u4eec\u5b66\u4f1a\u4e86\u4e09\u79cd\u4e3b\u6d41\u7684\u805a\u7c7b\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>K-Means&#xff0c;\u4ee5\u5176\u7b80\u6d01\u9ad8\u6548&#xff0c;\u4e3a\u6211\u4eec\u5bfb\u627e\u6570\u636e\u7684\u201c\u5f15\u529b\u4e2d\u5fc3\u201d\u3002<\/li>\n<li>\u5c42\u6b21\u805a\u7c7b&#xff0c;\u901a\u8fc7\u6784\u5efa\u6570\u636e\u7684\u201c\u5bb6\u65cf\u8c31\u7cfb\u201d&#xff0c;\u4e3a\u6211\u4eec\u5c55\u73b0\u4e86\u6837\u672c\u95f4\u7531\u8fd1\u53ca\u8fdc\u7684\u5b8c\u6574\u4eb2\u7f18\u5173\u7cfb\u3002<\/li>\n<li>DBSCAN&#xff0c;\u5219\u72ec\u8f9f\u8e4a\u5f84&#xff0c;\u4ece\u201c\u5bc6\u5ea6\u201d\u7684\u89c6\u89d2\u51fa\u53d1&#xff0c;\u53d1\u73b0\u4e86\u9690\u85cf\u5728\u6570\u636e\u4e2d\u7684\u4efb\u610f\u5f62\u72b6\u7684\u201c\u793e\u533a\u201d&#xff0c;\u5e76\u667a\u6167\u5730\u8bc6\u522b\u51fa\u4e86\u79bb\u7fa4\u7684\u201c\u72ec\u884c\u8005\u201d\u3002<\/li>\n<\/ul>\n<p>\u540c\u65f6&#xff0c;\u6211\u4eec\u8fd8\u638c\u63e1\u4e86PCA\u8fd9\u4e00\u5f3a\u5927\u7684\u964d\u7ef4\u201c\u795e\u5668\u201d\u3002\u5b83\u6559\u4f1a\u6211\u4eec\u5982\u4f55\u5728\u7eb7\u7e41\u590d\u6742\u7684\u6570\u636e\u4e2d&#xff0c;\u901a\u8fc7\u5bfb\u627e\u6700\u5927\u65b9\u5dee\u7684\u65b9\u5411&#xff0c;\u6293\u4f4f\u5176\u4e3b\u8981\u77db\u76fe&#xff0c;\u63d0\u70bc\u5176\u6838\u5fc3\u672c\u8d28&#xff0c;\u5b9e\u73b0\u201c\u5316\u7e41\u4e3a\u7b80\u201d\u7684\u667a\u6167\u3002<\/p>\n<p>\u81f3\u6b64&#xff0c;\u60a8\u5df2\u7ecf\u6784\u5efa\u4e86\u673a\u5668\u5b66\u4e60\u77e5\u8bc6\u4f53\u7cfb\u7684\u201c\u56db\u6881\u516b\u67f1\u201d&#xff1a;\u76d1\u7763\u5b66\u4e60\u7684\u5206\u7c7b\u4e0e\u56de\u5f52&#xff0c;\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u805a\u7c7b\u4e0e\u964d\u7ef4\u3002\u8fd9\u4e3a\u60a8\u89e3\u51b3\u7edd\u5927\u591a\u6570\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u673a\u5668\u5b66\u4e60\u95ee\u9898\u6253\u4e0b\u4e86\u575a\u5b9e\u7684\u57fa\u7840\u3002\u60a8\u5df2\u7ecf\u4ece\u4e00\u4e2a\u6c42\u77e5\u8005&#xff0c;\u6210\u957f\u4e3a\u4e86\u4e00\u4f4d\u62e5\u6709\u5b8c\u6574\u5de5\u5177\u7bb1\u7684\u5b9e\u8df5\u8005\u3002<\/p>\n<p>\u5728\u672c\u4e66\u7684\u6700\u540e\u4e00\u7ae0&#xff0c;\u6211\u4eec\u5c06\u628a\u76ee\u5149\u6295\u5411\u66f4\u8fdc\u7684\u5730\u5e73\u7ebf&#xff0c;\u7b80\u8981\u4ecb\u7ecd\u4e00\u4e9b\u66f4\u524d\u6cbf\u3001\u66f4\u4ee4\u4eba\u5174\u594b\u7684\u9886\u57df&#xff0c;\u5982\u6df1\u5ea6\u5b66\u4e60\u7684\u795e\u7ecf\u7f51\u7edc\u3001\u6a21\u578b\u90e8\u7f72\u7684\u5de5\u7a0b\u5b9e\u8df5\u7b49&#xff0c;\u4e3a\u60a8\u7684\u6301\u7eed\u5b66\u4e60\u4e0e\u6210\u957f\u4e4b\u65c5\u70b9\u4eae\u524d\u884c\u7684\u706f\u5854\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u516b\u7ae0&#xff1a;\u96c6\u6210\u5b66\u4e60\u2014\u2014\u4ece\u201c\u4e09\u4e2a\u81ed\u76ae\u5320\u201d\u5230\u201c\u8bf8\u845b\u4eae\u201d<\/h3>\n<ul>\n<li>8.1 Bagging\u601d\u60f3&#xff1a;\u968f\u673a\u68ee\u6797\u7684\u518d\u601d\u8003<\/li>\n<li>8.2 Boosting\u601d\u60f3&#xff1a;\u4eceAdaBoost\u5230\u68af\u5ea6\u63d0\u5347\u6811&#xff08;GBDT&#xff09;<\/li>\n<li>8.3 Stacking\/Blending&#xff1a;\u6a21\u578b\u7684\u201c\u5706\u684c\u4f1a\u8bae\u201d<\/li>\n<li>8.4 XGBoost\u4e0eLightGBM&#xff1a;\u5de5\u4e1a\u754c\u7684\u201c\u5927\u6740\u5668\u201d\u8be6\u89e3<\/li>\n<\/ul>\n<p>\u5728\u6211\u4eec\u7684\u673a\u5668\u5b66\u4e60\u63a2\u7d22\u4e4b\u65c5\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u7ed3\u8bc6\u4e86\u4f17\u591a\u5404\u5177\u7279\u8272\u7684\u7b97\u6cd5\u6a21\u578b\u3002\u5b83\u4eec\u5982\u540c\u8eab\u6000\u7edd\u6280\u7684\u4fa0\u5ba2&#xff0c;\u5728\u5404\u81ea\u64c5\u957f\u7684\u9886\u57df\u91cc\u8868\u73b0\u51fa\u8272\u3002\u7136\u800c&#xff0c;\u4e00\u4e2a\u81ea\u7136\u800c\u7136\u7684\u95ee\u9898\u662f&#xff1a;\u6211\u4eec\u80fd\u5426\u5c06\u8fd9\u4e9b\u201c\u4e2a\u4f53\u82f1\u96c4\u201d\u7684\u529b\u91cf\u96c6\u7ed3\u8d77\u6765&#xff0c;\u5f62\u6210\u4e00\u4e2a\u6218\u65e0\u4e0d\u80dc\u7684\u201c\u68a6\u4e4b\u961f\u201d&#xff1f;<\/p>\n<p>\u96c6\u6210\u5b66\u4e60&#xff08;Ensemble Learning&#xff09;\u6b63\u662f\u5bf9\u8fd9\u4e2a\u95ee\u9898\u6700\u54cd\u4eae\u7684\u56de\u7b54\u3002\u5b83\u5e76\u975e\u4e00\u79cd\u5177\u4f53\u7684\u7b97\u6cd5&#xff0c;\u800c\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5143\u7b97\u6cd5\u6846\u67b6&#xff08;Meta-algorithm Framework&#xff09;\u3002\u5176\u6838\u5fc3\u601d\u60f3\u662f&#xff0c;\u901a\u8fc7\u6784\u5efa\u5e76\u7ed3\u5408\u591a\u4e2a\u5b66\u4e60\u5668\u6765\u5b8c\u6210\u5b66\u4e60\u4efb\u52a1&#xff0c;\u4ee5\u671f\u83b7\u5f97\u6bd4\u4efb\u4f55\u5355\u4e2a\u5b66\u4e60\u5668\u90fd\u663e\u8457\u4f18\u8d8a\u7684\u6cdb\u5316\u6027\u80fd\u3002<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u96c6\u6210\u5b66\u4e60\u7684\u4e09\u5927\u4e3b\u6d41\u601d\u60f3&#xff1a;<\/p>\n<li>Bagging&#xff1a;\u901a\u8fc7\u5e76\u884c\u8bad\u7ec3\u591a\u4e2a\u72ec\u7acb\u6a21\u578b\u5e76\u53d6\u5176\u5e73\u5747&#xff0c;\u6765\u964d\u4f4e\u65b9\u5dee&#xff0c;\u8ffd\u6c42\u201c\u7a33\u5b9a\u538b\u5012\u4e00\u5207\u201d\u3002\u968f\u673a\u68ee\u6797\u662f\u5176\u6700\u6770\u51fa\u7684\u4ee3\u8868\u3002<\/li>\n<li>Boosting&#xff1a;\u901a\u8fc7\u4e32\u884c\u8bad\u7ec3&#xff0c;\u8ba9\u6a21\u578b\u5728\u524d\u8f88\u7684\u201c\u9519\u8bef\u201d\u4e2d\u4e0d\u65ad\u5b66\u4e60\u548c\u8fdb\u5316&#xff0c;\u6765\u964d\u4f4e\u504f\u5dee&#xff0c;\u8ffd\u6c42\u201c\u7cbe\u76ca\u6c42\u7cbe\u201d\u3002GBDT\u662f\u5176\u6838\u5fc3\u601d\u60f3\u7684\u4f53\u73b0\u3002<\/li>\n<li>Stacking&#xff1a;\u901a\u8fc7\u5206\u5c42\u7ed3\u6784&#xff0c;\u8ba9\u4e0d\u540c\u6a21\u578b\u5404\u53f8\u5176\u804c&#xff0c;\u518d\u7531\u4e00\u4e2a\u201c\u5143\u6a21\u578b\u201d\u6765\u5b66\u4e60\u5982\u4f55\u6700\u597d\u5730\u878d\u5408\u5b83\u4eec\u7684\u667a\u6167&#xff0c;\u8ffd\u6c42\u201c\u535a\u91c7\u4f17\u957f\u201d\u3002<\/li>\n<p>\u6700\u540e&#xff0c;\u6211\u4eec\u5c06\u8be6\u7ec6\u62c6\u89e3\u5728\u5f53\u4eca\u5de5\u4e1a\u754c\u548c\u6570\u636e\u79d1\u5b66\u7ade\u8d5b\u4e2d\u53f1\u54a4\u98ce\u4e91\u7684\u4e24\u5927\u201c\u795e\u5668\u201d\u2014\u2014XGBoost\u548cLightGBM&#xff0c;\u770b\u770b\u5b83\u4eec\u662f\u5982\u4f55\u5c06Boosting\u601d\u60f3\u63a8\u5411\u5de5\u7a0b\u548c\u7b97\u6cd5\u7684\u6781\u81f4\u3002\u51c6\u5907\u597d&#xff0c;\u8ba9\u6211\u4eec\u4e00\u8d77\u89c1\u8bc1\u201c\u4e09\u4e2a\u81ed\u76ae-\u5320\u201d\u5982\u4f55\u901a\u8fc7\u667a\u6167\u7684\u7ec4\u7ec7&#xff0c;\u5347\u534e\u4e3a\u8fd0\u7b79\u5e37\u5e44\u7684\u201c\u8bf8\u845b\u4eae\u201d\u3002<\/p>\n<hr \/>\n<h4>8.1 Bagging\u601d\u60f3&#xff1a;\u968f\u673a\u68ee\u6797\u7684\u518d\u601d\u8003<\/h4>\n<p>Bagging\u662f\u96c6\u6210\u5b66\u4e60\u4e2d\u6700\u57fa\u7840\u3001\u6700\u76f4\u89c2\u7684\u601d\u60f3\u4e4b\u4e00\u3002\u5b83\u7684\u7b56\u7565\u7b80\u5355\u800c\u6709\u6548&#xff1a;\u901a\u8fc7\u5f15\u5165\u968f\u673a\u6027\u6765\u6784\u5efa\u591a\u4e2a\u7565\u6709\u4e0d\u540c\u7684\u6a21\u578b&#xff0c;\u7136\u540e\u901a\u8fc7\u201c\u6c11\u4e3b\u6295\u7968\u201d\u7684\u65b9\u5f0f\u6c47\u96c6\u5b83\u4eec\u7684\u9884\u6d4b&#xff0c;\u4ee5\u83b7\u5f97\u4e00\u4e2a\u66f4\u7a33\u5b9a\u3001\u66f4\u53ef\u9760\u7684\u6700\u7ec8\u7ed3\u679c\u3002<\/p>\n<h5>8.1.1 \u6838\u5fc3\u601d\u60f3&#xff1a;\u901a\u8fc7\u201c\u968f\u673a\u201d\u964d\u4f4e\u201c\u65b9\u5dee\u201d<\/h5>\n<p>Bagging\u662f\u96c6\u6210\u5b66\u4e60\u4e2d\u6700\u57fa\u7840\u3001\u6700\u76f4\u89c2\u7684\u601d\u60f3\u4e4b\u4e00\u3002\u5b83\u7684\u7b56\u7565\u7b80\u5355\u800c\u6709\u6548&#xff1a;\u901a\u8fc7\u5f15\u5165\u968f\u673a\u6027\u6765\u6784\u5efa\u591a\u4e2a\u7565\u6709\u4e0d\u540c\u7684\u6a21\u578b&#xff0c;\u7136\u540e\u901a\u8fc7\u201c\u6c11\u4e3b\u51b3\u7b56\u201d\u7684\u65b9\u5f0f\u6c47\u96c6\u5b83\u4eec\u7684\u9884\u6d4b&#xff0c;\u4ee5\u83b7\u5f97\u4e00\u4e2a\u66f4\u7a33\u5b9a\u3001\u66f4\u53ef\u9760\u7684\u6700\u7ec8\u7ed3\u679c\u3002<\/p>\n<p>\u81ea\u52a9\u91c7\u6837\u6cd5&#xff08;Bootstrap Aggregating&#xff09;\u00a0Bagging\u8fd9\u4e2a\u8bcd\u672c\u8eab\u5c31\u662fBootstrap\u00a0Aggregating\u7684\u7f29\u5199&#xff0c;\u5b8c\u7f8e\u5730\u6982\u62ec\u4e86\u5176\u4e24\u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff1a;<\/p>\n<ul>\n<li>\u81ea\u52a9\u91c7\u6837&#xff08;Bootstrap&#xff09;&#xff1a;\u8fd9\u662fBagging\u5f15\u5165\u968f\u673a\u6027\u7684\u5173\u952e\u624b\u6bb5\u3002\u5047\u8bbe\u6211\u4eec\u6709\u00a0N\u00a0\u4e2a\u6837\u672c\u7684\u539f\u59cb\u8bad\u7ec3\u96c6\u3002\u6211\u4eec\u8fdb\u884c\u6709\u653e\u56de\u7684\u968f\u673a\u62bd\u6837\u00a0N\u00a0\u6b21&#xff0c;\u5f97\u5230\u4e00\u4e2a\u540c\u6837\u5927\u5c0f\u4e3a\u00a0N\u00a0\u7684\u201c\u81ea\u52a9\u6837\u672c\u96c6\u201d\u3002\u7531\u4e8e\u662f\u6709\u653e\u56de\u62bd\u6837&#xff0c;\u8fd9\u4e2a\u65b0\u7684\u6570\u636e\u96c6\u4e2d\u4f1a\u4e0d\u53ef\u907f\u514d\u5730\u5305\u542b\u4e00\u4e9b\u91cd\u590d\u6837\u672c&#xff0c;\u540c\u65f6&#xff0c;\u539f\u59cb\u6570\u636e\u4e2d\u7ea6\u670936.8%&#xff08;\u6570\u5b66\u4e0a\u8d8b\u8fd1\u4e8e\u00a01\/e&#xff09;\u7684\u6837\u672c\u4ece\u672a\u88ab\u62bd\u5230\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u6a21\u62df\u4e86\u4ece\u539f\u59cb\u6570\u636e\u5206\u5e03\u4e2d\u591a\u6b21\u91c7\u6837\u7684\u8fc7\u7a0b&#xff0c;\u521b\u9020\u4e86\u6570\u636e\u7684\u591a\u6837\u6027\u3002<\/li>\n<li>\u805a\u5408&#xff08;Aggregating&#xff09;&#xff1a;\u6211\u4eec\u91cd\u590d\u4e0a\u8ff0\u81ea\u52a9\u91c7\u6837\u8fc7\u7a0b\u00a0M\u00a0\u6b21&#xff0c;\u5f97\u5230\u00a0M\u00a0\u4e2a\u4e0d\u540c\u7684\u81ea\u52a9\u6837\u672c\u96c6\u3002\u7136\u540e&#xff0c;\u6211\u4eec\u5728\u8fd9\u00a0M\u00a0\u4e2a\u6570\u636e\u96c6\u4e0a\u72ec\u7acb\u5730\u3001\u5e76\u884c\u5730\u8bad\u7ec3\u00a0M\u00a0\u4e2a\u57fa\u5b66\u4e60\u5668&#xff08;\u4f8b\u5982&#xff0c;M\u00a0\u68f5\u51b3\u7b56\u6811&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u5e76\u884c\u8bad\u7ec3\u4e0e\u6295\u7968\/\u5e73\u5747<\/p>\n<ul>\n<li>\u5e76\u884c\u8bad\u7ec3&#xff1a;\u7531\u4e8e\u00a0M\u00a0\u4e2a\u57fa\u5b66\u4e60\u5668\u7684\u8bad\u7ec3\u8fc7\u7a0b\u4e92\u4e0d\u4f9d\u8d56&#xff0c;\u5b83\u4eec\u53ef\u4ee5\u5b8c\u5168\u5e76\u884c\u8fdb\u884c&#xff0c;\u8fd9\u4f7f\u5f97Bagging\u7684\u8bad\u7ec3\u6548\u7387\u5f88\u9ad8\u3002<\/li>\n<li>\u51b3\u7b56\u65b9\u5f0f&#xff1a;\n<ul>\n<li>\u5bf9\u4e8e\u5206\u7c7b\u4efb\u52a1&#xff0c;\u6700\u7ec8\u7ed3\u679c\u7531\u00a0M\u00a0\u4e2a\u57fa\u5b66\u4e60\u5668\u8fdb\u884c\u591a\u6570\u6295\u7968&#xff08;Majority Voting&#xff09;\u51b3\u5b9a\u3002<\/li>\n<li>\u5bf9\u4e8e\u56de\u5f52\u4efb\u52a1&#xff0c;\u6700\u7ec8\u7ed3\u679c\u662f\u00a0M\u00a0\u4e2a\u57fa\u5b66\u4e60\u5668\u9884\u6d4b\u503c\u7684\u5e73\u5747\u503c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u65b9\u5dee\u964d\u4f4e\u7684\u76f4\u89c2\u89e3\u91ca\u00a0Bagging\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u964d\u4f4e\u6a21\u578b\u7684\u65b9\u5dee\u3002\u65b9\u5dee\u8861\u91cf\u7684\u662f\u6a21\u578b\u5728\u4e0d\u540c\u8bad\u7ec3\u6570\u636e\u96c6\u4e0a\u7684\u9884\u6d4b\u7ed3\u679c\u7684\u6ce2\u52a8\u6027\u3002\u9ad8\u65b9\u5dee\u6a21\u578b&#xff08;\u5982\u672a\u526a\u679d\u7684\u51b3\u7b56\u6811&#xff09;\u5bb9\u6613\u8fc7\u62df\u5408&#xff0c;\u5bf9\u8bad\u7ec3\u6570\u636e\u7684\u5fae\u5c0f\u53d8\u5316\u975e\u5e38\u654f\u611f\u3002<\/p>\n<p>Bagging\u901a\u8fc7\u5728\u7565\u6709\u4e0d\u540c\u7684\u6570\u636e\u5b50\u96c6\u4e0a\u8bad\u7ec3\u51fa\u591a\u4e2a\u8fd9\u6837\u7684\u9ad8\u65b9\u5dee\u6a21\u578b&#xff0c;\u6bcf\u4e2a\u6a21\u578b\u90fd\u4ece\u4e00\u4e2a\u7565\u5fae\u4e0d\u540c\u7684\u201c\u89c6\u89d2\u201d\u6765\u770b\u5f85\u6570\u636e\u3002\u867d\u7136\u5355\u4e2a\u6a21\u578b\u53ef\u80fd\u4ecd\u7136\u5b58\u5728\u8fc7\u62df\u5408&#xff0c;\u4f46\u5b83\u4eec\u7684\u201c\u9519\u8bef\u201d\u662f\u5404\u4e0d\u76f8\u540c\u7684\u3001\u4e0d\u76f8\u5173\u7684\u3002\u901a\u8fc7\u6295\u7968\u6216\u5e73\u5747&#xff0c;\u8fd9\u4e9b\u4e94\u82b1\u516b\u95e8\u7684\u9519\u8bef\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u88ab\u76f8\u4e92\u62b5\u6d88\u4e86&#xff0c;\u6700\u7ec8\u7559\u4e0b\u7684\u662f\u6570\u636e\u4e2d\u7a33\u5b9a\u3001\u666e\u9002\u7684\u89c4\u5f8b&#xff0c;\u4ece\u800c\u4f7f\u5f97\u96c6\u6210\u6a21\u578b\u7684\u6574\u4f53\u65b9\u5dee\u5927\u5927\u964d\u4f4e\u3002\u8fd9\u5c31\u50cf\u6295\u8d44\u7ec4\u5408\u4e00\u6837&#xff0c;\u901a\u8fc7\u6301\u6709\u591a\u4e2a\u4e0d\u5b8c\u5168\u76f8\u5173\u7684\u8d44\u4ea7\u6765\u5206\u6563\u98ce\u9669\u3002<\/p>\n<h5>8.1.2 \u968f\u673a\u68ee\u6797&#xff08;Random Forest&#xff09;\u7684\u518d\u5ba1\u89c6<\/h5>\n<p>\u6211\u4eec\u5728\u7b2c\u4e94\u7ae0\u5df2\u7ecf\u5b66\u4e60\u8fc7\u968f\u673a\u68ee\u6797&#xff0c;\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u4eceBagging\u7684\u89c6\u89d2\u6765\u66f4\u6df1\u523b\u5730\u7406\u89e3\u5b83\u3002\u968f\u673a\u68ee\u6797\u662f\u4ee5\u51b3\u7b56\u6811\u4e3a\u57fa\u5b66\u4e60\u5668\u7684Bagging\u96c6\u6210\u6a21\u578b&#xff0c;\u5e76\u4e14\u5728Bagging\u7684\u57fa\u7840\u4e0a&#xff0c;\u66f4\u8fdb\u4e86\u4e00\u6b65&#xff0c;\u5f15\u5165\u4e86\u66f4\u5f3a\u7684\u968f\u673a\u6027\u3002<\/p>\n<p>\u8d85\u8d8a\u666e\u901aBagging&#xff1a;\u7279\u5f81\u968f\u673a\u5316\u00a0\u968f\u673a\u68ee\u6797\u5f15\u5165\u4e86\u201c\u53cc\u91cd\u968f\u673a\u6027\u201d&#xff1a;<\/p>\n<li>\u884c\u91c7\u6837&#xff08;\u6837\u672c\u968f\u673a&#xff09;&#xff1a;\u7ee7\u627f\u81eaBagging\u7684\u81ea\u52a9\u91c7\u6837\u3002<\/li>\n<li>\u5217\u91c7\u6837&#xff08;\u7279\u5f81\u968f\u673a&#xff09;&#xff1a;\u8fd9\u662f\u968f\u673a\u68ee\u6797\u7684\u72ec\u521b\u3002\u5728\u6784\u5efa\u6bcf\u68f5\u51b3\u7b56\u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u65f6&#xff0c;\u5e76\u4e0d\u662f\u4ece\u5168\u90e8\u7279\u5f81\u4e2d\u9009\u62e9\u6700\u4f18\u5206\u88c2\u70b9&#xff0c;\u800c\u662f\u5148\u4ece\u5168\u90e8\u7279\u5f81\u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u5b50\u96c6&#xff08;\u4f8b\u5982&#xff0c;\u5bf9\u4e8e\u5206\u7c7b\u95ee\u9898&#xff0c;\u901a\u5e38\u662f\u00a0sqrt(n_features)\u00a0\u4e2a&#xff09;&#xff0c;\u7136\u540e\u518d\u4ece\u8fd9\u4e2a\u5b50\u96c6\u4e2d\u9009\u62e9\u6700\u4f18\u7279\u5f81\u3002<\/li>\n<p>\u8fd9\u4e2a\u201c\u7279\u5f81\u968f\u673a\u5316\u201d\u7684\u6b65\u9aa4&#xff0c;\u8fdb\u4e00\u6b65\u964d\u4f4e\u4e86\u68ee\u6797\u4e2d\u6811\u4e0e\u6811\u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3002\u5982\u679c\u4e0d\u7528\u7279\u5f81\u968f\u673a\u5316&#xff0c;\u90a3\u4e48\u5728\u6bcf\u4e2a\u81ea\u52a9\u6837\u672c\u96c6\u4e0a&#xff0c;\u90a3\u4e9b\u5f3a\u7279\u5f81\u5f88\u53ef\u80fd\u603b\u662f\u88ab\u4f18\u5148\u9009\u4e2d&#xff0c;\u5bfc\u81f4\u68ee\u6797\u4e2d\u7684\u6811\u957f\u5f97\u201c\u5343\u7bc7\u4e00\u5f8b\u201d&#xff0c;\u76f8\u5173\u6027\u5f88\u9ad8\u3002\u800c\u5f15\u5165\u7279\u5f81\u968f\u673a\u5316\u540e&#xff0c;\u5373\u4f7f\u662f\u5f31\u7279\u5f81\u4e5f\u6709\u673a\u4f1a\u5728\u67d0\u4e9b\u6811\u7684\u67d0\u4e9b\u8282\u70b9\u4e0a\u6210\u4e3a\u6700\u4f18\u9009\u62e9&#xff0c;\u8fd9\u4f7f\u5f97\u68ee\u6797\u4e2d\u7684\u6811\u66f4\u52a0\u201c\u591a\u6837\u5316\u201d\u3002\u66f4\u591a\u6837\u5316\u7684\u6a21\u578b&#xff0c;\u5728\u805a\u5408\u65f6\u80fd\u66f4\u6709\u6548\u5730\u62b5\u6d88\u8bef\u5dee&#xff0c;\u4ece\u800c\u5e26\u6765\u66f4\u5f3a\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<p>\u5305\u5916&#xff08;Out-of-Bag, OOB&#xff09;\u4f30\u8ba1\u00a0\u7531\u4e8e\u81ea\u52a9\u91c7\u6837\u5e73\u5747\u7ea6\u670936.8%\u7684\u6570\u636e\u672a\u88ab\u7528\u4e8e\u8bad\u7ec3\u67d0\u4e00\u68f5\u7279\u5b9a\u7684\u6811&#xff0c;\u8fd9\u4e9b\u6570\u636e\u88ab\u79f0\u4e3a\u8be5\u6811\u7684\u5305\u5916&#xff08;Out-of-Bag&#xff09;\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e9b\u201c\u514d\u8d39\u201d\u7684\u3001\u672a\u88ab\u6a21\u578b\u89c1\u8fc7\u7684\u6570\u636e\u6765\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd&#xff0c;\u800c\u65e0\u9700\u518d\u5355\u72ec\u5212\u5206\u4e00\u4e2a\u9a8c\u8bc1\u96c6\u6216\u8fdb\u884c\u4ea4\u53c9\u9a8c\u8bc1\u3002<\/p>\n<p>\u5bf9\u4e8e\u6bcf\u4e2a\u6837\u672c&#xff0c;\u627e\u5230\u6240\u6709\u6ca1\u6709\u7528\u5b83\u6765\u8bad\u7ec3\u7684\u6811&#xff0c;\u8ba9\u8fd9\u4e9b\u6811\u5bf9\u5b83\u8fdb\u884c\u9884\u6d4b&#xff0c;\u7136\u540e\u5c06\u8fd9\u4e9b\u9884\u6d4b\u7ed3\u679c\u805a\u5408\u8d77\u6765&#xff0c;\u5f97\u5230\u8be5\u6837\u672c\u7684OOB\u9884\u6d4b\u3002\u6700\u540e&#xff0c;\u7528\u6240\u6709\u6837\u672c\u7684OOB\u9884\u6d4b\u548c\u771f\u5b9e\u6807\u7b7e\u6765\u8ba1\u7b97\u6a21\u578b\u7684OOB\u5f97\u5206\u3002\u5728Scikit-learn\u4e2d&#xff0c;\u53ea\u9700\u5728\u521b\u5efaRandomForestClassifier\u6216RandomForestRegressor\u65f6\u8bbe\u7f6eoob_score&#061;True\u5373\u53ef\u3002<\/p>\n<h5>8.1.3 Scikit-learn\u5b9e\u6218\u4e0eBagging\u7684\u6cdb\u5316<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0Scikit-learn\u63d0\u4f9b\u4e86\u901a\u7528\u7684BaggingClassifier\u548cBaggingRegressor&#xff0c;\u5b83\u4eec\u5141\u8bb8\u6211\u4eec\u5c06\u4efb\u4f55\u57fa\u5b66\u4e60\u5668\u8fdb\u884cBagging\u96c6\u6210\u3002<\/p>\n<p>from sklearn.ensemble import BaggingClassifier<br \/>\nfrom sklearn.neighbors import KNeighborsClassifier<br \/>\nfrom sklearn.tree import DecisionTreeClassifier<br \/>\nfrom sklearn.datasets import make_classification<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.metrics import accuracy_score<\/p>\n<p># \u751f\u6210\u6570\u636e<br \/>\nX, y &#061; make_classification(n_samples&#061;500, n_features&#061;20, n_informative&#061;15, n_redundant&#061;5, random_state&#061;42)<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, random_state&#061;42)<\/p>\n<p># 1. \u5355\u4e2a\u51b3\u7b56\u6811\u6a21\u578b<br \/>\ntree &#061; DecisionTreeClassifier(random_state&#061;42)<br \/>\ntree.fit(X_train, y_train)<br \/>\ny_pred_tree &#061; tree.predict(X_test)<br \/>\nprint(f&#034;\u5355\u4e2a\u51b3\u7b56\u6811\u6a21\u578b\u7684\u51c6\u786e\u7387: {accuracy_score(y_test, y_pred_tree):.4f}&#034;)<\/p>\n<p># 2. \u4f7f\u7528Bagging\u96c6\u6210\u51b3\u7b56\u6811\u6a21\u578b (\u8fd9\u5b9e\u9645\u4e0a\u5c31\u662f\u968f\u673a\u68ee\u6797\u7684\u7b80\u5316\u7248&#xff0c;\u6ca1\u6709\u7279\u5f81\u968f\u673a)<br \/>\nbagging_tree &#061; BaggingClassifier(<br \/>\n    estimator&#061;DecisionTreeClassifier(random_state&#061;42),<br \/>\n    n_estimators&#061;100,<br \/>\n    max_samples&#061;1.0, # \u4f7f\u7528\u5168\u90e8\u6837\u672c\u5927\u5c0f\u7684\u81ea\u52a9\u91c7\u6837<br \/>\n    bootstrap&#061;True,<br \/>\n    random_state&#061;42,<br \/>\n    n_jobs&#061;-1<br \/>\n)<br \/>\nbagging_tree.fit(X_train, y_train)<br \/>\ny_pred_bagging &#061; bagging_tree.predict(X_test)<br \/>\nprint(f&#034;Bagging\u51b3\u7b56\u6811\u6a21\u578b\u7684\u51c6\u786e\u7387: {accuracy_score(y_test, y_pred_bagging):.4f}&#034;)<\/p>\n<p>\u901a\u5e38&#xff0c;\u6211\u4eec\u4f1a\u770b\u5230\u96c6\u6210\u540e\u7684\u6a21\u578b\u6027\u80fd\u6bd4\u5355\u4e2a\u6a21\u578b\u66f4\u52a0\u7a33\u5b9a\u548c\u4f18\u8d8a\u3002<\/p>\n<p>\u57fa\u5b66\u4e60\u5668\u7684\u9009\u62e9\u00a0Bagging\u7684\u6838\u5fc3\u662f\u964d\u4f4e\u65b9\u5dee&#xff0c;\u56e0\u6b64\u5b83\u5bf9\u4e8e\u90a3\u4e9b\u672c\u8eab\u662f\u4f4e\u504f\u5dee\u3001\u9ad8\u65b9\u5dee\u7684\u6a21\u578b&#xff08;\u5373\u5bb9\u6613\u8fc7\u62df\u5408\u7684\u590d\u6742\u6a21\u578b&#xff09;\u6548\u679c\u6700\u597d\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5b83\u4e0e\u51b3\u7b56\u6811&#xff08;\u7279\u522b\u662f\u672a\u526a\u679d\u7684\u51b3\u7b56\u6811&#xff09;\u662f\u201c\u5929\u4f5c\u4e4b\u5408\u201d\u3002\u5c06Bagging\u5e94\u7528\u4e8e\u672c\u8eab\u5c31\u662f\u9ad8\u504f\u5dee\u7684\u7b80\u5355\u6a21\u578b&#xff08;\u5982\u903b\u8f91\u56de\u5f52&#xff09;&#xff0c;\u901a\u5e38\u4e0d\u4f1a\u5e26\u6765\u663e\u8457\u7684\u6027\u80fd\u63d0\u5347\u3002<\/p>\n<hr \/>\n<h4>8.2 Boosting\u601d\u60f3&#xff1a;\u4eceAdaBoost\u5230\u68af\u5ea6\u63d0\u5347\u6811&#xff08;GBDT&#xff09;<\/h4>\n<p>\u5982\u679c\u8bf4Bagging\u662f\u201c\u7fa4\u7b56\u7fa4\u529b\u3001\u6c11\u4e3b\u51b3\u7b56\u201d&#xff0c;\u90a3\u4e48Boosting\u5c31\u662f\u201c\u7cbe\u82f1\u57f9\u517b\u3001\u8fed\u4ee3\u4f18\u5316\u201d\u3002Boosting\u5bb6\u65cf\u7684\u7b97\u6cd5\u901a\u8fc7\u4e00\u79cd\u4e32\u884c\u7684\u65b9\u5f0f&#xff0c;\u8ba9\u6a21\u578b\u5728\u524d\u8f88\u7684\u201c\u9519\u8bef\u201d\u4e2d\u4e0d\u65ad\u5b66\u4e60\u548c\u8fdb\u5316&#xff0c;\u6700\u7ec8\u5c06\u4e00\u7fa4\u201c\u5f31\u5b66\u4e60\u5668\u201d\u63d0\u5347\u4e3a\u4e00\u4e2a\u5f3a\u5927\u7684\u201c\u5f3a\u5b66\u4e60\u5668\u201d\u3002<\/p>\n<h5>8.2.1 \u6838\u5fc3\u601d\u60f3&#xff1a;\u5728\u201c\u9519\u8bef\u201d\u4e2d\u8fed\u4ee3&#xff0c;\u5316\u201c\u5f31\u201d\u4e3a\u201c\u5f3a\u201d<\/h5>\n<p>\u4e32\u884c\u8bad\u7ec3\u7684\u54f2\u5b66\u00a0Boosting\u7684\u8bad\u7ec3\u8fc7\u7a0b\u662f\u4e32\u884c\u7684&#xff0c;\u8fd9\u610f\u5473\u7740\u57fa\u5b66\u4e60\u5668\u5fc5\u987b\u4e00\u4e2a\u63a5\u4e00\u4e2a\u5730\u3001\u6309\u987a\u5e8f\u8fdb\u884c\u8bad\u7ec3\u3002<\/p>\n<li>\u9996\u5148&#xff0c;\u8bad\u7ec3\u4e00\u4e2a\u521d\u59cb\u7684\u57fa\u5b66\u4e60\u5668\u3002<\/li>\n<li>\u7136\u540e&#xff0c;\u6839\u636e\u8fd9\u4e2a\u57fa\u5b66\u4e60\u5668\u7684\u8868\u73b0&#xff0c;\u8c03\u6574\u6570\u636e\u7684\u6743\u91cd\u6216\u5b66\u4e60\u76ee\u6807&#xff0c;\u4f7f\u5f97\u90a3\u4e9b\u88ab\u9519\u5206\u6216\u9884\u6d4b\u8bef\u5dee\u5927\u7684\u6837\u672c\u5728\u4e0b\u4e00\u8f6e\u8bad\u7ec3\u4e2d\u53d7\u5230\u66f4\u591a\u7684\u201c\u5173\u6ce8\u201d\u3002<\/li>\n<li>\u63a5\u7740&#xff0c;\u5728\u8c03\u6574\u540e\u7684\u6570\u636e\u4e0a\u8bad\u7ec3\u7b2c\u4e8c\u4e2a\u57fa\u5b66\u4e60\u5668\u3002<\/li>\n<li>\u4e0d\u65ad\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b&#xff0c;\u6bcf\u4e00\u8f6e\u90fd\u81f4\u529b\u4e8e\u5f25\u8865\u524d\u4e00\u8f6e\u6a21\u578b\u7684\u201c\u77ed\u677f\u201d\u3002<\/li>\n<li>\u6700\u7ec8&#xff0c;\u5c06\u6240\u6709\u57fa\u5b66\u4e60\u5668\u8fdb\u884c\u52a0\u6743\u7ec4\u5408&#xff0c;\u5f97\u5230\u6700\u7ec8\u7684\u5f3a\u5b66\u4e60\u5668\u3002<\/li>\n<p>Boosting\u4e0eBagging\u7684\u6839\u672c\u533a\u522b<\/p>\n<ul>\n<li>\u8bad\u7ec3\u65b9\u5f0f&#xff1a;Bagging\u662f\u5e76\u884c\u7684&#xff0c;\u6a21\u578b\u95f4\u72ec\u7acb&#xff1b;Boosting\u662f\u4e32\u884c\u7684&#xff0c;\u6a21\u578b\u95f4\u76f8\u4e92\u4f9d\u8d56\u3002<\/li>\n<li>\u6838\u5fc3\u76ee\u6807&#xff1a;Bagging\u4e3b\u8981\u964d\u4f4e\u65b9\u5dee&#xff08;variance&#xff09;&#xff0c;\u901a\u8fc7\u5e73\u5747\u6765\u5e73\u6ed1\u6a21\u578b\u7684\u6ce2\u52a8&#xff1b;Boosting\u4e3b\u8981\u964d\u4f4e\u504f\u5dee&#xff08;bias&#xff09;&#xff0c;\u901a\u8fc7\u4e0d\u65ad\u4fee\u6b63\u9519\u8bef\u6765\u63d0\u5347\u6a21\u578b\u7684\u51c6\u786e\u5ea6\u3002<\/li>\n<li>\u6837\u672c\u6743\u91cd&#xff1a;Bagging\u4e2d\u6837\u672c\u6743\u91cd\u4e0d\u53d8&#xff1b;Boosting\u4e2d\u6837\u672c\u6743\u91cd\u4f1a\u52a8\u6001\u8c03\u6574\u3002<\/li>\n<\/ul>\n<h5>8.2.2 AdaBoost&#xff08;Adaptive Boosting&#xff09;&#xff1a;\u5173\u6ce8\u88ab\u9519\u5206\u7684\u6837\u672c<\/h5>\n<p>AdaBoost&#xff08;\u81ea\u9002\u5e94\u63d0\u5347&#xff09;\u662fBoosting\u5bb6\u65cf\u7684\u65e9\u671f\u4ee3\u8868&#xff0c;\u5176\u601d\u60f3\u975e\u5e38\u76f4\u89c2\u3002<\/p>\n<li>\u521d\u59cb\u5316&#xff1a;\u4e3a\u6bcf\u4e2a\u8bad\u7ec3\u6837\u672c\u5206\u914d\u76f8\u7b49\u7684\u6743\u91cd\u3002<\/li>\n<li>\u8fed\u4ee3&#xff1a;\u5728\u6bcf\u4e00\u8f6e\u4e2d&#xff1a;\n<ul>\n<li>\u5728\u5e26\u6743\u7684\u8bad\u7ec3\u6570\u636e\u4e0a\u8bad\u7ec3\u4e00\u4e2a\u5f31\u5b66\u4e60\u5668&#xff08;\u901a\u5e38\u662f\u51b3\u7b56\u6811\u6869&#xff0c;\u5373\u6df1\u5ea6\u4e3a1\u7684\u51b3\u7b56\u6811&#xff09;\u3002<\/li>\n<li>\u8ba1\u7b97\u8fd9\u4e2a\u5f31\u5b66\u4e60\u5668\u7684\u9519\u8bef\u7387\u3002<\/li>\n<li>\u6839\u636e\u9519\u8bef\u7387\u8ba1\u7b97\u8be5\u5b66\u4e60\u5668\u7684\u6743\u91cd&#xff08;\u9519\u8bef\u7387\u8d8a\u4f4e&#xff0c;\u6743\u91cd\u8d8a\u5927&#xff09;\u3002<\/li>\n<li>\u66f4\u65b0\u6837\u672c\u6743\u91cd&#xff1a;\u63d0\u5347\u90a3\u4e9b\u88ab\u5f53\u524d\u5f31\u5b66\u4e60\u5668\u9519\u5206\u7684\u6837\u672c\u7684\u6743\u91cd&#xff0c;\u964d\u4f4e\u90a3\u4e9b\u88ab\u6b63\u786e\u5206\u7c7b\u7684\u6837\u672c\u7684\u6743\u91cd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7ec4\u5408&#xff1a;\u6700\u7ec8\u7684\u6a21\u578b\u662f\u6240\u6709\u5f31\u5b66\u4e60\u5668\u7684\u52a0\u6743\u6295\u7968\u7ed3\u679c&#xff0c;\u8868\u73b0\u597d\u7684\u5b66\u4e60\u5668\u62e5\u6709\u66f4\u5927\u7684\u201c\u8bdd\u8bed\u6743\u201d\u3002<\/li>\n<h5>8.2.3 \u68af\u5ea6\u63d0\u5347\u6811&#xff08;GBDT&#xff09;&#xff1a;\u62df\u5408\u6b8b\u5dee\u7684\u667a\u6167<\/h5>\n<p>\u68af\u5ea6\u63d0\u5347\u6811&#xff08;Gradient Boosting Decision Tree&#xff09;\u662fBoosting\u601d\u60f3\u66f4\u901a\u7528\u3001\u66f4\u5f3a\u5927\u7684\u4f53\u73b0\u3002\u5b83\u4e0d\u518d\u50cfAdaBoost\u90a3\u6837\u901a\u8fc7\u8c03\u6574\u6837\u672c\u6743\u91cd&#xff0c;\u800c\u662f\u901a\u8fc7\u4e00\u79cd\u66f4\u5de7\u5999\u7684\u65b9\u5f0f\u6765\u5173\u6ce8\u201c\u9519\u8bef\u201d\u2014\u2014\u76f4\u63a5\u62df\u5408\u9519\u8bef\u7684\u672c\u8eab\u3002<\/p>\n<p>\u6b8b\u5dee&#xff08;Residuals&#xff09;\u4f5c\u4e3a\u5b66\u4e60\u76ee\u6807\u00a0\u5bf9\u4e8e\u56de\u5f52\u95ee\u9898&#xff0c;GBDT\u7684\u6d41\u7a0b\u975e\u5e38\u6e05\u6670&#xff1a;<\/p>\n<li>\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u6a21\u578b&#xff08;\u5982\u6240\u6709\u6837\u672c\u7684\u5747\u503c&#xff09;\u4f5c\u4e3a\u521d\u59cb\u9884\u6d4b\u3002<\/li>\n<li>\u8ba1\u7b97\u5f53\u524d\u6a21\u578b\u7684\u6b8b\u5dee&#xff0c;\u5373\u00a0\u771f\u5b9e\u503c &#8211; \u9884\u6d4b\u503c\u3002<\/li>\n<li>\u8bad\u7ec3\u4e00\u68f5\u65b0\u7684\u51b3\u7b56\u6811&#xff0c;\u4f46\u8fd9\u68f5\u6811\u7684\u5b66\u4e60\u76ee\u6807\u4e0d\u518d\u662f\u539f\u59cb\u7684\u00a0y&#xff0c;\u800c\u662f\u4e0a\u4e00\u8f6e\u7684\u6b8b\u5dee\u3002<\/li>\n<li>\u5c06\u8fd9\u68f5\u201c\u6b8b\u5dee\u6811\u201d\u7684\u9884\u6d4b\u7ed3\u679c\u4e58\u4ee5\u4e00\u4e2a\u5b66\u4e60\u7387&#xff08;learning_rate&#xff09;&#xff0c;\u7136\u540e\u52a0\u5230\u4e0a\u4e00\u8f6e\u7684\u9884\u6d4b\u7ed3\u679c\u4e0a&#xff0c;\u5f97\u5230\u65b0\u7684\u9884\u6d4b\u3002<\/li>\n<li>\u4e0d\u65ad\u91cd\u590d\u6b65\u9aa42-4&#xff0c;\u6bcf\u4e00\u68f5\u65b0\u6811\u90fd\u5728\u52aa\u529b\u4fee\u6b63\u524d\u9762\u6240\u6709\u6811\u7559\u4e0b\u6765\u7684\u201c\u96c6\u4f53\u9519\u8bef\u201d\u3002<\/li>\n<p>\u68af\u5ea6\u4e0b\u964d\u7684\u89c6\u89d2\u00a0\u4e3a\u4f55\u53eb\u201c\u68af\u5ea6\u201d\u63d0\u5347&#xff1f;\u56e0\u4e3a\u4ece\u66f4\u6570\u5b66\u5316\u7684\u89d2\u5ea6\u770b&#xff0c;\u4e0a\u8ff0\u62df\u5408\u6b8b\u5dee\u7684\u8fc7\u7a0b&#xff0c;\u7b49\u4ef7\u4e8e\u5728\u51fd\u6570\u7a7a\u95f4\u4e2d&#xff0c;\u8ba9\u6a21\u578b\u6cbf\u7740\u635f\u5931\u51fd\u6570\u7684\u8d1f\u68af\u5ea6\u65b9\u5411\u8fdb\u884c\u4f18\u5316\u3002\u5bf9\u4e8e\u56de\u5f52\u95ee\u9898\u5e38\u7528\u7684MSE\u635f\u5931\u51fd\u6570&#xff0c;\u5176\u8d1f\u68af\u5ea6\u6070\u597d\u5c31\u662f\u6b8b\u5dee\u3002\u8fd9\u4e2a\u89c6\u89d2\u5c06Boosting\u7edf\u4e00\u5230\u4e86\u68af\u5ea6\u4e0b\u964d\u7684\u6846\u67b6\u4e0b&#xff0c;\u4f7f\u5176\u53ef\u4ee5\u63a8\u5e7f\u5230\u4efb\u4f55\u53ef\u5fae\u5206\u7684\u635f\u5931\u51fd\u6570&#xff0c;\u4ece\u800c\u4e5f\u80fd\u5904\u7406\u5206\u7c7b\u95ee\u9898\u3002<\/p>\n<p>\u5b66\u4e60\u7387&#xff08;Learning Rate&#xff09;\u00a0\u5b66\u4e60\u7387&#xff08;\u4e5f\u79f0shrinkage&#xff09;\u662f\u4e00\u4e2a\u975e\u5e38\u5173\u952e\u7684\u8d85\u53c2\u6570&#xff08;\u901a\u5e38\u8bbe\u4e3a\u4e00\u4e2a\u5c0f\u503c&#xff0c;\u59820.1&#xff09;\u3002\u5b83\u63a7\u5236\u4e86\u6bcf\u4e00\u68f5\u6811\u5bf9\u6700\u7ec8\u7ed3\u679c\u7684\u8d21\u732e\u5ea6&#xff0c;\u5373\u6bcf\u6b21\u201c\u8fdb\u6b65\u201d\u7684\u6b65\u957f\u3002\u8f83\u5c0f\u7684\u5b66\u4e60\u7387\u610f\u5473\u7740\u9700\u8981\u66f4\u591a\u7684\u6811&#xff08;n_estimators&#xff09;\u624d\u80fd\u8fbe\u5230\u597d\u7684\u6548\u679c&#xff0c;\u4f46\u901a\u5e38\u80fd\u8ba9\u6a21\u578b\u5177\u6709\u66f4\u597d\u7684\u6cdb\u5316\u80fd\u529b&#xff0c;\u9632\u6b62\u8fc7\u62df\u5408\u3002<\/p>\n<hr \/>\n<h4>8.3 Stacking\/Blending&#xff1a;\u6a21\u578b\u7684\u201c\u5706\u684c\u4f1a\u8bae\u201d<\/h4>\n<p>\u5982\u679c\u8bf4Bagging\u662f\u201c\u4e00\u4eba\u4e00\u7968\u201d&#xff0c;Boosting\u662f\u201c\u8001\u5e08\u5e26\u5b66\u751f\u201d&#xff0c;\u90a3\u4e48Stacking&#xff08;\u5806\u53e0&#xff09;\u5c31\u662f\u4e00\u573a\u201c\u5706\u684c\u4f1a\u8bae\u201d\u3002\u5b83\u9080\u8bf7\u4e0d\u540c\u9886\u57df\u7684\u201c\u4e13\u5bb6\u201d&#xff08;\u5f02\u6784\u7684\u57fa\u5b66\u4e60\u5668&#xff09;&#xff0c;\u8ba9\u4ed6\u4eec\u5404\u81ea\u53d1\u8868\u610f\u89c1&#xff0c;\u6700\u540e\u7531\u4e00\u4f4d\u66f4\u9ad8\u7ea7\u7684\u201c\u4e3b\u5e2d\u201d&#xff08;\u5143\u5b66\u4e60\u5668&#xff09;\u6765\u7efc\u5408\u6240\u6709\u610f\u89c1&#xff0c;\u505a\u51fa\u6700\u7ec8\u7684\u88c1\u51b3\u3002<\/p>\n<h5>8.3.1 \u6838\u5fc3\u601d\u60f3&#xff1a;\u8ba9\u6a21\u578b\u201c\u5404\u6292\u5df1\u89c1\u201d&#xff0c;\u518d\u7531\u201c\u4e3b\u5e2d\u201d\u5b9a\u593a<\/h5>\n<p>\u5206\u5c42\u7ed3\u6784\u00a0Stacking\u901a\u5e38\u5305\u542b\u4e24\u5c42\u6a21\u578b&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u5b66\u4e60\u5668\u5c42&#xff08;Level 0&#xff09;&#xff1a;\u5305\u542b\u591a\u4e2a&#xff08;\u901a\u5e38\u662f\u4e0d\u540c\u7c7b\u578b\u7684&#xff09;\u57fa\u5b66\u4e60\u5668\u3002\u4f8b\u5982&#xff0c;\u6211\u4eec\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u903b\u8f91\u56de\u5f52\u3001SVM\u3001\u968f\u673a\u68ee\u6797\u548cKNN\u4f5c\u4e3a\u57fa\u5b66\u4e60\u5668\u3002<\/li>\n<li>\u5143\u5b66\u4e60\u5668&#xff08;Meta-learner, Level 1&#xff09;&#xff1a;\u53ea\u6709\u4e00\u4e2a\u6a21\u578b&#xff0c;\u5b83\u7684\u4efb\u52a1\u662f\u5b66\u4e60\u5982\u4f55\u6700\u597d\u5730\u7ec4\u5408\u57fa\u5b66\u4e60\u5668\u7684\u9884\u6d4b\u7ed3\u679c\u3002\u5143\u5b66\u4e60\u5668\u901a\u5e38\u9009\u62e9\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u6a21\u578b&#xff0c;\u5982\u903b\u8f91\u56de\u5f52\u6216\u5cad\u56de\u5f52\u3002<\/li>\n<\/ul>\n<p>Stacking\u7684\u5de5\u4f5c\u6d41\u7a0b<\/p>\n<li>\u5c06\u8bad\u7ec3\u96c6\u5212\u5206\u4e3a\u8bad\u7ec3\u5b50\u96c6\u548c\u6d4b\u8bd5\u5b50\u96c6\u3002<\/li>\n<li>\u5728\u8bad\u7ec3\u5b50\u96c6\u4e0a\u8bad\u7ec3\u591a\u4e2a\u57fa\u5b66\u4e60\u5668\u3002<\/li>\n<li>\u8ba9\u8fd9\u4e9b\u8bad\u7ec3\u597d\u7684\u57fa\u5b66\u4e60\u5668\u5bf9\u6d4b\u8bd5\u5b50\u96c6\u8fdb\u884c\u9884\u6d4b&#xff0c;\u8fd9\u4e9b\u9884\u6d4b\u7ed3\u679c\u5c06\u6784\u6210\u5143\u5b66\u4e60\u5668\u7684\u65b0\u7279\u5f81\u3002<\/li>\n<li>\u5143\u5b66\u4e60\u5668\u5c31\u4ee5\u8fd9\u4e9b\u65b0\u7279\u5f81\u4f5c\u4e3a\u8f93\u5165&#xff0c;\u4ee5\u6d4b\u8bd5\u5b50\u96c6\u7684\u771f\u5b9e\u6807\u7b7e\u4f5c\u4e3a\u76ee\u6807&#xff0c;\u8fdb\u884c\u8bad\u7ec3\u3002<\/li>\n<li>\u5728\u9884\u6d4b\u65b0\u6570\u636e\u65f6&#xff0c;\u5148\u5c06\u6570\u636e\u8f93\u5165\u5230\u6240\u6709\u57fa\u5b66\u4e60\u5668\u4e2d\u5f97\u5230\u9884\u6d4b&#xff0c;\u518d\u5c06\u8fd9\u4e9b\u9884\u6d4b\u4f5c\u4e3a\u65b0\u7279\u5f81\u8f93\u5165\u5230\u5143\u5b66\u4e60\u5668\u4e2d&#xff0c;\u5f97\u5230\u6700\u7ec8\u7684\u9884\u6d4b\u7ed3\u679c\u3002<\/li>\n<h5>8.3.2 \u907f\u514d\u201c\u4fe1\u606f\u6cc4\u9732\u201d&#xff1a;\u4ea4\u53c9\u9a8c\u8bc1\u5728Stacking\u4e2d\u7684\u5999\u7528<\/h5>\n<p>\u4e0a\u8ff0\u7b80\u5355\u6d41\u7a0b\u6709\u4e00\u4e2a\u4e25\u91cd\u7684\u95ee\u9898&#xff1a;\u57fa\u5b66\u4e60\u5668\u5728\u9884\u6d4b\u65f6\u770b\u5230\u4e86\u5b83\u4eec\u7528\u6765\u8bad\u7ec3\u7684\u6570\u636e&#xff0c;\u8fd9\u4f1a\u5bfc\u81f4\u201c\u4fe1\u606f\u6cc4\u9732\u201d&#xff0c;\u4f7f\u5f97\u5143\u5b66\u4e60\u5668\u8fc7\u62df\u5408\u3002<\/p>\n<p>K-\u6298\u4ea4\u53c9\u9884\u6d4b\u00a0\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u6807\u51c6\u7684Stacking\u6d41\u7a0b\u4f7f\u7528\u4e86K-\u6298\u4ea4\u53c9\u9a8c\u8bc1\u7684\u601d\u60f3&#xff1a;<\/p>\n<li>\u5c06\u539f\u59cb\u8bad\u7ec3\u96c6\u5212\u5206\u4e3a\u00a0K\u00a0\u6298\u3002<\/li>\n<li>\u8fdb\u884c\u00a0K\u00a0\u6b21\u5faa\u73af\u3002\u5728\u7b2c\u00a0i\u00a0\u6b21\u5faa\u73af\u4e2d&#xff1a;\n<ul>\n<li>\u7528\u9664\u4e86\u7b2c\u00a0i\u00a0\u6298\u4e4b\u5916\u7684\u00a0K-1\u00a0\u6298\u6570\u636e\u6765\u8bad\u7ec3\u6240\u6709\u7684\u57fa\u5b66\u4e60\u5668\u3002<\/li>\n<li>\u8ba9\u8bad\u7ec3\u597d\u7684\u57fa\u5b66\u4e60\u5668\u5bf9\u7b2c\u00a0i\u00a0\u6298\u6570\u636e\u8fdb\u884c\u9884\u6d4b\u3002\u8fd9\u00a0K\u00a0\u6b21\u5faa\u73af\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u5bf9\u6574\u4e2a\u539f\u59cb\u8bad\u7ec3\u96c6\u7684\u4e00\u4e2a\u201c\u5e72\u51c0\u201d\u7684\u9884\u6d4b&#xff0c;\u8fd9\u4e9b\u9884\u6d4b\u5c06\u4f5c\u4e3a\u5143\u5b66\u4e60\u5668\u7684\u8bad\u7ec3\u7279\u5f81\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5728\u751f\u6210\u5143\u5b66\u4e60\u5668\u7684\u8bad\u7ec3\u6570\u636e\u540e&#xff0c;\u8fd8\u9700\u8981\u7528\u5b8c\u6574\u7684\u539f\u59cb\u8bad\u7ec3\u96c6\u91cd\u65b0\u8bad\u7ec3\u4e00\u904d\u6240\u6709\u7684\u57fa\u5b66\u4e60\u5668&#xff0c;\u4ee5\u4fbf\u5b83\u4eec\u5728\u672a\u6765\u9884\u6d4b\u65b0\u6570\u636e\u65f6\u80fd\u5229\u7528\u6240\u6709\u4fe1\u606f\u3002<\/li>\n<p>Blending\u00a0Blending\u662fStacking\u7684\u4e00\u79cd\u7b80\u5316\u5f62\u5f0f\u3002\u5b83\u4e0d\u518d\u4f7f\u7528\u590d\u6742\u7684K-\u6298\u4ea4\u53c9&#xff0c;\u800c\u662f\u76f4\u63a5\u5c06\u539f\u59cb\u8bad\u7ec3\u96c6\u5212\u5206\u4e3a\u4e00\u4e2a\u66f4\u5c0f\u7684\u8bad\u7ec3\u96c6\u548c\u4e00\u4e2a\u7559\u51fa\u96c6&#xff08;hold-out set&#xff09;\u3002\u57fa\u5b66\u4e60\u5668\u5728\u8bad\u7ec3\u96c6\u4e0a\u8bad\u7ec3&#xff0c;\u7136\u540e\u5728\u7559\u51fa\u96c6\u4e0a\u8fdb\u884c\u9884\u6d4b&#xff0c;\u7528\u8fd9\u4e9b\u9884\u6d4b\u6765\u8bad\u7ec3\u5143\u5b66\u4e60\u5668\u3002Blending\u66f4\u7b80\u5355&#xff0c;\u4f46\u6570\u636e\u5229\u7528\u7387\u8f83\u4f4e\u3002<\/p>\n<h5>8.3.3 Scikit-learn\u5b9e\u6218\u4e0e\u6a21\u578b\u591a\u6837\u6027\u7684\u91cd\u8981\u6027<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0Scikit-learn 0.22\u7248\u672c\u540e&#xff0c;\u63d0\u4f9b\u4e86\u5b98\u65b9\u7684StackingClassifier\u548cStackingRegressor&#xff0c;\u4f7f\u5f97\u5b9e\u73b0Stacking\u53d8\u5f97\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p>from sklearn.ensemble import StackingClassifier<br \/>\nfrom sklearn.linear_model import LogisticRegression<br \/>\nfrom sklearn.svm import SVC<br \/>\nfrom sklearn.ensemble import RandomForestClassifier<\/p>\n<p># \u5b9a\u4e49\u57fa\u5b66\u4e60\u5668<br \/>\nestimators &#061; [<br \/>\n    (&#039;rf&#039;, RandomForestClassifier(n_estimators&#061;10, random_state&#061;42)),<br \/>\n    (&#039;svr&#039;, SVC(random_state&#061;42, probability&#061;True)) # probability&#061;True\u5f88\u91cd\u8981<br \/>\n]<\/p>\n<p># \u5b9a\u4e49\u5143\u5b66\u4e60\u5668<br \/>\nfinal_estimator &#061; LogisticRegression()<\/p>\n<p># \u6784\u5efaStacking\u6a21\u578b<br \/>\n# cv&#061;5\u8868\u793a\u4f7f\u75285\u6298\u4ea4\u53c9\u9a8c\u8bc1\u6765\u751f\u6210\u5143\u5b66\u4e60\u5668\u7684\u8bad\u7ec3\u6570\u636e<br \/>\nstacking_clf &#061; StackingClassifier(<br \/>\n    estimators&#061;estimators,<br \/>\n    final_estimator&#061;final_estimator,<br \/>\n    cv&#061;5<br \/>\n)<\/p>\n<p># \u8bad\u7ec3\u548c\u9884\u6d4b<br \/>\nstacking_clf.fit(X_train, y_train)<br \/>\ny_pred_stacking &#061; stacking_clf.predict(X_test)<br \/>\nprint(f&#034;\\\\nStacking\u6a21\u578b\u7684\u51c6\u786e\u7387: {accuracy_score(y_test, y_pred_stacking):.4f}&#034;)<\/p>\n<p>\u201c\u548c\u800c\u4e0d\u540c\u201d\u00a0Stacking\u6210\u529f\u7684\u5173\u952e\u5728\u4e8e\u57fa\u5b66\u4e60\u5668\u7684\u591a\u6837\u6027\u3002\u5982\u679c\u6240\u6709\u7684\u57fa\u5b66\u4e60\u5668\u90fd\u662f\u540c\u8d28\u7684&#xff0c;\u6216\u8005\u5b83\u4eec\u7684\u9884\u6d4b\u7ed3\u679c\u9ad8\u5ea6\u76f8\u5173&#xff0c;\u90a3\u4e48\u5143\u5b66\u4e60\u5668\u5c31\u5b66\u4e0d\u5230\u4ec0\u4e48\u6709\u7528\u7684\u7ec4\u5408\u4fe1\u606f\u3002\u56e0\u6b64&#xff0c;\u5728\u9009\u62e9\u57fa\u5b66\u4e60\u5668\u65f6&#xff0c;\u6211\u4eec\u5e94\u8be5\u5c3d\u91cf\u9009\u62e9\u90a3\u4e9b\u201c\u601d\u8003\u65b9\u5f0f\u201d\u4e0d\u540c\u3001\u9519\u8bef\u6a21\u5f0f\u4e5f\u4e0d\u540c\u7684\u6a21\u578b\u3002\u4f8b\u5982&#xff0c;\u5c06\u7ebf\u6027\u6a21\u578b&#xff08;\u903b\u8f91\u56de\u5f52&#xff09;\u3001\u57fa\u4e8e\u8ddd\u79bb\u7684\u6a21\u578b&#xff08;KNN&#xff09;\u548c\u57fa\u4e8e\u6811\u7684\u6a21\u578b&#xff08;\u968f\u673a\u68ee\u6797&#xff09;\u7ec4\u5408\u5728\u4e00\u8d77&#xff0c;\u901a\u5e38\u4f1a\u6bd4\u7ec4\u5408\u4e09\u4e2a\u4e0d\u540c\u53c2\u6570\u7684\u968f\u673a\u68ee\u6797\u6548\u679c\u66f4\u597d\u3002<\/p>\n<hr \/>\n<h4>8.4 XGBoost\u4e0eLightGBM&#xff1a;\u5de5\u4e1a\u754c\u7684\u201c\u5927\u6740\u5668\u201d\u8be6\u89e3<\/h4>\n<p>XGBoost\u548cLightGBM\u90fd\u662f\u5bf9GBDT\u601d\u60f3\u7684\u6781\u81f4\u5de5\u7a0b\u5b9e\u73b0\u548c\u7b97\u6cd5\u4f18\u5316&#xff0c;\u5b83\u4eec\u51ed\u501f\u5353\u8d8a\u7684\u6027\u80fd\u548c\u6548\u7387&#xff0c;\u6210\u4e3a\u4e86\u5f53\u4eca\u6570\u636e\u79d1\u5b66\u9886\u57df\u5e94\u7528\u6700\u5e7f\u6cdb\u7684\u6a21\u578b\u3002<\/p>\n<h5>8.4.1 XGBoost&#xff08;eXtreme Gradient Boosting&#xff09;&#xff1a;GBDT\u7684\u6781\u81f4\u8fdb\u5316<\/h5>\n<p>XGBoost\u5728GBDT\u7684\u57fa\u7840\u4e0a&#xff0c;\u4ece\u7b97\u6cd5\u548c\u5de5\u7a0b\u4e24\u4e2a\u5c42\u9762\u90fd\u8fdb\u884c\u4e86\u6df1\u5ea6\u4f18\u5316\u3002<\/p>\n<ul>\n<li>\u7b97\u6cd5\u5c42\u9762\u7684\u4f18\u5316&#xff1a;\n<ul>\n<li>\u6b63\u5219\u5316&#xff1a;XGBoost\u5728\u635f\u5931\u51fd\u6570\u4e2d\u76f4\u63a5\u52a0\u5165\u4e86\u5bf9\u6811\u7684\u590d\u6742\u5ea6\u7684\u6b63\u5219\u5316\u9879&#xff0c;\u5305\u62ec\u5bf9\u53f6\u5b50\u8282\u70b9\u6570\u91cf&#xff08;T&#xff09;\u548c\u53f6\u5b50\u8282\u70b9\u8f93\u51fa\u503c&#xff08;w&#xff09;\u7684L2\u6b63\u5219\u5316\u3002\u8fd9\u4f7f\u5f97XGBoost\u80fd\u66f4\u597d\u5730\u63a7\u5236\u8fc7\u62df\u5408\u3002<\/li>\n<li>\u4e8c\u9636\u6cf0\u52d2\u5c55\u5f00&#xff1a;\u4f20\u7edf\u7684GBDT\u53ea\u5229\u7528\u4e86\u635f\u5931\u51fd\u6570\u7684\u4e00\u9636\u68af\u5ea6\u4fe1\u606f&#xff0c;\u800cXGBoost\u5bf9\u635f\u5931\u51fd\u6570\u8fdb\u884c\u4e86\u4e8c\u9636\u6cf0\u52d2\u5c55\u5f00&#xff0c;\u540c\u65f6\u5229\u7528\u4e86\u4e00\u9636\u548c\u4e8c\u9636\u68af\u5ea6\u4fe1\u606f&#xff0c;\u4f7f\u5f97\u6a21\u578b\u80fd\u66f4\u7cbe\u51c6\u5730\u5411\u6700\u4f18\u89e3\u903c\u8fd1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5de5\u7a0b\u5c42\u9762\u7684\u9769\u65b0&#xff1a;\n<ul>\n<li>\u5e76\u884c\u5316&#xff1a;\u867d\u7136\u6811\u7684\u751f\u6210\u662f\u4e32\u884c\u7684&#xff0c;\u4f46\u5728\u6bcf\u4e2a\u8282\u70b9\u5bfb\u627e\u6700\u4f73\u5206\u88c2\u70b9\u65f6&#xff0c;XGBoost\u53ef\u4ee5\u9ad8\u6548\u5730\u5bf9\u7279\u5f81\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\u3002<\/li>\n<li>\u7f13\u5b58\u611f\u77e5\u4e0e\u6838\u5916\u8ba1\u7b97&#xff1a;\u5728\u5de5\u7a0b\u4e0a\u505a\u4e86\u5f88\u591a\u4f18\u5316&#xff0c;\u4f7f\u5f97\u5b83\u80fd\u5904\u7406\u8d85\u51fa\u5185\u5b58\u7684\u5927\u89c4\u6a21\u6570\u636e\u96c6\u3002<\/li>\n<li>\u5185\u7f6e\u7a00\u758f\u6570\u636e\u5904\u7406&#xff1a;\u80fd\u81ea\u52a8\u5904\u7406\u7f3a\u5931\u503c\u548c\u7a00\u758f\u7279\u5f81\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4e3a\u4f55\u79f0\u738b&#xff1a;XGBoost\u901a\u8fc7\u8fd9\u4e9b\u4f18\u5316&#xff0c;\u5b9e\u73b0\u4e86\u901f\u5ea6\u4e0e\u7cbe\u5ea6\u7684\u5b8c\u7f8e\u7ed3\u5408&#xff0c;\u4f7f\u5176\u5728\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\u5185\u7edf\u6cbb\u4e86\u5404\u5927\u673a\u5668\u5b66\u4e60\u7ade\u8d5b\u3002<\/p>\n<h5>8.4.2 LightGBM&#xff08;Light Gradient Boosting Machine&#xff09;&#xff1a;\u66f4\u5feb\u3001\u66f4\u8f7b\u3001\u66f4\u5f3a<\/h5>\n<p>LightGBM\u662f\u5fae\u8f6f\u63a8\u51fa\u7684\u4e00\u4e2aGBDT\u6846\u67b6&#xff0c;\u5b83\u7684\u76ee\u6807\u662f\u201c\u66f4\u5feb\u3001\u66f4\u8f7b\u201d\u3002<\/p>\n<ul>\n<li>\u57fa\u4e8e\u76f4\u65b9\u56fe\u7684\u7b97\u6cd5&#xff1a;\u4f20\u7edf\u7684GBDT\u5728\u5bfb\u627e\u5206\u88c2\u70b9\u65f6\u9700\u8981\u904d\u5386\u6240\u6709\u6570\u636e\u70b9\u3002LightGBM\u5219\u5148\u5c06\u8fde\u7eed\u7684\u6d6e\u70b9\u6570\u7279\u5f81\u79bb\u6563\u5316\u4e3aK\u4e2a\u6574\u6570\u7bb1&#xff08;bins&#xff09;&#xff0c;\u5e76\u6784\u5efa\u4e00\u4e2a\u5bbd\u5ea6\u4e3aK\u7684\u76f4\u65b9\u56fe\u3002\u540e\u7eed\u5bfb\u627e\u5206\u88c2\u70b9\u65f6&#xff0c;\u53ea\u9700\u5728\u8fd9\u4e9b\u7bb1\u7684\u8fb9\u754c\u4e0a\u8fdb\u884c&#xff0c;\u6781\u5927\u5730\u63d0\u5347\u4e86\u6548\u7387\u548c\u964d\u4f4e\u4e86\u5185\u5b58\u6d88\u8017\u3002<\/li>\n<li>\u5e26\u6df1\u5ea6\u9650\u5236\u7684Leaf-wise\u751f\u957f\u7b56\u7565&#xff1a;\u4f20\u7edf\u7684GBDT\u548cXGBoost\u5927\u591a\u91c7\u7528Level-wise&#xff08;\u6309\u5c42&#xff09;\u7684\u751f\u957f\u7b56\u7565&#xff0c;\u5b83\u5bf9\u540c\u4e00\u5c42\u7684\u6240\u6709\u53f6\u5b50\u8282\u70b9\u8fdb\u884c\u65e0\u5dee\u522b\u5206\u88c2&#xff0c;\u5bb9\u6613\u4ea7\u751f\u5f88\u591a\u4e0d\u5fc5\u8981\u7684\u5206\u88c2\u3002LightGBM\u5219\u91c7\u7528Leaf-wise&#xff08;\u6309\u53f6\u5b50&#xff09;\u7684\u751f\u957f\u7b56\u7565&#xff0c;\u6bcf\u6b21\u90fd\u4ece\u5f53\u524d\u6240\u6709\u53f6\u5b50\u4e2d&#xff0c;\u627e\u5230\u90a3\u4e2a\u5206\u88c2\u589e\u76ca\u6700\u5927\u7684\u53f6\u5b50\u8fdb\u884c\u5206\u88c2\u3002\u8fd9\u79cd\u7b56\u7565\u5728\u5206\u88c2\u6b21\u6570\u76f8\u540c\u65f6&#xff0c;\u80fd\u83b7\u5f97\u66f4\u9ad8\u7684\u7cbe\u5ea6&#xff0c;\u4f46\u53ef\u80fd\u5bfc\u81f4\u6811\u7684\u6df1\u5ea6\u8fc7\u6df1\u800c\u8fc7\u62df\u5408&#xff0c;\u56e0\u6b64\u9700\u8981\u901a\u8fc7max_depth\u6765\u9650\u5236\u3002<\/li>\n<\/ul>\n<p>\u5e94\u7528\u573a\u666f&#xff1a;\u7531\u4e8e\u5176\u5353\u8d8a\u7684\u6548\u7387&#xff0c;LightGBM\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u96c6\u65f6&#xff0c;\u901a\u5e38\u6bd4XGBoost\u66f4\u5feb&#xff0c;\u6027\u80fd\u4e5f\u6781\u5177\u7ade\u4e89\u529b\u3002<\/p>\n<h5>8.4.3 \u5b9e\u6218\u5bf9\u6bd4\u4e0e\u9009\u62e9\u4e4b\u9053<\/h5>\n<p>\u4ee3\u7801\u5b9e\u73b0\u00a0XGBoost\u548cLightGBM\u90fd\u662f\u72ec\u7acb\u7684\u5e93&#xff0c;\u9700\u8981\u5355\u72ec\u5b89\u88c5 (pip install xgboost lightgbm)\u3002\u5b83\u4eec\u7684API\u4e0eScikit-learn\u9ad8\u5ea6\u517c\u5bb9\u3002<\/p>\n<p>import xgboost as xgb<br \/>\nimport lightgbm as lgb<\/p>\n<p># XGBoost<br \/>\nxgb_clf &#061; xgb.XGBClassifier(n_estimators&#061;100, learning_rate&#061;0.1, max_depth&#061;3, random_state&#061;42, use_label_encoder&#061;False, eval_metric&#061;&#039;logloss&#039;)<br \/>\nxgb_clf.fit(X_train, y_train)<br \/>\ny_pred_xgb &#061; xgb_clf.predict(X_test)<br \/>\nprint(f&#034;\\\\nXGBoost\u6a21\u578b\u7684\u51c6\u786e\u7387: {accuracy_score(y_test, y_pred_xgb):.4f}&#034;)<\/p>\n<p># LightGBM<br \/>\nlgb_clf &#061; lgb.LGBMClassifier(n_estimators&#061;100, learning_rate&#061;0.1, max_depth&#061;3, random_state&#061;42)<br \/>\nlgb_clf.fit(X_train, y_train)<br \/>\ny_pred_lgb &#061; lgb_clf.predict(X_test)<br \/>\nprint(f&#034;LightGBM\u6a21\u578b\u7684\u51c6\u786e\u7387: {accuracy_score(y_test, y_pred_lgb):.4f}&#034;)<\/p>\n<p>\u4f55\u65f6\u7528\u54ea\u4e2a<\/p>\n<ul>\n<li>\u6570\u636e\u89c4\u6a21&#xff1a;\n<ul>\n<li>\u5bf9\u4e8e\u4e2d\u5c0f\u89c4\u6a21\u7684\u6570\u636e\u96c6&#xff08;\u51e0\u4e07\u5230\u51e0\u5341\u4e07\u884c&#xff09;&#xff0c;XGBoost\u548cLightGBM\u6027\u80fd\u76f8\u8fd1&#xff0c;XGBoost\u7684\u793e\u533a\u548c\u6587\u6863\u66f4\u6210\u719f\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u89c4\u6a21\u7684\u6570\u636e\u96c6&#xff08;\u767e\u4e07\u884c\u4ee5\u4e0a&#xff09;&#xff0c;LightGBM\u7684\u901f\u5ea6\u4f18\u52bf\u4f1a\u975e\u5e38\u660e\u663e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u8c03\u53c2&#xff1a;\u4e24\u8005\u90fd\u6709\u5927\u91cf\u7684\u8d85\u53c2\u6570\u53ef\u4ee5\u8c03\u4f18\u3002XGBoost\u7684\u53c2\u6570\u66f4\u76f4\u89c2\u4e00\u4e9b&#xff0c;\u800cLightGBM\u7531\u4e8e\u5176\u72ec\u7279\u7684\u751f\u957f\u7b56\u7565&#xff0c;\u8c03\u53c2\u65f6\u9700\u8981\u7279\u522b\u6ce8\u610f\u63a7\u5236\u8fc7\u62df\u5408\u3002<\/li>\n<li>\u4e00\u822c\u5efa\u8bae&#xff1a;\u5728\u65b0\u7684\u9879\u76ee\u4e2d&#xff0c;\u53ef\u4ee5\u4f18\u5148\u5c1d\u8bd5LightGBM&#xff0c;\u56e0\u4e3a\u5b83\u901a\u5e38\u80fd\u4ee5\u66f4\u5feb\u7684\u901f\u5ea6\u83b7\u5f97\u4e00\u4e2a\u975e\u5e38\u6709\u7ade\u4e89\u529b\u7684\u57fa\u7ebf\u6a21\u578b\u3002\u5982\u679c\u5bf9\u7cbe\u5ea6\u6709\u6781\u81f4\u8981\u6c42&#xff0c;\u53ef\u4ee5\u518d\u7cbe\u8c03XGBoost\u8fdb\u884c\u6bd4\u8f83\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u6df1\u5165\u63a2\u7d22\u4e86\u96c6\u6210\u5b66\u4e60\u7684\u5b8f\u4f1f\u6bbf\u5802\u3002\u6211\u4eec\u7406\u89e3\u4e86Bagging\u5982\u4f55\u901a\u8fc7\u5e76\u884c\u548c\u968f\u673a\u6765\u8ffd\u6c42\u7a33\u5b9a&#xff0c;\u9886\u609f\u4e86Boosting\u5982\u4f55\u901a\u8fc7\u4e32\u884c\u548c\u8fed\u4ee3\u6765\u8ffd\u6c42\u5353\u8d8a&#xff0c;\u4e5f\u89c1\u8bc6\u4e86Stacking\u5982\u4f55\u901a\u8fc7\u5206\u5c42\u548c\u878d\u5408\u6765\u8ffd\u6c42\u534f\u540c\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u62c6\u89e3\u4e86XGBoost\u548cLightGBM\u8fd9\u4e24\u67c4\u5de5\u4e1a\u754c\u7684\u201c\u795e\u5175\u5229\u5668\u201d\u3002<\/p>\n<p>\u638c\u63e1\u96c6\u6210\u5b66\u4e60&#xff0c;\u610f\u5473\u7740\u60a8\u4e0d\u518d\u5c06\u6a21\u578b\u89c6\u4e3a\u5b64\u7acb\u7684\u4e2a\u4f53&#xff0c;\u800c\u662f\u5b66\u4f1a\u4e86\u5982\u4f55\u6210\u4e3a\u4e00\u540d\u8fd0\u7b79\u5e37\u5e44\u7684\u201c\u5c06\u519b\u201d&#xff0c;\u5c06\u4e0d\u540c\u7684\u5175\u79cd&#xff08;\u6a21\u578b&#xff09;\u6392\u5175\u5e03\u9635&#xff0c;\u4ee5\u96c6\u4f53\u7684\u667a\u6167\u53bb\u653b\u514b\u6700\u8270\u96be\u7684\u5821\u5792\u3002<\/p>\n<p>\u81f3\u6b64&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u5bf9\u4e3b\u6d41\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u7684\u5168\u9762\u5b66\u4e60\u3002\u5728\u672c\u4e66\u7684\u6700\u540e\u4e00\u7ae0&#xff0c;\u6211\u4eec\u5c06\u628a\u89c6\u91ce\u6295\u5411\u66f4\u5e7f\u9614\u7684\u672a\u6765&#xff0c;\u63a2\u8ba8\u5982\u4f55\u5c06\u6211\u4eec\u5b66\u5230\u7684\u77e5\u8bc6\u4ed8\u8bf8\u5b9e\u8df5&#xff0c;\u5e76\u4e3a\u60a8\u7684\u4e0b\u4e00\u6b65\u5b66\u4e60\u6307\u660e\u65b9\u5411\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e5d\u7ae0&#xff1a;\u795e\u7ecf\u7f51\u7edc\u5165\u95e8\u2014\u2014\u901a\u5f80\u6df1\u5ea6\u5b66\u4e60\u7684\u6865\u6881<\/h3>\n<ul>\n<li>9.1 \u4ece\u751f\u7269\u795e\u7ecf\u5143\u5230\u611f\u77e5\u673a\u6a21\u578b<\/li>\n<li>9.2 \u591a\u5c42\u611f\u77e5\u673a&#xff08;MLP&#xff09;\u4e0e\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5<\/li>\n<li>9.3 \u6fc0\u6d3b\u51fd\u6570&#xff1a;\u4e3a\u795e\u7ecf\u7f51\u7edc\u6ce8\u5165\u201c\u7075\u9b42\u201d<\/li>\n<li>9.4 \u4f7f\u7528Scikit-Learn\u4e0eKeras\/TensorFlow\u6784\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc<\/li>\n<\/ul>\n<p>\u5728\u6211\u4eec\u8fc4\u4eca\u4e3a\u6b62\u7684\u65c5\u7a0b\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u63a2\u7d22\u4e86\u4f17\u591a\u5f3a\u5927\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u3002\u8fd9\u4e9b\u7b97\u6cd5\u5728\u5904\u7406\u7ed3\u6784\u5316\u6570\u636e\u3001\u8fdb\u884c\u5206\u7c7b\u3001\u56de\u5f52\u548c\u805a\u7c7b\u4efb\u52a1\u65f6\u8868\u73b0\u51fa\u8272\u3002\u7136\u800c&#xff0c;\u5f53\u9762\u5bf9\u5982\u56fe\u50cf\u3001\u58f0\u97f3\u3001\u81ea\u7136\u8bed\u8a00\u7b49\u6781\u5176\u590d\u6742\u3001\u9ad8\u7ef4\u4e14\u975e\u7ed3\u6784\u5316\u7684\u6570\u636e\u65f6&#xff0c;\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u5f80\u5f80\u4f1a\u9047\u5230\u74f6\u9888\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e9b\u6311\u6218&#xff0c;\u4e00\u4e2a\u6e90\u4e8e\u751f\u7269\u5b66\u7075\u611f\u3001\u62e5\u6709\u5f3a\u5927\u8868\u5f81\u5b66\u4e60\u80fd\u529b\u7684\u9886\u57df\u5e94\u8fd0\u800c\u751f\u2014\u2014\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc&#xff08;Artificial Neural Networks, ANN&#xff09;&#xff0c;\u5b83\u6784\u6210\u4e86\u73b0\u4ee3\u6df1\u5ea6\u5b66\u4e60&#xff08;Deep Learning&#xff09;\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u672c\u7ae0\u662f\u60a8\u4ece\u7ecf\u5178\u673a\u5668\u5b66\u4e60\u8fc8\u5411\u6df1\u5ea6\u5b66\u4e60\u7684\u5173\u952e\u6865\u6881\u3002\u6211\u4eec\u5c06\u8ffd\u672c\u6eaf\u6e90&#xff0c;\u4ece\u6a21\u62df\u751f\u7269\u795e\u7ecf\u5143\u7684\u6700\u7b80\u5355\u6a21\u578b\u201c\u611f\u77e5\u673a\u201d\u5f00\u59cb&#xff0c;\u9010\u6b65\u63ed\u793a\u795e\u7ecf\u7f51\u7edc\u5982\u4f55\u901a\u8fc7\u589e\u52a0\u5c42\u6b21&#xff08;\u201c\u6df1\u5ea6\u201d&#xff09;\u6765\u83b7\u5f97\u5b66\u4e60\u590d\u6742\u6a21\u5f0f\u7684\u80fd\u529b\u3002\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u9a71\u52a8\u5176\u5b66\u4e60\u7684\u201c\u7075\u9b42\u201d\u7b97\u6cd5\u2014\u2014\u53cd\u5411\u4f20\u64ad&#xff0c;\u5e76\u5de1\u793c\u90a3\u4e9b\u4e3a\u7f51\u7edc\u6ce8\u5165\u975e\u7ebf\u6027\u201c\u6d3b\u529b\u201d\u7684\u6fc0\u6d3b\u51fd\u6570\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u6211\u4eec\u5c06\u4ece\u6211\u4eec\u719f\u6089\u7684Scikit-Learn\u5e73\u7a33\u8fc7\u6e21\u5230\u5de5\u4e1a\u754c\u6807\u51c6\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6Keras\/TensorFlow&#xff0c;\u4eb2\u624b\u642d\u5efa\u3001\u8bad\u7ec3\u5e76\u8bc4\u4f30\u60a8\u7684\u7b2c\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc\u3002\u8fd9\u4e0d\u4ec5\u662f\u5b66\u4e60\u4e00\u79cd\u65b0\u7684\u6a21\u578b&#xff0c;\u66f4\u662f\u5f00\u542f\u4e00\u79cd\u5168\u65b0\u7684\u3001\u4ee5\u201c\u7aef\u5230\u7aef\u201d\u5b66\u4e60\u4e3a\u6838\u5fc3\u7684\u89e3\u51b3\u95ee\u9898\u7684\u601d\u7ef4\u65b9\u5f0f\u3002<\/p>\n<hr \/>\n<h4>9.1 \u4ece\u751f\u7269\u795e\u7ecf\u5143\u5230\u611f\u77e5\u673a\u6a21\u578b<\/h4>\n<p>\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc\u7684\u6700\u521d\u6784\u60f3&#xff0c;\u662f\u5bf9\u4eba\u8111\u57fa\u672c\u5904\u7406\u5355\u5143\u2014\u2014\u795e\u7ecf\u5143\u2014\u2014\u7684\u4e00\u6b21\u5927\u80c6\u800c\u7b80\u5316\u7684\u6a21\u4eff\u3002\u7406\u89e3\u8fd9\u4e2a\u7075\u611f\u4e4b\u6e90&#xff0c;\u80fd\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u628a\u63e1\u5176\u6838\u5fc3\u8bbe\u8ba1\u54f2\u5b66\u3002<\/p>\n<h5>9.1.1 \u7075\u611f\u4e4b\u6e90&#xff1a;\u5927\u8111\u795e\u7ecf\u5143\u7684\u5de5\u4f5c\u673a\u5236<\/h5>\n<p>\u4e00\u4e2a\u5178\u578b\u7684\u751f\u7269\u795e\u7ecf\u5143\u7531\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206\u7ec4\u6210&#xff1a;<\/p>\n<ul>\n<li>\u6811\u7a81&#xff08;Dendrites&#xff09;&#xff1a;\u50cf\u5929\u7ebf\u4e00\u6837&#xff0c;\u63a5\u6536\u6765\u81ea\u5176\u4ed6\u6210\u5343\u4e0a\u4e07\u4e2a\u795e\u7ecf\u5143\u7684\u4fe1\u53f7\u3002<\/li>\n<li>\u7ec6\u80de\u4f53&#xff08;Soma&#xff09;&#xff1a;\u5c06\u6240\u6709\u63a5\u6536\u5230\u7684\u4fe1\u53f7\u8fdb\u884c\u6574\u5408\u5904\u7406\u3002<\/li>\n<li>\u8f74\u7a81&#xff08;Axon&#xff09;&#xff1a;\u5982\u679c\u6574\u5408\u540e\u7684\u4fe1\u53f7\u5f3a\u5ea6\u8d85\u8fc7\u4e86\u4e00\u4e2a\u7279\u5b9a\u7684\u6fc0\u6d3b\u9608\u503c&#xff08;Activation Threshold&#xff09;&#xff0c;\u7ec6\u80de\u4f53\u5c31\u4f1a\u4ea7\u751f\u4e00\u6b21\u7535\u8109\u51b2&#xff08;\u52a8\u4f5c\u7535\u4f4d&#xff09;&#xff0c;\u5e76\u901a\u8fc7\u8f74\u7a81\u5c06\u8fd9\u4e2a\u4fe1\u53f7\u4f20\u9012\u51fa\u53bb\u3002<\/li>\n<li>\u7a81\u89e6&#xff08;Synapse&#xff09;&#xff1a;\u8f74\u7a81\u7684\u672b\u68a2&#xff0c;\u901a\u8fc7\u91ca\u653e\u5316\u5b66\u7269\u8d28&#xff08;\u795e\u7ecf\u9012\u8d28&#xff09;\u5c06\u4fe1\u53f7\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a\u795e\u7ecf\u5143\u7684\u6811\u7a81\u3002\u7a81\u89e6\u7684\u8fde\u63a5\u5f3a\u5ea6\u662f\u53ef\u4ee5\u53d8\u5316\u7684&#xff0c;\u8fd9\u88ab\u8ba4\u4e3a\u662f\u5b66\u4e60\u548c\u8bb0\u5fc6\u7684\u751f\u7269\u5b66\u57fa\u7840\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u88ab\u9ad8\u5ea6\u7b80\u5316\u4e3a&#xff1a;\u591a\u4e2a\u8f93\u5165\u4fe1\u53f7\u88ab\u52a0\u6743\u6c42\u548c&#xff0c;\u5f53\u603b\u548c\u8d85\u8fc7\u4e00\u4e2a\u9608\u503c\u65f6&#xff0c;\u795e\u7ecf\u5143\u88ab\u201c\u6fc0\u6d3b\u201d\u5e76\u4ea7\u751f\u4e00\u4e2a\u8f93\u51fa\u4fe1\u53f7\u3002<\/p>\n<h5>9.1.2 \u611f\u77e5\u673a&#xff08;Perceptron&#xff09;&#xff1a;\u6700\u65e9\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b<\/h5>\n<p>1957\u5e74&#xff0c;\u5fc3\u7406\u5b66\u5bb6\u5f17\u5170\u514b\u00b7\u7f57\u68ee\u5e03\u62c9\u7279&#xff08;Frank Rosenblatt&#xff09;\u53d7\u751f\u7269\u795e\u7ecf\u5143\u7684\u542f\u53d1&#xff0c;\u63d0\u51fa\u4e86\u611f\u77e5\u673a\u6a21\u578b\u3002\u8fd9\u4e0d\u53ea\u662f\u4e00\u4e2a\u62bd\u8c61\u7684\u6982\u5ff5&#xff0c;\u800c\u662f\u7b2c\u4e00\u4e2a\u7528\u7b97\u6cd5\u7cbe\u786e\u5b9a\u4e49\u7684\u3001\u53ef\u5b66\u4e60\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b&#xff0c;\u662f\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc\u9886\u57df\u7684\u201c\u5f00\u5c71\u9f3b\u7956\u201d\u3002<\/p>\n<p>\u6570\u5b66\u5f62\u5f0f\u00a0\u4e00\u4e2a\u63a5\u6536\u00a0n\u00a0\u4e2a\u8f93\u5165\u7684\u611f\u77e5\u673a&#xff0c;\u5176\u5de5\u4f5c\u6d41\u7a0b\u53ef\u4ee5\u5206\u89e3\u4e3a\u4ee5\u4e0b\u51e0\u6b65&#xff1a;<\/p>\n<li>\u8f93\u5165\u4e0e\u6743\u91cd&#xff1a;\u6a21\u578b\u63a5\u6536\u4e00\u4e2a\u8f93\u5165\u5411\u91cf\u00a0x &#061; (x\u2081, x\u2082, &#8230;, x\u2099)\u3002\u6bcf\u4e2a\u8f93\u5165\u00a0x\u1d62\u00a0\u90fd\u88ab\u8d4b\u4e88\u4e00\u4e2a\u76f8\u5e94\u7684\u6743\u91cd\u00a0w\u1d62&#xff0c;\u8fd9\u4e2a\u6743\u91cd\u4ee3\u8868\u4e86\u8be5\u8f93\u5165\u4fe1\u53f7\u7684\u91cd\u8981\u6027\u3002\u6b64\u5916&#xff0c;\u8fd8\u6709\u4e00\u4e2a\u504f\u7f6e\u9879\u00a0b&#xff08;bias&#xff09;&#xff0c;\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a\u53ef\u5b66\u4e60\u7684\u6fc0\u6d3b\u9608\u503c\u3002<\/li>\n<li>\u52a0\u6743\u548c&#xff08;Net Input&#xff09;&#xff1a;\u5c06\u6240\u6709\u8f93\u5165\u4fe1\u53f7\u4e0e\u5176\u5bf9\u5e94\u7684\u6743\u91cd\u76f8\u4e58&#xff0c;\u7136\u540e\u6c42\u548c&#xff0c;\u6700\u540e\u52a0\u4e0a\u504f\u7f6e\u9879\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u8ba1\u7b97\u51fa\u4e00\u4e2a\u51c0\u8f93\u5165\u503c\u00a0z\u3002\u00a0z &#061; (w\u2081x\u2081 &#043; w\u2082x\u2082 &#043; &#8230; &#043; w\u2099x\u2099) &#043; b &#061; w \u00b7 x &#043; b<\/li>\n<li>\u6fc0\u6d3b\u51fd\u6570&#xff08;Activation Function&#xff09;&#xff1a;\u5c06\u51c0\u8f93\u5165\u503c\u00a0z\u00a0\u4f20\u9012\u7ed9\u4e00\u4e2a\u6fc0\u6d3b\u51fd\u6570\u3002\u5728\u7ecf\u5178\u7684\u611f\u77e5\u673a\u4e2d&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5355\u4f4d\u9636\u8dc3\u51fd\u6570&#xff08;Heaviside Step Function&#xff09;\u3002\u00a0y &#061; f(z) &#061; 1\u00a0\u5982\u679c\u00a0z \u2265 0\u00a0y &#061; f(z) &#061; 0\u00a0\u5982\u679c\u00a0z &lt; 0\u00a0\u6700\u7ec8\u7684\u8f93\u51fa\u00a0y\u00a0\u5c31\u662f\u6a21\u578b\u7684\u9884\u6d4b\u7ed3\u679c&#xff08;\u901a\u5e38\u662f\u7c7b\u522b1\u6216\u7c7b\u522b0&#xff09;\u3002<\/li>\n<p>\u5b66\u4e60\u89c4\u5219\u00a0\u611f\u77e5\u673a\u7684\u5b66\u4e60\u8fc7\u7a0b\u975e\u5e38\u76f4\u89c2&#xff1a;\u5bf9\u4e8e\u4e00\u4e2a\u8bad\u7ec3\u6837\u672c&#xff0c;\u5982\u679c\u9884\u6d4b\u9519\u8bef&#xff0c;\u5c31\u8c03\u6574\u6743\u91cd\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u771f\u5b9e\u6807\u7b7e\u662f1&#xff0c;\u4f46\u6a21\u578b\u9884\u6d4b\u4e3a0&#xff08;\u5373\u00a0z &lt; 0&#xff09;&#xff0c;\u8bf4\u660e\u6743\u91cd\u592a\u5c0f\u4e86&#xff0c;\u9700\u8981\u589e\u5927\u3002\u66f4\u65b0\u89c4\u5219\u4e3a&#xff1a;w_new &#061; w_old &#043; \u03b7 * x&#xff0c;b_new &#061; b_old &#043; \u03b7\u3002&#xff08;\u03b7\u662f\u5b66\u4e60\u7387&#xff09;<\/li>\n<li>\u5982\u679c\u771f\u5b9e\u6807\u7b7e\u662f0&#xff0c;\u4f46\u6a21\u578b\u9884\u6d4b\u4e3a1&#xff08;\u5373\u00a0z \u2265 0&#xff09;&#xff0c;\u8bf4\u660e\u6743\u91cd\u592a\u5927\u4e86&#xff0c;\u9700\u8981\u51cf\u5c0f\u3002\u66f4\u65b0\u89c4\u5219\u4e3a&#xff1a;w_new &#061; w_old &#8211; \u03b7 * x&#xff0c;b_new &#061; b_old &#8211; \u03b7\u3002 \u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u4e00\u76f4\u8fed\u4ee3&#xff0c;\u76f4\u5230\u6a21\u578b\u80fd\u6b63\u786e\u5206\u7c7b\u6240\u6709\u8bad\u7ec3\u6837\u672c\u3002<\/li>\n<\/ul>\n<p>\u51e0\u4f55\u610f\u4e49\u00a0w \u00b7 x &#043; b &#061; 0\u00a0\u8fd9\u4e2a\u65b9\u7a0b\u5728\u4e8c\u7ef4\u7a7a\u95f4\u4e2d\u5b9a\u4e49\u4e86\u4e00\u6761\u76f4\u7ebf&#xff0c;\u5728\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5e73\u9762&#xff0c;\u5728\u66f4\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u5219\u5b9a\u4e49\u4e86\u4e00\u4e2a\u8d85\u5e73\u9762&#xff08;Hyperplane&#xff09;\u3002\u8fd9\u4e2a\u8d85\u5e73\u9762\u6070\u597d\u662f\u51b3\u7b56\u7684\u8fb9\u754c\u3002\u611f\u77e5\u673a\u7684\u4efb\u52a1&#xff0c;\u5c31\u662f\u901a\u8fc7\u5b66\u4e60\u8c03\u6574\u6743\u91cd\u00a0w\u00a0\u548c\u504f\u7f6e\u00a0b&#xff0c;\u6765\u627e\u5230\u8fd9\u6837\u4e00\u4e2a\u8d85\u5e73\u9762&#xff0c;\u5c06\u7279\u5f81\u7a7a\u95f4\u4e00\u5206\u4e3a\u4e8c&#xff0c;\u4f7f\u5f97\u4e00\u8fb9\u7684\u70b9\u88ab\u9884\u6d4b\u4e3a\u4e00\u7c7b&#xff0c;\u53e6\u4e00\u8fb9\u7684\u70b9\u88ab\u9884\u6d4b\u4e3a\u53e6\u4e00\u7c7b\u3002\u56e0\u6b64&#xff0c;\u611f\u77e5\u673a\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u7ebf\u6027\u4e8c\u5206\u7c7b\u5668\u3002<\/p>\n<p>\u611f\u77e5\u673a\u7684\u5c40\u9650\u6027\u00a0\u611f\u77e5\u673a\u7684\u8f89\u714c\u662f\u77ed\u6682\u7684\u30021969\u5e74&#xff0c;\u4eba\u5de5\u667a\u80fd\u9886\u57df\u7684\u4e24\u4f4d\u5de8\u64d8\u9a6c\u6587\u00b7\u660e\u65af\u57fa&#xff08;Marvin Minsky&#xff09;\u548c\u897f\u6469\u5c14\u00b7\u4f69\u73c0\u7279&#xff08;Seymour Papert&#xff09;\u5728\u4ed6\u4eec\u7684\u8457\u4f5c\u300a\u611f\u77e5\u673a\u300b\u4e2d&#xff0c;\u7cfb\u7edf\u5730\u6307\u51fa\u4e86\u5176\u81f4\u547d\u7f3a\u9677&#xff1a;\u611f\u77e5\u673a\u53ea\u80fd\u89e3\u51b3\u7ebf\u6027\u53ef\u5206\u95ee\u9898\u3002<\/p>\n<p>\u6700\u8457\u540d\u7684\u53cd\u4f8b\u5c31\u662f**\u201c\u5f02\u6216&#xff08;XOR&#xff09;\u201d\u95ee\u9898**\u3002\u5bf9\u4e8e\u8f93\u5165(0,0)\u548c(1,1)&#xff0c;XOR\u8f93\u51fa0&#xff1b;\u5bf9\u4e8e(0,1)\u548c(1,0)&#xff0c;XOR\u8f93\u51fa1\u3002\u4f60\u65e0\u6cd5\u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a\u7528\u4e00\u6761\u76f4\u7ebf\u5c06\u8fd9\u4e24\u7ec4\u70b9&#xff08;(0,0),(1,1)\u00a0vs\u00a0(0,1),(1,0)&#xff09;\u5206\u5f00\u3002\u8fd9\u4e2a\u770b\u4f3c\u7b80\u5355\u7684\u95ee\u9898&#xff0c;\u5374\u6210\u4e86\u5355\u5c42\u611f\u77e5\u673a\u7684\u201c\u6ed1\u94c1\u5362\u201d\u3002\u8fd9\u4e00\u53d1\u73b0\u6781\u5927\u5730\u6253\u51fb\u4e86\u5f53\u65f6\u5bf9\u795e\u7ecf\u7f51\u7edc\u7684\u70ed\u60c5&#xff0c;\u4f7f\u5176\u7814\u7a76\u8fdb\u5165\u4e86\u957f\u8fbe\u5341\u4f59\u5e74\u7684\u201c\u5bd2\u51ac\u201d\u3002\u7136\u800c&#xff0c;\u4e5f\u6b63\u662f\u8fd9\u4e2a\u5c40\u9650\u6027&#xff0c;\u8feb\u4f7f\u7814\u7a76\u8005\u4eec\u601d\u8003&#xff1a;\u5355\u4e2a\u795e\u7ecf\u5143\u4e0d\u884c&#xff0c;\u90a3\u591a\u4e2a\u795e\u7ecf\u5143\u7ec4\u5408\u8d77\u6765\u5462&#xff1f;<\/p>\n<hr \/>\n<h4>9.2 \u591a\u5c42\u611f\u77e5\u673a&#xff08;MLP&#xff09;\u4e0e\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5<\/h4>\n<p>\u8981\u7a81\u7834\u7ebf\u6027\u67b7\u9501&#xff0c;\u5c31\u9700\u8981\u6784\u5efa\u66f4\u590d\u6742\u7684\u6a21\u578b\u3002\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u591a\u4e2a\u611f\u77e5\u673a&#xff08;\u6216\u66f4\u901a\u7528\u7684\u795e\u7ecf\u5143&#xff09;\u5806\u53e0\u8d77\u6765&#xff0c;\u5f62\u6210\u591a\u5c42\u611f\u77e5\u673a&#xff08;Multi-Layer Perceptron, MLP&#xff09;\u3002<\/p>\n<h5>9.2.1 \u7a81\u7834\u7ebf\u6027\u67b7\u9501&#xff1a;\u4ece\u5355\u5c42\u5230\u591a\u5c42<\/h5>\n<p>\u7f51\u7edc\u7ed3\u6784\u00a0\u4e00\u4e2aMLP\u81f3\u5c11\u5305\u542b\u4e09\u5c42&#xff1a;<\/p>\n<ul>\n<li>\u8f93\u5165\u5c42&#xff08;Input Layer&#xff09;&#xff1a;\u63a5\u6536\u539f\u59cb\u7684\u7279\u5f81\u6570\u636e\u3002\u5b83\u4e0d\u7b97\u4f5c\u771f\u6b63\u7684\u8ba1\u7b97\u5c42&#xff0c;\u53ea\u662f\u6570\u636e\u7684\u5165\u53e3\u3002<\/li>\n<li>\u9690\u85cf\u5c42&#xff08;Hidden Layers&#xff09;&#xff1a;\u4f4d\u4e8e\u8f93\u5165\u5c42\u548c\u8f93\u51fa\u5c42\u4e4b\u95f4&#xff0c;\u53ef\u4ee5\u6709\u4e00\u5c42\u6216\u591a\u5c42\u3002\u8fd9\u4e9b\u5c42\u5bf9\u8f93\u5165\u6570\u636e\u8fdb\u884c\u4e00\u7cfb\u5217\u975e\u7ebf\u6027\u7684\u53d8\u6362&#xff0c;\u662f\u795e\u7ecf\u7f51\u7edc\u201c\u9b54\u529b\u201d\u7684\u6838\u5fc3\u6240\u5728\u3002<\/li>\n<li>\u8f93\u51fa\u5c42&#xff08;Output Layer&#xff09;&#xff1a;\u4ea7\u751f\u6700\u7ec8\u7684\u9884\u6d4b\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u201c\u6df1\u5ea6\u201d\u7684\u7531\u6765\u00a0\u5f53\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u9690\u85cf\u5c42\u65f6&#xff0c;\u6211\u4eec\u5c31\u5f00\u59cb\u79f0\u5176\u4e3a\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc&#xff08;Deep Neural Network, DNN&#xff09;&#xff0c;\u8fd9\u4e5f\u662f\u201c\u6df1\u5ea6\u5b66\u4e60\u201d\u4e00\u8bcd\u7684\u6765\u6e90\u3002\u6bcf\u4e00\u5c42\u9690\u85cf\u5c42\u90fd\u53ef\u4ee5\u770b\u4f5c\u662f\u5bf9\u524d\u4e00\u5c42\u8f93\u51fa\u7684\u7279\u5f81\u8fdb\u884c\u66f4\u9ad8\u5c42\u6b21\u3001\u66f4\u62bd\u8c61\u7684\u7ec4\u5408\u4e0e\u8868\u8fbe\u3002\u4f8b\u5982&#xff0c;\u5728\u56fe\u50cf\u8bc6\u522b\u4e2d&#xff0c;\u7b2c\u4e00\u5c42\u53ef\u80fd\u5b66\u4e60\u5230\u8fb9\u7f18\u548c\u89d2\u70b9&#xff0c;\u7b2c\u4e8c\u5c42\u53ef\u80fd\u5c06\u8fb9\u7f18\u7ec4\u5408\u6210\u773c\u775b\u3001\u9f3b\u5b50\u7b49\u90e8\u4ef6&#xff0c;\u7b2c\u4e09\u5c42\u5219\u53ef\u80fd\u5c06\u8fd9\u4e9b\u90e8\u4ef6\u7ec4\u5408\u6210\u4e00\u5f20\u4eba\u8138\u3002\u6b63\u662f\u8fd9\u79cd\u5c42\u6b21\u5316\u7684\u7279\u5f81\u5b66\u4e60\u80fd\u529b&#xff0c;\u4f7f\u5f97\u6df1\u5ea6\u7f51\u7edc\u80fd\u591f\u89e3\u51b3\u50cfXOR\u8fd9\u6837\u590d\u6742\u7684\u975e\u7ebf\u6027\u95ee\u9898\u3002<\/p>\n<p>\u901a\u7528\u8fd1\u4f3c\u5b9a\u7406&#xff08;Universal Approximation Theorem&#xff09;\u00a0\u8fd9\u4e2a\u91cd\u8981\u7684\u7406\u8bba\u6307\u51fa&#xff1a;\u4e00\u4e2a\u5305\u542b\u5355\u4e2a\u9690\u85cf\u5c42\u3001\u4e14\u8be5\u9690\u85cf\u5c42\u6709\u8db3\u591f\u591a\u795e\u7ecf\u5143\u5e76\u4f7f\u7528\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\u7684MLP&#xff0c;\u53ef\u4ee5\u4ee5\u4efb\u610f\u7cbe\u5ea6\u8fd1\u4f3c\u4efb\u4f55\u8fde\u7eed\u51fd\u6570\u3002\u8fd9\u4ece\u7406\u8bba\u4e0a\u4fdd\u8bc1\u4e86\u795e\u7ecf\u7f51\u7edc\u7684\u5f3a\u5927\u8868\u8fbe\u80fd\u529b\u3002\u5b83\u544a\u8bc9\u6211\u4eec&#xff0c;\u53ea\u8981\u7f51\u7edc\u201c\u8db3\u591f\u5bbd\u201d&#xff0c;\u5b83\u5c31\u80fd\u62df\u5408\u51fa\u4efb\u610f\u590d\u6742\u7684\u5f62\u72b6\u3002\u800c\u201c\u6df1\u5ea6\u201d\u5b66\u4e60\u5219\u8fdb\u4e00\u6b65\u8868\u660e&#xff0c;\u589e\u52a0\u7f51\u7edc\u7684\u6df1\u5ea6&#xff08;\u5c42\u6570&#xff09;\u901a\u5e38\u6bd4\u589e\u52a0\u5bbd\u5ea6&#xff08;\u795e\u7ecf\u5143\u6570\u91cf&#xff09;\u66f4\u6709\u6548\u7387\u3002<\/p>\n<h5>9.2.2 \u53cd\u5411\u4f20\u64ad&#xff08;Backpropagation&#xff09;&#xff1a;\u795e\u7ecf\u7f51\u7edc\u7684\u201c\u7075\u9b42\u201d\u7b97\u6cd5<\/h5>\n<p>\u6709\u4e86\u591a\u5c42\u7ed3\u6784&#xff0c;\u6211\u4eec\u5982\u4f55\u6709\u6548\u5730\u8bad\u7ec3\u8fd9\u4e2a\u5305\u542b\u6210\u5343\u4e0a\u4e07\u4e2a\u6743\u91cd\u7684\u590d\u6742\u7f51\u7edc\u5462&#xff1f;\u7b54\u6848\u5c31\u662f\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5&#xff0c;\u5b83\u4e0e\u68af\u5ea6\u4e0b\u964d\u6cd5\u76f8\u7ed3\u5408&#xff0c;\u6784\u6210\u4e86\u73b0\u4ee3\u795e\u7ecf\u7f51\u7edc\u8bad\u7ec3\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u6838\u5fc3\u601d\u60f3\u00a0\u53cd\u5411\u4f20\u64ad\u7684\u6838\u5fc3\u662f\u5fae\u79ef\u5206\u4e2d\u7684\u94fe\u5f0f\u6cd5\u5219&#xff08;Chain Rule&#xff09;\u3002\u5b83\u662f\u4e00\u79cd\u9ad8\u6548\u8ba1\u7b97\u590d\u6742\u51fd\u6570\u68af\u5ea6\u7684\u65b9\u6cd5\u3002<\/p>\n<li>\u524d\u5411\u4f20\u64ad&#xff08;Forward Pass&#xff09;&#xff1a;\u5c06\u4e00\u4e2a\u8bad\u7ec3\u6837\u672c\u8f93\u5165\u7f51\u7edc&#xff0c;\u4fe1\u53f7\u4ece\u8f93\u5165\u5c42\u9010\u5c42\u5411\u524d\u4f20\u64ad&#xff0c;\u7ecf\u8fc7\u6bcf\u4e00\u5c42\u7684\u8ba1\u7b97&#xff0c;\u6700\u7ec8\u5728\u8f93\u51fa\u5c42\u5f97\u5230\u4e00\u4e2a\u9884\u6d4b\u503c\u3002<\/li>\n<li>\u8ba1\u7b97\u635f\u5931&#xff08;Loss Calculation&#xff09;&#xff1a;\u5c06\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u6807\u7b7e\u8fdb\u884c\u6bd4\u8f83&#xff0c;\u901a\u8fc7\u4e00\u4e2a\u635f\u5931\u51fd\u6570&#xff08;\u5982\u5206\u7c7b\u4efb\u52a1\u7684\u4ea4\u53c9\u71b5\u635f\u5931&#xff0c;\u56de\u5f52\u4efb\u52a1\u7684\u5747\u65b9\u8bef\u5dee\u635f\u5931&#xff09;\u6765\u91cf\u5316\u6a21\u578b\u7684\u201c\u9519\u8bef\u201d\u7a0b\u5ea6\u3002<\/li>\n<li>\u53cd\u5411\u4f20\u64ad&#xff08;Backward Pass&#xff09;&#xff1a;\n<ul>\n<li>\u9996\u5148&#xff0c;\u8ba1\u7b97\u635f\u5931\u51fd\u6570\u5bf9\u8f93\u51fa\u5c42\u6743\u91cd\u7684\u68af\u5ea6\u3002<\/li>\n<li>\u7136\u540e&#xff0c;\u5229\u7528\u94fe\u5f0f\u6cd5\u5219&#xff0c;\u5c06\u8fd9\u4e2a\u201c\u8bef\u5dee\u4fe1\u53f7\u201d\u9010\u5c42\u5411\u540e&#xff08;\u53cd\u5411&#xff09;\u4f20\u64ad\u3002\u5728\u6bcf\u4e00\u5c42&#xff0c;\u6211\u4eec\u90fd\u8ba1\u7b97\u51fa\u635f\u5931\u5bf9\u8be5\u5c42\u6743\u91cd\u7684\u68af\u5ea6\u3002<\/li>\n<li>\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u50cf\u662f\u5728\u201c\u8ffd\u7a76\u8d23\u4efb\u201d&#xff1a;\u8f93\u51fa\u5c42\u7684\u8bef\u5dee\u6709\u591a\u5927\u201c\u8d23\u4efb\u201d\u5e94\u8be5\u7531\u5012\u6570\u7b2c\u4e8c\u5c42\u627f\u62c5&#xff1f;\u5012\u6570\u7b2c\u4e8c\u5c42\u7684\u8bef\u5dee\u53c8\u8be5\u5982\u4f55\u5206\u914d\u7ed9\u66f4\u524d\u4e00\u5c42\u7684\u6743\u91cd&#xff1f;\u53cd\u5411\u4f20\u64ad\u5b8c\u7f8e\u5730\u89e3\u51b3\u4e86\u8fd9\u4e2a\u201c\u8d23\u4efb\u5206\u914d\u201d\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u68af\u5ea6\u4e0b\u964d\u7684\u518d\u6b21\u767b\u573a\u00a0\u4e00\u65e6\u901a\u8fc7\u53cd\u5411\u4f20\u64ad\u8ba1\u7b97\u51fa\u4e86\u7f51\u7edc\u4e2d\u6240\u6709\u6743\u91cd\u76f8\u5bf9\u4e8e\u603b\u635f\u5931\u7684\u68af\u5ea6&#xff0c;\u63a5\u4e0b\u6765\u7684\u6b65\u9aa4\u5c31\u548c\u6211\u4eec\u719f\u6089\u7684\u68af\u5ea6\u4e0b\u964d\u5b8c\u5168\u4e00\u6837\u4e86&#xff1a;\u7528\u8fd9\u4e9b\u68af\u5ea6\u6765\u66f4\u65b0\u6bcf\u4e00\u4e2a\u6743\u91cd&#xff0c;\u4f7f\u5f97\u603b\u635f\u5931\u5411\u7740\u51cf\u5c0f\u7684\u65b9\u5411\u79fb\u52a8\u4e00\u5c0f\u6b65\u3002\u00a0w_new &#061; w_old &#8211; \u03b7 * (\u2202Loss \/ \u2202w)\u00a0\u8fd9\u4e2a\u201c\u524d\u5411\u4f20\u64ad -&gt; \u8ba1\u7b97\u635f\u5931 -&gt; \u53cd\u5411\u4f20\u64ad -&gt; \u66f4\u65b0\u6743\u91cd\u201d\u7684\u5faa\u73af&#xff0c;\u4f1a\u901a\u8fc7\u6210\u5343\u4e0a\u4e07\u4e2a\u8bad\u7ec3\u6837\u672c\u4e0d\u65ad\u8fed\u4ee3&#xff0c;\u6700\u7ec8\u5c06\u7f51\u7edc\u8bad\u7ec3\u5230\u4e00\u4e2a\u80fd\u591f\u5f88\u597d\u5730\u5b8c\u6210\u4efb\u52a1\u7684\u72b6\u6001\u3002<\/p>\n<hr \/>\n<h4>9.3 \u6fc0\u6d3b\u51fd\u6570&#xff1a;\u4e3a\u795e\u7ecf\u7f51\u7edc\u6ce8\u5165\u201c\u7075\u9b42\u201d<\/h4>\n<p>\u5728MLP\u7684\u8ba8\u8bba\u4e2d&#xff0c;\u6211\u4eec\u63d0\u5230\u4e86\u201c\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\u201d\u3002\u5b83\u662f\u5c06\u7b80\u5355\u7684\u7ebf\u6027\u6a21\u578b\u8f6c\u53d8\u4e3a\u5f3a\u5927\u7684\u975e\u7ebf\u6027\u5b66\u4e60\u673a\u5668\u7684\u5173\u952e\u3002<\/p>\n<h5>9.3.1 \u4e3a\u4f55\u9700\u8981\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570&#xff1f;<\/h5>\n<p>\u60f3\u8c61\u4e00\u4e0b&#xff0c;\u5982\u679c\u6211\u4eec\u4f7f\u7528\u7684\u6fc0\u6d3b\u51fd\u6570\u662f\u7ebf\u6027\u7684&#xff08;\u4f8b\u5982\u00a0f(z) &#061; z&#xff09;\u3002\u90a3\u4e48&#xff0c;\u4e00\u4e2a\u9690\u85cf\u5c42\u7684\u8f93\u51fa\u5c31\u662f\u5176\u8f93\u5165\u7684\u7ebf\u6027\u7ec4\u5408\u3002\u5f53\u8fd9\u4e2a\u8f93\u51fa\u518d\u4f5c\u4e3a\u4e0b\u4e00\u5c42\u7684\u8f93\u5165\u65f6&#xff0c;\u6700\u7ec8\u6574\u4e2a\u7f51\u7edc\u7684\u8f93\u51fa\u4ecd\u7136\u53ea\u662f\u539f\u59cb\u8f93\u5165\u7684\u67d0\u79cd\u7ebf\u6027\u7ec4\u5408\u3002\u8fd9\u610f\u5473\u7740&#xff0c;\u65e0\u8bba\u4f60\u5806\u53e0\u591a\u5c11\u5c42&#xff0c;\u6574\u4e2a\u7f51\u7edc\u672c\u8d28\u4e0a\u7b49\u4ef7\u4e8e\u4e00\u4e2a\u5355\u5c42\u7684\u7ebf\u6027\u6a21\u578b\u3002\u5b83\u5c06\u5931\u53bb\u5b66\u4e60\u590d\u6742\u975e\u7ebf\u6027\u5173\u7cfb\u7684\u80fd\u529b&#xff0c;\u9000\u5316\u6210\u4e00\u4e2a\u666e\u901a\u7684\u7ebf\u6027\u5206\u7c7b\u5668\u6216\u56de\u5f52\u5668\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u975e\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\u662f\u8d4b\u4e88\u795e\u7ecf\u7f51\u7edc\u6df1\u5ea6\u548c\u8868\u8fbe\u80fd\u529b\u7684\u201c\u7075\u9b42\u201d\u3002<\/p>\n<h5>9.3.2 \u5e38\u7528\u6fc0\u6d3b\u51fd\u6570\u5de1\u793c<\/h5>\n<ul>\n<li>Sigmoid&#xff1a;f(z) &#061; 1 \/ (1 &#043; e\u207b\u1dbb)\n<ul>\n<li>\u7279\u70b9&#xff1a;\u5c06\u4efb\u610f\u5b9e\u6570\u538b\u7f29\u5230\u00a0(0, 1)\u00a0\u533a\u95f4&#xff0c;\u5e38\u7528\u4e8e\u4e8c\u5206\u7c7b\u95ee\u9898\u7684\u8f93\u51fa\u5c42&#xff08;\u8868\u793a\u6982\u7387&#xff09;\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u5f53\u8f93\u5165\u503c\u975e\u5e38\u5927\u6216\u975e\u5e38\u5c0f\u65f6&#xff0c;\u5176\u5bfc\u6570&#xff08;\u68af\u5ea6&#xff09;\u8d8b\u8fd1\u4e8e0&#xff0c;\u8fd9\u4f1a\u5bfc\u81f4**\u68af\u5ea6\u6d88\u5931&#xff08;Vanishing Gradients&#xff09;**\u95ee\u9898&#xff0c;\u4f7f\u5f97\u6df1\u5c42\u7f51\u7edc\u7684\u8bad\u7ec3\u975e\u5e38\u56f0\u96be\u3002<\/li>\n<\/ul>\n<\/li>\n<li>Tanh&#xff08;\u53cc\u66f2\u6b63\u5207&#xff09;&#xff1a;f(z) &#061; (e\u1dbb &#8211; e\u207b\u1dbb) \/ (e\u1dbb &#043; e\u207b\u1dbb)\n<ul>\n<li>\u7279\u70b9&#xff1a;\u5c06\u4efb\u610f\u5b9e\u6570\u538b\u7f29\u5230\u00a0(-1, 1)\u00a0\u533a\u95f4&#xff0c;\u662f\u201c\u4ee50\u4e3a\u4e2d\u5fc3\u201d\u7684&#xff0c;\u901a\u5e38\u6bd4Sigmoid\u6536\u655b\u66f4\u5feb\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u540c\u6837\u5b58\u5728\u68af\u5ea6\u6d88\u5931\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<li>ReLU&#xff08;Rectified Linear Unit&#xff09;&#xff1a;f(z) &#061; max(0, z)\n<ul>\n<li>\u7279\u70b9&#xff1a;\u73b0\u4ee3\u795e\u7ecf\u7f51\u7edc\u6700\u5e38\u7528\u7684\u6fc0\u6d3b\u51fd\u6570\u3002\u5b83\u8ba1\u7b97\u975e\u5e38\u7b80\u5355&#xff08;\u4e00\u4e2a\u9608\u503c\u5224\u65ad&#xff09;&#xff0c;\u5e76\u4e14\u5728\u6b63\u6570\u533a\u95f4\u7684\u68af\u5ea6\u6052\u4e3a1&#xff0c;\u6781\u5927\u5730\u7f13\u89e3\u4e86\u68af\u5ea6\u6d88\u5931\u95ee\u9898&#xff0c;\u4f7f\u5f97\u8bad\u7ec3\u6df1\u5c42\u7f51\u7edc\u6210\u4e3a\u53ef\u80fd\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u5f53\u8f93\u5165\u4e3a\u8d1f\u6570\u65f6&#xff0c;\u5176\u68af\u5ea6\u4e3a0&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u67d0\u4e9b\u795e\u7ecf\u5143\u6c38\u8fdc\u65e0\u6cd5\u88ab\u6fc0\u6d3b&#xff0c;\u5373**\u201c\u6b7b\u4ea1ReLU\u95ee\u9898\u201d&#xff08;Dying ReLU Problem&#xff09;**\u3002<\/li>\n<\/ul>\n<\/li>\n<li>Leaky ReLU, PReLU, ELU&#xff1a;\u8fd9\u4e9b\u90fd\u662f\u5bf9ReLU\u7684\u6539\u8fdb&#xff0c;\u8bd5\u56fe\u89e3\u51b3\u201c\u6b7b\u4ea1ReLU\u95ee\u9898\u201d\u3002\u4f8b\u5982&#xff0c;Leaky ReLU\u5728\u8f93\u5165\u4e3a\u8d1f\u6570\u65f6&#xff0c;\u4f1a\u7ed9\u4e00\u4e2a\u975e\u5e38\u5c0f\u7684\u6b63\u659c\u7387&#xff08;\u59820.01&#xff09;&#xff0c;\u800c\u4e0d\u662f0\u3002<\/li>\n<li>Softmax&#xff1a;f(z\u1d62) &#061; e\u1dbb\u1d62 \/ \u03a3\u2c7c(e\u1dbb\u2c7c)\n<ul>\n<li>\u7279\u70b9&#xff1a;\u5b83\u4e0d\u662f\u4f5c\u7528\u4e8e\u5355\u4e2a\u795e\u7ecf\u5143&#xff0c;\u800c\u662f\u4f5c\u7528\u4e8e\u6574\u4e2a\u8f93\u51fa\u5c42\u3002\u5b83\u80fd\u5c06\u8f93\u51fa\u5c42\u7684\u4e00\u7ec4\u4efb\u610f\u5b9e\u6570\u503c&#xff0c;\u8f6c\u6362\u4e3a\u4e00\u4e2a\u548c\u4e3a1\u7684\u6982\u7387\u5206\u5e03\u3002\u56e0\u6b64&#xff0c;\u5b83\u662f\u591a\u5206\u7c7b\u95ee\u9898\u8f93\u51fa\u5c42\u7684\u6807\u51c6\u9009\u62e9\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>9.4 \u4f7f\u7528Scikit-Learn\u4e0eKeras\/TensorFlow\u6784\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc<\/h4>\n<p>\u7406\u8bba\u5b66\u4e60\u4e4b\u540e&#xff0c;\u6700\u597d\u7684\u6d88\u5316\u65b9\u5f0f\u5c31\u662f\u52a8\u624b\u5b9e\u8df5\u3002\u6211\u4eec\u5c06\u4ece\u6211\u4eec\u719f\u6089\u7684Scikit-Learn\u5f00\u59cb&#xff0c;\u7136\u540e\u8fc8\u5411\u66f4\u4e13\u4e1a\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u3002<\/p>\n<h5>9.4.1 Scikit-Learn\u4e2d\u7684MLPClassifier\u4e0eMLPRegressor<\/h5>\n<p>Scikit-Learn\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6613\u4e8e\u4f7f\u7528\u7684MLP\u5b9e\u73b0&#xff0c;\u975e\u5e38\u9002\u5408\u8fdb\u884c\u5feb\u901f\u7684\u539f\u578b\u9a8c\u8bc1\u3002<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>from sklearn.neural_network import MLPClassifier<br \/>\nfrom sklearn.datasets import make_moons<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.preprocessing import StandardScaler<\/p>\n<p># \u4f7f\u7528\u6708\u7259\u5f62\u6570\u636e&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u975e\u7ebf\u6027\u53ef\u5206\u95ee\u9898<br \/>\nX, y &#061; make_moons(n_samples&#061;200, noise&#061;0.2, random_state&#061;42)<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, random_state&#061;42)<\/p>\n<p># \u795e\u7ecf\u7f51\u7edc\u5bf9\u7279\u5f81\u5c3a\u5ea6\u654f\u611f&#xff0c;\u6807\u51c6\u5316\u662f\u91cd\u8981\u6b65\u9aa4<br \/>\nscaler &#061; StandardScaler()<br \/>\nX_train_scaled &#061; scaler.fit_transform(X_train)<br \/>\nX_test_scaled &#061; scaler.transform(X_test)<\/p>\n<p># \u6784\u5efa\u548c\u8bad\u7ec3MLP<br \/>\n# hidden_layer_sizes&#061;(10, 5) \u8868\u793a\u4e24\u4e2a\u9690\u85cf\u5c42&#xff0c;\u7b2c\u4e00\u4e2a10\u4e2a\u795e\u7ecf\u5143&#xff0c;\u7b2c\u4e8c\u4e2a5\u4e2a<br \/>\nmlp &#061; MLPClassifier(hidden_layer_sizes&#061;(10, 5), max_iter&#061;1000, random_state&#061;42)<br \/>\nmlp.fit(X_train_scaled, y_train)<\/p>\n<p>print(f&#034;Scikit-Learn MLP Accuracy: {mlp.score(X_test_scaled, y_test):.4f}&#034;)<\/p>\n<p>\u6838\u5fc3\u8d85\u53c2\u6570<\/p>\n<ul>\n<li>hidden_layer_sizes: \u4e00\u4e2a\u5143\u7ec4&#xff0c;\u5b9a\u4e49\u4e86\u6bcf\u4e2a\u9690\u85cf\u5c42\u7684\u795e\u7ecf\u5143\u6570\u91cf\u3002<\/li>\n<li>activation: \u6fc0\u6d3b\u51fd\u6570&#xff0c;\u9ed8\u8ba4\u4e3a&#039;relu&#039;\u3002<\/li>\n<li>solver: \u6743\u91cd\u4f18\u5316\u7684\u6c42\u89e3\u5668&#xff0c;\u9ed8\u8ba4\u4e3a&#039;adam&#039;&#xff0c;\u4e00\u4e2a\u9ad8\u6548\u7684\u68af\u5ea6\u4e0b\u964d\u53d8\u4f53\u3002<\/li>\n<li>alpha: L2\u6b63\u5219\u5316\u7684\u5f3a\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u5c40\u9650\u6027&#xff1a;Scikit-Learn\u7684MLP\u5b9e\u73b0\u529f\u80fd\u76f8\u5bf9\u57fa\u7840&#xff0c;\u4e0d\u652f\u6301GPU\u52a0\u901f&#xff0c;\u4e5f\u65e0\u6cd5\u65b9\u4fbf\u5730\u6784\u5efa\u5982\u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff08;CNN&#xff09;\u3001\u5faa\u73af\u795e\u7ecf\u7f51\u7edc&#xff08;RNN&#xff09;\u7b49\u590d\u6742\u7684\u7f51\u7edc\u7ed3\u6784\u3002\u5f53\u6211\u4eec\u9700\u8981\u66f4\u5927\u7684\u7075\u6d3b\u6027\u548c\u6027\u80fd\u65f6&#xff0c;\u5c31\u9700\u8981\u8f6c\u5411\u4e13\u4e1a\u7684\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u3002<\/p>\n<h5>9.4.2 \u8fc8\u5411\u4e13\u4e1a\u6846\u67b6&#xff1a;TensorFlow\u4e0eKeras\u7b80\u4ecb<\/h5>\n<ul>\n<li>TensorFlow&#xff1a;\u7531Google\u5f00\u53d1\u7684\u5f00\u6e90\u6df1\u5ea6\u5b66\u4e60\u5e73\u53f0\u3002\u5b83\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e95\u5c42\u5f15\u64ce&#xff0c;\u63d0\u4f9b\u4e86\u6784\u5efa\u548c\u90e8\u7f72\u5927\u89c4\u6a21\u673a\u5668\u5b66\u4e60\u6a21\u578b\u6240\u9700\u7684\u5168\u5957\u5de5\u5177\u3002<\/li>\n<li>Keras&#xff1a;\u4e00\u4e2a\u9ad8\u7ea7\u795e\u7ecf\u7f51\u7edcAPI&#xff0c;\u4ee5\u5176\u7528\u6237\u53cb\u597d\u3001\u6a21\u5757\u5316\u548c\u53ef\u6269\u5c55\u6027\u800c\u95fb\u540d\u3002\u5b83\u73b0\u5728\u5df2\u7ecf\u6b63\u5f0f\u6210\u4e3aTensorFlow\u9879\u76ee\u7684\u5b98\u65b9\u9ad8\u7ea7API\u3002<\/li>\n<\/ul>\n<p>\u5b83\u4eec\u7684\u5173\u7cfb\u53ef\u4ee5\u7406\u89e3\u4e3a&#xff1a;Keras\u662f\u201c\u524d\u7aef\u201d&#xff0c;\u8d1f\u8d23\u4ee5\u7b80\u5355\u76f4\u89c2\u7684\u65b9\u5f0f\u5b9a\u4e49\u7f51\u7edc\u7ed3\u6784&#xff1b;TensorFlow\u662f\u201c\u540e\u7aef\u201d&#xff0c;\u8d1f\u8d23\u5728\u5e95\u5c42\u9ad8\u6548\u5730\u6267\u884c\u8ba1\u7b97\u3002<\/p>\n<h5>9.4.3 Keras\u5b9e\u6218&#xff1a;\u5e8f\u8d2f\u6a21\u578b&#xff08;Sequential API&#xff09;\u5165\u95e8<\/h5>\n<p>Keras\u6700\u7b80\u5355\u7684\u6a21\u578b\u662f\u5e8f\u8d2f\u6a21\u578b&#xff08;Sequential Model&#xff09;&#xff0c;\u5b83\u5141\u8bb8\u6211\u4eec\u50cf\u5806\u53e0\u79ef\u6728\u4e00\u6837&#xff0c;\u4e00\u5c42\u4e00\u5c42\u5730\u6784\u5efa\u7f51\u7edc\u3002<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p># \u9700\u8981\u5148\u5b89\u88c5tensorflow: pip install tensorflow<br \/>\nimport tensorflow as tf<br \/>\nfrom tensorflow import keras<\/p>\n<p># 1. \u6784\u5efa\u6a21\u578b<br \/>\n# Sequential\u6a21\u578b\u662f\u4e00\u4e2a\u7ebf\u6027\u7684\u5c42\u5806\u6808<br \/>\nmodel &#061; keras.Sequential([<br \/>\n    # Dense\u5c42\u5c31\u662f\u5168\u8fde\u63a5\u5c42\u3002input_shape\u53ea\u9700\u5728\u7b2c\u4e00\u5c42\u6307\u5b9a\u3002<br \/>\n    keras.layers.Dense(10, activation&#061;&#039;relu&#039;, input_shape&#061;(X_train_scaled.shape[1],)),<br \/>\n    keras.layers.Dense(5, activation&#061;&#039;relu&#039;),<br \/>\n    # \u8f93\u51fa\u5c42&#xff0c;\u56e0\u4e3a\u662f\u4e8c\u5206\u7c7b&#xff0c;\u7528\u4e00\u4e2asigmoid\u795e\u7ecf\u5143<br \/>\n    keras.layers.Dense(1, activation&#061;&#039;sigmoid&#039;)<br \/>\n])<\/p>\n<p># 2. \u7f16\u8bd1\u6a21\u578b<br \/>\n# \u5728\u8fd9\u91cc\u6211\u4eec\u5b9a\u4e49\u635f\u5931\u51fd\u6570\u3001\u4f18\u5316\u5668\u548c\u8bc4\u4f30\u6307\u6807<br \/>\nmodel.compile(optimizer&#061;&#039;adam&#039;,<br \/>\n              loss&#061;&#039;binary_crossentropy&#039;, # \u4e8c\u5206\u7c7b\u4ea4\u53c9\u71b5<br \/>\n              metrics&#061;[&#039;accuracy&#039;])<\/p>\n<p># \u6253\u5370\u6a21\u578b\u6982\u89c8<br \/>\nmodel.summary()<\/p>\n<p># 3. \u8bad\u7ec3\u6a21\u578b<br \/>\n# epochs: \u8bad\u7ec3\u8f6e\u6570; batch_size: \u6bcf\u6279\u6b21\u6837\u672c\u6570<br \/>\nhistory &#061; model.fit(X_train_scaled, y_train, epochs&#061;100, batch_size&#061;16, verbose&#061;0) # verbose&#061;0\u4e0d\u6253\u5370\u8fc7\u7a0b<\/p>\n<p># 4. \u8bc4\u4f30\u6a21\u578b<br \/>\nloss, accuracy &#061; model.evaluate(X_test_scaled, y_test)<br \/>\nprint(f&#034;\\\\nKeras MLP Accuracy: {accuracy:.4f}&#034;)<\/p>\n<p>\u4ee3\u7801\u5bf9\u6bd4&#xff1a;\u901a\u8fc7\u4e0eScikit-Learn\u7684\u5bf9\u6bd4&#xff0c;\u6211\u4eec\u53ef\u4ee5\u770b\u5230Keras\u7684\u5b9e\u73b0\u66f4\u52a0\u6e05\u6670\u548c\u6a21\u5757\u5316\u3002\u6bcf\u4e00\u5c42\u90fd\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u5bf9\u8c61&#xff0c;\u6211\u4eec\u53ef\u4ee5\u81ea\u7531\u5730\u7ec4\u5408\u5b83\u4eec\u3002compile\u548cfit\u7684\u6b65\u9aa4\u4e5f\u8ba9\u6211\u4eec\u5bf9\u8bad\u7ec3\u8fc7\u7a0b\u6709\u4e86\u66f4\u7cbe\u7ec6\u7684\u63a7\u5236\u3002\u8fd9\u79cd\u8bbe\u8ba1\u54f2\u5b66&#xff0c;\u4e3a\u6211\u4eec\u672a\u6765\u6784\u5efa\u66f4\u590d\u6742\u7684\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u94fa\u5e73\u4e86\u9053\u8def\u3002<\/p>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u6210\u529f\u5730\u642d\u5efa\u4e86\u4ece\u7ecf\u5178\u673a\u5668\u5b66\u4e60\u901a\u5f80\u6df1\u5ea6\u5b66\u4e60\u7684\u6865\u6881\u3002\u6211\u4eec\u4ece\u751f\u7269\u5b66\u7684\u7075\u611f\u51fa\u53d1&#xff0c;\u7406\u89e3\u4e86\u611f\u77e5\u673a\u7684\u8bde\u751f\u4e0e\u5c40\u9650&#xff0c;\u89c1\u8bc1\u4e86\u591a\u5c42\u611f\u77e5\u673a\u5982\u4f55\u901a\u8fc7\u201c\u6df1\u5ea6\u201d\u548c\u201c\u975e\u7ebf\u6027\u201d\u6253\u7834\u67b7\u9501\u3002\u6211\u4eec\u63ed\u5f00\u4e86\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5\u7684\u795e\u79d8\u9762\u7eb1&#xff0c;\u5e76\u719f\u6089\u4e86\u6fc0\u6d3b\u51fd\u6570\u8fd9\u4e2a\u795e\u7ecf\u7f51\u7edc\u7684\u201c\u7075\u9b42\u201d\u5bb6\u65cf\u3002<\/p>\n<p>\u6700\u91cd\u8981\u7684\u662f&#xff0c;\u6211\u4eec\u8de8\u51fa\u4e86\u4ece\u4f7f\u7528\u4fbf\u6377\u5de5\u5177\u5230\u638c\u63e1\u4e13\u4e1a\u6846\u67b6\u7684\u5173\u952e\u4e00\u6b65\u3002\u60a8\u73b0\u5728\u5df2\u7ecf\u5177\u5907\u4e86\u4f7f\u7528Keras\/TensorFlow\u6784\u5efa\u548c\u8bad\u7ec3\u795e\u7ecf\u7f51\u7edc\u7684\u57fa\u672c\u80fd\u529b\u3002<\/p>\n<p>\u8fd9\u5e76\u975e\u6211\u4eec\u65c5\u7a0b\u7684\u7ec8\u70b9&#xff0c;\u800c\u662f\u4e00\u4e2a\u66f4\u5b8f\u5927\u3001\u66f4\u6fc0\u52a8\u4eba\u5fc3\u7684\u8d77\u70b9\u3002\u6df1\u5ea6\u5b66\u4e60\u7684\u4e16\u754c\u5e7f\u9614\u65e0\u57a0&#xff0c;\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u4e2d\u53f1\u54a4\u98ce\u4e91&#xff0c;\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\u5728\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4e2d\u5927\u653e\u5f02\u5f69\u3002\u613f\u672c\u7ae0\u6240\u5b66&#xff0c;\u80fd\u6210\u4e3a\u60a8\u63a2\u7d22\u8fd9\u4e2a\u65b0\u4e16\u754c\u7684\u575a\u5b9e\u57fa\u77f3\u548c\u4e0d\u7aed\u52a8\u529b\u3002<\/p>\n<hr \/>\n<h2>\u7b2c\u4e09\u90e8\u5206&#xff1a;\u767b\u5802\u5165\u5ba4\u2014\u2014\u9ad8\u7ea7\u4e13\u9898\u4e0e\u5b9e\u6218\u6f14\u7ec3<\/h2>\n<p>\u6838\u5fc3\u76ee\u6807&#xff1a;\u00a0\u5c06\u7406\u8bba\u77e5\u8bc6\u5e94\u7528\u4e8e\u771f\u5b9e\u4e16\u754c\u7684\u590d\u6742\u95ee\u9898\u3002\u63d0\u4f9b\u4ece\u6570\u636e\u83b7\u53d6\u5230\u6a21\u578b\u90e8\u7f72\u7684\u5168\u6d41\u7a0b\u9879\u76ee\u6307\u5bfc&#xff0c;\u5e76\u4ecb\u7ecd\u66f4\u524d\u6cbf\u7684\u9886\u57df&#xff0c;\u5f00\u62d3\u5b66\u4e60\u8005\u89c6\u91ce\u3002<\/p>\n<h3>\u00a0\u7b2c\u5341\u7ae0&#xff1a;\u5b9e\u6218\u9879\u76ee\u4e00&#xff1a;\u91d1\u878d\u98ce\u63a7\u2014\u2014\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b<\/h3>\n<ul>\n<li>10.1 \u95ee\u9898\u5b9a\u4e49\u4e0e\u6570\u636e\u63a2\u7d22&#xff1a;\u7406\u89e3\u4e0d\u5e73\u8861\u6570\u636e<\/li>\n<li>10.2 \u7279\u5f81\u5de5\u7a0b\u4e0e\u91c7\u6837\u6280\u672f&#xff08;SMOTE&#xff09;<\/li>\n<li>10.3 \u6a21\u578b\u9009\u62e9\u3001\u8bad\u7ec3\u4e0e\u8bc4\u4f30<\/li>\n<li>10.4 \u89e3\u91ca\u6027\u5206\u6790&#xff1a;\u6a21\u578b\u4e3a\u4f55\u505a\u51fa\u8fd9\u6837\u7684\u51b3\u7b56&#xff1f; (SHAP\/LIME)<\/li>\n<\/ul>\n<p>\u6b22\u8fce\u6765\u5230\u6211\u4eec\u7684\u7b2c\u4e00\u4e2a\u7efc\u5408\u5b9e\u6218\u9879\u76ee\u3002\u5728\u672c\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u5c06\u5316\u8eab\u4e3a\u4e00\u540d\u91d1\u878d\u79d1\u6280\u516c\u53f8\u7684\u6570\u636e\u79d1\u5b66\u5bb6&#xff0c;\u76f4\u9762\u4e00\u4e2a\u6781\u5177\u6311\u6218\u6027\u4e14\u4ef7\u503c\u5de8\u5927\u7684\u4efb\u52a1&#xff1a;\u6784\u5efa\u4e00\u4e2a\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b\u6a21\u578b\u3002\u8fd9\u4e2a\u9879\u76ee\u5c06\u4e0d\u518d\u662f\u5b64\u7acb\u5730\u5b66\u4e60\u67d0\u4e2a\u7b97\u6cd5&#xff0c;\u800c\u662f\u8981\u6c42\u6211\u4eec\u7efc\u5408\u8fd0\u7528\u6570\u636e\u63a2\u7d22\u3001\u7279\u5f81\u5de5\u7a0b\u3001\u6a21\u578b\u8bad\u7ec3\u3001\u8bc4\u4f30\u548c\u89e3\u91ca\u7b49\u4e00\u7cfb\u5217\u6280\u80fd&#xff0c;\u6765\u89e3\u51b3\u4e00\u4e2a\u771f\u5b9e\u7684\u5546\u4e1a\u95ee\u9898\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u8981\u5904\u7406\u7684\u6570\u636e\u6709\u4e00\u4e2a\u975e\u5e38\u663e\u8457\u7684\u7279\u70b9\u2014\u2014\u4e25\u91cd\u7684\u7c7b\u522b\u4e0d\u5e73\u8861\u3002\u5728\u73b0\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u7edd\u5927\u591a\u6570\u7684\u4fe1\u7528\u5361\u4ea4\u6613\u90fd\u662f\u5408\u6cd5\u7684&#xff0c;\u6b3a\u8bc8\u4ea4\u6613\u53ea\u5360\u6781\u5c0f\u7684\u4e00\u90e8\u5206\u3002\u8fd9\u79cd\u4e0d\u5e73\u8861\u6027\u7ed9\u6a21\u578b\u8bad\u7ec3\u5e26\u6765\u4e86\u5de8\u5927\u7684\u6311\u6218&#xff0c;\u4e5f\u4f7f\u5f97\u6211\u4eec\u5fc5\u987b\u91cd\u65b0\u5ba1\u89c6\u548c\u9009\u62e9\u5408\u9002\u7684\u8bc4\u4f30\u6307\u6807\u3002<\/p>\n<p>\u672c\u7ae0\u7684\u76ee\u6807\u4e0d\u4ec5\u662f\u6784\u5efa\u4e00\u4e2a\u9ad8\u7cbe\u5ea6\u7684\u6a21\u578b&#xff0c;\u66f4\u662f\u8981\u7ecf\u5386\u4e00\u4e2a\u5b8c\u6574\u7684\u3001\u7aef\u5230\u7aef\u7684\u6570\u636e\u79d1\u5b66\u9879\u76ee\u6d41\u7a0b\u3002\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u5904\u7406\u4e0d\u5e73\u8861\u6570\u636e&#xff0c;\u5982\u4f55\u5728\u591a\u4e2a\u6a21\u578b\u548c\u7b56\u7565\u4e2d\u8fdb\u884c\u6743\u8861&#xff0c;\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u5148\u8fdb\u7684\u5de5\u5177\u6765\u201c\u6253\u5f00\u201d\u6a21\u578b\u7684\u9ed1\u7bb1&#xff0c;\u7406\u89e3\u5176\u51b3\u7b56\u80cc\u540e\u7684\u903b\u8f91\u3002\u8fd9\u5bf9\u4e8e\u5728\u91d1\u878d\u3001\u533b\u7597\u7b49\u9ad8\u98ce\u9669\u9886\u57df\u5efa\u7acb\u53ef\u4fe1\u8d56\u7684AI\u7cfb\u7edf\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<hr \/>\n<h4>10.1 \u95ee\u9898\u5b9a\u4e49\u4e0e\u6570\u636e\u63a2\u7d22&#xff1a;\u7406\u89e3\u4e0d\u5e73\u8861\u6570\u636e<\/h4>\n<p>\u5728\u52a8\u624b\u5199\u4ee3\u7801\u4e4b\u524d&#xff0c;\u9996\u8981\u4efb\u52a1\u662f\u6e05\u6670\u5730\u7406\u89e3\u95ee\u9898\u548c\u6211\u4eec\u624b\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<h5>10.1.1 \u4e1a\u52a1\u80cc\u666f\u4e0e\u95ee\u9898\u5b9a\u4e49<\/h5>\n<ul>\n<li>\n<p>\u4e1a\u52a1\u76ee\u6807&#xff1a;\u94f6\u884c\u6216\u91d1\u878d\u673a\u6784\u7684\u6838\u5fc3\u8bc9\u6c42\u662f&#xff0c;\u5728\u4e0d\u5f71\u54cd\u7edd\u5927\u591a\u6570\u6b63\u5e38\u7528\u6237\u4ea4\u6613\u4f53\u9a8c\u7684\u524d\u63d0\u4e0b&#xff0c;\u5c3d\u53ef\u80fd\u51c6\u786e\u3001\u5feb\u901f\u5730\u8bc6\u522b\u51fa\u6b3a\u8bc8\u4ea4\u6613&#xff0c;\u4ee5\u51cf\u5c11\u8d44\u91d1\u635f\u5931\u3002\u8fd9\u91cc\u5b58\u5728\u4e00\u4e2a\u5929\u7136\u7684\u6743\u8861&#xff1a;<\/p>\n<ul>\n<li>\u6f0f\u62a5&#xff08;False Negative&#xff09;&#xff1a;\u5c06\u6b3a\u8bc8\u4ea4\u6613\u8bef\u5224\u4e3a\u6b63\u5e38\u4ea4\u6613\u3002\u8fd9\u662f\u6700\u4e25\u91cd\u7684\u9519\u8bef&#xff0c;\u76f4\u63a5\u5bfc\u81f4\u8d44\u91d1\u635f\u5931\u3002<\/li>\n<li>\u8bef\u62a5&#xff08;False Positive&#xff09;&#xff1a;\u5c06\u6b63\u5e38\u4ea4\u6613\u8bef\u5224\u4e3a\u6b3a\u8bc8\u4ea4\u6613\u3002\u8fd9\u4f1a\u7ed9\u7528\u6237\u5e26\u6765\u4e0d\u4fbf&#xff08;\u5982\u4ea4\u6613\u88ab\u62d2&#xff0c;\u9700\u7535\u8bdd\u6838\u5b9e&#xff09;&#xff0c;\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li>\u6211\u4eec\u7684\u6a21\u578b\u9700\u8981\u5728\u964d\u4f4e\u6f0f\u62a5\u7387&#xff08;\u5373\u63d0\u9ad8\u53ec\u56de\u7387&#xff09;\u548c\u63a7\u5236\u8bef\u62a5\u7387&#xff08;\u5373\u63d0\u9ad8\u7cbe\u786e\u7387&#xff09;\u4e4b\u95f4\u627e\u5230\u4e00\u4e2a\u6700\u4f73\u5e73\u8861\u70b9\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u673a\u5668\u5b66\u4e60\u95ee\u9898\u5b9a\u6027&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u4e8c\u5206\u7c7b\u95ee\u9898\u3002\u8f93\u5165\u662f\u4ea4\u6613\u7684\u5404\u9879\u7279\u5f81&#xff0c;\u8f93\u51fa\u662f\u4e24\u4e2a\u7c7b\u522b\u4e4b\u4e00&#xff1a;0&#xff08;\u6b63\u5e38&#xff09;\u6216\u00a01&#xff08;\u6b3a\u8bc8&#xff09;\u3002\u5176\u6838\u5fc3\u96be\u70b9\u5728\u4e8e\u201c\u6b3a\u8bc8\u201d\u8fd9\u4e2a\u7c7b\u522b\u662f\u6781\u5c11\u6570\u7c7b\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>10.1.2 \u6570\u636e\u96c6\u4ecb\u7ecd\u4e0e\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790&#xff08;EDA&#xff09;<\/h5>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528Kaggle\u4e0a\u4e00\u4e2a\u975e\u5e38\u7ecf\u5178\u7684\u201c\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b\u201d\u6570\u636e\u96c6\u3002<\/p>\n<p>\u6570\u636e\u52a0\u8f7d\u4e0e\u521d\u6b65\u89c2\u5bdf<\/p>\n<p>import pandas as pd<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\nimport seaborn as sns<\/p>\n<p># \u52a0\u8f7d\u6570\u636e<br \/>\ndf &#061; pd.read_csv(&#039;creditcard.csv&#039;)<\/p>\n<p># \u67e5\u770b\u6570\u636e\u57fa\u672c\u4fe1\u606f<br \/>\nprint(df.head())<br \/>\nprint(df.info())<br \/>\nprint(df.describe())<\/p>\n<p># \u68c0\u67e5\u7f3a\u5931\u503c<br \/>\nprint(&#034;\\\\n\u7f3a\u5931\u503c\u68c0\u67e5:&#034;)<br \/>\nprint(df.isnull().sum().max())<\/p>\n<ul>\n<li>\u7279\u5f81\u5206\u6790&#xff1a;\u6570\u636e\u5305\u542b31\u5217\u3002Time\u662f\u81ea\u7b2c\u4e00\u7b14\u4ea4\u6613\u4ee5\u6765\u7684\u79d2\u6570\u3002Amount\u662f\u4ea4\u6613\u91d1\u989d\u3002Class\u662f\u6211\u4eec\u7684\u76ee\u6807\u53d8\u91cf&#xff08;1\u8868\u793a\u6b3a\u8bc8&#xff0c;0\u8868\u793a\u6b63\u5e38&#xff09;\u3002V1\u5230V28\u662f\u7ecf\u8fc7**\u4e3b\u6210\u5206\u5206\u6790&#xff08;PCA&#xff09;**\u5904\u7406\u540e\u7684\u7279\u5f81&#xff0c;\u8fd9\u662f\u4e3a\u4e86\u4fdd\u62a4\u7528\u6237\u9690\u79c1\u548c\u6570\u636e\u5b89\u5168\u3002PCA\u5904\u7406\u8fc7\u540e\u7684\u7279\u5f81\u5df2\u7ecf\u53bb\u9664\u4e86\u539f\u59cb\u610f\u4e49&#xff0c;\u5e76\u4e14\u5c3a\u5ea6\u76f8\u5bf9\u7edf\u4e00&#xff0c;\u4f46Time\u548cAmount\u8fd8\u4fdd\u7559\u7740\u539f\u59cb\u5c3a\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u4e0d\u5e73\u8861\u6027\u53ef\u89c6\u5316\u00a0\u8fd9\u662f\u7406\u89e3\u672c\u95ee\u9898\u7684\u5173\u952e\u7b2c\u4e00\u6b65\u3002<\/p>\n<p># \u67e5\u770b\u7c7b\u522b\u5206\u5e03<br \/>\nclass_counts &#061; df[&#039;Class&#039;].value_counts()<br \/>\nprint(&#034;\\\\n\u7c7b\u522b\u5206\u5e03:&#034;)<br \/>\nprint(class_counts)<\/p>\n<p># \u7ed8\u5236\u8ba1\u6570\u56fe<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nsns.countplot(x&#061;&#039;Class&#039;, data&#061;df)<br \/>\nplt.title(f&#039;Class Distribution \\\\n (0: Normal || 1: Fraud)&#039;)<br \/>\nplt.show()<\/p>\n<p># \u8ba1\u7b97\u6bd4\u4f8b<br \/>\nfraud_percentage &#061; (class_counts[1] \/ class_counts.sum()) * 100<br \/>\nprint(f&#034;\u6b3a\u8bc8\u4ea4\u6613\u5360\u6bd4: {fraud_percentage:.4f}%&#034;)<\/p>\n<p>\u6211\u4eec\u4f1a\u53d1\u73b0&#xff0c;\u6b3a\u8bc8\u4ea4\u6613\u7684\u6570\u91cf&#xff08;492\u7b14&#xff09;\u76f8\u5bf9\u4e8e\u6b63\u5e38\u4ea4\u6613&#xff08;284,315\u7b14&#xff09;\u6765\u8bf4\u5fae\u4e4e\u5176\u5fae&#xff0c;\u5360\u6bd4\u4ec5\u4e3a\u7ea60.1727%\u3002\u8fd9\u79cd\u60ac\u6b8a\u7684\u6bd4\u4f8b\u662f\u6211\u4eec\u5728\u540e\u7eed\u6240\u6709\u5de5\u4f5c\u4e2d\u90fd\u5fc5\u987b\u7262\u8bb0\u7684\u6838\u5fc3\u80cc\u666f\u3002<\/p>\n<p>Amount\u548cTime\u7279\u5f81\u7684\u5206\u5e03<\/p>\n<p>\u6211\u4eec\u6765\u89c2\u5bdf\u4e00\u4e0b\u8fd9\u4e24\u4e2a\u672a\u7ecfPCA\u5904\u7406\u7684\u7279\u5f81\u4e0e\u6b3a\u8bc8\u884c\u4e3a\u7684\u5173\u7cfb\u3002<\/p>\n<p>fig, axes &#061; plt.subplots(1, 2, figsize&#061;(18, 4))<\/p>\n<p># \u4ea4\u6613\u91d1\u989d\u5206\u5e03<br \/>\nsns.histplot(df[&#039;Amount&#039;], ax&#061;axes[0], bins&#061;50, kde&#061;True)<br \/>\naxes[0].set_title(&#039;Distribution of Transaction Amount&#039;)<\/p>\n<p># \u4ea4\u6613\u65f6\u95f4\u5206\u5e03<br \/>\nsns.histplot(df[&#039;Time&#039;], ax&#061;axes[1], bins&#061;50, kde&#061;True)<br \/>\naxes[1].set_title(&#039;Distribution of Transaction Time&#039;)<\/p>\n<p>plt.show()<\/p>\n<p># \u67e5\u770b\u6b3a\u8bc8\u4ea4\u6613\u548c\u6b63\u5e38\u4ea4\u6613\u5728Amount\u4e0a\u7684\u5dee\u5f02<br \/>\nprint(&#034;\\\\n\u4ea4\u6613\u91d1\u989d\u63cf\u8ff0 (\u6b63\u5e38 vs \u6b3a\u8bc8):&#034;)<br \/>\nprint(df.groupby(&#039;Class&#039;)[&#039;Amount&#039;].describe())<\/p>\n<p>\u901a\u8fc7\u5bf9Amount\u7684\u63cf\u8ff0\u6027\u7edf\u8ba1&#xff0c;\u6211\u4eec\u53ef\u80fd\u4f1a\u53d1\u73b0\u6b3a\u8bc8\u4ea4\u6613\u7684\u5e73\u5747\u91d1\u989d\u4e0e\u6b63\u5e38\u4ea4\u6613\u6709\u6240\u4e0d\u540c\u3002\u540c\u65f6&#xff0c;\u6211\u4eec\u4e5f\u53ef\u4ee5\u7ed8\u5236\u6b3a\u8bc8\u4ea4\u6613\u548c\u6b63\u5e38\u4ea4\u6613\u5728Time\u548cAmount\u4e0a\u7684\u5206\u5e03\u56fe&#xff0c;\u6765\u66f4\u76f4\u89c2\u5730\u5bfb\u627e\u5dee\u5f02\u3002<\/p>\n<p># \u6b3a\u8bc8\u548c\u6b63\u5e38\u4ea4\u6613\u7684\u91d1\u989d\u4e0e\u65f6\u95f4\u5206\u5e03\u5bf9\u6bd4<br \/>\nfig, axes &#061; plt.subplots(2, 1, figsize&#061;(12, 10), sharex&#061;True)<\/p>\n<p>sns.histplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 1, &#039;Amount&#039;], bins&#061;30, ax&#061;axes[0], color&#061;&#039;r&#039;, label&#061;&#039;Fraud&#039;)<br \/>\naxes[0].set_title(&#039;Amount Distribution for Fraudulent Transactions&#039;)<br \/>\naxes[0].legend()<\/p>\n<p>sns.histplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 0, &#039;Amount&#039;], bins&#061;30, ax&#061;axes[1], color&#061;&#039;b&#039;, label&#061;&#039;Normal&#039;)<br \/>\naxes[1].set_title(&#039;Amount Distribution for Normal Transactions&#039;)<br \/>\naxes[1].legend()<\/p>\n<p>plt.xlim((0, 5000)) # \u9650\u5236x\u8f74\u8303\u56f4\u4ee5\u4fbf\u89c2\u5bdf<br \/>\nplt.show()<\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u770b\u5230\u4e86Amount\u548cTime\u7684\u6574\u4f53\u5206\u5e03&#xff0c;\u73b0\u5728\u8ba9\u6211\u4eec\u66f4\u7ec6\u81f4\u5730\u6bd4\u8f83\u4e00\u4e0b\u6b63\u5e38\u4ea4\u6613\u4e0e\u6b3a\u8bc8\u4ea4\u6613\u5728\u8fd9\u4e24\u4e2a\u7ef4\u5ea6\u4e0a\u7684\u5dee\u5f02\u3002<\/p>\n<p># \u6b3a\u8bc8\u548c\u6b63\u5e38\u4ea4\u6613\u7684\u91d1\u989d\u4e0e\u65f6\u95f4\u5206\u5e03\u5bf9\u6bd4<br \/>\nfig, axes &#061; plt.subplots(2, 2, figsize&#061;(18, 10))<\/p>\n<p># &#8212; Amount \u5bf9\u6bd4 &#8212;<br \/>\nsns.kdeplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 0, &#039;Amount&#039;], ax&#061;axes[0, 0], label&#061;&#039;Normal&#039;, fill&#061;True)<br \/>\nsns.kdeplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 1, &#039;Amount&#039;], ax&#061;axes[0, 1], label&#061;&#039;Fraud&#039;, fill&#061;True, color&#061;&#039;r&#039;)<br \/>\naxes[0, 0].set_title(&#039;Amount Distribution (Normal)&#039;)<br \/>\naxes[0, 1].set_title(&#039;Amount Distribution (Fraud)&#039;)<br \/>\naxes[0, 0].set_xlim(-50, 500) # \u9650\u5236\u8303\u56f4\u4ee5\u4fbf\u89c2\u5bdf<br \/>\naxes[0, 1].set_xlim(-50, 500)<\/p>\n<p># &#8212; Time \u5bf9\u6bd4 &#8212;<br \/>\n# \u65f6\u95f4\u7279\u5f81\u4ee5\u79d2\u4e3a\u5355\u4f4d&#xff0c;\u8de8\u5ea6\u4e3a\u4e24\u5929&#xff0c;\u53ef\u80fd\u5b58\u5728\u663c\u591c\u6a21\u5f0f<br \/>\nsns.kdeplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 0, &#039;Time&#039;], ax&#061;axes[1, 0], label&#061;&#039;Normal&#039;, fill&#061;True)<br \/>\nsns.kdeplot(df.loc[df[&#039;Class&#039;] &#061;&#061; 1, &#039;Time&#039;], ax&#061;axes[1, 1], label&#061;&#039;Fraud&#039;, fill&#061;True, color&#061;&#039;r&#039;)<br \/>\naxes[1, 0].set_title(&#039;Time Distribution (Normal)&#039;)<br \/>\naxes[1, 1].set_title(&#039;Time Distribution (Fraud)&#039;)<\/p>\n<p>plt.tight_layout()<br \/>\nplt.show()<\/p>\n<p>\u89c2\u5bdf\u4e0e\u53d1\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u91d1\u989d&#xff08;Amount&#xff09;&#xff1a;\u6b63\u5e38\u4ea4\u6613\u7684\u91d1\u989d\u5206\u5e03\u975e\u5e38\u5e7f\u6cdb&#xff0c;\u800c\u6b3a\u8bc8\u4ea4\u6613\u7684\u91d1\u989d\u4f3c\u4e4e\u66f4\u96c6\u4e2d\u5728\u8f83\u5c0f\u7684\u6570\u503c\u533a\u57df\u3002\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u6709\u7528\u7684\u4fe1\u53f7\u3002<\/li>\n<li>\u65f6\u95f4&#xff08;Time&#xff09;&#xff1a;\u6b63\u5e38\u4ea4\u6613\u7684\u65f6\u95f4\u5206\u5e03\u5448\u73b0\u51fa\u660e\u663e\u7684\u5468\u671f\u6027&#xff0c;\u6709\u4e24\u4e2a\u4f4e\u8c37&#xff0c;\u8fd9\u5f88\u53ef\u80fd\u5bf9\u5e94\u7740\u6df1\u591c\u4ea4\u6613\u91cf\u51cf\u5c11\u7684\u6a21\u5f0f\u3002\u800c\u6b3a\u8bc8\u4ea4\u6613\u7684\u65f6\u95f4\u5206\u5e03\u5219\u663e\u5f97\u66f4\u52a0\u5747\u5300&#xff0c;\u4f3c\u4e4e\u5168\u5929\u5019\u90fd\u5728\u53d1\u751f\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u521d\u6b65\u7684EDA&#xff08;\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790&#xff09;\u7ed9\u4e86\u6211\u4eec\u4fe1\u5fc3&#xff0c;\u8bf4\u660e\u8fd9\u4e9b\u7279\u5f81\u4e2d\u786e\u5b9e\u5305\u542b\u4e86\u53ef\u4ee5\u7528\u4e8e\u533a\u5206\u4e24\u7c7b\u4ea4\u6613\u7684\u4fe1\u606f\u3002<\/p>\n<hr \/>\n<h4>10.2 \u7279\u5f81\u5de5\u7a0b\u4e0e\u91c7\u6837\u6280\u672f<\/h4>\n<p>\u5728\u5c06\u6570\u636e\u5582\u7ed9\u6a21\u578b\u4e4b\u524d&#xff0c;\u6211\u4eec\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u5fc5\u8981\u7684\u51c6\u5907\u5de5\u4f5c\u3002<\/p>\n<h5>10.2.1 \u7279\u5f81\u6807\u51c6\u5316<\/h5>\n<p>Amount\u548cTime\u7279\u5f81\u7684\u6570\u503c\u8303\u56f4&#xff08;Amount\u53ef\u4ee5\u4e0a\u4e07&#xff0c;Time\u53ef\u4ee5\u8fbe\u5230\u5341\u51e0\u4e07&#xff09;\u4e0e\u5176\u4ed6\u7ecf\u8fc7PCA\u5904\u7406\u7684V1-V28\u7279\u5f81&#xff08;\u5927\u591a\u96c6\u4e2d\u57280\u9644\u8fd1&#xff09;\u5dee\u5f02\u5de8\u5927\u3002\u5982\u679c\u76f4\u63a5\u4f7f\u7528&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u90a3\u4e9b\u6570\u503c\u8303\u56f4\u5927\u7684\u7279\u5f81\u5728\u6a21\u578b\u8bad\u7ec3\u4e2d\u5360\u636e\u4e3b\u5bfc\u5730\u4f4d&#xff0c;\u7279\u522b\u662f\u5bf9\u4e8e\u90a3\u4e9b\u5bf9\u5c3a\u5ea6\u654f\u611f\u7684\u7b97\u6cd5&#xff08;\u5982\u903b\u8f91\u56de\u5f52\u3001SVM\u3001\u795e\u7ecf\u7f51\u7edc&#xff09;\u3002\u56e0\u6b64&#xff0c;\u6807\u51c6\u5316\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u6b65\u9aa4\u3002<\/p>\n<p>RobustScaler\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9&#xff0c;\u56e0\u4e3a\u5b83\u4f7f\u7528\u56db\u5206\u4f4d\u6570\u8fdb\u884c\u7f29\u653e&#xff0c;\u5bf9\u4e8e\u5f02\u5e38\u503c\u4e0d\u90a3\u4e48\u654f\u611f&#xff0c;\u800c\u91d1\u878d\u6570\u636e\u4e2d\u5f80\u5f80\u5b58\u5728\u4e00\u4e9b\u6781\u7aef\u7684\u5927\u989d\u4ea4\u6613\u3002<\/p>\n<p>from sklearn.preprocessing import RobustScaler<\/p>\n<p># \u521b\u5efaRobustScaler\u5b9e\u4f8b<br \/>\nrob_scaler &#061; RobustScaler()<\/p>\n<p># \u5bf9Amount\u548cTime\u8fdb\u884c\u7f29\u653e<br \/>\ndf[&#039;scaled_amount&#039;] &#061; rob_scaler.fit_transform(df[&#039;Amount&#039;].values.reshape(-1,1))<br \/>\ndf[&#039;scaled_time&#039;] &#061; rob_scaler.fit_transform(df[&#039;Time&#039;].values.reshape(-1,1))<\/p>\n<p># \u5220\u9664\u539f\u59cb\u7684Time\u548cAmount\u5217<br \/>\ndf.drop([&#039;Time&#039;,&#039;Amount&#039;], axis&#061;1, inplace&#061;True)<\/p>\n<p># \u5c06scaled_amount\u548cscaled_time\u79fb\u52a8\u5230\u524d\u9762&#xff0c;\u65b9\u4fbf\u67e5\u770b<br \/>\nscaled_amount &#061; df[&#039;scaled_amount&#039;]<br \/>\nscaled_time &#061; df[&#039;scaled_time&#039;]<br \/>\ndf.drop([&#039;scaled_amount&#039;, &#039;scaled_time&#039;], axis&#061;1, inplace&#061;True)<br \/>\ndf.insert(0, &#039;scaled_amount&#039;, scaled_amount)<br \/>\ndf.insert(1, &#039;scaled_time&#039;, scaled_time)<\/p>\n<p>print(&#034;\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\u5934\u90e8:&#034;)<br \/>\nprint(df.head())<\/p>\n<h5>10.2.2 \u5e94\u5bf9\u7c7b\u522b\u4e0d\u5e73\u8861&#xff1a;\u91c7\u6837\u6280\u672f<\/h5>\n<p>\u8fd9\u662f\u672c\u9879\u76ee\u6700\u6838\u5fc3\u7684\u6311\u6218\u3002\u5982\u679c\u76f4\u63a5\u5728\u539f\u59cb\u7684\u4e0d\u5e73\u8861\u6570\u636e\u4e0a\u8bad\u7ec3&#xff0c;\u5927\u591a\u6570\u6a21\u578b\u4f1a\u5b66\u5230\u4e00\u4e2a\u201c\u5077\u61d2\u201d\u7684\u7b56\u7565&#xff1a;\u5c06\u6240\u6709\u4ea4\u6613\u90fd\u9884\u6d4b\u4e3a\u6b63\u5e38\u3002\u8fd9\u6837\u505a\u867d\u7136\u80fd\u8fbe\u523099.8%\u4ee5\u4e0a\u7684\u51c6\u786e\u7387&#xff0c;\u4f46\u5b83\u5b8c\u5168\u6ca1\u6709\u8bc6\u522b\u51fa\u4efb\u4f55\u6b3a\u8bc8\u4ea4\u6613&#xff0c;\u5bf9\u4e8e\u6211\u4eec\u7684\u4e1a\u52a1\u76ee\u6807\u6765\u8bf4\u6beb\u65e0\u4ef7\u503c\u3002<\/p>\n<p>\u4e0b\u91c7\u6837&#xff08;Undersampling&#xff09;\u00a0\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u968f\u673a\u5220\u9664\u591a\u6570\u7c7b&#xff08;\u6b63\u5e38\u4ea4\u6613&#xff09;\u7684\u6837\u672c&#xff0c;\u4f7f\u5176\u6570\u91cf\u4e0e\u5c11\u6570\u7c7b&#xff08;\u6b3a\u8bc8\u4ea4\u6613&#xff09;\u76f8\u5339\u914d\u3002<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u901f\u5ea6\u5feb&#xff0c;\u6570\u636e\u96c6\u53d8\u5c0f&#xff0c;\u8bad\u7ec3\u6210\u672c\u964d\u4f4e\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u4f1a\u4e22\u5931\u5927\u91cf\u4fe1\u606f\u3002\u88ab\u5220\u9664\u7684\u6b63\u5e38\u4ea4\u6613\u6837\u672c\u4e2d\u53ef\u80fd\u5305\u542b\u4e86\u533a\u5206\u6b63\u5e38\u4e0e\u6b3a\u8bc8\u7684\u91cd\u8981\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<p>\u8fc7\u91c7\u6837&#xff08;Oversampling&#xff09;\u00a0\u4e0e\u4e0b\u91c7\u6837\u76f8\u53cd&#xff0c;\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u5c11\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf&#xff0c;\u901a\u5e38\u901a\u8fc7\u968f\u673a\u590d\u5236\u6765\u5b9e\u73b0\u3002<\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u6ca1\u6709\u4fe1\u606f\u4e22\u5931\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u7531\u4e8e\u662f\u7b80\u5355\u590d\u5236&#xff0c;\u5bb9\u6613\u5bfc\u81f4\u6a21\u578b\u5bf9\u7279\u5b9a\u7684\u5c11\u6570\u7c7b\u6837\u672c\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n<h5>10.2.3 SMOTE&#xff1a;\u66f4\u667a\u80fd\u7684\u8fc7\u91c7\u6837<\/h5>\n<p>\u4e3a\u4e86\u89e3\u51b3\u7b80\u5355\u8fc7\u91c7\u6837\u7684\u8fc7\u62df\u5408\u95ee\u9898&#xff0c;SMOTE&#xff08;Synthetic Minority Over-sampling Technique&#xff09;\u88ab\u63d0\u4e86\u51fa\u6765\u3002<\/p>\n<ul>\n<li>\u6838\u5fc3\u601d\u60f3&#xff1a;SMOTE\u4e0d\u662f\u7b80\u5355\u5730\u590d\u5236\u5c11\u6570\u7c7b\u6837\u672c&#xff0c;\u800c\u662f\u5408\u6210\u65b0\u7684\u3001\u770b\u8d77\u6765\u5f88\u771f\u5b9e\u7684\u5c11\u6570\u7c7b\u6837\u672c\u3002\u5176\u8fc7\u7a0b\u662f&#xff1a;\n<li>\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5c11\u6570\u7c7b\u6837\u672c\u00a0A\u3002<\/li>\n<li>\u627e\u5230\u5b83\u5728\u5c11\u6570\u7c7b\u6837\u672c\u4e2d\u7684\u00a0k\u00a0\u4e2a\u6700\u8fd1\u90bb&#xff08;k\u901a\u5e38\u4e3a5&#xff09;\u3002<\/li>\n<li>\u4ece\u8fd9\u00a0k\u00a0\u4e2a\u8fd1\u90bb\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6837\u672c\u00a0B\u3002<\/li>\n<li>\u5728\u00a0A\u00a0\u548c\u00a0B\u00a0\u4e4b\u95f4\u7684\u8fde\u7ebf\u4e0a\u968f\u673a\u53d6\u4e00\u70b9&#xff0c;\u4f5c\u4e3a\u65b0\u7684\u5408\u6210\u6837\u672c\u3002\u8fd9\u4e2a\u65b0\u6837\u672c\u7684\u8ba1\u7b97\u516c\u5f0f\u662f\u00a0A &#043; \u03bb * (B &#8211; A)&#xff0c;\u5176\u4e2d\u00a0\u03bb\u00a0\u662f\u4e00\u4e2a0\u52301\u4e4b\u95f4\u7684\u968f\u673a\u6570\u3002<\/li>\n<\/li>\n<li>\u6548\u679c&#xff1a;\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;SMOTE\u4e3a\u5c11\u6570\u7c7b\u751f\u6210\u4e86\u65b0\u7684\u3001\u591a\u6837\u5316\u7684\u6837\u672c&#xff0c;\u6269\u5927\u4e86\u5c11\u6570\u7c7b\u7684\u51b3\u7b56\u533a\u57df&#xff0c;\u6709\u52a9\u4e8e\u6a21\u578b\u5b66\u4e60\u5230\u66f4\u9c81\u68d2\u7684\u5206\u7c7b\u8fb9\u754c\u3002<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5e93\u00a0imbalanced-learn\u00a0\u6765\u5b9e\u73b0SMOTE\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5&#xff0c;\u8bf7\u5148\u8fd0\u884c&#xff1a;<\/p>\n<p>pip install -U imbalanced-learn<\/p>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u5728\u4ee3\u7801\u4e2d\u5b9e\u9645\u5e94\u7528SMOTE\u3002\u5173\u952e\u5728\u4e8e&#xff0c;SMOTE\u53ea\u80fd\u5e94\u7528\u4e8e\u8bad\u7ec3\u96c6&#xff0c;\u7edd\u4e0d\u80fd\u5e94\u7528\u4e8e\u6d4b\u8bd5\u96c6\u3002\u56e0\u4e3a\u6d4b\u8bd5\u96c6\u5fc5\u987b\u4fdd\u6301\u5176\u539f\u59cb\u7684\u3001\u771f\u5b9e\u7684\u6570\u636e\u5206\u5e03&#xff0c;\u4ee5\u516c\u6b63\u5730\u8bc4\u4f30\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<p>from sklearn.model_selection import train_test_split<br \/>\nfrom imblearn.over_sampling import SMOTE<br \/>\nimport pandas as pd<\/p>\n<p># \u5047\u8bbe df \u662f\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u7279\u5f81\u6807\u51c6\u5316\u7684DataFrame<br \/>\n# X \u662f\u7279\u5f81, y \u662f\u6807\u7b7e<br \/>\nX &#061; df.drop(&#039;Class&#039;, axis&#061;1)<br \/>\ny &#061; df[&#039;Class&#039;]<\/p>\n<p># 1. \u9996\u5148&#xff0c;\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<br \/>\n# \u4f7f\u7528 stratify&#061;y \u6765\u786e\u4fdd\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u4e2d\u7684\u7c7b\u522b\u6bd4\u4f8b\u4e0e\u539f\u59cb\u6570\u636e\u96c6\u4e00\u81f4<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.2, random_state&#061;42, stratify&#061;y)<\/p>\n<p>print(&#034;&#8212; \u6570\u636e\u5212\u5206\u540e &#8212;&#034;)<br \/>\nprint(&#034;\u539f\u59cb\u8bad\u7ec3\u96c6\u4e2d\u7684\u7c7b\u522b\u5206\u5e03:&#034;)<br \/>\nprint(y_train.value_counts())<br \/>\nprint(&#034;\\\\n\u539f\u59cb\u6d4b\u8bd5\u96c6\u4e2d\u7684\u7c7b\u522b\u5206\u5e03:&#034;)<br \/>\nprint(y_test.value_counts())<\/p>\n<p># 2. \u521b\u5efaSMOTE\u5b9e\u4f8b\u5e76\u5e94\u7528\u4e8e\u8bad\u7ec3\u96c6<br \/>\nprint(&#034;\\\\n&#8212; \u5e94\u7528SMOTE &#8212;&#034;)<br \/>\nsmote &#061; SMOTE(random_state&#061;42)<br \/>\nX_train_smote, y_train_smote &#061; smote.fit_resample(X_train, y_train)<\/p>\n<p># 3. \u68c0\u67e5SMOTE\u5904\u7406\u540e\u8bad\u7ec3\u96c6\u7684\u7c7b\u522b\u5206\u5e03<br \/>\nprint(&#034;\\\\nSMOTE\u5904\u7406\u540e\u8bad\u7ec3\u96c6\u7684\u7c7b\u522b\u5206\u5e03:&#034;)<br \/>\nprint(y_train_smote.value_counts())<\/p>\n<p>\u4ee3\u7801\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>\u6211\u4eec\u9996\u5148\u5c06\u6574\u4e2a\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002\u8fd9\u662f\u81f3\u5173\u91cd\u8981\u7684\u4e00\u6b65\u3002<\/li>\n<li>\u7136\u540e&#xff0c;\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aSMOTE\u5bf9\u8c61\u3002<\/li>\n<li>\u6700\u5173\u952e\u7684\u4e00\u884c\u662f\u00a0smote.fit_resample(X_train, y_train)\u3002fit_resample\u65b9\u6cd5\u4f1a\u5b66\u4e60\u8bad\u7ec3\u6570\u636e\u4e2d\u5c11\u6570\u7c7b\u7684\u5206\u5e03&#xff0c;\u5e76\u751f\u6210\u65b0\u7684\u5408\u6210\u6837\u672c&#xff0c;\u6700\u7ec8\u8fd4\u56de\u4e00\u4e2a\u7c7b\u522b\u5b8c\u5168\u5e73\u8861\u7684\u65b0\u8bad\u7ec3\u96c6\u00a0X_train_smote\u00a0\u548c\u00a0y_train_smote\u3002<\/li>\n<li>\u4ece\u8f93\u51fa\u53ef\u4ee5\u770b\u5230&#xff0c;\u7ecf\u8fc7SMOTE\u5904\u7406\u540e&#xff0c;\u8bad\u7ec3\u96c6\u4e2d\u7684\u5c11\u6570\u7c7b&#xff08;\u6b3a\u8bc8&#xff09;\u6837\u672c\u6570\u91cf\u88ab\u63d0\u5347\u5230\u4e0e\u591a\u6570\u7c7b&#xff08;\u6b63\u5e38&#xff09;\u76f8\u540c&#xff0c;\u800c\u6d4b\u8bd5\u96c6\u5219\u4fdd\u6301\u539f\u6837&#xff0c;\u8fd9\u5b8c\u5168\u7b26\u5408\u6211\u4eec\u7684\u8981\u6c42\u3002<\/li>\n<\/ul>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u62e5\u6709\u4e86\u4e00\u4e2a\u7ecf\u8fc7SMOTE\u5904\u7406\u3001\u7c7b\u522b\u5e73\u8861\u7684\u8bad\u7ec3\u96c6\u00a0(X_train_smote, y_train_smote)&#xff0c;\u4ee5\u53ca\u4e00\u4e2a\u539f\u59cb\u7684\u3001\u4e0d\u5e73\u8861\u7684\u6d4b\u8bd5\u96c6\u00a0(X_test, y_test)\u3002\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u653e\u5fc3\u5730\u4f7f\u7528\u8fd9\u4e2a\u65b0\u7684\u8bad\u7ec3\u96c6\u6765\u8bad\u7ec3\u6211\u4eec\u7684\u6a21\u578b\u4e86\u3002<\/p>\n<hr \/>\n<h4>10.3 \u6a21\u578b\u9009\u62e9\u3001\u8bad\u7ec3\u4e0e\u8bc4\u4f30<\/h4>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u51c6\u5907\u597d\u8fdb\u5165\u6a21\u578b\u6784\u5efa\u9636\u6bb5\u4e86\u3002<\/p>\n<h5>10.3.1 \u9009\u62e9\u5408\u9002\u7684\u8bc4\u4f30\u6307\u6807<\/h5>\n<p>\u6b63\u5982\u4e4b\u524d\u6240\u8bf4&#xff0c;**\u51c6\u786e\u7387&#xff08;Accuracy&#xff09;**\u5728\u8fd9\u91cc\u662f\u5b8c\u5168\u4e0d\u53ef\u4fe1\u7684\u3002\u6211\u4eec\u9700\u8981\u5173\u6ce8\u90a3\u4e9b\u80fd\u771f\u5b9e\u53cd\u6620\u6a21\u578b\u5728\u4e0d\u5e73\u8861\u6570\u636e\u4e0a\u8868\u73b0\u7684\u6307\u6807&#xff1a;<\/p>\n<ul>\n<li>\u7cbe\u786e\u7387&#xff08;Precision&#xff09;&#xff1a;TP \/ (TP &#043; FP)\u3002\u5728\u6240\u6709\u88ab\u6a21\u578b\u9884\u6d4b\u4e3a\u201c\u6b3a\u8bc8\u201d\u7684\u4ea4\u6613\u4e2d&#xff0c;\u771f\u6b63\u662f\u6b3a\u8bc8\u7684\u6bd4\u4f8b\u3002\u5b83\u8861\u91cf\u4e86\u6a21\u578b\u7684\u67e5\u51c6\u7387&#xff0c;\u9ad8\u7cbe\u786e\u7387\u610f\u5473\u7740\u4f4e\u7684\u8bef\u62a5\u7387\u3002<\/li>\n<li>\u53ec\u56de\u7387&#xff08;Recall&#xff09;&#xff1a;TP \/ (TP &#043; FN)\u3002\u5728\u6240\u6709\u771f\u6b63\u7684\u6b3a\u8bc8\u4ea4\u6613\u4e2d&#xff0c;\u88ab\u6a21\u578b\u6210\u529f\u8bc6\u522b\u51fa\u6765\u7684\u6bd4\u4f8b\u3002\u5b83\u8861\u91cf\u4e86\u6a21\u578b\u7684\u67e5\u5168\u7387&#xff0c;\u9ad8\u53ec\u56de\u7387\u610f\u5473\u7740\u4f4e\u7684\u6f0f\u62a5\u7387\u3002<\/li>\n<li>F1-Score&#xff1a;\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u7684\u8c03\u548c\u5e73\u5747\u6570&#xff0c;\u662f\u4e24\u8005\u7684\u7efc\u5408\u8003\u91cf\u3002<\/li>\n<li>PR\u66f2\u7ebf&#xff08;Precision-Recall Curve&#xff09;&#xff1a;\u4ee5\u53ec\u56de\u7387\u4e3a\u6a2a\u8f74&#xff0c;\u7cbe\u786e\u7387\u4e3a\u7eb5\u8f74\u7ed8\u5236\u7684\u66f2\u7ebf\u3002\u66f2\u7ebf\u4e0b\u7684\u9762\u79ef&#xff08;AUC-PR&#xff09;\u662f\u8861\u91cf\u6a21\u578b\u6574\u4f53\u6027\u80fd\u7684\u4f18\u79c0\u6307\u6807&#xff0c;\u5c24\u5176\u662f\u5728\u4e0d\u5e73\u8861\u573a\u666f\u4e0b\u3002\u4e00\u4e2a\u7406\u60f3\u6a21\u578b\u7684PR\u66f2\u7ebf\u4f1a\u5c3d\u53ef\u80fd\u5730\u9760\u8fd1\u53f3\u4e0a\u89d2\u3002<\/li>\n<\/ul>\n<h5>10.3.2 \u6a21\u578b\u8bad\u7ec3\u4e0e\u6bd4\u8f83<\/h5>\n<p>\u6211\u4eec\u5c06\u8fdb\u884c\u4e00\u4e2a\u5bf9\u6bd4\u5b9e\u9a8c&#xff0c;\u770b\u770b\u4e0d\u540c\u6570\u636e\u5904\u7406\u7b56\u7565\u5bf9\u6a21\u578b\u6027\u80fd\u7684\u5f71\u54cd\u3002<\/p>\n<p>from sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.linear_model import LogisticRegression<br \/>\nfrom sklearn.metrics import classification_report, precision_recall_curve, auc<br \/>\nfrom imblearn.over_sampling import SMOTE<\/p>\n<p># \u51c6\u5907\u6570\u636e<br \/>\nX &#061; df.drop(&#039;Class&#039;, axis&#061;1)<br \/>\ny &#061; df[&#039;Class&#039;]<\/p>\n<p># \u5212\u5206\u539f\u59cb\u6570\u636e\u96c6<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X, y, test_size&#061;0.2, random_state&#061;42, stratify&#061;y)<\/p>\n<p># &#8212; 1. \u5728\u539f\u59cb\u4e0d\u5e73\u8861\u6570\u636e\u4e0a\u8bad\u7ec3 &#8212;<br \/>\nprint(&#034;&#8212; 1. \u8bad\u7ec3\u4e8e\u539f\u59cb\u4e0d\u5e73\u8861\u6570\u636e &#8212;&#034;)<br \/>\nlr_original &#061; LogisticRegression(solver&#061;&#039;liblinear&#039;)<br \/>\nlr_original.fit(X_train, y_train)<br \/>\ny_pred_original &#061; lr_original.predict(X_test)<br \/>\nprint(classification_report(y_test, y_pred_original, target_names&#061;[&#039;Normal&#039;, &#039;Fraud&#039;]))<\/p>\n<p># &#8212; 2. \u4f7f\u7528SMOTE\u5904\u7406\u6570\u636e\u5e76\u8bad\u7ec3 &#8212;<br \/>\nprint(&#034;\\\\n&#8212; 2. \u8bad\u7ec3\u4e8eSMOTE\u5904\u7406\u540e\u7684\u6570\u636e &#8212;&#034;)<br \/>\nsmote &#061; SMOTE(random_state&#061;42)<br \/>\nX_train_smote, y_train_smote &#061; smote.fit_resample(X_train, y_train)<\/p>\n<p>print(&#034;SMOTE\u5904\u7406\u540e\u8bad\u7ec3\u96c6\u7c7b\u522b\u5206\u5e03:&#034;)<br \/>\nprint(y_train_smote.value_counts())<\/p>\n<p>lr_smote &#061; LogisticRegression(solver&#061;&#039;liblinear&#039;)<br \/>\nlr_smote.fit(X_train_smote, y_train_smote)<br \/>\ny_pred_smote &#061; lr_smote.predict(X_test)<br \/>\nprint(classification_report(y_test, y_pred_smote, target_names&#061;[&#039;Normal&#039;, &#039;Fraud&#039;]))<\/p>\n<p>\u7ed3\u679c\u5206\u6790&#xff1a;<\/p>\n<ul>\n<li>\u5728\u539f\u59cb\u6570\u636e\u4e0a\u8bad\u7ec3\u7684\u6a21\u578b&#xff0c;\u5176\u5bf9\u6b3a\u8bc8\u7c7b&#xff08;Fraud&#xff09;\u7684**\u53ec\u56de\u7387&#xff08;recall&#xff09;**\u4f1a\u975e\u5e38\u4f4e&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u6f0f\u6389\u4e86\u5927\u91cf\u7684\u6b3a\u8bc8\u4ea4\u6613\u3002<\/li>\n<li>\u5728SMOTE\u5904\u7406\u8fc7\u7684\u6570\u636e\u4e0a\u8bad\u7ec3\u7684\u6a21\u578b&#xff0c;\u5176\u5bf9\u6b3a\u8bc8\u7c7b\u7684\u53ec\u56de\u7387\u4f1a\u663e\u8457\u63d0\u5347&#xff0c;\u4f46**\u7cbe\u786e\u7387&#xff08;precision&#xff09;**\u53ef\u80fd\u4f1a\u6709\u6240\u4e0b\u964d\u3002\u8fd9\u662f\u4e00\u79cd\u5178\u578b\u7684\u6743\u8861\u3002<\/li>\n<\/ul>\n<h5>10.3.3 \u7cbe\u8c03\u4e0e\u51b3\u7b56<\/h5>\n<p>\u4ec5\u4ec5\u5f97\u5230\u9884\u6d4b\u7c7b\u522b\u662f\u4e0d\u591f\u7684&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u5229\u7528\u9884\u6d4b\u6982\u7387\u6765\u505a\u66f4\u7cbe\u7ec6\u7684\u51b3\u7b56\u3002<\/p>\n<p>\u9608\u503c\u79fb\u52a8&#xff08;Threshold Moving&#xff09;\u00a0\u5927\u591a\u6570\u5206\u7c7b\u5668\u9ed8\u8ba4\u4f7f\u75280.5\u4f5c\u4e3a\u5206\u7c7b\u9608\u503c\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u8fd9\u4e2a\u9608\u503c&#xff0c;\u6765\u4e3b\u52a8\u5730\u5728\u7cbe\u786e\u7387\u548c\u53ec\u56de\u7387\u4e4b\u95f4\u8fdb\u884c\u6743\u8861\u3002<\/p>\n<p># \u83b7\u53d6SMOTE\u6a21\u578b\u5728\u6d4b\u8bd5\u96c6\u4e0a\u7684\u9884\u6d4b\u6982\u7387<br \/>\ny_proba_smote &#061; lr_smote.predict_proba(X_test)[:, 1]<\/p>\n<p># \u8ba1\u7b97PR\u66f2\u7ebf<br \/>\nprecision, recall, thresholds &#061; precision_recall_curve(y_test, y_proba_smote)<br \/>\nauc_pr &#061; auc(recall, precision)<\/p>\n<p># \u7ed8\u5236PR\u66f2\u7ebf<br \/>\nplt.figure(figsize&#061;(8, 6))<br \/>\nplt.plot(recall, precision, label&#061;f&#039;Logistic Regression (AUC-PR &#061; {auc_pr:.2f})&#039;)<br \/>\nplt.xlabel(&#039;Recall&#039;)<br \/>\nplt.ylabel(&#039;Precision&#039;)<br \/>\nplt.title(&#039;Precision-Recall Curve&#039;)<br \/>\nplt.legend(loc&#061;&#039;best&#039;)<br \/>\nplt.grid(True)<br \/>\nplt.show()<\/p>\n<p>\u901a\u8fc7\u89c2\u5bdfPR\u66f2\u7ebf&#xff0c;\u4e1a\u52a1\u51b3\u7b56\u8005\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u6700\u7b26\u5408\u4ed6\u4eec\u98ce\u9669\u504f\u597d\u7684\u70b9\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u94f6\u884c\u5bf9\u6f0f\u62a5\u7684\u5bb9\u5fcd\u5ea6\u6781\u4f4e&#xff0c;\u4ed6\u4eec\u53ef\u80fd\u4f1a\u9009\u62e9\u4e00\u4e2a\u9ad8\u53ec\u56de\u7387\u3001\u4e2d\u7b49\u7cbe\u786e\u7387\u7684\u9608\u503c\u70b9\u3002<\/p>\n<hr \/>\n<h4>10.4 \u89e3\u91ca\u6027\u5206\u6790&#xff1a;\u6a21\u578b\u4e3a\u4f55\u505a\u51fa\u8fd9\u6837\u7684\u51b3\u7b56&#xff1f;<\/h4>\n<p>\u4e00\u4e2a\u6a21\u578b\u5373\u4f7f\u8868\u73b0\u518d\u597d&#xff0c;\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u5b8c\u5168\u7684\u201c\u9ed1\u7bb1\u201d&#xff0c;\u5728\u91d1\u878d\u98ce\u63a7\u8fd9\u6837\u7684\u9ad8\u98ce\u9669\u9886\u57df\u4e5f\u5f88\u96be\u88ab\u5b8c\u5168\u4fe1\u4efb\u548c\u91c7\u7eb3\u3002\u6211\u4eec\u9700\u8981\u77e5\u9053\u6a21\u578b\u505a\u51fa\u51b3\u7b56\u7684\u4f9d\u636e\u3002<\/p>\n<h5>10.4.1 \u6a21\u578b\u53ef\u89e3\u91ca\u6027\u7684\u91cd\u8981\u6027<\/h5>\n<ul>\n<li>\u5efa\u7acb\u4fe1\u4efb&#xff1a;\u8ba9\u4e1a\u52a1\u4eba\u5458\u548c\u76d1\u7ba1\u673a\u6784\u76f8\u4fe1\u6a21\u578b\u662f\u53ef\u9760\u7684\u3002<\/li>\n<li>\u6a21\u578b\u8c03\u8bd5&#xff1a;\u7406\u89e3\u6a21\u578b\u7684\u9519\u8bef&#xff0c;\u53d1\u73b0\u5176\u51b3\u7b56\u903b\u8f91\u7684\u6f0f\u6d1e\u3002<\/li>\n<li>\u53d1\u73b0\u65b0\u77e5&#xff1a;\u4ece\u6a21\u578b\u7684\u51b3\u7b56\u6a21\u5f0f\u4e2d&#xff0c;\u53ef\u80fd\u4f1a\u53d1\u73b0\u4e00\u4e9b\u4eba\u7c7b\u4e13\u5bb6\u672a\u66fe\u6ce8\u610f\u5230\u7684\u6b3a\u8bc8\u6a21\u5f0f\u3002<\/li>\n<li>\u6ee1\u8db3\u5408\u89c4&#xff1a;\u5f88\u591a\u5730\u533a\u7684\u6cd5\u89c4&#xff08;\u5982GDPR&#xff09;\u8981\u6c42\u5bf9\u7b97\u6cd5\u51b3\u7b56\u7ed9\u51fa\u89e3\u91ca\u3002<\/li>\n<\/ul>\n<h5>10.4.2 SHAP&#xff08;SHapley Additive exPlanations&#xff09;\u7b80\u4ecb<\/h5>\n<p>SHAP\u662f\u4e00\u4e2a\u57fa\u4e8e\u535a\u5f08\u8bba\u4e2d\u6c99\u666e\u5229\u503c&#xff08;Shapley Value&#xff09;\u7684\u3001\u5f3a\u5927\u7684\u6a21\u578b\u89e3\u91ca\u6846\u67b6\u3002<\/p>\n<ul>\n<li>\u6838\u5fc3\u601d\u60f3&#xff1a;\u5b83\u5c06\u6a21\u578b\u7684\u5355\u6b21\u9884\u6d4b\u7ed3\u679c\u770b\u4f5c\u662f\u6240\u6709\u7279\u5f81\u5171\u540c\u534f\u4f5c\u5b8c\u6210\u7684\u201c\u6536\u76ca\u201d&#xff0c;\u800cSHAP\u503c\u5219\u516c\u5e73\u5730\u5c06\u8fd9\u4efd\u201c\u6536\u76ca\u201d&#xff08;\u5373\u9884\u6d4b\u503c\u4e0e\u57fa\u51c6\u503c\u7684\u5dee\u5f02&#xff09;\u5206\u914d\u7ed9\u6bcf\u4e00\u4e2a\u7279\u5f81&#xff0c;\u91cf\u5316\u4e86\u6bcf\u4e2a\u7279\u5f81\u7684\u8d21\u732e\u3002<\/li>\n<li>SHAP\u503c\u7684\u542b\u4e49&#xff1a;\u5bf9\u4e8e\u67d0\u4e2a\u9884\u6d4b&#xff0c;\u4e00\u4e2a\u7279\u5f81\u7684SHAP\u503c\u4e3a\u6b63&#xff0c;\u8868\u793a\u8be5\u7279\u5f81\u5c06\u9884\u6d4b\u63a8\u5411\u4e86\u6b63\u7c7b&#xff08;\u6b3a\u8bc8&#xff09;&#xff1b;\u4e3a\u8d1f&#xff0c;\u5219\u8868\u793a\u63a8\u5411\u4e86\u8d1f\u7c7b&#xff08;\u6b63\u5e38&#xff09;\u3002<\/li>\n<\/ul>\n<h5>10.4.3 \u4f7f\u7528SHAP\u8fdb\u884c\u6a21\u578b\u89e3\u91ca<\/h5>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528shap\u5e93\u6765\u89e3\u91ca\u6211\u4eec\u8bad\u7ec3\u7684LightGBM\u6216XGBoost\u6a21\u578b&#xff08;\u56e0\u4e3a\u5b83\u4eec\u901a\u5e38\u6027\u80fd\u66f4\u597d&#xff0c;\u4e5f\u66f4\u503c\u5f97\u89e3\u91ca&#xff09;\u3002<\/p>\n<p>pip install shap<\/p>\n<p>import lightgbm as lgb<br \/>\nimport shap<\/p>\n<p># \u5728SMOTE\u6570\u636e\u4e0a\u8bad\u7ec3\u4e00\u4e2aLightGBM\u6a21\u578b<br \/>\nlgbm &#061; lgb.LGBMClassifier(random_state&#061;42)<br \/>\nlgbm.fit(X_train_smote, y_train_smote)<\/p>\n<p># 1. \u521b\u5efaSHAP\u89e3\u91ca\u5668<br \/>\nexplainer &#061; shap.TreeExplainer(lgbm)<\/p>\n<p># 2. \u8ba1\u7b97\u6d4b\u8bd5\u96c6\u7684SHAP\u503c<br \/>\nshap_values &#061; explainer.shap_values(X_test)<\/p>\n<p># 3. \u5168\u5c40\u89e3\u91ca&#xff1a;\u7279\u5f81\u91cd\u8981\u6027\u56fe (Summary Plot)<br \/>\n# shap_values[1] \u5bf9\u5e94\u6b63\u7c7b&#xff08;\u6b3a\u8bc8&#xff09;\u7684SHAP\u503c<br \/>\nshap.summary_plot(shap_values[1], X_test, plot_type&#061;&#034;dot&#034;)<\/p>\n<p>Summary Plot\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u4e00\u884c\u4ee3\u8868\u4e00\u4e2a\u7279\u5f81&#xff0c;\u6309\u5176\u5168\u5c40\u91cd\u8981\u6027\u6392\u5e8f\u3002<\/li>\n<li>\u6bcf\u4e2a\u70b9\u4ee3\u8868\u4e00\u4e2a\u6837\u672c\u3002<\/li>\n<li>\u70b9\u7684\u989c\u8272\u8868\u793a\u8be5\u6837\u672c\u4e0a\u8be5\u7279\u5f81\u7684\u539f\u59cb\u503c&#xff08;\u7ea2\u8272\u9ad8&#xff0c;\u84dd\u8272\u4f4e&#xff09;\u3002<\/li>\n<li>\u70b9\u5728\u6a2a\u8f74\u4e0a\u7684\u4f4d\u7f6e\u8868\u793a\u8be5\u6837\u672c\u4e0a\u8be5\u7279\u5f81\u7684SHAP\u503c\u3002<\/li>\n<li>\u4ece\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230&#xff0c;\u4f8b\u5982&#xff0c;V14\u7279\u5f81\u503c\u8f83\u4f4e&#xff08;\u84dd\u8272&#xff09;\u65f6&#xff0c;\u5176SHAP\u503c\u4e3a\u6b63&#xff0c;\u5f3a\u70c8\u5730\u5c06\u9884\u6d4b\u63a8\u5411\u201c\u6b3a\u8bc8\u201d&#xff1b;\u800cV12\u7279\u5f81\u503c\u8f83\u9ad8&#xff08;\u7ea2\u8272&#xff09;\u65f6&#xff0c;\u5176SHAP\u503c\u4e3a\u8d1f&#xff0c;\u5c06\u9884\u6d4b\u63a8\u5411\u201c\u6b63\u5e38\u201d\u3002<\/li>\n<\/ul>\n<p>\u4e2a\u4f53\u89e3\u91ca&#xff1a;\u529b\u56fe&#xff08;Force Plot&#xff09;\u00a0\u6211\u4eec\u8fd8\u53ef\u4ee5\u5bf9\u5355\u4e2a\u9884\u6d4b\u8fdb\u884c\u89e3\u91ca\u3002<\/p>\n<p># \u89e3\u91ca\u7b2c\u4e00\u4e2a\u6d4b\u8bd5\u6837\u672c<br \/>\nshap.initjs() # \u521d\u59cb\u5316JS\u73af\u5883\u4ee5\u4fbf\u5728notebook\u4e2d\u7ed8\u56fe<br \/>\nshap.force_plot(explainer.expected_value[1], shap_values[1][0,:], X_test.iloc[0,:])<\/p>\n<p>Force Plot\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u51c6\u503c&#xff08;base value&#xff09;&#xff1a;\u662f\u6a21\u578b\u5728\u6574\u4e2a\u6570\u636e\u96c6\u4e0a\u7684\u5e73\u5747\u9884\u6d4b\u6982\u7387\u3002<\/li>\n<li>\u7ea2\u8272\u90e8\u5206&#xff1a;\u662f\u5c06\u9884\u6d4b\u6982\u7387\u63a8\u9ad8\u7684\u7279\u5f81\u3002<\/li>\n<li>\u84dd\u8272\u90e8\u5206&#xff1a;\u662f\u5c06\u9884\u6d4b\u6982\u7387\u62c9\u4f4e\u7684\u7279\u5f81\u3002<\/li>\n<li>\u8fd9\u4e2a\u56fe\u6e05\u6670\u5730\u5c55\u793a\u4e86\u5bf9\u4e8e\u8fd9\u4e00\u4e2a\u7279\u5b9a\u7684\u4ea4\u6613&#xff0c;\u662f\u54ea\u4e9b\u7279\u5f81\u4ee5\u53ca\u5b83\u4eec\u7684\u53d6\u503c&#xff0c;\u5171\u540c\u4f5c\u7528\u5bfc\u81f4\u4e86\u6700\u7ec8\u7684\u9884\u6d4b\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u5b9e\u6218\u9879\u76ee&#xff0c;\u6211\u4eec\u8d70\u5b8c\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6570\u636e\u79d1\u5b66\u6d41\u7a0b\u3002\u6211\u4eec\u4ece\u7406\u89e3\u4e00\u4e2a\u5145\u6ee1\u6311\u6218\u7684\u4e1a\u52a1\u95ee\u9898\u5f00\u59cb&#xff0c;\u901a\u8fc7\u7ec6\u81f4\u7684\u6570\u636e\u63a2\u7d22\u53d1\u73b0\u4e86\u6838\u5fc3\u96be\u70b9\u2014\u2014\u7c7b\u522b\u4e0d\u5e73\u8861\u3002\u6211\u4eec\u5b66\u4e60\u5e76\u5e94\u7528\u4e86SMOTE\u6280\u672f\u6765\u5904\u7406\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u5e76\u9009\u62e9\u4e86\u5408\u9002\u7684\u8bc4\u4f30\u6307\u6807\u6765\u516c\u6b63\u5730\u8bc4\u4ef7\u6211\u4eec\u7684\u6a21\u578b\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u8fd8\u5229\u7528SHAP\u8fd9\u4e00\u5f3a\u5927\u5de5\u5177&#xff0c;\u6253\u5f00\u4e86\u6a21\u578b\u7684\u201c\u9ed1\u7bb1\u201d&#xff0c;\u7aa5\u63a2\u4e86\u5176\u51b3\u7b56\u7684\u5185\u5728\u903b\u8f91\u3002<\/p>\n<p>\u8fd9\u4e0d\u4ec5\u4ec5\u662f\u4e00\u6b21\u6280\u672f\u7684\u6f14\u7ec3&#xff0c;\u66f4\u662f\u4e00\u6b21\u601d\u7ef4\u7684\u5347\u534e\u3002\u60a8\u73b0\u5728\u6240\u638c\u63e1\u7684&#xff0c;\u5df2\u7ecf\u4e0d\u518d\u662f\u96f6\u6563\u7684\u77e5\u8bc6\u70b9&#xff0c;\u800c\u662f\u4e00\u5957\u53ef\u4ee5\u8fc1\u79fb\u5230\u5176\u4ed6\u9886\u57df\u7684\u3001\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u7684\u5b8c\u6574\u65b9\u6cd5\u8bba\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u5341\u4e00\u7ae0&#xff1a;\u5b9e\u6218\u9879\u76ee\u4e8c&#xff1a;\u81ea\u7136\u8bed\u8a00\u5904\u7406\u2014\u2014\u6587\u672c\u60c5\u611f\u5206\u6790<\/h3>\n<ul>\n<li>11.1 \u6587\u672c\u6570\u636e\u7684\u9884\u5904\u7406&#xff1a;\u5206\u8bcd\u3001\u505c\u7528\u8bcd\u4e0e\u5411\u91cf\u5316&#xff08;TF-IDF, Word2Vec&#xff09;<\/li>\n<li>11.2 \u4ece\u4f20\u7edf\u6a21\u578b\u5230\u7b80\u5355\u795e\u7ecf\u7f51\u7edc\u7684\u60c5\u611f\u5206\u7c7b<\/li>\n<li>11.3 \u4e3b\u9898\u6a21\u578b&#xff08;LDA&#xff09;&#xff1a;\u6316\u6398\u6587\u672c\u80cc\u540e\u7684\u9690\u85cf\u4e3b\u9898<\/li>\n<\/ul>\n<p>\u5728\u5b8c\u6210\u4e86\u5bf9\u7ed3\u6784\u5316\u6570\u5b57\u4e16\u754c\u7684\u63a2\u7d22\u4e4b\u540e&#xff0c;\u6211\u4eec\u7684\u5b9e\u6218\u65c5\u7a0b\u5c06\u8f6c\u5411\u4e00\u4e2a\u66f4\u8d34\u8fd1\u4eba\u7c7b\u667a\u6167\u6838\u5fc3\u7684\u9886\u57df\u2014\u2014\u81ea\u7136\u8bed\u8a00\u5904\u7406&#xff08;Natural Language Processing, NLP&#xff09;\u3002\u672c\u9879\u76ee\u4e2d&#xff0c;\u6211\u4eec\u5c06\u6311\u6218\u4e00\u4e2aNLP\u4e2d\u6700\u7ecf\u5178\u3001\u4e5f\u6700\u5177\u5546\u4e1a\u4ef7\u503c\u7684\u4efb\u52a1\u4e4b\u4e00&#xff1a;\u6587\u672c\u60c5\u611f\u5206\u6790&#xff08;Sentiment Analysis&#xff09;\u3002<\/p>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f\u6559\u4f1a\u673a\u5668\u53bb\u201c\u9605\u8bfb\u201d\u4e00\u6bb5\u6587\u672c&#xff08;\u4f8b\u5982\u4e00\u6761\u7535\u5f71\u8bc4\u8bba\u3001\u4e00\u6761\u4ea7\u54c1\u53cd\u9988&#xff09;&#xff0c;\u5e76\u5224\u65ad\u5176\u4e2d\u8574\u542b\u7684\u60c5\u611f\u662f\u79ef\u6781\u7684\u3001\u6d88\u6781\u7684\u8fd8\u662f\u4e2d\u6027\u7684\u3002\u8fd9\u9879\u6280\u672f\u662f\u6784\u5efa\u667a\u80fd\u5ba2\u670d\u3001\u8fdb\u884c\u8206\u60c5\u76d1\u63a7\u3001\u5206\u6790\u7528\u6237\u53cd\u9988\u7b49\u4f17\u591a\u5e94\u7528\u7684\u6838\u5fc3\u3002<\/p>\n<p>\u4e0e\u4e0a\u4e00\u4e2a\u9879\u76ee\u4e0d\u540c&#xff0c;\u6211\u4eec\u8fd9\u6b21\u9762\u5bf9\u7684\u4e0d\u518d\u662f\u6574\u9f50\u7684\u3001\u6570\u503c\u5316\u7684\u6570\u636e&#xff0c;\u800c\u662f\u7531\u8bcd\u8bed\u3001\u53e5\u5b50\u548c\u6bb5\u843d\u7ec4\u6210\u7684\u975e\u7ed3\u6784\u5316\u6587\u672c\u3002\u56e0\u6b64&#xff0c;\u672c\u7ae0\u7684\u91cd\u70b9\u5c06\u9996\u5148\u805a\u7126\u4e8e\u5982\u4f55\u5c06\u8fd9\u4e9b\u4eba\u7c7b\u8bed\u8a00\u201c\u7ffb\u8bd1\u201d\u6210\u673a\u5668\u80fd\u591f\u7406\u89e3\u7684\u6570\u5b66\u8bed\u8a00\u2014\u2014\u5373\u6587\u672c\u5411\u91cf\u5316\u3002\u6211\u4eec\u5c06\u63a2\u7d22\u4ece\u7ecf\u5178\u7684TF-IDF\u5230\u66f4\u73b0\u4ee3\u7684Word2Vec\u8bcd\u5d4c\u5165\u6280\u672f\u3002<\/p>\n<p>\u968f\u540e&#xff0c;\u6211\u4eec\u5c06\u5206\u522b\u4f7f\u7528\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6a21\u578b\u548c\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\u6765\u6784\u5efa\u60c5\u611f\u5206\u7c7b\u5668&#xff0c;\u5e76\u6bd4\u8f83\u5b83\u4eec\u7684\u6027\u80fd\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u8fd8\u5c06\u5b66\u4e60\u4e00\u79cd\u5f3a\u5927\u7684\u65e0\u76d1\u7763\u6280\u672f\u2014\u2014\u4e3b\u9898\u6a21\u578b&#xff08;LDA&#xff09;&#xff0c;\u5b83\u80fd\u5e2e\u52a9\u6211\u4eec\u81ea\u52a8\u5730\u4ece\u6d77\u91cf\u6587\u672c\u4e2d\u6316\u6398\u51fa\u4eba\u4eec\u6b63\u5728\u8ba8\u8bba\u7684\u6838\u5fc3\u8bdd\u9898&#xff0c;\u4e3a\u6211\u4eec\u63d0\u4f9b\u8d85\u8d8a\u60c5\u611f\u5206\u7c7b\u7684\u66f4\u6df1\u5c42\u6b21\u6d1e\u5bdf\u3002<\/p>\n<hr \/>\n<h4>11.1 \u6587\u672c\u6570\u636e\u7684\u9884\u5904\u7406&#xff1a;\u5206\u8bcd\u3001\u505c\u7528\u8bcd\u4e0e\u5411\u91cf\u5316<\/h4>\n<p>\u5728NLP\u4e2d&#xff0c;\u539f\u59cb\u6587\u672c\u6570\u636e\u5f80\u5f80\u662f\u201c\u5608\u6742\u201d\u7684&#xff0c;\u9700\u8981\u7ecf\u8fc7\u4e00\u7cfb\u5217\u7cbe\u5fc3\u7684\u9884\u5904\u7406\u548c\u8f6c\u6362&#xff0c;\u624d\u80fd\u88ab\u673a\u5668\u5b66\u4e60\u6a21\u578b\u6240\u7528\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u7684\u597d\u574f&#xff0c;\u76f4\u63a5\u51b3\u5b9a\u4e86\u6574\u4e2a\u9879\u76ee\u7684\u6210\u8d25\u3002<\/p>\n<h5>11.1.1 NLP\u7684\u7b2c\u4e00\u6b65&#xff1a;\u6587\u672c\u6e05\u6d17\u4e0e\u89c4\u8303\u5316<\/h5>\n<p>\u6211\u4eec\u5c06\u4ee5\u4e00\u4e2aIMDb\u7535\u5f71\u8bc4\u8bba\u6570\u636e\u96c6\u4e3a\u4f8b&#xff0c;\u8fd9\u4e2a\u6570\u636e\u96c6\u4e2d\u5305\u542b\u4e865\u4e07\u6761\u5e26\u6709\u6b63\u9762\u6216\u8d1f\u9762\u6807\u7b7e\u7684\u7535\u5f71\u8bc4\u8bba\u3002<\/p>\n<p>\u6570\u636e\u52a0\u8f7d\u4e0e\u6e05\u6d17\u6d41\u7a0b<\/p>\n<p>import pandas as pd<br \/>\nimport re<\/p>\n<p># \u5047\u8bbe\u6570\u636e\u5df2\u52a0\u8f7d\u5230DataFrame df \u4e2d&#xff0c;\u5305\u542b &#039;review&#039; \u548c &#039;sentiment&#039; \u4e24\u5217<br \/>\n# df &#061; pd.read_csv(&#039;IMDB_Dataset.csv&#039;)<\/p>\n<p># \u793a\u4f8b\u6570\u636e<br \/>\ndata &#061; {&#039;review&#039;: [&#034;This movie was awesome! The acting was great.&#034;,<br \/>\n                   &#034;A truly TERRIBLE film. 1\/10. Don&#039;t waste your time.&#034;,<br \/>\n                   &#034;&lt;br \/&gt;&lt;br \/&gt;What a masterpiece!&#034;],<br \/>\n        &#039;sentiment&#039;: [&#039;positive&#039;, &#039;negative&#039;, &#039;positive&#039;]}<br \/>\ndf &#061; pd.DataFrame(data)<\/p>\n<p>def clean_text(text):<br \/>\n    # 1. \u8f6c\u6362\u4e3a\u5c0f\u5199<br \/>\n    text &#061; text.lower()<br \/>\n    # 2. \u79fb\u9664HTML\u6807\u7b7e<br \/>\n    text &#061; re.sub(r&#039;&lt;.*?&gt;&#039;, &#039;&#039;, text)<br \/>\n    # 3. \u79fb\u9664\u6807\u70b9\u7b26\u53f7\u548c\u6570\u5b57<br \/>\n    text &#061; re.sub(r&#039;[^a-z\\\\s]&#039;, &#039;&#039;, text)<br \/>\n    # 4. \u79fb\u9664\u591a\u4f59\u7684\u7a7a\u683c<br \/>\n    text &#061; re.sub(r&#039;\\\\s&#043;&#039;, &#039; &#039;, text).strip()<br \/>\n    return text<\/p>\n<p>df[&#039;cleaned_review&#039;] &#061; df[&#039;review&#039;].apply(clean_text)<br \/>\nprint(df[[&#039;review&#039;, &#039;cleaned_review&#039;]])<\/p>\n<h5>11.1.2 \u5206\u8bcd&#xff08;Tokenization&#xff09;\u4e0e\u505c\u7528\u8bcd&#xff08;Stop Words&#xff09;<\/h5>\n<p>\u6e05\u6d17\u5b8c\u6210\u540e&#xff0c;\u6211\u4eec\u9700\u8981\u5c06\u8fde\u7eed\u7684\u6587\u672c\u5207\u5206\u6210\u72ec\u7acb\u7684\u5355\u5143&#xff0c;\u5373\u201c\u8bcd\u5143\u201d&#xff08;Token&#xff09;\u3002<\/p>\n<ul>\n<li>\u5206\u8bcd&#xff1a;\u5bf9\u4e8e\u82f1\u6587&#xff0c;\u5206\u8bcd\u76f8\u5bf9\u7b80\u5355&#xff0c;\u901a\u5e38\u6309\u7a7a\u683c\u548c\u6807\u70b9\u6765\u5207\u5206\u3002\u5bf9\u4e8e\u4e2d\u6587\u7b49\u6ca1\u6709\u660e\u786e\u5355\u8bcd\u8fb9\u754c\u7684\u8bed\u8a00&#xff0c;\u5219\u9700\u8981\u4f7f\u7528\u4e13\u95e8\u7684\u5206\u8bcd\u7b97\u6cd5\u5e93&#xff08;\u5982jieba&#xff09;\u3002<\/li>\n<li>\u505c\u7528\u8bcd&#xff1a;\u6587\u672c\u4e2d\u6709\u5f88\u591a\u8bcd&#xff0c;\u5982\u201ca\u201d, \u201cthe\u201d, \u201cis\u201d, \u201cin\u201d\u7b49&#xff0c;\u5b83\u4eec\u9891\u7e41\u51fa\u73b0\u4f46\u51e0\u4e4e\u4e0d\u643a\u5e26\u4efb\u4f55\u60c5\u611f\u4fe1\u606f\u3002\u8fd9\u4e9b\u8bcd\u88ab\u79f0\u4e3a\u201c\u505c\u7528\u8bcd\u201d&#xff0c;\u901a\u5e38\u9700\u8981\u88ab\u79fb\u9664&#xff0c;\u4ee5\u51cf\u5c11\u566a\u58f0\u548c\u8ba1\u7b97\u91cf\u3002<\/li>\n<\/ul>\n<p>import nltk<br \/>\n# nltk.download(&#039;stopwords&#039;) # \u9996\u6b21\u4f7f\u7528\u9700\u8981\u4e0b\u8f7d<br \/>\n# nltk.download(&#039;punkt&#039;)<br \/>\nfrom nltk.corpus import stopwords<br \/>\nfrom nltk.tokenize import word_tokenize<\/p>\n<p>stop_words &#061; set(stopwords.words(&#039;english&#039;))<\/p>\n<p>def tokenize_and_remove_stopwords(text):<br \/>\n    tokens &#061; word_tokenize(text)<br \/>\n    filtered_tokens &#061; [word for word in tokens if word not in stop_words]<br \/>\n    return filtered_tokens<\/p>\n<p>df[&#039;tokens&#039;] &#061; df[&#039;cleaned_review&#039;].apply(tokenize_and_remove_stopwords)<br \/>\nprint(&#034;\\\\n\u5206\u8bcd\u4e0e\u79fb\u9664\u505c\u7528\u8bcd\u540e:&#034;)<br \/>\nprint(df[[&#039;cleaned_review&#039;, &#039;tokens&#039;]])<\/p>\n<h5>11.1.3 \u5c06\u6587\u672c\u8f6c\u5316\u4e3a\u5411\u91cf&#xff1a;\u4ece\u8bcd\u888b\u5230\u8bcd\u5d4c\u5165<\/h5>\n<p>\u8fd9\u662f\u6700\u5173\u952e\u7684\u4e00\u6b65&#xff1a;\u5c06\u8bcd\u5143\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u503c\u5411\u91cf\u3002<\/p>\n<p>TF-IDF&#xff08;Term Frequency-Inverse Document Frequency&#xff09;\u00a0TF-IDF\u662f\u8bcd\u888b\u6a21\u578b&#xff08;BoW&#xff09;\u7684\u4e00\u79cd\u7ecf\u5178\u5347\u7ea7\u3002\u5b83\u8ba4\u4e3a\u4e00\u4e2a\u8bcd\u7684\u91cd\u8981\u6027\u4e0e\u5b83\u5728**\u5f53\u524d\u6587\u6863\u4e2d\u51fa\u73b0\u7684\u9891\u7387&#xff08;TF&#xff09;\u6210\u6b63\u6bd4&#xff0c;\u4e0e\u5b83\u5728\u6240\u6709\u6587\u6863\u4e2d\u51fa\u73b0\u7684\u9891\u7387&#xff08;IDF&#xff09;**\u6210\u53cd\u6bd4\u3002\u4e00\u4e2a\u8bcd\u5728\u5f53\u524d\u6587\u6863\u91cc\u51fa\u73b0\u6b21\u6570\u591a&#xff0c;\u4f46\u5728\u5176\u4ed6\u6587\u6863\u91cc\u5f88\u5c11\u51fa\u73b0&#xff0c;\u90a3\u4e48\u5b83\u5f88\u53ef\u80fd\u5c31\u662f\u5f53\u524d\u6587\u6863\u7684\u5173\u952e\u8bcd&#xff0c;\u5e94\u8be5\u88ab\u8d4b\u4e88\u9ad8\u6743\u91cd\u3002<\/p>\n<p>from sklearn.feature_extraction.text import TfidfVectorizer<\/p>\n<p># \u4e3a\u4e86\u4f7f\u7528TfidfVectorizer&#xff0c;\u6211\u4eec\u9700\u8981\u5c06\u8bcd\u5143\u5217\u8868\u91cd\u65b0\u7ec4\u5408\u6210\u5b57\u7b26\u4e32<br \/>\ndf[&#039;processed_text&#039;] &#061; df[&#039;tokens&#039;].apply(lambda x: &#039; &#039;.join(x))<\/p>\n<p>tfidf_vectorizer &#061; TfidfVectorizer(max_features&#061;5000) # \u9650\u5236\u6700\u5927\u7279\u5f81\u6570\u4e3a5000<br \/>\nX_tfidf &#061; tfidf_vectorizer.fit_transform(df[&#039;processed_text&#039;])<\/p>\n<p>print(&#034;\\\\nTF-IDF\u5411\u91cf\u7684\u7ef4\u5ea6:&#034;)<br \/>\nprint(X_tfidf.shape) # (\u6587\u6863\u6570, \u7279\u5f81\u6570)<br \/>\n# \u8fd9\u662f\u4e00\u4e2a\u7a00\u758f\u77e9\u9635<\/p>\n<p>\u8bcd\u5d4c\u5165&#xff08;Word Embeddings&#xff09;\u00a0TF-IDF\u867d\u7136\u7ecf\u5178&#xff0c;\u4f46\u5b83\u6709\u4e00\u4e2a\u91cd\u5927\u7f3a\u9677&#xff1a;\u5b83\u65e0\u6cd5\u7406\u89e3\u8bcd\u4e0e\u8bcd\u4e4b\u95f4\u7684\u8bed\u4e49\u5173\u7cfb\u3002\u5728TF-IDF\u770b\u6765&#xff0c;\u201cgood\u201d, \u201cexcellent\u201d, \u201csuperb\u201d\u662f\u4e09\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684\u3001\u6beb\u65e0\u5173\u8054\u7684\u8bcd\u3002<\/p>\n<p>\u8bcd\u5d4c\u5165\u6280\u672f\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<ul>\n<li>\u6838\u5fc3\u601d\u60f3&#xff1a;\u5b83\u5c06\u6bcf\u4e2a\u8bcd\u6620\u5c04\u5230\u4e00\u4e2a\u4f4e\u7ef4&#xff08;\u5982100\u7ef4\u6216300\u7ef4&#xff09;\u3001\u7a20\u5bc6\u7684\u6d6e\u70b9\u6570\u5411\u91cf\u3002\u8fd9\u4e2a\u6620\u5c04\u662f\u901a\u8fc7\u5728\u5927\u91cf\u6587\u672c\u4e0a\u8bad\u7ec3\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc\u6765\u5b66\u4e60\u7684&#xff0c;\u5176\u5b66\u4e60\u76ee\u6807\u662f\u8ba9\u4e0a\u4e0b\u6587\u76f8\u4f3c\u7684\u8bcd&#xff0c;\u5176\u5bf9\u5e94\u7684\u5411\u91cf\u5728\u5411\u91cf\u7a7a\u95f4\u4e2d\u4e5f\u76f8\u4e92\u9760\u8fd1\u3002\u4f8b\u5982&#xff0c;\u201cking\u201d\u7684\u5411\u91cf\u4f1a\u548c\u201cqueen\u201d\u7684\u5411\u91cf\u5f88\u63a5\u8fd1\u3002<\/li>\n<li>Word2Vec&#xff1a;\u662fGoogle\u57282013\u5e74\u63a8\u51fa\u7684\u4e00\u4e2a\u91cc\u7a0b\u7891\u5f0f\u7684\u8bcd\u5d4c\u5165\u6a21\u578b\u3002\u5b83\u6709\u4e24\u79cd\u4e3b\u8981\u7684\u8bad\u7ec3\u7b97\u6cd5&#xff1a;\n<ul>\n<li>CBOW (Continuous Bag-of-Words)&#xff1a;\u6839\u636e\u4e0a\u4e0b\u6587\u8bcd\u6765\u9884\u6d4b\u4e2d\u5fc3\u8bcd\u3002<\/li>\n<li>Skip-gram&#xff1a;\u6839\u636e\u4e2d\u5fc3\u8bcd\u6765\u9884\u6d4b\u4e0a\u4e0b\u6587\u8bcd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4f7f\u7528\u9884\u8bad\u7ec3\u6a21\u578b&#xff1a;\u8bad\u7ec3\u4e00\u4e2a\u9ad8\u8d28\u91cf\u7684Word2Vec\u6a21\u578b\u9700\u8981\u6d77\u91cf\u7684\u6587\u672c\u548c\u5de8\u5927\u7684\u8ba1\u7b97\u8d44\u6e90\u3002\u5e78\u8fd0\u7684\u662f&#xff0c;\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Google\u3001Facebook\u7b49\u673a\u6784\u5728\u5927\u89c4\u6a21\u8bed\u6599\u5e93&#xff08;\u5982\u7ef4\u57fa\u767e\u79d1\u3001\u65b0\u95fb\u6587\u7ae0&#xff09;\u4e0a\u8bad\u7ec3\u597d\u7684\u9884\u8bad\u7ec3\u8bcd\u5d4c\u5165\u6a21\u578b\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>11.2 \u4ece\u4f20\u7edf\u6a21\u578b\u5230\u7b80\u5355\u795e\u7ecf\u7f51\u7edc\u7684\u60c5\u611f\u5206\u7c7b<\/h4>\n<p>\u73b0\u5728\u6211\u4eec\u6709\u4e86\u4e24\u79cd\u5c06\u6587\u672c\u8868\u793a\u4e3a\u5411\u91cf\u7684\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u5f00\u59cb\u6784\u5efa\u5206\u7c7b\u6a21\u578b\u4e86\u3002<\/p>\n<h5>11.2.1 \u4f7f\u7528TF-IDF\u4e0e\u4f20\u7edf\u673a\u5668\u5b66\u4e60\u6a21\u578b<\/h5>\n<p>TF-IDF\u4ea7\u751f\u7684\u9ad8\u7ef4\u7a00\u758f\u5411\u91cf&#xff0c;\u4e0e\u903b\u8f91\u56de\u5f52\u3001\u6734\u7d20\u8d1d\u53f6\u65af\u7b49\u7ebf\u6027\u6a21\u578b\u662f\u201c\u5929\u4f5c\u4e4b\u5408\u201d\u3002<\/p>\n<p>from sklearn.model_selection import train_test_split<br \/>\nfrom sklearn.linear_model import LogisticRegression<br \/>\nfrom sklearn.metrics import classification_report<br \/>\nfrom sklearn.preprocessing import LabelEncoder<\/p>\n<p># \u51c6\u5907\u6807\u7b7e<br \/>\nle &#061; LabelEncoder()<br \/>\ny &#061; le.fit_transform(df[&#039;sentiment&#039;])<\/p>\n<p># \u5212\u5206\u6570\u636e<br \/>\nX_train, X_test, y_train, y_test &#061; train_test_split(X_tfidf, y, test_size&#061;0.2, random_state&#061;42)<\/p>\n<p># \u8bad\u7ec3\u903b\u8f91\u56de\u5f52\u6a21\u578b<br \/>\nlr_model &#061; LogisticRegression(solver&#061;&#039;liblinear&#039;, random_state&#061;42)<br \/>\nlr_model.fit(X_train, y_train)<\/p>\n<p># \u8bc4\u4f30<br \/>\ny_pred &#061; lr_model.predict(X_test)<br \/>\nprint(&#034;&#8212; TF-IDF &#043; \u903b\u8f91\u56de\u5f52 \u6a21\u578b\u8bc4\u4f30 &#8212;&#034;)<br \/>\n# \u7531\u4e8e\u6211\u4eec\u7684\u793a\u4f8b\u6570\u636e\u592a\u5c11&#xff0c;\u8fd9\u91cc\u53ea\u5c55\u793a\u6d41\u7a0b&#xff0c;\u771f\u5b9e\u6570\u636e\u96c6\u4e0a\u624d\u80fd\u770b\u5230\u6709\u610f\u4e49\u7684\u7ed3\u679c<br \/>\n# print(classification_report(y_test, y_pred, target_names&#061;le.classes_))<br \/>\nprint(&#034;\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u3002\u5728\u771f\u5b9e\u6570\u636e\u96c6\u4e0a&#xff0c;\u6b64\u65b9\u6cd5\u901a\u5e38\u80fd\u83b7\u5f97\u975e\u5e38\u597d\u7684\u57fa\u7ebf\u6027\u80fd\u3002&#034;)<\/p>\n<h5>11.2.2 \u4f7f\u7528Word2Vec\u4e0e\u795e\u7ecf\u7f51\u7edc<\/h5>\n<p>\u4f7f\u7528\u8bcd\u5d4c\u5165\u65f6&#xff0c;\u6211\u4eec\u9700\u8981\u5148\u5c06\u4e00\u6761\u8bc4\u8bba\u4e2d\u7684\u6240\u6709\u8bcd\u5411\u91cf\u805a\u5408\u6210\u4e00\u4e2a\u80fd\u4ee3\u8868\u6574\u6761\u8bc4\u8bba\u7684\u53e5\u5b50\u5411\u91cf\u3002\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u53d6\u5e73\u5747\u503c\u3002<\/p>\n<p># \u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u52a0\u8f7d\u4e86\u4e00\u4e2a\u9884\u8bad\u7ec3\u7684Word2Vec\u6a21\u578b (\u4f8b\u5982 gensim.models.KeyedVectors.load_word2vec_format)<br \/>\n# word2vec_model &#061; &#8230;<br \/>\n# embedding_dim &#061; word2vec_model.vector_size<\/p>\n<p># \u6b64\u5904\u4e3a\u6f14\u793a&#xff0c;\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5047\u7684Word2Vec\u6a21\u578b<br \/>\nembedding_dim &#061; 100<br \/>\nvocab &#061; set(word for tokens_list in df[&#039;tokens&#039;] for word in tokens_list)<br \/>\nword2vec_model &#061; {word: np.random.rand(embedding_dim) for word in vocab}<\/p>\n<p>def sentence_to_vector(tokens, model, embedding_dim):<br \/>\n    # \u5c06\u53e5\u5b50\u4e2d\u6240\u6709\u8bcd\u7684\u5411\u91cf\u76f8\u52a0&#xff0c;\u7136\u540e\u9664\u4ee5\u8bcd\u6570<br \/>\n    vectors &#061; [model[word] for word in tokens if word in model]<br \/>\n    if not vectors:<br \/>\n        return np.zeros(embedding_dim)<br \/>\n    return np.mean(vectors, axis&#061;0)<\/p>\n<p># \u4e3a\u6bcf\u6761\u8bc4\u8bba\u521b\u5efa\u53e5\u5b50\u5411\u91cf<br \/>\nX_w2v &#061; np.array([sentence_to_vector(tokens, word2vec_model, embedding_dim) for tokens in df[&#039;tokens&#039;]])<\/p>\n<p>print(&#034;\\\\nWord2Vec\u53e5\u5b50\u5411\u91cf\u7684\u7ef4\u5ea6:&#034;)<br \/>\nprint(X_w2v.shape)<\/p>\n<p># \u5212\u5206\u6570\u636e<br \/>\nX_train_w2v, X_test_w2v, y_train_w2v, y_test_w2v &#061; train_test_split(X_w2v, y, test_size&#061;0.2, random_state&#061;42)<\/p>\n<p># \u4f7f\u7528Keras\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684MLP<br \/>\nimport tensorflow as tf<br \/>\nfrom tensorflow import keras<\/p>\n<p>model &#061; keras.Sequential([<br \/>\n    keras.layers.Dense(64, activation&#061;&#039;relu&#039;, input_shape&#061;(embedding_dim,)),<br \/>\n    keras.layers.Dropout(0.5), # Dropout\u5c42\u7528\u4e8e\u9632\u6b62\u8fc7\u62df\u5408<br \/>\n    keras.layers.Dense(1, activation&#061;&#039;sigmoid&#039;) # \u4e8c\u5206\u7c7b\u8f93\u51fa<br \/>\n])<\/p>\n<p>model.compile(optimizer&#061;&#039;adam&#039;,<br \/>\n              loss&#061;&#039;binary_crossentropy&#039;,<br \/>\n              metrics&#061;[&#039;accuracy&#039;])<\/p>\n<p># \u8bad\u7ec3<br \/>\n# model.fit(X_train_w2v, y_train_w2v, epochs&#061;10, batch_size&#061;32, validation_split&#061;0.1)<br \/>\nprint(&#034;\\\\n&#8212; Word2Vec &#043; \u795e\u7ecf\u7f51\u7edc \u6a21\u578b &#8212;&#034;)<br \/>\nprint(&#034;\u6a21\u578b\u6784\u5efa\u5b8c\u6210\u3002\u8fd9\u79cd\u65b9\u6cd5\u80fd\u6355\u6349\u8bcd\u6c47\u7684\u8bed\u4e49\u4fe1\u606f&#xff0c;\u5728\u66f4\u590d\u6742\u7684NLP\u4efb\u52a1\u4e2d\u6f5c\u529b\u5de8\u5927\u3002&#034;)<\/p>\n<p>\u6027\u80fd\u5bf9\u6bd4&#xff1a;\u5728\u7b80\u5355\u7684\u60c5\u611f\u5206\u6790\u4efb\u52a1\u4e2d&#xff0c;\u7cbe\u5fc3\u8c03\u4f18\u7684TF-IDF&#043;\u903b\u8f91\u56de\u5f52\u6a21\u578b\u6709\u65f6\u751a\u81f3\u4e0d\u8f93\u4e8e\u7b80\u5355\u7684\u795e\u7ecf\u7f51\u7edc\u3002\u4f46\u8bcd\u5d4c\u5165&#043;\u795e\u7ecf\u7f51\u7edc\u7684\u67b6\u6784\u5177\u6709\u66f4\u5f3a\u7684\u6269\u5c55\u6027&#xff0c;\u662f\u901a\u5f80\u66f4\u9ad8\u7ea7NLP\u6a21\u578b&#xff08;\u5982RNN\u3001LSTM\u3001Transformer&#xff09;\u7684\u5fc5\u7ecf\u4e4b\u8def\u3002<\/p>\n<hr \/>\n<h4>11.3 \u4e3b\u9898\u6a21\u578b&#xff08;LDA&#xff09;&#xff1a;\u6316\u6398\u6587\u672c\u80cc\u540e\u7684\u9690\u85cf\u4e3b\u9898<\/h4>\n<p>\u60c5\u611f\u5206\u6790\u544a\u8bc9\u6211\u4eec\u4eba\u4eec\u7684\u8bc4\u4ef7\u662f\u201c\u597d\u201d\u662f\u201c\u574f\u201d&#xff0c;\u4f46\u6211\u4eec\u8fd8\u60f3\u77e5\u9053&#xff0c;\u4ed6\u4eec\u5230\u5e95\u5728\u8ba8\u8bba\u4ec0\u4e48&#xff1f;<\/p>\n<h5>11.3.1 \u65e0\u76d1\u7763\u7684\u63a2\u7d22&#xff1a;\u4ec0\u4e48\u662f\u4e3b\u9898\u6a21\u578b&#xff1f;<\/h5>\n<p>\u4e3b\u9898\u6a21\u578b\u662f\u4e00\u79cd\u65e0\u76d1\u7763\u5b66\u4e60\u6280\u672f&#xff0c;\u5b83\u80fd\u5728\u4e0d\u77e5\u9053\u4efb\u4f55\u6807\u7b7e\u7684\u60c5\u51b5\u4e0b&#xff0c;\u81ea\u52a8\u5730\u4ece\u5927\u91cf\u6587\u6863\u4e2d\u53d1\u73b0\u9690\u85cf\u7684\u201c\u4e3b\u9898\u201d\u7ed3\u6784\u3002<\/p>\n<ul>\n<li>LDA&#xff08;Latent Dirichlet Allocation&#xff09;\u00a0\u662f\u6700\u8457\u540d\u7684\u4e3b\u9898\u6a21\u578b\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u975e\u5e38\u7b26\u5408\u76f4\u89c9&#xff1a;\n<li>\u4e00\u7bc7\u6587\u7ae0\u88ab\u770b\u4f5c\u662f\u591a\u4e2a\u4e3b\u9898\u7684\u6982\u7387\u6df7\u5408\u3002\u4f8b\u5982&#xff0c;\u4e00\u7bc7\u5f71\u8bc4\u53ef\u80fd\u662f70%\u7684\u201c\u5267\u60c5\u201d\u4e3b\u9898 &#043; 20%\u7684\u201c\u6f14\u5458\u201d\u4e3b\u9898 &#043; 10%\u7684\u201c\u914d\u4e50\u201d\u4e3b\u9898\u3002<\/li>\n<li>\u4e00\u4e2a\u4e3b\u9898\u88ab\u770b\u4f5c\u662f\u591a\u4e2a\u8bcd\u8bed\u7684\u6982\u7387\u5206\u5e03\u3002\u4f8b\u5982&#xff0c;\u201c\u5267\u60c5\u201d\u4e3b\u9898\u4e0b&#xff0c;\u201cplot\u201d, \u201cstory\u201d, \u201ccharacter\u201d\u8fd9\u4e9b\u8bcd\u51fa\u73b0\u7684\u6982\u7387\u4f1a\u5f88\u9ad8\u3002<\/li>\n<\/li>\n<\/ul>\n<h5>11.3.2 LDA\u7684\u5b9e\u73b0\u4e0e\u7ed3\u679c\u89e3\u8bfb<\/h5>\n<p>LDA\u7684\u8f93\u5165\u4e0d\u80fd\u662fTF-IDF&#xff0c;\u800c\u5fc5\u987b\u662f\u57fa\u4e8e\u8bcd\u9891\u8ba1\u6570\u7684\u8bcd\u888b\u6a21\u578b\u77e9\u9635\u3002<\/p>\n<p>from sklearn.feature_extraction.text import CountVectorizer<br \/>\nfrom sklearn.decomposition import LatentDirichletAllocation<\/p>\n<p># 1. \u521b\u5efa\u8bcd\u9891\u8ba1\u6570\u5411\u91cf\u5668<br \/>\ncount_vectorizer &#061; CountVectorizer(max_df&#061;0.95, min_df&#061;2, max_features&#061;1000, stop_words&#061;&#039;english&#039;)<br \/>\nX_counts &#061; count_vectorizer.fit_transform(df[&#039;cleaned_review&#039;]) # \u4f7f\u7528\u6e05\u6d17\u540e\u7684\u6587\u672c<\/p>\n<p># 2. \u8bad\u7ec3LDA\u6a21\u578b<br \/>\n# n_components \u5c31\u662f\u6211\u4eec\u60f3\u8981\u53d1\u73b0\u7684\u4e3b\u9898\u6570\u91cf<br \/>\nnum_topics &#061; 5<br \/>\nlda &#061; LatentDirichletAllocation(n_components&#061;num_topics, random_state&#061;42)<br \/>\nlda.fit(X_counts)<\/p>\n<p># 3. \u7ed3\u679c\u89e3\u8bfb&#xff1a;\u6253\u5370\u6bcf\u4e2a\u4e3b\u9898\u4e0b\u6700\u91cd\u8981\u7684\u8bcd<br \/>\ndef print_top_words(model, feature_names, n_top_words):<br \/>\n    for topic_idx, topic in enumerate(model.components_):<br \/>\n        message &#061; f&#034;Topic #{topic_idx}: &#034;<br \/>\n        message &#043;&#061; &#034; &#034;.join([feature_names[i]<br \/>\n                             for i in topic.argsort()[:-n_top_words &#8211; 1:-1]])<br \/>\n        print(message)<\/p>\n<p>print(&#034;\\\\n&#8212; LDA \u4e3b\u9898\u53d1\u73b0\u7ed3\u679c &#8212;&#034;)<br \/>\nfeature_names &#061; count_vectorizer.get_feature_names_out()<br \/>\nprint_top_words(lda, feature_names, 10)<\/p>\n<p>\u7ed3\u679c\u89e3\u8bfb&#xff1a;\u901a\u8fc7\u89c2\u5bdf\u6bcf\u4e2a\u4e3b\u9898\u4e0b\u7684\u9ad8\u9891\u8bcd&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4eba\u4e3a\u5730\u53bb\u201c\u547d\u540d\u201d\u548c\u7406\u89e3\u8fd9\u4e2a\u4e3b\u9898\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u4e00\u4e2a\u4e3b\u9898\u4e0b\u90fd\u662f\u201caction\u201d, \u201cfight\u201d, \u201cexplosion\u201d&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u5176\u6807\u8bb0\u4e3a\u201c\u52a8\u4f5c\u573a\u9762\u201d\u4e3b\u9898\u3002<\/p>\n<h5>11.3.3 \u5e94\u7528\u573a\u666f\u4e0e\u6d1e\u5bdf<\/h5>\n<ul>\n<li>\u5546\u4e1a\u6d1e\u5bdf&#xff1a;\u5bf9\u4e8e\u4e00\u4e2a\u624b\u673a\u5382\u5546&#xff0c;\u901a\u8fc7\u5bf9\u6d77\u91cf\u7528\u6237\u8bc4\u8bba\u8fd0\u884cLDA&#xff0c;\u53ef\u4ee5\u81ea\u52a8\u53d1\u73b0\u7528\u6237\u6700\u5173\u5fc3\u7684\u51e0\u4e2a\u65b9\u9762\u662f\u201c\u7535\u6c60\u7eed\u822a\u201d\u3001\u201c\u62cd\u7167\u6548\u679c\u201d\u3001\u201c\u5c4f\u5e55\u8d28\u91cf\u201d\u8fd8\u662f\u201c\u7cfb\u7edf\u6d41\u7545\u5ea6\u201d&#xff0c;\u4ece\u800c\u6307\u5bfc\u4ea7\u54c1\u6539\u8fdb\u3002<\/li>\n<li>\u5185\u5bb9\u805a\u5408\u4e0e\u63a8\u8350&#xff1a;\u5c06\u65b0\u95fb\u6587\u7ae0\u6309\u4e3b\u9898\u8fdb\u884c\u5206\u7c7b&#xff0c;\u4e3a\u7528\u6237\u63a8\u8350\u4ed6\u4eec\u611f\u5174\u8da3\u4e3b\u9898\u4e0b\u7684\u5176\u4ed6\u6587\u7ae0\u3002<\/li>\n<li>\u8206\u60c5\u76d1\u63a7&#xff1a;\u5206\u6790\u793e\u4ea4\u5a92\u4f53\u4e0a\u5173\u4e8e\u67d0\u4e2a\u4e8b\u4ef6\u7684\u8ba8\u8bba&#xff0c;\u770b\u516c\u4f17\u7684\u8ba8\u8bba\u7126\u70b9\u5728\u54ea\u4e9b\u65b9\u9762\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u5728\u672c\u7ae0\u4e2d&#xff0c;\u6211\u4eec\u6210\u529f\u5730\u8fdb\u5165\u4e86\u81ea\u7136\u8bed\u8a00\u5904\u7406\u7684\u4e16\u754c\u3002\u6211\u4eec\u638c\u63e1\u4e86\u5904\u7406\u6587\u672c\u6570\u636e\u7684\u4e00\u6574\u5957\u6d41\u7a0b&#xff1a;\u4ece\u6e05\u6d17\u3001\u5206\u8bcd&#xff0c;\u5230\u4f7f\u7528TF-IDF\u548cWord2Vec\u8fdb\u884c\u5411\u91cf\u5316\u3002\u6211\u4eec\u6784\u5efa\u4e86\u80fd\u591f\u5224\u65ad\u6587\u672c\u60c5\u611f\u7684\u5206\u7c7b\u6a21\u578b&#xff0c;\u5e76\u4f53\u9a8c\u4e86\u4ece\u4f20\u7edf\u65b9\u6cd5\u5230\u795e\u7ecf\u7f51\u7edc\u7684\u6f14\u8fdb\u3002\u6700\u540e&#xff0c;\u6211\u4eec\u8fd8\u5b66\u4e60\u4e86\u5982\u4f55\u4f7f\u7528LDA\u8fd9\u4e00\u65e0\u76d1\u7763\u5229\u5668&#xff0c;\u4ece\u6587\u672c\u4e2d\u6316\u6398\u51fa\u66f4\u6df1\u5c42\u6b21\u7684\u3001\u4eba\u7c7b\u96be\u4ee5\u76f4\u63a5\u53d1\u73b0\u7684\u4e3b\u9898\u7ed3\u6784\u3002<\/p>\n<p>\u60a8\u73b0\u5728\u5df2\u7ecf\u5177\u5907\u4e86\u5206\u6790\u6587\u672c\u6570\u636e\u7684\u57fa\u672c\u80fd\u529b&#xff0c;\u4e3a\u60a8\u6253\u5f00\u4e86\u901a\u5f80\u667a\u80fd\u95ee\u7b54\u3001\u673a\u5668\u7ffb\u8bd1\u3001\u6587\u672c\u751f\u6210\u7b49\u66f4\u9ad8\u7ea7NLP\u9886\u57df\u7684\u5927\u95e8\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u5341\u4e8c\u7ae0&#xff1a;\u6a21\u578b\u90e8\u7f72\u4e0e\u5de5\u7a0b\u5316\u2014\u2014\u8ba9\u6a21\u578b\u201c\u6d3b\u201d\u8d77\u6765<\/h3>\n<ul>\n<li>12.1 \u6a21\u578b\u6301\u4e45\u5316&#xff1a;\u5e8f\u5217\u5316\u4e0e\u4fdd\u5b58<\/li>\n<li>12.2 \u4f7f\u7528Flask\/FastAPI\u6784\u5efaAPI\u670d\u52a1<\/li>\n<li>12.3 Docker\u5bb9\u5668\u5316&#xff1a;\u4e3a\u6a21\u578b\u6253\u9020\u4e00\u4e2a\u201c\u5bb6\u201d<\/li>\n<li>12.4 MLOps\u521d\u63a2&#xff1a;\u81ea\u52a8\u5316\u3001\u76d1\u63a7\u4e0e\u518d\u8bad\u7ec3<\/li>\n<\/ul>\n<p>\u7ecf\u8fc7\u524d\u9762\u7ae0\u8282\u7684\u8270\u82e6\u8dcb\u6d89&#xff0c;\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u8bad\u7ec3\u51fa\u4e86\u80fd\u591f\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002\u5b83\u4eec\u5728\u6211\u4eec\u7684\u5f00\u53d1\u73af\u5883\u4e2d\u8868\u73b0\u4f18\u5f02&#xff0c;\u4f46\u8fd9\u53ea\u662f\u4e07\u91cc\u957f\u5f81\u7684\u7b2c\u4e00\u6b65\u3002\u4e00\u4e2a\u771f\u6b63\u6709\u4ef7\u503c\u7684\u6a21\u578b&#xff0c;\u5fc5\u987b\u80fd\u591f\u8d70\u51fa\u5b9e\u9a8c\u5ba4&#xff0c;\u88ab\u96c6\u6210\u5230\u5b9e\u9645\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d&#xff0c;\u4e3a\u7528\u6237\u63d0\u4f9b\u6301\u7eed\u3001\u53ef\u9760\u7684\u670d\u52a1\u3002\u8fd9\u4e2a\u8fc7\u7a0b&#xff0c;\u5c31\u662f\u6a21\u578b\u90e8\u7f72\u4e0e\u5de5\u7a0b\u5316\u3002<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u805a\u7126\u4e8e\u5982\u4f55\u5c06\u6211\u4eec\u7cbe\u5fc3\u8bad\u7ec3\u7684\u6a21\u578b&#xff0c;\u4ece\u4e00\u4e2a\u9759\u6001\u7684\u6587\u4ef6&#xff0c;\u8f6c\u53d8\u4e3a\u4e00\u4e2a\u52a8\u6001\u7684\u3001\u53ef\u4ea4\u4e92\u7684\u3001\u5065\u58ee\u7684\u5728\u7ebf\u670d\u52a1\u3002\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u4fdd\u5b58\u548c\u52a0\u8f7d\u6a21\u578b&#xff0c;\u5982\u4f55\u7528Web\u6846\u67b6\u4e3a\u5176\u521b\u5efa\u4e00\u4e2aAPI\u63a5\u53e3&#xff0c;\u5982\u4f55\u7528Docker\u5c06\u5176\u6253\u5305\u6210\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u3001\u53ef\u79fb\u690d\u7684\u201c\u96c6\u88c5\u7bb1\u201d&#xff0c;\u6700\u540e&#xff0c;\u6211\u4eec\u8fd8\u5c06\u521d\u6b65\u63a2\u8ba8MLOps\u7684\u7406\u5ff5&#xff0c;\u4e86\u89e3\u5982\u4f55\u5bf9\u201c\u6d3b\u201d\u8d77\u6765\u7684\u6a21\u578b\u8fdb\u884c\u6301\u7eed\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406\u3002<\/p>\n<p>\u638c\u63e1\u672c\u7ae0\u5185\u5bb9&#xff0c;\u610f\u5473\u7740\u60a8\u5c06\u6253\u901a\u4ece\u6570\u636e\u5230\u4ef7\u503c\u7684\u201c\u6700\u540e\u4e00\u516c\u91cc\u201d&#xff0c;\u8ba9\u60a8\u7684\u7b97\u6cd5\u771f\u6b63\u843d\u5730\u751f\u6839&#xff0c;\u5f00\u82b1\u7ed3\u679c\u3002<\/p>\n<hr \/>\n<h4>12.1 \u6a21\u578b\u6301\u4e45\u5316&#xff1a;\u5e8f\u5217\u5316\u4e0e\u4fdd\u5b58<\/h4>\n<h5>12.1.1 \u4e3a\u4f55\u9700\u8981\u6301\u4e45\u5316&#xff1f;<\/h5>\n<p>\u6a21\u578b\u6301\u4e45\u5316&#xff0c;\u5c31\u662f\u5c06\u5185\u5b58\u4e2d\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u8c61&#xff0c;\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\u4fdd\u5b58\u5230\u786c\u76d8\u4e0a\u3002\u8fd9\u662f\u6a21\u578b\u90e8\u7f72\u7684\u7edd\u5bf9\u524d\u63d0\u3002<\/p>\n<ul>\n<li>\u4fdd\u5b58\u52b3\u52a8\u6210\u679c&#xff1a;\u8bb8\u591a\u590d\u6742\u7684\u6a21\u578b&#xff08;\u5c24\u5176\u662f\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b&#xff09;\u8bad\u7ec3\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u6570\u5c0f\u65f6\u751a\u81f3\u6570\u5929\u3002\u5c06\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u4fdd\u5b58\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u91cd\u65b0\u52a0\u8f7d\u5b83&#xff0c;\u800c\u65e0\u9700\u518d\u6b21\u8fdb\u884c\u8017\u65f6\u8017\u529b\u7684\u8bad\u7ec3\u3002<\/li>\n<li>\u5b9e\u73b0\u90e8\u7f72\u8fc1\u79fb&#xff1a;\u6211\u4eec\u901a\u5e38\u5728\u4e00\u4e2a\u73af\u5883&#xff08;\u5982\u914d\u5907GPU\u7684\u5f00\u53d1\u670d\u52a1\u5668&#xff09;\u4e2d\u8bad\u7ec3\u6a21\u578b&#xff0c;\u800c\u5728\u53e6\u4e00\u4e2a\u6216\u591a\u4e2a\u73af\u5883&#xff08;\u5982\u751f\u4ea7\u670d\u52a1\u5668\u96c6\u7fa4&#xff09;\u4e2d\u4f7f\u7528\u6a21\u578b\u3002\u6301\u4e45\u5316\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6a21\u578b\u6587\u4ef6\u4ece\u4e00\u4e2a\u5730\u65b9\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\u3002<\/li>\n<\/ul>\n<h5>12.1.2 Python\u4e2d\u7684\u5e8f\u5217\u5316\u5de5\u5177&#xff1a;pickle\u4e0ejoblib<\/h5>\n<p>\u5e8f\u5217\u5316\u662f\u5c06Python\u5bf9\u8c61\u7ed3\u6784\u8f6c\u6362\u4e3a\u5b57\u8282\u6d41\u7684\u8fc7\u7a0b&#xff0c;\u4ee5\u4fbf\u5c06\u5176\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\u6216\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u3002<\/p>\n<ul>\n<li>pickle&#xff1a;\u662fPython\u6807\u51c6\u5e93\u4e2d\u5185\u5efa\u7684\u5e8f\u5217\u5316\u6a21\u5757\u3002\u5b83\u529f\u80fd\u5f3a\u5927&#xff0c;\u53ef\u4ee5\u5e8f\u5217\u5316\u51e0\u4e4e\u4efb\u4f55Python\u5bf9\u8c61\u3002<\/li>\n<li>joblib&#xff1a;\u662f\u4e00\u4e2a\u7531Scikit-learn\u793e\u533a\u7ef4\u62a4\u7684\u5e93&#xff0c;\u5176\u5e8f\u5217\u5316\u529f\u80fd&#xff08;joblib.dump\u548cjoblib.load&#xff09;\u5728\u5904\u7406\u5305\u542b\u5927\u578bNumPy\u6570\u7ec4\u7684\u5bf9\u8c61\u65f6&#xff0c;\u6bd4pickle\u66f4\u9ad8\u6548\u3002\u56e0\u6b64&#xff0c;\u5bf9\u4e8eScikit-learn\u8bad\u7ec3\u51fa\u7684\u6a21\u578b&#xff0c;\u5b98\u65b9\u63a8\u8350\u4f7f\u7528joblib\u3002<\/li>\n<\/ul>\n<h5>12.1.3 \u5b9e\u6218\u6f14\u7ec3&#xff1a;\u4fdd\u5b58\u4e0e\u52a0\u8f7dScikit-learn\u6a21\u578b<\/h5>\n<p>\u8ba9\u6211\u4eec\u4ee5\u4e4b\u524d\u8bad\u7ec3\u7684\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b\u6a21\u578b&#xff08;\u4f8b\u5982&#xff0c;\u5728SMOTE\u6570\u636e\u4e0a\u8bad\u7ec3\u7684LightGBM\u6a21\u578b&#xff09;\u4e3a\u4f8b\u3002<\/p>\n<p>\u4fdd\u5b58\u6a21\u578b\u00a0\u5728\u4e00\u4e2a\u8bad\u7ec3\u811a\u672c&#xff08;\u4f8b\u5982train.py&#xff09;\u7684\u672b\u5c3e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801&#xff1a;<\/p>\n<p># train.py<br \/>\nimport joblib<br \/>\nimport lightgbm as lgb<br \/>\nfrom sklearn.model_selection import train_test_split<br \/>\nfrom imblearn.over_sampling import SMOTE<br \/>\nimport pandas as pd<\/p>\n<p># &#8230; (\u6b64\u5904\u7701\u7565\u6570\u636e\u52a0\u8f7d\u3001\u9884\u5904\u7406\u3001SMOTE\u548c\u6a21\u578b\u8bad\u7ec3\u7684\u4ee3\u7801) &#8230;<br \/>\n# \u5047\u8bbe lgbm_model \u662f\u6211\u4eec\u5df2\u7ecf\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u5bf9\u8c61<br \/>\n# df &#061; pd.read_csv(&#039;creditcard.csv&#039;)<br \/>\n# &#8230; (\u9884\u5904\u7406) &#8230;<br \/>\n# X_train_smote, y_train_smote &#061; &#8230; (SMOTE) &#8230;<br \/>\n# lgbm_model &#061; lgb.LGBMClassifier(random_state&#061;42)<br \/>\n# lgbm_model.fit(X_train_smote, y_train_smote)<\/p>\n<p># \u5b9a\u4e49\u4fdd\u5b58\u8def\u5f84\u548c\u6587\u4ef6\u540d<br \/>\nmodel_filename &#061; &#039;fraud_detection_lgbm.joblib&#039;<\/p>\n<p># \u4f7f\u7528joblib.dump\u4fdd\u5b58\u6a21\u578b<br \/>\n# compress&#061;3 \u662f\u4e00\u4e2a\u53ef\u9009\u53c2\u6570&#xff0c;\u8868\u793a\u538b\u7f29\u7ea7\u522b&#xff0c;\u53ef\u4ee5\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f<br \/>\njoblib.dump(lgbm_model, model_filename, compress&#061;3)<\/p>\n<p>print(f&#034;\u6a21\u578b\u5df2\u4fdd\u5b58\u5230: {model_filename}&#034;)<\/p>\n<p>\u52a0\u8f7d\u5e76\u4f7f\u7528\u6a21\u578b\u00a0\u73b0\u5728&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5728\u4e00\u4e2a\u5168\u65b0\u7684Python\u811a\u672c&#xff08;\u4f8b\u5982predict.py&#xff09;\u4e2d&#xff0c;\u52a0\u8f7d\u8fd9\u4e2a\u6a21\u578b\u5e76\u7528\u5b83\u6765\u8fdb\u884c\u9884\u6d4b&#xff0c;\u5b8c\u5168\u8131\u79bb\u539f\u59cb\u7684\u8bad\u7ec3\u6570\u636e\u548c\u8bad\u7ec3\u8fc7\u7a0b\u3002<\/p>\n<p># predict.py<br \/>\nimport joblib<br \/>\nimport numpy as np<\/p>\n<p># \u52a0\u8f7d\u6a21\u578b<br \/>\ntry:<br \/>\n    loaded_model &#061; joblib.load(&#039;fraud_detection_lgbm.joblib&#039;)<br \/>\n    print(&#034;\u6a21\u578b\u52a0\u8f7d\u6210\u529f&#xff01;&#034;)<br \/>\nexcept FileNotFoundError:<br \/>\n    print(&#034;\u9519\u8bef&#xff1a;\u627e\u4e0d\u5230\u6a21\u578b\u6587\u4ef6\u3002\u8bf7\u5148\u8fd0\u884c\u8bad\u7ec3\u811a\u672c\u3002&#034;)<br \/>\n    exit()<\/p>\n<p># \u51c6\u5907\u4e00\u6761\u65b0\u7684\u3001\u5f85\u9884\u6d4b\u7684\u6570\u636e\u6837\u672c<br \/>\n# \u7279\u5f81\u7ef4\u5ea6\u548c\u987a\u5e8f\u9700\u8981\u4e0e\u8bad\u7ec3\u65f6\u4e25\u683c\u4e00\u81f4<br \/>\n# \u8fd9\u91cc\u7684new_data\u662f\u4e00\u4e2a\u793a\u4f8b&#xff0c;\u5b9e\u9645\u5e94\u7528\u4e2d\u5b83\u4f1a\u6765\u81eaAPI\u8bf7\u6c42<br \/>\n# \u5047\u8bbe\u6709 scaled_time, scaled_amount, V1-V28&#xff0c;\u517130\u4e2a\u7279\u5f81<br \/>\nnew_data &#061; np.random.rand(1, 30) <\/p>\n<p># \u4f7f\u7528\u52a0\u8f7d\u7684\u6a21\u578b\u8fdb\u884c\u9884\u6d4b<br \/>\nprediction &#061; loaded_model.predict(new_data)<br \/>\nprediction_proba &#061; loaded_model.predict_proba(new_data)<\/p>\n<p>print(f&#034;\\\\n\u5bf9\u65b0\u6570\u636e\u7684\u9884\u6d4b\u7c7b\u522b: {&#039;\u6b3a\u8bc8&#039; if prediction[0] &#061;&#061; 1 else &#039;\u6b63\u5e38&#039;}&#034;)<br \/>\nprint(f&#034;\u9884\u6d4b\u4e3a&#039;\u6b63\u5e38&#039;\u7684\u6982\u7387: {prediction_proba[0][0]:.4f}&#034;)<br \/>\nprint(f&#034;\u9884\u6d4b\u4e3a&#039;\u6b3a\u8bc8&#039;\u7684\u6982\u7387: {prediction_proba[0][1]:.4f}&#034;)<\/p>\n<p>\u91cd\u8981\u6ce8\u610f\u4e8b\u9879&#xff1a;\u7248\u672c\u4f9d\u8d56\u00a0\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316&#xff08;\u52a0\u8f7d&#xff09;\u8fc7\u7a0b\u5bf9\u5e93\u7684\u7248\u672c\u975e\u5e38\u654f\u611f\u3002\u5982\u679c\u5728Python 3.8\u548cLightGBM 3.2\u7248\u672c\u4e0b\u4fdd\u5b58\u7684\u6a21\u578b&#xff0c;\u5c1d\u8bd5\u5728Python 3.9\u548cLightGBM 4.0\u7684\u73af\u5883\u4e0b\u52a0\u8f7d&#xff0c;\u5f88\u53ef\u80fd\u4f1a\u5931\u8d25\u3002\u56e0\u6b64&#xff0c;\u5728\u90e8\u7f72\u65f6&#xff0c;\u786e\u4fdd\u751f\u4ea7\u73af\u5883\u7684\u5e93\u7248\u672c\u4e0e\u8bad\u7ec3\u73af\u5883\u7684\u5e93\u7248\u672c\u4e25\u683c\u4e00\u81f4\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u6211\u4eec\u7a0d\u540e\u5c06\u770b\u5230\u7684Docker&#xff0c;\u6b63\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u5229\u5668\u3002<\/p>\n<hr \/>\n<h4>12.2 \u4f7f\u7528Flask\/FastAPI\u6784\u5efaAPI\u670d\u52a1<\/h4>\n<p>\u6a21\u578b\u6587\u4ef6\u672c\u8eab\u8fd8\u4e0d\u80fd\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u3002\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u7a0b\u5e8f&#xff0c;\u5b83\u80fd\u76d1\u542c\u7f51\u7edc\u8bf7\u6c42&#xff0c;\u63a5\u6536\u4f20\u5165\u7684\u6570\u636e&#xff0c;\u8c03\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b&#xff0c;\u7136\u540e\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9\u8bf7\u6c42\u65b9\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u5c31\u662fAPI\u670d\u52a1\u3002<\/p>\n<h5>12.2.1 API&#xff1a;\u6a21\u578b\u4e0e\u5916\u754c\u6c9f\u901a\u7684\u201c\u7a97\u53e3\u201d<\/h5>\n<ul>\n<li>API&#xff08;Application Programming Interface&#xff09;&#xff1a;\u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u63a5\u53e3\u3002\u5b83\u5b9a\u4e49\u4e86\u4e0d\u540c\u8f6f\u4ef6\u7ec4\u4ef6\u4e4b\u95f4\u5982\u4f55\u76f8\u4e92\u901a\u4fe1\u3002\u5bf9\u4e8e\u6211\u4eec\u7684\u6a21\u578b&#xff0c;\u5c31\u662f\u5b9a\u4e49\u4e00\u4e2a\u63a5\u6536\u8f93\u5165\u6570\u636e\u3001\u8fd4\u56de\u9884\u6d4b\u7ed3\u679c\u7684\u6807\u51c6\u5316\u7f51\u7edc\u63a5\u53e3\u3002<\/li>\n<li>RESTful API&#xff1a;\u4e00\u79cd\u6d41\u884c\u7684API\u8bbe\u8ba1\u98ce\u683c&#xff0c;\u5b83\u4f7f\u7528\u6807\u51c6\u7684HTTP\u65b9\u6cd5&#xff08;\u5982GET, POST, PUT, DELETE&#xff09;\u6765\u64cd\u4f5c\u8d44\u6e90\u3002\u6211\u4eec\u7684\u9884\u6d4b\u670d\u52a1\u901a\u5e38\u4f1a\u4f7f\u7528POST\u65b9\u6cd5&#xff0c;\u56e0\u4e3a\u5ba2\u6237\u7aef\u9700\u8981\u5411\u670d\u52a1\u5668\u53d1\u9001\u5305\u542b\u7279\u5f81\u6570\u636e\u7684\u8bf7\u6c42\u4f53\u3002\u6570\u636e\u4ea4\u6362\u683c\u5f0f\u901a\u5e38\u662fJSON\u3002<\/li>\n<\/ul>\n<h5>12.2.2 \u8f7b\u91cf\u7ea7Web\u6846\u67b6\u7b80\u4ecb<\/h5>\n<ul>\n<li>Flask&#xff1a;\u7ecf\u5178\u3001\u7075\u6d3b\u3001\u6613\u4e8e\u4e0a\u624b\u7684Python Web\u6846\u67b6&#xff0c;\u662f\u8bb8\u591a\u4eba\u5165\u95e8Web\u5f00\u53d1\u548cAPI\u6784\u5efa\u7684\u9996\u9009\u3002<\/li>\n<li>FastAPI&#xff1a;\u4e00\u4e2a\u73b0\u4ee3\u3001\u9ad8\u6027\u80fd\u7684Web\u6846\u67b6\u3002\u5b83\u57fa\u4e8ePython 3.6&#043;\u7684\u7c7b\u578b\u63d0\u793a&#xff0c;\u5e76\u56e0\u6b64\u83b7\u5f97\u4e86\u4e24\u5927\u201c\u6740\u624b\u7ea7\u201d\u7279\u6027&#xff1a;\n<li>\u6781\u9ad8\u7684\u6027\u80fd&#xff1a;\u53ef\u4e0eNodeJS\u548cGo\u76f8\u5ab2\u7f8e\u3002<\/li>\n<li>\u81ea\u52a8\u751f\u6210\u4ea4\u4e92\u5f0fAPI\u6587\u6863&#xff1a;\u57fa\u4e8eOpenAPI&#xff08;\u4ee5\u524d\u79f0\u4e3aSwagger&#xff09;\u548cJSON Schema\u6807\u51c6&#xff0c;\u6781\u5927\u5730\u65b9\u4fbf\u4e86API\u7684\u6d4b\u8bd5\u548c\u534f\u4f5c\u3002 \u57fa\u4e8e\u8fd9\u4e9b\u4f18\u70b9&#xff0c;\u6211\u4eec\u9009\u62e9FastAPI\u6765\u6784\u5efa\u6211\u4eec\u7684\u670d\u52a1\u3002<\/li>\n<\/li>\n<\/ul>\n<h5>12.2.3 \u5b9e\u6218\u6f14\u7ec3&#xff1a;\u4f7f\u7528FastAPI\u5305\u88c5\u6211\u4eec\u7684\u6a21\u578b<\/h5>\n<p>\u9996\u5148&#xff0c;\u5b89\u88c5FastAPI\u548c\u5176\u8fd0\u884c\u6240\u9700\u7684ASGI\u670d\u52a1\u5668Uvicorn&#xff1a;\u00a0pip install fastapi &#034;uvicorn[standard]&#034;<\/p>\n<p>\u7136\u540e&#xff0c;\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amain.py\u7684\u6587\u4ef6\u3002<\/p>\n<p># main.py<br \/>\nfrom fastapi import FastAPI, HTTPException<br \/>\nfrom pydantic import BaseModel, Field<br \/>\nimport joblib<br \/>\nimport numpy as np<br \/>\nfrom typing import List<\/p>\n<p># 1. \u521b\u5efaFastAPI\u5e94\u7528\u5b9e\u4f8b<br \/>\napp &#061; FastAPI(title&#061;&#034;\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4bAPI&#034;, description&#061;&#034;\u4e00\u4e2a\u4f7f\u7528LightGBM\u6a21\u578b\u8fdb\u884c\u6b3a\u8bc8\u68c0\u6d4b\u7684API&#034;)<\/p>\n<p># 2. \u5b9a\u4e49\u8f93\u5165\u6570\u636e\u7684\u6a21\u578b (\u6570\u636e\u5951\u7ea6)<br \/>\n# \u4f7f\u7528pydantic\u7684BaseModel\u6765\u5b9a\u4e49\u8bf7\u6c42\u4f53\u7684\u6570\u636e\u7ed3\u6784\u548c\u7c7b\u578b<br \/>\nclass Transaction(BaseModel):<br \/>\n    features: List[float] &#061; Field(&#8230;, example&#061;[0.1, -0.2, &#8230;, 1.5], description&#061;&#034;\u5305\u542b30\u4e2a\u7279\u5f81\u7684\u5217\u8868&#034;)<\/p>\n<p>    class Config:<br \/>\n        schema_extra &#061; {<br \/>\n            &#034;example&#034;: {<br \/>\n                &#034;features&#034;: list(np.random.rand(30))<br \/>\n            }<br \/>\n        }<\/p>\n<p># 3. \u52a0\u8f7d\u6211\u4eec\u8bad\u7ec3\u597d\u7684\u6a21\u578b<br \/>\ntry:<br \/>\n    model &#061; joblib.load(&#039;fraud_detection_lgbm.joblib&#039;)<br \/>\nexcept FileNotFoundError:<br \/>\n    # \u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u5982\u679c\u6a21\u578b\u52a0\u8f7d\u5931\u8d25&#xff0c;\u670d\u52a1\u5e94\u8be5\u65e0\u6cd5\u542f\u52a8<br \/>\n    # \u8fd9\u91cc\u4e3a\u4e86\u7b80\u5355\u8d77\u89c1&#xff0c;\u6211\u4eec\u53ea\u6253\u5370\u9519\u8bef<br \/>\n    model &#061; None<br \/>\n    print(&#034;\u9519\u8bef&#xff1a;\u6a21\u578b\u6587\u4ef6\u672a\u627e\u5230&#xff01;API\u5c06\u65e0\u6cd5\u5de5\u4f5c\u3002&#034;)<\/p>\n<p># 4. \u521b\u5efaAPI\u7aef\u70b9 (endpoint)<br \/>\n&#064;app.post(&#034;\/predict&#034;, summary&#061;&#034;\u8fdb\u884c\u6b3a\u8bc8\u68c0\u6d4b\u9884\u6d4b&#034;)<br \/>\ndef predict_fraud(transaction: Transaction):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u63a5\u6536\u4e00\u7b14\u4ea4\u6613\u7684\u7279\u5f81\u6570\u636e&#xff0c;\u8fd4\u56de\u5176\u662f\u5426\u4e3a\u6b3a\u8bc8\u7684\u9884\u6d4b\u7ed3\u679c\u548c\u6982\u7387\u3002<br \/>\n    &#8211; **transaction**: \u5305\u542b\u7279\u5f81\u5217\u8868\u7684JSON\u5bf9\u8c61\u3002<br \/>\n    &#8211; **\u8fd4\u56de**: \u5305\u542b\u9884\u6d4b\u7c7b\u522b\u548c\u6982\u7387\u7684JSON\u5bf9\u8c61\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    if model is None:<br \/>\n        raise HTTPException(status_code&#061;503, detail&#061;&#034;\u6a21\u578b\u5f53\u524d\u4e0d\u53ef\u7528&#xff0c;\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458\u3002&#034;)<\/p>\n<p>    # \u5c06\u8f93\u5165\u7684\u5217\u8868\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4&#xff0c;\u5e76reshape\u6210(1, n_features)\u7684\u5f62\u72b6<br \/>\n    features_array &#061; np.array(transaction.features).reshape(1, -1)<\/p>\n<p>    if features_array.shape[1] !&#061; 30: # \u5047\u8bbe\u6211\u4eec\u7684\u6a21\u578b\u9700\u898130\u4e2a\u7279\u5f81<br \/>\n        raise HTTPException(status_code&#061;400, detail&#061;f&#034;\u8f93\u5165\u7279\u5f81\u6570\u91cf\u9519\u8bef&#xff0c;\u9700\u898130\u4e2a&#xff0c;\u4f46\u6536\u5230\u4e86{features_array.shape[1]}\u4e2a\u3002&#034;)<\/p>\n<p>    # \u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b<br \/>\n    prediction &#061; model.predict(features_array)<br \/>\n    probability &#061; model.predict_proba(features_array)<\/p>\n<p>    # \u51c6\u5907\u8fd4\u56de\u7ed3\u679c<br \/>\n    return {<br \/>\n        &#034;is_fraud&#034;: int(prediction[0]), # \u9884\u6d4b\u7c7b\u522b (0: \u6b63\u5e38, 1: \u6b3a\u8bc8)<br \/>\n        &#034;probability_normal&#034;: float(probability[0][0]),<br \/>\n        &#034;probability_fraud&#034;: float(probability[0][1])<br \/>\n    }<\/p>\n<p># \u521b\u5efa\u4e00\u4e2a\u6839\u7aef\u70b9&#xff0c;\u7528\u4e8e\u5065\u5eb7\u68c0\u67e5<br \/>\n&#064;app.get(&#034;\/&#034;, summary&#061;&#034;API\u5065\u5eb7\u68c0\u67e5&#034;)<br \/>\ndef read_root():<br \/>\n    return {&#034;status&#034;: &#034;ok&#034;, &#034;message&#034;: &#034;\u6b22\u8fce\u6765\u5230\u6b3a\u8bc8\u68c0\u6d4bAPI&#xff01;&#034;}<\/p>\n<p>\u8fd0\u884cAPI\u670d\u52a1\u00a0\u5728\u7ec8\u7aef\u4e2d&#xff0c;\u5207\u6362\u5230main.py\u6240\u5728\u7684\u76ee\u5f55&#xff0c;\u7136\u540e\u8fd0\u884c&#xff1a;\u00a0uvicorn main:app &#8211;reload<\/p>\n<ul>\n<li>main: \u6307\u7684\u662fmain.py\u6587\u4ef6\u3002<\/li>\n<li>app: \u6307\u7684\u662f\u6211\u4eec\u5728main.py\u4e2d\u521b\u5efa\u7684FastAPI\u5bf9\u8c61app\u3002<\/li>\n<li>&#8211;reload: \u8fd9\u4e2a\u53c2\u6570\u4f1a\u8ba9\u670d\u52a1\u5668\u5728\u4ee3\u7801\u6587\u4ef6\u88ab\u4fee\u6539\u540e\u81ea\u52a8\u91cd\u542f&#xff0c;\u975e\u5e38\u9002\u5408\u5f00\u53d1\u9636\u6bb5\u3002<\/li>\n<\/ul>\n<p>\u6d4b\u8bd5API\u00a0\u670d\u52a1\u8fd0\u884c\u540e&#xff0c;\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\u00a0http:\/\/127.0.0.1:8000\/docs\u00a0\u3002\u4f60\u4f1a\u770b\u5230FastAPI\u81ea\u52a8\u751f\u6210\u7684\u4ea4\u4e92\u5f0fAPI\u6587\u6863&#xff08;Swagger UI&#xff09;\u3002\u4f60\u53ef\u4ee5\u5728\u8fd9\u4e2a\u9875\u9762\u4e0a\u76f4\u63a5\u6d4b\u8bd5\u4f60\u7684\/predict\u7aef\u70b9&#xff0c;\u8f93\u5165\u793a\u4f8b\u6570\u636e&#xff0c;\u7136\u540e\u70b9\u51fb\u201cExecute\u201d&#xff0c;\u5c31\u80fd\u770b\u5230\u670d\u52a1\u5668\u8fd4\u56de\u7684\u9884\u6d4b\u7ed3\u679c\u3002\u8fd9\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u5f00\u53d1\u548c\u8c03\u8bd5\u7684\u6548\u7387\u3002<\/p>\n<hr \/>\n<h4>12.3 Docker\u5bb9\u5668\u5316&#xff1a;\u4e3a\u6a21\u578b\u6253\u9020\u4e00\u4e2a\u201c\u5bb6\u201d<\/h4>\n<p>\u6211\u4eec\u7684API\u670d\u52a1\u73b0\u5728\u53ef\u4ee5\u5728\u672c\u5730\u8fd0\u884c\u4e86&#xff0c;\u4f46\u5982\u679c\u60f3\u628a\u5b83\u90e8\u7f72\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u6216\u4e91\u4e0a&#xff0c;\u5c31\u4f1a\u9047\u5230\u201c\u5728\u6211\u7535\u8111\u4e0a\u80fd\u8dd1\u201d\u7684\u7ecf\u5178\u56f0\u5883\u3002Docker\u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u800c\u751f\u7684\u3002<\/p>\n<h5>12.3.1 \u201c\u5728\u6211\u7535\u8111\u4e0a\u80fd\u8dd1\u201d\u7684\u56f0\u5883<\/h5>\n<p>\u95ee\u9898\u7684\u6839\u6e90\u5728\u4e8e\u73af\u5883\u4f9d\u8d56\u7684\u5dee\u5f02&#xff1a;<\/p>\n<ul>\n<li>Python\u7248\u672c\u4e0d\u540c\u3002<\/li>\n<li>scikit-learn,\u00a0lightgbm,\u00a0fastapi\u7b49\u5e93\u7684\u7248\u672c\u4e0d\u540c\u3002<\/li>\n<li>\u751a\u81f3\u64cd\u4f5c\u7cfb\u7edf\u5e95\u5c42\u7684\u4e00\u4e9b\u4f9d\u8d56\u5e93\u4e5f\u53ef\u80fd\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<h5>12.3.2 Docker\u7684\u6838\u5fc3\u601d\u60f3&#xff1a;\u96c6\u88c5\u7bb1\u5f0f\u7684\u6807\u51c6\u5316<\/h5>\n<p>Docker\u901a\u8fc7\u201c\u5bb9\u5668\u5316\u201d\u6280\u672f&#xff0c;\u5c06\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u53ca\u5176\u6240\u6709\u4f9d\u8d56&#xff08;\u4ee3\u7801\u3001\u8fd0\u884c\u65f6\u3001\u5e93\u3001\u73af\u5883\u53d8\u91cf&#xff09;\u6253\u5305\u5230\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u3001\u53ef\u79fb\u690d\u7684\u5355\u5143\u4e2d&#xff0c;\u8fd9\u4e2a\u5355\u5143\u5c31\u662f\u5bb9\u5668\u3002<\/p>\n<ul>\n<li>\u955c\u50cf&#xff08;Image&#xff09;&#xff1a;\u4e00\u4e2a\u53ea\u8bfb\u7684\u6a21\u677f&#xff0c;\u662f\u5bb9\u5668\u7684\u201c\u84dd\u56fe\u201d\u3002<\/li>\n<li>\u5bb9\u5668&#xff08;Container&#xff09;&#xff1a;\u955c\u50cf\u7684\u4e00\u4e2a\u53ef\u8fd0\u884c\u5b9e\u4f8b\u3002\u5b83\u4e0e\u5bbf\u4e3b\u7cfb\u7edf\u548c\u5176\u4ed6\u5bb9\u5668\u76f8\u4e92\u9694\u79bb&#xff0c;\u62e5\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u6587\u4ef6\u7cfb\u7edf\u548c\u7f51\u7edc\u7a7a\u95f4\u3002<\/li>\n<li>Dockerfile&#xff1a;\u4e00\u4e2a\u6587\u672c\u6587\u4ef6&#xff0c;\u50cf\u4e00\u4efd\u201c\u83dc\u8c31\u201d&#xff0c;\u5b9a\u4e49\u4e86\u6784\u5efa\u4e00\u4e2aDocker\u955c\u50cf\u6240\u9700\u7684\u6240\u6709\u6b65\u9aa4\u3002<\/li>\n<\/ul>\n<h5>12.3.3 \u5b9e\u6218\u6f14\u7ec3&#xff1a;\u5c06\u6211\u4eec\u7684FastAPI\u670d\u52a1\u6253\u5305\u6210Docker\u955c\u50cf<\/h5>\n<li>\n<p>\u521b\u5efarequirements.txt\u6587\u4ef6\u00a0\u8fd9\u4e2a\u6587\u4ef6\u5217\u51fa\u4e86\u6211\u4eec\u9879\u76ee\u7684\u6240\u6709Python\u4f9d\u8d56\u3002<\/p>\n<p>fastapi<br \/>\nuvicorn[standard]<br \/>\nscikit-learn<br \/>\nlightgbm<br \/>\njoblib<br \/>\nnumpy<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Dockerfile\u00a0\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aDockerfile&#xff08;\u6ca1\u6709\u6269\u5c55\u540d&#xff09;\u7684\u6587\u4ef6\u3002<\/p>\n<p># 1. \u9009\u62e9\u4e00\u4e2a\u5b98\u65b9\u7684Python\u8fd0\u884c\u65f6\u4f5c\u4e3a\u57fa\u7840\u955c\u50cf<br \/>\nFROM python:3.9-slim<\/p>\n<p># 2. \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55<br \/>\nWORKDIR \/app<\/p>\n<p># 3. \u590d\u5236\u4f9d\u8d56\u6587\u4ef6\u5230\u5de5\u4f5c\u76ee\u5f55<br \/>\nCOPY requirements.txt .<\/p>\n<p># 4. \u5b89\u88c5\u4f9d\u8d56<br \/>\nRUN pip install &#8211;no-cache-dir -r requirements.txt<\/p>\n<p># 5. \u590d\u5236\u9879\u76ee\u7684\u6240\u6709\u6587\u4ef6\u5230\u5de5\u4f5c\u76ee\u5f55<br \/>\nCOPY . .<\/p>\n<p># 6. \u66b4\u9732\u7aef\u53e3&#xff0c;\u8ba9\u5bb9\u5668\u5916\u7684\u4e16\u754c\u53ef\u4ee5\u8bbf\u95ee<br \/>\nEXPOSE 8000<\/p>\n<p># 7. \u5b9a\u4e49\u5bb9\u5668\u542f\u52a8\u65f6\u8981\u6267\u884c\u7684\u547d\u4ee4<br \/>\nCMD [&#034;uvicorn&#034;, &#034;main:app&#034;, &#034;&#8211;host&#034;, &#034;0.0.0.0&#034;, &#034;&#8211;port&#034;, &#034;8000&#034;]<\/p>\n<\/li>\n<li>\n<p>\u6784\u5efa\u4e0e\u8fd0\u884c\u00a0\u786e\u4fdd\u4f60\u7684\u673a\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Docker\u3002\u5728\u7ec8\u7aef\u4e2d&#xff0c;\u786e\u4fdd\u4f60\u5728Dockerfile\u6240\u5728\u7684\u76ee\u5f55\u4e0b&#xff0c;\u7136\u540e\u6267\u884c&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6784\u5efa\u955c\u50cf&#xff1a;\u00a0docker build -t fraud-detection-api .\u00a0&#xff08;-t\u53c2\u6570\u4e3a\u955c\u50cf\u547d\u540d&#xff0c;.\u8868\u793a\u4f7f\u7528\u5f53\u524d\u76ee\u5f55\u7684Dockerfile&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u8fd0\u884c\u5bb9\u5668&#xff1a;\u00a0docker run -p 8000:8000 fraud-detection-api\u00a0&#xff08;-p 8000:8000\u5c06\u5bbf\u4e3b\u673a\u76848000\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u76848000\u7aef\u53e3&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u73b0\u5728&#xff0c;\u4f60\u7684API\u670d\u52a1\u5c31\u5728\u4e00\u4e2a\u9694\u79bb\u7684\u3001\u6807\u51c6\u5316\u7684\u5bb9\u5668\u4e2d\u8fd0\u884c\u4e86\u3002\u4f60\u53ef\u4ee5\u518d\u6b21\u8bbf\u95eehttp:\/\/127.0.0.1:8000\/docs\u6765\u9a8c\u8bc1\u5b83 \u3002\u8fd9\u4e2a\u5bb9\u5668\u53ef\u4ee5\u88ab\u8f7b\u677e\u5730\u90e8\u7f72\u5230\u4efb\u4f55\u5b89\u88c5\u4e86Docker\u7684\u670d\u52a1\u5668\u6216\u4e91\u5e73\u53f0\u4e0a&#xff0c;\u5b8c\u7f8e\u5730\u89e3\u51b3\u4e86\u73af\u5883\u4f9d\u8d56\u95ee\u9898\u3002<\/p>\n<hr \/>\n<h4>12.4 MLOps\u521d\u63a2&#xff1a;\u81ea\u52a8\u5316\u3001\u76d1\u63a7\u4e0e\u518d\u8bad\u7ec3<\/h4>\n<p>\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u90e8\u7f72\u4e86\u6a21\u578b&#xff0c;\u4f46\u8fd9\u53ea\u662f\u4e00\u4e2a\u9759\u6001\u7684\u90e8\u7f72\u3002\u5728\u771f\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u6570\u636e\u662f\u4e0d\u65ad\u53d8\u5316\u7684&#xff0c;\u6a21\u578b\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b\u3002<\/p>\n<h5>12.4.1 \u8d85\u8d8a\u4e00\u6b21\u6027\u90e8\u7f72&#xff1a;\u6a21\u578b\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406<\/h5>\n<ul>\n<li>\u6a21\u578b\u9000\u5316&#xff08;Model Decay&#xff09;&#xff1a;\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb&#xff0c;\u73b0\u5b9e\u4e16\u754c\u7684\u6570\u636e\u5206\u5e03\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316&#xff08;\u4f8b\u5982&#xff0c;\u6b3a\u8bc8\u624b\u6bb5\u66f4\u65b0\u4e86&#xff09;&#xff0c;\u5bfc\u81f4\u6a21\u578b\u7684\u9884\u6d4b\u6027\u80fd\u9010\u6e10\u4e0b\u964d\u3002\u8fd9\u5c31\u662f\u201c\u6a21\u578b\u9000\u5316\u201d\u3002<\/li>\n<li>MLOps&#xff08;Machine Learning Operations&#xff09;&#xff1a;\u5b83\u501f\u9274\u4e86\u8f6f\u4ef6\u5de5\u7a0b\u4e2dDevOps\u7684\u7406\u5ff5&#xff0c;\u662f\u4e00\u5957\u65e8\u5728\u5b9e\u73b0\u673a\u5668\u5b66\u4e60\u6a21\u578b\u5f00\u53d1&#xff08;Dev&#xff09;\u3001\u90e8\u7f72\u548c\u8fd0\u7ef4&#xff08;Ops&#xff09;\u81ea\u52a8\u5316\u4e0e\u6807\u51c6\u5316\u7684\u5b9e\u8df5\u548c\u539f\u5219\u3002\u5176\u76ee\u6807\u662f\u7f29\u77ed\u6a21\u578b\u8fed\u4ee3\u5468\u671f&#xff0c;\u63d0\u9ad8\u90e8\u7f72\u8d28\u91cf\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ul>\n<h5>12.4.2 MLOps\u7684\u6838\u5fc3\u7406\u5ff5<\/h5>\n<ul>\n<li>CI\/CD for ML&#xff1a;\u5c06\u6301\u7eed\u96c6\u6210\/\u6301\u7eed\u90e8\u7f72\u7684\u601d\u60f3\u5e94\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u3002\n<ul>\n<li>CI&#xff08;\u6301\u7eed\u96c6\u6210&#xff09;&#xff1a;\u4ee3\u7801&#xff08;\u5305\u62ec\u6570\u636e\u5904\u7406\u3001\u6a21\u578b\u8bad\u7ec3\u4ee3\u7801&#xff09;\u7684\u4efb\u4f55\u53d8\u66f4\u90fd\u4f1a\u81ea\u52a8\u89e6\u53d1\u6d4b\u8bd5\u548c\u9a8c\u8bc1\u3002<\/li>\n<li>CD&#xff08;\u6301\u7eed\u4ea4\u4ed8\/\u90e8\u7f72&#xff09;&#xff1a;\u4e00\u65e6\u6a21\u578b\u901a\u8fc7\u6240\u6709\u6d4b\u8bd5&#xff0c;\u5c31\u4f1a\u88ab\u81ea\u52a8\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u81ea\u52a8\u5316\u6d41\u6c34\u7ebf&#xff08;Pipeline&#xff09;&#xff1a;\u5c06\u6570\u636e\u83b7\u53d6\u3001\u9884\u5904\u7406\u3001\u7279\u5f81\u5de5\u7a0b\u3001\u6a21\u578b\u8bad\u7ec3\u3001\u8bc4\u4f30\u3001\u7248\u672c\u63a7\u5236\u3001\u90e8\u7f72\u7b49\u73af\u8282\u4e32\u8054\u6210\u4e00\u4e2a\u81ea\u52a8\u5316\u7684\u5de5\u4f5c\u6d41\u3002<\/li>\n<li>\u76d1\u63a7&#xff08;Monitoring&#xff09;&#xff1a;\u6301\u7eed\u76d1\u63a7\u7ebf\u4e0a\u6a21\u578b\u7684\u6027\u80fd\u3002\n<ul>\n<li>\u6280\u672f\u6307\u6807&#xff1a;API\u7684\u5ef6\u8fdf\u3001QPS\u3001\u9519\u8bef\u7387\u3002<\/li>\n<li>\u6a21\u578b\u6307\u6807&#xff1a;\u9884\u6d4b\u7ed3\u679c\u7684\u5206\u5e03\u662f\u5426\u7a33\u5b9a&#xff1f;\u8f93\u5165\u7279\u5f81\u7684\u5206\u5e03\u662f\u5426\u53d1\u751f\u4e86\u6570\u636e\u6f02\u79fb&#xff08;Data Drift&#xff09;&#xff1f;\u5982\u679c\u80fd\u83b7\u53d6\u5230\u771f\u5b9e\u6807\u7b7e&#xff0c;\u6a21\u578b\u7684\u51c6\u786e\u7387\u3001\u53ec\u56de\u7387\u662f\u5426\u4e0b\u964d&#xff1f;<\/li>\n<\/ul>\n<\/li>\n<li>\u518d\u8bad\u7ec3&#xff08;Retraining&#xff09;&#xff1a;\u5efa\u7acb\u89e6\u53d1\u673a\u5236&#xff08;\u5982\u6027\u80fd\u4e0b\u964d\u5230\u67d0\u4e2a\u9608\u503c&#xff0c;\u6216\u5b9a\u671f\u5982\u6bcf\u5468\/\u6bcf\u6708&#xff09;&#xff0c;\u81ea\u52a8\u4f7f\u7528\u6700\u65b0\u7684\u6570\u636e\u5bf9\u6a21\u578b\u8fdb\u884c\u518d\u8bad\u7ec3&#xff0c;\u5e76\u751f\u6210\u65b0\u7248\u672c\u7684\u6a21\u578b&#xff0c;\u7136\u540e\u901a\u8fc7\u6d41\u6c34\u7ebf\u8fdb\u884c\u8bc4\u4f30\u548c\u90e8\u7f72\u3002<\/li>\n<\/ul>\n<h5>12.4.3 \u5de5\u5177\u4e0e\u5c55\u671b<\/h5>\n<p>MLOps\u662f\u4e00\u4e2a\u5e9e\u5927\u800c\u590d\u6742\u7684\u9886\u57df&#xff0c;\u901a\u5e38\u9700\u8981\u4e13\u95e8\u7684\u5de5\u5177\u548c\u5e73\u53f0\u6765\u652f\u6491\u3002<\/p>\n<ul>\n<li>\u5f00\u6e90\u5de5\u5177&#xff1a;\n<ul>\n<li>\u5b9e\u9a8c\u8ffd\u8e2a\u4e0e\u6a21\u578b\u6ce8\u518c&#xff1a;MLflow,\u00a0DVC<\/li>\n<li>\u5de5\u4f5c\u6d41\u7f16\u6392&#xff1a;Kubeflow,\u00a0Airflow<\/li>\n<li>\u6a21\u578b\u670d\u52a1&#xff1a;Seldon Core,\u00a0KServe<\/li>\n<\/ul>\n<\/li>\n<li>\u4e91\u5e73\u53f0\u670d\u52a1&#xff1a;\u5404\u5927\u4e91\u5382\u5546\u90fd\u63d0\u4f9b\u4e86\u7aef\u5230\u7aef\u7684MLOps\u89e3\u51b3\u65b9\u6848&#xff0c;\u5982Amazon SageMaker,\u00a0Google AI Platform (Vertex AI),\u00a0Azure Machine Learning\u3002\u5b83\u4eec\u5c06\u4e0a\u8ff0\u8bb8\u591a\u529f\u80fd\u96c6\u6210\u5728\u4e86\u4e00\u8d77&#xff0c;\u964d\u4f4e\u4e86\u5b9e\u65bdMLOps\u7684\u95e8\u69db\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u4ece\u7b97\u6cd5\u5230\u670d\u52a1\u7684\u5173\u952e\u4e00\u8dc3\u3002\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u4fdd\u5b58\u548c\u52a0\u8f7d\u6a21\u578b&#xff0c;\u5982\u4f55\u7528FastAPI\u4e3a\u5176\u7a7f\u4e0aAPI\u7684\u201c\u5916\u8863\u201d&#xff0c;\u5982\u4f55\u7528Docker\u4e3a\u5176\u6253\u9020\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u201c\u5bb6\u201d&#xff0c;\u5e76\u6700\u7ec8\u5c06\u89c6\u91ce\u6295\u5411\u4e86MLOps\u8fd9\u7247\u66f4\u5e7f\u9614\u7684\u661f\u8fb0\u5927\u6d77\u3002<\/p>\n<p>\u81f3\u6b64&#xff0c;\u6211\u4eec\u5df2\u7ecf\u8d70\u5b8c\u4e86\u4e00\u540d\u6570\u636e\u79d1\u5b66\u5bb6\u4ece\u5165\u95e8\u5230\u5b9e\u8df5\u7684\u5168\u8fc7\u7a0b\u3002\u60a8\u4e0d\u4ec5\u638c\u63e1\u4e86\u673a\u5668\u5b66\u4e60\u7684\u6838\u5fc3\u7406\u8bba\u4e0e\u7b97\u6cd5&#xff0c;\u66f4\u5177\u5907\u4e86\u5c06\u6a21\u578b\u4ed8\u8bf8\u5b9e\u8df5\u3001\u521b\u9020\u771f\u5b9e\u4ef7\u503c\u7684\u5de5\u7a0b\u80fd\u529b\u3002\u8fd9\u5e76\u975e\u7ec8\u70b9&#xff0c;\u800c\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u3001\u6fc0\u52a8\u4eba\u5fc3\u7684\u8d77\u70b9\u3002\u613f\u60a8\u5e26\u7740\u8fd9\u4efd\u5b8c\u6574\u7684\u77e5\u8bc6\u4f53\u7cfb&#xff0c;\u5728\u6570\u636e\u79d1\u5b66\u7684\u9053\u8def\u4e0a&#xff0c;\u4e0d\u65ad\u63a2\u7d22&#xff0c;\u4e0d\u65ad\u521b\u9020&#xff0c;\u884c\u7a33\u81f4\u8fdc\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u5341\u4e09\u7ae0&#xff1a;\u8d85\u8d8a\u7ecf\u5178\u2014\u2014\u672a\u6765\u5c55\u671b\u4e0e\u8fdb\u9636\u8def\u5f84<\/h3>\n<ul>\n<li>13.1 \u6df1\u5ea6\u5b66\u4e60\u6982\u89c8&#xff1a;CNN\u3001RNN\u7684\u4e16\u754c<\/li>\n<li>13.2 \u5f3a\u5316\u5b66\u4e60&#xff1a;\u4e0e\u73af\u5883\u4ea4\u4e92\u7684\u667a\u80fd\u4f53<\/li>\n<li>13.3 \u56fe\u795e\u7ecf\u7f51\u7edc\u3001\u8054\u90a6\u5b66\u4e60\u7b49\u524d\u6cbf\u7b80\u4ecb<\/li>\n<li>13.4 \u201c\u77e5\u884c\u5408\u4e00\u201d&#xff1a;\u5982\u4f55\u6301\u7eed\u5b66\u4e60\u4e0e\u6210\u957f<\/li>\n<\/ul>\n<p>\u4eb2\u7231\u7684\u8bfb\u8005&#xff0c;\u5f53\u60a8\u62b5\u8fbe\u672c\u4e66\u7684\u7ec8\u7ae0&#xff0c;\u60a8\u5df2\u4e0d\u518d\u662f\u65c1\u89c2\u8005&#xff0c;\u800c\u662f\u8eab\u6000\u7edd\u6280\u7684\u5165\u5c40\u8005\u3002\u60a8\u6240\u638c\u63e1\u7684\u7ecf\u5178\u673a\u5668\u5b66\u4e60\u7406\u8bba\u4e0e\u5b9e\u8df5&#xff0c;\u662f\u7406\u89e3\u8fd9\u4e2a\u6570\u636e\u9a71\u52a8\u65f6\u4ee3\u7684\u575a\u56fa\u57fa\u77f3\u3002\u7136\u800c&#xff0c;\u6280\u672f\u7684\u5730\u5e73\u7ebf\u603b\u5728\u4e0d\u65ad\u5411\u8fdc\u65b9\u5ef6\u4f38&#xff0c;\u5f15\u9886\u6d6a\u6f6e\u4e4b\u5dc5\u7684&#xff0c;\u6b63\u662f\u6df1\u5ea6\u5b66\u4e60\u90a3\u7480\u74a8\u7684\u7fa4\u661f\u3002<\/p>\n<p>\u672c\u7ae0&#xff0c;\u6211\u4eec\u5c06\u4ee5\u4e00\u79cd\u524d\u6240\u672a\u6709\u7684\u6df1\u5ea6&#xff0c;\u53bb\u63a2\u7d22\u6df1\u5ea6\u5b66\u4e60\u7684\u6838\u5fc3\u5206\u652f\u3002\u6211\u4eec\u4e0d\u518d\u6ee1\u8db3\u4e8e\u6982\u5ff5\u7684\u7f57\u5217&#xff0c;\u800c\u662f\u8981\u6df1\u5165\u5176\u8bbe\u8ba1\u7684\u54f2\u5b66&#xff0c;\u5256\u6790\u5176\u6570\u5b66\u7684\u808c\u7406&#xff0c;\u8ffd\u6eaf\u5176\u6f14\u5316\u7684\u903b\u8f91\u3002\u6211\u4eec\u5c06\u63a2\u8ba8\u6bcf\u4e00\u4e2a\u6a21\u578b\u8bde\u751f\u7684\u201c\u52a8\u673a\u201d\u2014\u2014\u5b83\u89e3\u51b3\u4e86\u524d\u8f88\u7684\u4f55\u79cd\u201c\u56f0\u5883\u201d&#xff1f;\u6211\u4eec\u8fd8\u5c06\u63d0\u4f9b\u4e00\u4efd\u8be6\u5c3d\u7684\u201c\u8fdb\u9636\u8def\u7ebf\u56fe\u201d&#xff0c;\u5305\u542b\u5fc5\u8bfb\u7684\u201c\u5723\u7ecf\u7ea7\u201d\u8bba\u6587\u53ca\u53ef\u4e0a\u624b\u7684\u201c\u91cc\u7a0b\u7891\u5f0f\u201d\u9879\u76ee\u548c\u503c\u5f97\u5173\u6ce8\u7684\u201c\u524d\u6cbf\u65b9\u5411\u201d\u3002<\/p>\n<p>\u8fd9\u4e0d\u4ec5\u662f\u77e5\u8bc6\u7684\u4f20\u9012&#xff0c;\u66f4\u662f\u4e00\u6b21\u601d\u7ef4\u7684\u6dec\u70bc\u3002\u613f\u60a8\u5728\u672c\u7ae0\u7684\u5f15\u9886\u4e0b&#xff0c;\u5b8c\u6210\u4ece\u201c\u6a21\u578b\u4f7f\u7528\u8005\u201d\u5230\u201c\u7b97\u6cd5\u601d\u60f3\u5bb6\u201d\u7684\u8715\u53d8\u3002<\/p>\n<hr \/>\n<h4>13.1 \u6df1\u5ea6\u5b66\u4e60\u8fdb\u9636&#xff1a;\u4ece\u201c\u4e07\u91d1\u6cb9\u201d\u5230\u201c\u7279\u79cd\u5175\u201d\u7684\u67b6\u6784\u6f14\u5316<\/h4>\n<p>\u6211\u4eec\u5728\u7b2c\u4e5d\u7ae0\u5b66\u4e60\u7684\u591a\u5c42\u611f\u77e5\u673a&#xff08;MLP&#xff09;&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u201c\u901a\u7528\u51fd\u6570\u62df\u5408\u5668\u201d\u3002\u5b83\u5c06\u8f93\u5165\u6570\u636e\u201c\u4e00\u89c6\u540c\u4ec1\u201d\u5730\u5c55\u5e73\u4e3a\u4e00\u7ef4\u5411\u91cf&#xff0c;\u5e76\u901a\u8fc7\u5168\u8fde\u63a5\u5c42\u8fdb\u884c\u53d8\u6362\u3002\u8fd9\u79cd\u201c\u4e07\u91d1\u6cb9\u201d\u5f0f\u7684\u8bbe\u8ba1&#xff0c;\u5728\u5904\u7406\u7f3a\u4e4f\u5185\u5728\u7ed3\u6784\u7684\u6570\u636e\u65f6\u8868\u73b0\u5c1a\u53ef\u3002\u4f46\u5f53\u9762\u5bf9\u5177\u6709\u7cbe\u5de7\u7ed3\u6784\u7684\u6570\u636e\u2014\u2014\u5982\u56fe\u50cf\u4e2d\u50cf\u7d20\u7684\u7a7a\u95f4\u6392\u5217\u3001\u8bed\u8a00\u4e2d\u8bcd\u8bed\u7684\u65f6\u95f4\u5e8f\u5217\u2014\u2014MLP\u7684\u201c\u4e00\u89c6\u540c\u4ec1\u201d\u5c31\u53d8\u6210\u4e86\u5b83\u7684\u201c\u963f\u5580\u7409\u65af\u4e4b\u8e35\u201d\u3002\u5b83\u4e0d\u4ec5\u4f1a\u56e0\u53c2\u6570\u91cf\u7206\u70b8\u800c\u9677\u5165\u201c\u7ef4\u5ea6\u707e\u96be\u201d&#xff0c;\u66f4\u4f1a\u7c97\u66b4\u5730\u7834\u574f\u6389\u6570\u636e\u4e2d\u6700\u5b9d\u8d35\u7684\u7ed3\u6784\u4fe1\u606f\u3002<\/p>\n<p>\u6df1\u5ea6\u5b66\u4e60\u7684\u9769\u547d\u6027\u7a81\u7834&#xff0c;\u6b63\u5728\u4e8e\u5b83\u53d1\u5c55\u51fa\u4e86\u4e00\u7cfb\u5217\u201c\u7279\u79cd\u5175\u201d\u5f0f\u7684\u7f51\u7edc\u67b6\u6784\u3002\u8fd9\u4e9b\u67b6\u6784\u5185\u7f6e\u4e86\u9488\u5bf9\u7279\u5b9a\u6570\u636e\u7ed3\u6784\u7684\u5f52\u7eb3\u504f\u7f6e&#xff08;Inductive Bias&#xff09;&#xff0c;\u5373\u4e00\u79cd\u57fa\u4e8e\u5148\u9a8c\u77e5\u8bc6\u7684\u201c\u4e16\u754c\u89c2\u201d\u5047\u8bbe\u3002\u6b63\u662f\u8fd9\u4e9b\u201c\u504f\u89c1\u201d&#xff0c;\u8ba9\u6a21\u578b\u80fd\u66f4\u9ad8\u6548\u3001\u66f4\u6df1\u523b\u5730\u5b66\u4e60\u3002<\/p>\n<h5>13.1.1 \u5377\u79ef\u795e\u7ecf\u7f51\u7edc&#xff08;CNN&#xff09;&#xff1a;\u4e3a\u201c\u7a7a\u95f4\u201d\u800c\u751f\u7684\u89c6\u89c9\u5927\u5e08<\/h5>\n<p>1. \u52a8\u673a\u4e0e\u54f2\u5b66&#xff1a;\u4e3a\u4f55\u5377\u79ef&#xff1f;<\/p>\n<ul>\n<li>\n<p>\u56f0\u5883&#xff1a;\u7528MLP\u5904\u7406\u4e00\u5f20\u4ec5\u4e3a224x224x3\u7684\u5f69\u8272\u56fe\u50cf&#xff08;ImageNet\u7ade\u8d5b\u7684\u7ecf\u5178\u5c3a\u5bf8&#xff09;&#xff0c;\u8f93\u5165\u5c42\u795e\u7ecf\u5143\u6570\u91cf\u9ad8\u8fbe150,528\u4e2a\u3002\u82e5\u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\u67094096\u4e2a\u795e\u7ecf\u5143&#xff08;AlexNet\u7684\u914d\u7f6e&#xff09;&#xff0c;\u4ec5\u8fd9\u4e00\u5c42\u7684\u6743\u91cd\u53c2\u6570\u5c31\u5c06\u8fbe\u5230\u60ca\u4eba\u7684\u00a06\u4ebf&#xff08;150528 * 4096&#xff09;&#xff01;\u8fd9\u5728\u8ba1\u7b97\u4e0a\u96be\u4ee5\u627f\u53d7&#xff0c;\u5728\u6570\u636e\u4e0a\u6781\u6613\u8fc7\u62df\u5408\u3002\u66f4\u81f4\u547d\u7684\u662f&#xff0c;\u5b83\u5b8c\u5168\u5ffd\u7565\u4e86\u56fe\u50cf\u7684\u4e24\u4e2a\u57fa\u672c\u5148\u9a8c&#xff1a;<\/p>\n<li>\u5c40\u90e8\u76f8\u5173\u6027&#xff08;Locality&#xff09;&#xff1a;\u4e00\u4e2a\u50cf\u7d20\u7684\u542b\u4e49&#xff0c;\u4e0e\u5176\u7d27\u90bb\u7684\u50cf\u7d20\u5173\u7cfb\u6700\u5bc6\u5207\u3002\u8fdc\u9694\u5343\u91cc\u7684\u4e24\u4e2a\u50cf\u7d20\u51e0\u4e4e\u6ca1\u6709\u76f4\u63a5\u5173\u8054\u3002<\/li>\n<li>\u5e73\u79fb\u4e0d\u53d8\u6027&#xff08;Translation Invariance&#xff09;&#xff1a;\u4e00\u53ea\u732b&#xff0c;\u65e0\u8bba\u51fa\u73b0\u5728\u56fe\u50cf\u7684\u5de6\u4e0a\u89d2\u8fd8\u662f\u53f3\u4e0b\u89d2&#xff0c;\u5b83\u4ecd\u7136\u662f\u4e00\u53ea\u732b\u3002\u6211\u4eec\u5bfb\u627e\u7684\u7279\u5f81&#xff08;\u5982\u732b\u7684\u8033\u6735&#xff09;\u5e94\u8be5\u4e0e\u4f4d\u7f6e\u65e0\u5173\u3002<\/li>\n<\/li>\n<li>\n<p>\u54f2\u5b66\u7a81\u7834&#xff1a;\u5f15\u5165\u201c\u7a7a\u95f4\u201d\u7684\u5f52\u7eb3\u504f\u7f6e\u00a0CNN\u7684\u8bbe\u8ba1\u54f2\u5b66&#xff0c;\u5c31\u662f\u5c06\u8fd9\u4e24\u4e2a\u201c\u5148\u9a8c\u201d\u786c\u7f16\u7801\u5230\u7f51\u7edc\u7ed3\u6784\u4e2d\u3002\u5b83\u4e0d\u518d\u5c06\u56fe\u50cf\u770b\u4f5c\u6241\u5e73\u7684\u5411\u91cf&#xff0c;\u800c\u662f\u770b\u4f5c\u4e00\u4e2a\u6709\u957f\u3001\u5bbd\u3001\u6df1&#xff08;\u901a\u9053&#xff09;\u7684\u4e09\u7ef4\u5f20\u91cf\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2. \u6838\u5fc3\u6b66\u5668\u5e93&#xff1a;CNN\u7684\u4e24\u5927\u57fa\u77f3<\/p>\n<ul>\n<li>\n<p>\u57fa\u77f3\u4e00&#xff1a;\u5c40\u90e8\u611f\u53d7\u91ce&#xff08;Local Receptive Fields&#xff09;\u4e0e\u5377\u79ef&#xff08;Convolution&#xff09;<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;CNN\u4e0d\u518d\u8fdb\u884c\u5168\u8fde\u63a5&#xff0c;\u800c\u662f\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4e2a\u5c0f\u7684\u3001\u5171\u4eab\u7684\u5377\u79ef\u6838&#xff08;Kernel\/Filter&#xff09;\u3002\u6bcf\u4e2a\u795e\u7ecf\u5143\u53ea\u201c\u770b\u201d\u8f93\u5165\u56fe\u50cf\u7684\u4e00\u5c0f\u5757\u533a\u57df&#xff08;\u5373\u5c40\u90e8\u611f\u53d7\u91ce&#xff09;&#xff0c;\u8fd9\u4e2a\u533a\u57df\u7684\u5927\u5c0f\u5c31\u662f\u5377\u79ef\u6838\u7684\u5927\u5c0f&#xff08;\u59823&#215;3, 5&#215;5&#xff09;\u3002\u5377\u79ef\u6838\u5185\u5305\u542b\u4e00\u7ec4\u53ef\u5b66\u4e60\u7684\u6743\u91cd&#xff0c;\u5b83\u5728\u6574\u4e2a\u8f93\u5165\u56fe\u50cf\u4e0a\u6309\u6b65\u957f&#xff08;Stride&#xff09;\u6ed1\u52a8&#xff0c;\u6bcf\u6ed1\u52a8\u5230\u4e00\u4e2a\u4f4d\u7f6e&#xff0c;\u5c31\u4e0e\u8be5\u4f4d\u7f6e\u7684\u5c40\u90e8\u56fe\u50cf\u5757\u8fdb\u884c\u70b9\u79ef\u8fd0\u7b97&#xff0c;\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u8f93\u51fa\u503c\u3002\u6240\u6709\u8f93\u51fa\u503c\u5171\u540c\u6784\u6210\u4e00\u5f20\u7279\u5f81\u56fe&#xff08;Feature Map&#xff09;\u3002<\/li>\n<li>\u610f\u4e49&#xff1a;\u8fd9\u5b8c\u7f8e\u5730\u4f53\u73b0\u4e86\u201c\u5c40\u90e8\u76f8\u5173\u6027\u201d\u3002\u6bcf\u4e2a\u8f93\u51fa\u503c\u90fd\u53ea\u7531\u4e00\u5c0f\u7247\u5c40\u90e8\u4fe1\u606f\u8ba1\u7b97\u800c\u6765\u3002\u4e00\u4e2a\u5377\u79ef\u6838&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u53ef\u5b66\u4e60\u7684\u201c\u6a21\u5f0f\u63a2\u6d4b\u5668\u201d&#xff0c;\u4e13\u95e8\u8d1f\u8d23\u5bfb\u627e\u4e00\u79cd\u7279\u5b9a\u7684\u5fae\u89c2\u6a21\u5f0f&#xff0c;\u5982\u6c34\u5e73\u8fb9\u7f18\u3001\u7eff\u8272\u6591\u5757\u6216\u67d0\u4e2a\u7279\u5b9a\u7684\u7eb9\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u57fa\u77f3\u4e8c&#xff1a;\u53c2\u6570\u5171\u4eab&#xff08;Parameter Sharing&#xff09;\u4e0e\u6c60\u5316&#xff08;Pooling&#xff09;<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;\n<ul>\n<li>\u53c2\u6570\u5171\u4eab&#xff1a;\u7528\u4e8e\u751f\u6210\u540c\u4e00\u5f20\u7279\u5f81\u56fe\u7684\u90a3\u4e2a\u5377\u79ef\u6838&#xff0c;\u5176\u5185\u90e8\u7684\u6743\u91cd\u5728\u6ed1\u52a8\u5230\u56fe\u50cf\u7684\u4efb\u4f55\u4f4d\u7f6e\u65f6\u90fd\u662f\u5b8c\u5168\u76f8\u540c\u7684\u3002\u8fd9\u610f\u5473\u7740&#xff0c;\u7f51\u7edc\u7528\u540c\u4e00\u5957\u53c2\u6570\u53bb\u5bfb\u627e\u56fe\u50cf\u4e2d\u6240\u6709\u4f4d\u7f6e\u7684\u540c\u4e00\u79cd\u7279\u5f81\u3002<\/li>\n<li>\u6c60\u5316&#xff1a;\u5728\u5377\u79ef\u5c42\u4e4b\u540e&#xff0c;\u901a\u5e38\u4f1a\u63a5\u4e00\u4e2a\u6c60\u5316\u5c42&#xff08;\u5982\u6700\u5927\u6c60\u5316Max Pooling&#xff09;\u3002\u5b83\u5c06\u7279\u5f81\u56fe\u5212\u5206\u4e3a\u82e5\u5e72\u4e2a\u4e0d\u91cd\u53e0\u7684\u533a\u57df&#xff08;\u59822&#215;2&#xff09;&#xff0c;\u5e76\u4ece\u6bcf\u4e2a\u533a\u57df\u4e2d\u53d6\u6700\u5927\u503c\u4f5c\u4e3a\u8f93\u51fa\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u610f\u4e49&#xff1a;\n<ul>\n<li>\u53c2\u6570\u5171\u4eab\u662fCNN\u6700\u5929\u624d\u7684\u8bbe\u8ba1\u3002\u5b83\u76f4\u63a5\u5c06\u201c\u5e73\u79fb\u4e0d\u53d8\u6027\u201d\u7684\u5047\u8bbe\u6ce8\u5165\u4e86\u6a21\u578b&#xff0c;\u5e76\u4f7f\u5f97\u6a21\u578b\u7684\u53c2\u6570\u91cf\u4ece\u201c\u4ebf\u201d\u7ea7\u522b\u9aa4\u964d\u5230\u201c\u4e07\u201d\u751a\u81f3\u201c\u5343\u201d\u7ea7\u522b&#xff0c;\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u548c\u8bad\u7ec3\u6548\u7387\u3002<\/li>\n<li>\u6c60\u5316\u64cd\u4f5c\u5219\u63d0\u4f9b\u4e86\u53e6\u4e00\u79cd\u5f62\u5f0f\u7684\u5e73\u79fb\u4e0d\u53d8\u6027&#xff0c;\u5e76\u5b9e\u73b0\u4e86\u5bf9\u7279\u5f81\u56fe\u7684\u964d\u91c7\u6837&#xff0c;\u65e2\u51cf\u5c11\u4e86\u540e\u7eed\u8ba1\u7b97\u91cf&#xff0c;\u53c8\u589e\u5927\u4e86\u4e0a\u5c42\u795e\u7ecf\u5143\u7684\u201c\u611f\u53d7\u91ce\u201d&#xff08;\u5373\u5b83\u80fd\u770b\u5230\u7684\u539f\u59cb\u56fe\u50cf\u533a\u57df\u8303\u56f4&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>3. \u67b6\u6784\u6f14\u5316\u4e0e\u8fdb\u9636\u8def\u5f84<\/p>\n<ul>\n<li>\n<p>\u9636\u6bb5\u4e00&#xff1a;\u5960\u57fa\u4e0e\u9a8c\u8bc1 (LeNet-5, AlexNet)<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u65e0\u9700\u8bfbLeCun 1998\u5e74\u7684\u8bba\u6587&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u770bKrizhevsky\u7b49\u4eba2012\u5e74\u7684\u300aImageNet Classification with Deep Convolutional Neural Networks\u300b(AlexNet)\u3002\u8fd9\u7bc7\u8bba\u6587\u662f\u5f15\u7206\u6df1\u5ea6\u5b66\u4e60\u9769\u547d\u7684\u201c\u5b87\u5b99\u5927\u7206\u70b8\u201d\u5947\u70b9\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u7406\u89e3\u7ecf\u5178\u7684\u201c\u5377\u79ef-\u6fc0\u6d3b-\u6c60\u5316\u201d\u5806\u53e0\u6a21\u5f0f\u3002\u6ce8\u610fAlexNet\u5982\u4f55\u4f7f\u7528ReLU\u6fc0\u6d3b\u51fd\u6570\u4ee3\u66ffSigmoid\/Tanh\u6765\u89e3\u51b3\u68af\u5ea6\u6d88\u5931\u95ee\u9898&#xff0c;\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528Dropout\u6765\u5bf9\u6297\u8fc7\u62df\u5408\u3002<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u5728PyTorch\u6216TensorFlow\u4e2d&#xff0c;\u4ece\u96f6\u5f00\u59cb\u642d\u5efa\u4e00\u4e2a\u7c7b\u4f3cLeNet-5\u6216\u7b80\u5316\u7248AlexNet\u7684\u7ed3\u6784&#xff0c;\u5728MNIST\u6216CIFAR-10\u6570\u636e\u96c6\u4e0a\u8fdb\u884c\u8bad\u7ec3\u3002\u76ee\u6807\u662f\u4eb2\u624b\u5b9e\u73b0\u5377\u79ef\u5c42\u3001\u6c60\u5316\u5c42\u3001\u5168\u8fde\u63a5\u5c42\u7684\u8fde\u63a5&#xff0c;\u5e76\u89c2\u5bdf\u6a21\u578b\u4ece\u968f\u673a\u6743\u91cd\u5f00\u59cb\u5b66\u4e60\u5230\u6709\u6548\u7279\u5f81\u7684\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e8c&#xff1a;\u8d70\u5411\u6df1\u5ea6 (VGG, GoogLeNet)<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u300aVery Deep Convolutional Networks for Large-Scale Image Recognition\u300b(VGG) \u548c \u300aGoing Deeper with Convolutions\u300b(GoogLeNet)\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\n<ul>\n<li>VGG&#xff1a;\u63a2\u7d22\u4e86\u201c\u6df1\u5ea6\u201d\u7684\u529b\u91cf\u3002\u5b83\u8bc1\u660e\u4e86\u901a\u8fc7\u5806\u53e0\u975e\u5e38\u5c0f\u7684&#xff08;3&#215;3&#xff09;\u5377\u79ef\u6838&#xff0c;\u53ef\u4ee5\u6784\u5efa\u51fa\u6bd4\u4f7f\u7528\u5927\u5377\u79ef\u6838\u66f4\u6df1\u3001\u66f4\u6709\u6548\u7684\u7f51\u7edc\u3002\u5176\u7ed3\u6784\u975e\u5e38\u89c4\u6574&#xff0c;\u6613\u4e8e\u7406\u89e3\u3002<\/li>\n<li>GoogLeNet&#xff1a;\u5f15\u5165\u4e86\u521b\u65b0\u7684Inception\u6a21\u5757&#xff0c;\u5728\u4e00\u4e2a\u7f51\u7edc\u5c42\u4e2d\u5e76\u884c\u5730\u4f7f\u7528\u4e0d\u540c\u5c3a\u5bf8\u7684\u5377\u79ef\u6838\u548c\u6c60\u5316\u64cd\u4f5c&#xff0c;\u7136\u540e\u5c06\u7ed3\u679c\u62fc\u63a5\u8d77\u6765\u3002\u8fd9\u8ba9\u7f51\u7edc\u53ef\u4ee5\u81ea\u9002\u5e94\u5730\u9009\u62e9\u6700\u5408\u9002\u7684\u611f\u53d7\u91ce\u6765\u6355\u6349\u7279\u5f81&#xff0c;\u5b9e\u73b0\u4e86\u201c\u5bbd\u5ea6\u201d\u548c\u201c\u6df1\u5ea6\u201d\u7684\u7ed3\u5408\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u5b66\u4e60\u4f7f\u7528Keras\u6216PyTorch\u7684API&#xff0c;\u52a0\u8f7d\u4e00\u4e2a\u9884\u8bad\u7ec3&#xff08;Pre-trained&#xff09;\u7684VGG16\u6216InceptionV3\u6a21\u578b\u3002\u7136\u540e&#xff0c;\u66ff\u6362\u6389\u5176\u9876\u90e8\u7684\u5168\u8fde\u63a5\u5c42&#xff0c;\u6362\u4e0a\u4f60\u81ea\u5df1\u5b9a\u4e49\u7684\u5206\u7c7b\u5934&#xff0c;\u5728\u4e00\u4e2a\u65b0\u7684\u3001\u8f83\u5c0f\u7684\u6570\u636e\u96c6\u4e0a&#xff08;\u5982\u732b\u72d7\u5206\u7c7b&#xff09;\u8fdb\u884c\u8fc1\u79fb\u5b66\u4e60&#xff08;Transfer Learning&#xff09;\u3002\u8fd9\u662f\u5de5\u4e1a\u754c\u5e94\u7528CNN\u6700\u6838\u5fc3\u3001\u6700\u9ad8\u6548\u7684\u8303\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e09&#xff1a;\u8de8\u8d8a\u74f6\u9888 (ResNet)<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u4f55\u607a\u660e\u7b49\u4eba\u7684\u300aDeep Residual Learning for Image Recognition\u300b(ResNet)&#xff0c;\u8fd9\u662f\u8ba1\u7b97\u673a\u89c6\u89c9\u9886\u57df\u5f15\u7528\u91cf\u6700\u9ad8\u7684\u8bba\u6587\u4e4b\u4e00&#xff0c;\u601d\u60f3\u6df1\u523b\u800c\u4f18\u7f8e\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u5f53\u7f51\u7edc\u5806\u5f97\u975e\u5e38\u6df1\u65f6&#xff0c;\u4f1a\u51fa\u73b0\u201c\u9000\u5316\u201d\u73b0\u8c61&#xff08;Deeper is not better&#xff09;\u3002ResNet\u5929\u624d\u5730\u5f15\u5165\u4e86\u6b8b\u5dee\u8fde\u63a5&#xff08;Residual Connection&#xff09;\/\u5feb\u6377\u8fde\u63a5&#xff08;Shortcut Connection&#xff09;\u3002\u5b83\u5141\u8bb8\u8f93\u5165\u4fe1\u53f7\u53ef\u4ee5\u201c\u8df3\u8fc7\u201d\u4e00\u4e2a\u6216\u591a\u4e2a\u5c42&#xff0c;\u76f4\u63a5\u52a0\u5230\u540e\u7eed\u5c42\u7684\u8f93\u51fa\u4e0a\u3002\u8fd9\u4f7f\u5f97\u7f51\u7edc\u9700\u8981\u5b66\u4e60\u7684\u4e0d\u518d\u662f\u5b8c\u6574\u7684\u6620\u5c04H(x)&#xff0c;\u800c\u662f\u4e00\u4e2a\u66f4\u5bb9\u6613\u5b66\u4e60\u7684\u6b8b\u5deeF(x) &#061; H(x) &#8211; x\u3002\u5982\u679c\u67d0\u4e2a\u5c42\u662f\u591a\u4f59\u7684&#xff0c;\u7f51\u7edc\u53ea\u9700\u5c06F(x)\u5b66\u4e60\u4e3a0\u5373\u53ef&#xff0c;\u8fd9\u6bd4\u8ba9\u5b83\u5b66\u4e60\u4e00\u4e2a\u6052\u7b49\u6620\u5c04H(x)&#061;x\u8981\u5bb9\u6613\u5f97\u591a\u3002\u8fd9\u4e00\u7ed3\u6784\u6781\u5927\u5730\u7f13\u89e3\u4e86\u6df1\u5ea6\u7f51\u7edc\u7684\u68af\u5ea6\u6d88\u5931\u548c\u9000\u5316\u95ee\u9898&#xff0c;\u4f7f\u5f97\u8bad\u7ec3\u6210\u767e\u4e0a\u5343\u5c42\u7684\u7f51\u7edc\u6210\u4e3a\u53ef\u80fd\u3002<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u5728\u4ee3\u7801\u4e2d\u4eb2\u624b\u5b9e\u73b0\u4e00\u4e2a\u201c\u6b8b\u5dee\u5757&#xff08;Residual Block&#xff09;\u201d\u3002\u7136\u540e&#xff0c;\u5c1d\u8bd5\u5c06\u4f60\u4e4b\u524d\u642d\u5efa\u7684\u201c\u5e73\u539f\u7f51\u7edc&#xff08;Plain Network&#xff09;\u201d\u6539\u9020\u4e3a\u201c\u6b8b\u5dee\u7f51\u7edc\u201d&#xff0c;\u5e76\u6bd4\u8f83\u4e24\u8005\u5728\u66f4\u6df1\u5c42\u6570\u4e0b\u7684\u8bad\u7ec3\u6536\u655b\u6027\u548c\u6700\u7ec8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u524d\u6cbf\u65b9\u5411&#xff1a;<\/p>\n<ul>\n<li>\u8f7b\u91cf\u5316\u7f51\u7edc&#xff1a;MobileNet, ShuffleNet\u7b49&#xff0c;\u4e3a\u5728\u79fb\u52a8\u7aef\u548c\u5d4c\u5165\u5f0f\u8bbe\u5907\u4e0a\u9ad8\u6548\u8fd0\u884c\u800c\u8bbe\u8ba1\u3002<\/li>\n<li>\u6ce8\u610f\u529b\u673a\u5236&#xff1a;Squeeze-and-Excitation Networks (SENet)\u7b49&#xff0c;\u8ba9\u7f51\u7edc\u5b66\u4e60\u4e0d\u540c\u901a\u9053\u7279\u5f81\u7684\u91cd\u8981\u6027\u3002<\/li>\n<li>\u65b0\u67b6\u6784\u63a2\u7d22&#xff1a;Vision Transformer (ViT) \u5c06Transformer\u67b6\u6784\u6210\u529f\u5e94\u7528\u4e8e\u89c6\u89c9&#xff0c;\u6311\u6218\u4e86CNN\u7684\u7edf\u6cbb\u5730\u4f4d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>13.1.2 \u5faa\u73af\u795e\u7ecf\u7f51\u7edc&#xff08;RNN&#xff09;\u53ca\u5176\u53d8\u4f53&#xff1a;\u4e3a\u201c\u65f6\u95f4\u201d\u800c\u751f\u7684\u5e8f\u5217\u8bd7\u4eba<\/h5>\n<p>1. \u52a8\u673a\u4e0e\u54f2\u5b66&#xff1a;\u4e3a\u4f55\u5faa\u73af&#xff1f;<\/p>\n<ul>\n<li>\n<p>\u56f0\u5883&#xff1a;\u65e0\u8bba\u662fMLP\u8fd8\u662fCNN&#xff0c;\u5b83\u4eec\u90fd\u5185\u542b\u4e00\u4e2a\u6839\u672c\u6027\u7684\u5047\u8bbe\u2014\u2014\u8f93\u5165\u6570\u636e&#xff08;\u6216\u7279\u5f81&#xff09;\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684&#xff08;i.i.d. assumption&#xff09;\u3002\u8fd9\u4e2a\u5047\u8bbe\u5728\u5904\u7406\u5982\u8bed\u8a00\u3001\u8bed\u97f3\u3001\u91d1\u878d\u65f6\u95f4\u5e8f\u5217\u7b49\u6570\u636e\u65f6&#xff0c;\u662f\u5b8c\u5168\u9519\u8bef\u7684\u3002\u5bf9\u4e8e\u5e8f\u5217\u6570\u636e&#xff0c;**\u987a\u5e8f&#xff08;Order&#xff09;\u548c\u4e0a\u4e0b\u6587&#xff08;Context&#xff09;**\u662f\u5176\u7075\u9b42\u3002\u4e00\u4e2a\u8bcd\u7684\u610f\u4e49&#xff0c;\u4e25\u91cd\u4f9d\u8d56\u4e8e\u5b83\u524d\u9762\u7684\u8bcd&#xff1b;\u4eca\u5929\u7684\u80a1\u4ef7&#xff0c;\u4e0e\u6628\u5929\u7684\u80a1\u4ef7\u606f\u606f\u76f8\u5173\u3002CNN\u867d\u7136\u80fd\u6355\u6349\u5c40\u90e8\u7a7a\u95f4\u6a21\u5f0f&#xff0c;\u4f46\u5176\u56fa\u5b9a\u5927\u5c0f\u7684\u5377\u79ef\u6838\u65e0\u6cd5\u7075\u6d3b\u5904\u7406\u957f\u77ed\u4e0d\u4e00\u3001\u4f9d\u8d56\u5173\u7cfb\u590d\u6742\u7684\u5e8f\u5217\u3002<\/p>\n<\/li>\n<li>\n<p>\u54f2\u5b66\u7a81\u7834&#xff1a;\u5f15\u5165\u201c\u65f6\u95f4\u201d\u7684\u5f52\u7eb3\u504f\u7f6e\u00a0RNN\u7684\u8bbe\u8ba1\u54f2\u5b66&#xff0c;\u662f\u5c06\u201c\u65f6\u95f4\u201d\u548c\u201c\u8bb0\u5fc6\u201d\u7684\u6982\u5ff5&#xff0c;\u76f4\u63a5\u7f16\u7801\u5230\u5176\u7f51\u7edc\u7ed3\u6784\u4e2d\u3002\u5b83\u4e0d\u518d\u5c06\u5e8f\u5217\u89c6\u4e3a\u4e00\u4e2a\u9759\u6001\u7684\u6574\u4f53&#xff0c;\u800c\u662f\u5c06\u5176\u89c6\u4e3a\u4e00\u4e2a\u968f\u65f6\u95f4\u6f14\u5316\u7684\u52a8\u6001\u8fc7\u7a0b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2. \u6838\u5fc3\u6b66\u5668\u5e93&#xff1a;\u5faa\u73af\u3001\u72b6\u6001\u4e0e\u95e8\u63a7<\/p>\n<ul>\n<li>\n<p>\u57fa\u77f3\u4e00&#xff1a;\u5faa\u73af\u8fde\u63a5&#xff08;Recurrent Connection&#xff09;\u4e0e\u9690\u85cf\u72b6\u6001&#xff08;Hidden State&#xff09;<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;RNN\u7684\u6838\u5fc3\u5728\u4e8e\u5176\u795e\u7ecf\u5143&#xff08;\u6216\u4e00\u5c42\u795e\u7ecf\u5143&#xff09;\u62e5\u6709\u4e00\u4e2a\u81ea\u8fde\u63a5\u7684\u5faa\u73af\u8fb9\u3002\u5728\u5904\u7406\u5e8f\u5217\u7684\u7b2c\u00a0t\u00a0\u4e2a\u5143\u7d20\u00a0x_t\u00a0\u65f6&#xff0c;RNN\u7684\u8ba1\u7b97\u5355\u5143\u4e0d\u4ec5\u63a5\u6536\u00a0x_t\u00a0\u4f5c\u4e3a\u8f93\u5165&#xff0c;\u8fd8\u63a5\u6536\u6765\u81ea\u4e0a\u4e00\u4e2a\u65f6\u95f4\u6b65\u00a0t-1\u00a0\u7684\u8f93\u51fa&#xff0c;\u5373\u9690\u85cf\u72b6\u6001\u00a0h_{t-1}\u3002\u5b83\u5c06\u4e24\u8005\u7ed3\u5408\u8d77\u6765&#xff0c;\u8ba1\u7b97\u51fa\u5f53\u524d\u65f6\u95f4\u6b65\u7684\u9690\u85cf\u72b6\u6001\u00a0h_t\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u7528\u516c\u5f0f\u8868\u8fbe\u4e3a&#xff1a;h_t &#061; f(W * x_t &#043; U * h_{t-1} &#043; b)&#xff0c;\u5176\u4e2d\u00a0W\u00a0\u548c\u00a0U\u00a0\u662f\u53ef\u5b66\u4e60\u7684\u6743\u91cd\u77e9\u9635&#xff0c;f\u00a0\u662f\u6fc0\u6d3b\u51fd\u6570&#xff08;\u901a\u5e38\u662ftanh&#xff09;\u3002<\/li>\n<li>\u610f\u4e49&#xff1a;\u9690\u85cf\u72b6\u6001\u00a0h_t\u00a0\u6210\u4e3a\u4e86\u7f51\u7edc\u7684**\u201c\u8bb0\u5fc6\u201d\u3002\u5b83\u7406\u8bba\u4e0a\u7f16\u7801\u4e86\u4ece\u5e8f\u5217\u5f00\u59cb\u5230\u5f53\u524d\u65f6\u523b\u00a0t\u00a0\u7684\u6240\u6709\u5386\u53f2\u4fe1\u606f\u3002\u5728\u6574\u4e2a\u5e8f\u5217\u5904\u7406\u8fc7\u7a0b\u4e2d&#xff0c;\u6743\u91cd\u77e9\u9635\u00a0W\u00a0\u548c\u00a0U\u00a0\u662f\u5171\u4eab**\u7684&#xff0c;\u8fd9\u4e0eCNN\u4e2d\u5377\u79ef\u6838\u7684\u53c2\u6570\u5171\u4eab\u5f02\u66f2\u540c\u5de5&#xff0c;\u6781\u5927\u5730\u51cf\u5c11\u4e86\u53c2\u6570\u91cf&#xff0c;\u5e76\u4f7f\u5f97\u6a21\u578b\u80fd\u5904\u7406\u4efb\u610f\u957f\u5ea6\u7684\u5e8f\u5217\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u57fa\u77f3\u4e8c&#xff1a;\u95e8\u63a7\u673a\u5236&#xff08;Gating Mechanism&#xff09;\u2014\u2014\u5bf9\u6297\u9057\u5fd8\u7684\u667a\u6167<\/p>\n<ul>\n<li>\u56f0\u5883&#xff1a;\u957f\u671f\u4f9d\u8d56\u95ee\u9898&#xff08;Long-Term Dependencies Problem&#xff09;\u00a0\u7ecf\u5178\u7684RNN\u5728\u5b9e\u8df5\u4e2d\u96be\u4ee5\u5b66\u4e60\u5230\u76f8\u9694\u8f83\u8fdc\u7684\u8bcd\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u53cd\u5411\u4f20\u64ad&#xff08;BPTT&#xff09;\u8fc7\u7a0b\u4e2d&#xff0c;\u68af\u5ea6\u9700\u8981\u7a7f\u8d8a\u5f88\u957f\u7684\u65f6\u95f4\u6b65\u8fdb\u884c\u8fde\u4e58\u3002\u5982\u679c\u6fc0\u6d3b\u51fd\u6570\u7684\u5bfc\u6570\u957f\u671f\u5c0f\u4e8e1&#xff0c;\u68af\u5ea6\u4f1a\u6307\u6570\u7ea7\u8870\u51cf&#xff0c;\u5bfc\u81f4\u68af\u5ea6\u6d88\u5931&#xff08;Vanishing Gradients&#xff09;&#xff1b;\u53cd\u4e4b\u5219\u4f1a\u5bfc\u81f4\u68af\u5ea6\u7206\u70b8&#xff08;Exploding Gradients&#xff09;\u3002\u8fd9\u4f7f\u5f97\u7f51\u7edc\u51e0\u4e4e\u65e0\u6cd5\u6839\u636e\u9065\u8fdc\u672a\u6765\u7684\u8bef\u5dee\u6765\u8c03\u6574\u9065\u8fdc\u8fc7\u53bb\u7684\u6743\u91cd\u3002<\/li>\n<li>\u89e3\u51b3\u65b9\u6848&#xff1a;\u957f\u77ed\u671f\u8bb0\u5fc6\u7f51\u7edc&#xff08;LSTM&#xff09;\u00a0LSTM\u5e76\u975e\u7b80\u5355\u5730\u7528\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u6fc0\u6d3b\u51fd\u6570&#xff0c;\u800c\u662f\u8bbe\u8ba1\u4e86\u4e00\u5957\u7cbe\u5de7\u7684\u5185\u90e8\u8bb0\u5fc6\u7ba1\u7406\u7cfb\u7edf\u3002\u5176\u6838\u5fc3\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u7ec6\u80de\u72b6\u6001&#xff08;Cell State, C_t&#xff09;&#xff0c;\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u6761\u4fe1\u606f\u9ad8\u901f\u516c\u8def&#xff0c;\u4fe1\u606f\u5728\u4e0a\u9762\u53ef\u4ee5\u5f88\u987a\u7545\u5730\u6d41\u52a8\u800c\u4e0d\u53d1\u751f\u5267\u70c8\u53d8\u5316\u3002\u540c\u65f6&#xff0c;LSTM\u5f15\u5165\u4e86\u4e09\u4e2a\u201c\u95e8\u201d\u7ed3\u6784&#xff08;\u672c\u8d28\u4e0a\u662f\u5e26\u6709Sigmoid\u6fc0\u6d3b\u51fd\u6570\u7684\u5168\u8fde\u63a5\u5c42&#xff0c;\u8f93\u51fa0\u52301\u4e4b\u95f4\u7684\u503c&#xff0c;\u4ee3\u8868\u4fe1\u606f\u7684\u901a\u8fc7\u7387&#xff09;\u6765\u7cbe\u5bc6\u5730\u63a7\u5236\u8fd9\u6761\u9ad8\u901f\u516c\u8def&#xff1a;\n<li>\u9057\u5fd8\u95e8&#xff08;Forget Gate&#xff09;&#xff1a;\u51b3\u5b9a\u5e94\u8be5\u4ece\u4e0a\u4e00\u4e2a\u7ec6\u80de\u72b6\u6001\u00a0C_{t-1}\u00a0\u4e2d\u9057\u5fd8\u6389\u54ea\u4e9b\u65e7\u4fe1\u606f\u3002<\/li>\n<li>\u8f93\u5165\u95e8&#xff08;Input Gate&#xff09;&#xff1a;\u51b3\u5b9a\u5f53\u524d\u65f6\u523b\u6709\u54ea\u4e9b\u65b0\u4fe1\u606f\u00a0x_t\u00a0\u5e94\u8be5\u88ab\u5b58\u5165\u5230\u7ec6\u80de\u72b6\u6001\u4e2d\u3002<\/li>\n<li>\u8f93\u51fa\u95e8&#xff08;Output Gate&#xff09;&#xff1a;\u51b3\u5b9a\u5f53\u524d\u7ec6\u80de\u72b6\u6001\u00a0C_t\u00a0\u7684\u54ea\u4e9b\u90e8\u5206\u5e94\u8be5\u88ab\u8f93\u51fa\u4e3a\u5f53\u524d\u65f6\u523b\u7684\u9690\u85cf\u72b6\u6001\u00a0h_t\u3002 \u8fd9\u79cd\u8bbe\u8ba1\u4f7f\u5f97LSTM\u80fd\u591f\u6709\u9009\u62e9\u5730\u3001\u52a8\u6001\u5730\u9057\u5fd8\u3001\u8bb0\u5fc6\u548c\u8f93\u51fa\u4fe1\u606f&#xff0c;\u4ece\u800c\u6709\u6548\u5730\u6355\u6349\u957f\u671f\u4f9d\u8d56\u3002<\/li>\n<\/li>\n<li>\u7b80\u5316\u65b9\u6848&#xff1a;\u95e8\u63a7\u5faa\u73af\u5355\u5143&#xff08;GRU&#xff09;\u00a0GRU\u662fLSTM\u7684\u4e00\u4e2a\u6d41\u884c\u53d8\u4f53\u3002\u5b83\u5c06\u9057\u5fd8\u95e8\u548c\u8f93\u5165\u95e8\u5408\u5e76\u4e3a\u5355\u4e00\u7684\u66f4\u65b0\u95e8&#xff08;Update Gate&#xff09;&#xff0c;\u5e76\u878d\u5408\u4e86\u7ec6\u80de\u72b6\u6001\u548c\u9690\u85cf\u72b6\u6001\u3002GRU\u7684\u53c2\u6570\u66f4\u5c11&#xff0c;\u8ba1\u7b97\u6548\u7387\u66f4\u9ad8&#xff0c;\u5728\u8bb8\u591a\u4efb\u52a1\u4e0a\u80fd\u53d6\u5f97\u4e0eLSTM\u76f8\u5f53\u7684\u6027\u80fd&#xff0c;\u662f\u5b9e\u8df5\u4e2d\u4e00\u4e2a\u503c\u5f97\u5c1d\u8bd5\u7684\u4f18\u79c0\u66ff\u4ee3\u65b9\u6848\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>3. \u67b6\u6784\u6f14\u5316\u4e0e\u8fdb\u9636\u8def\u5f84<\/p>\n<ul>\n<li>\n<p>\u9636\u6bb5\u4e00&#xff1a;\u7406\u89e3\u5faa\u73af\u4e0e\u8bb0\u5fc6<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u6587\u732e&#xff1a;Chris Olah\u7684\u535a\u5ba2\u6587\u7ae0\u300aUnderstanding LSTM Networks\u300b\u662f\u5168\u4e16\u754c\u516c\u8ba4\u7684\u3001\u56fe\u6587\u5e76\u8302\u7684\u6700\u4f73\u5165\u95e8\u6750\u6599&#xff0c;\u6bd4\u76f4\u63a5\u9605\u8bfb\u539f\u59cb\u8bba\u6587\u66f4\u76f4\u89c2\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u4e0d\u8981\u6ee1\u8db3\u4e8eAPI\u8c03\u7528&#xff0c;\u5fc5\u987b\u4eb2\u624b\u5728\u7eb8\u4e0a\u6216\u767d\u677f\u4e0a\u753b\u51faLSTM\u5355\u5143\u7684\u5185\u90e8\u6570\u636e\u6d41\u56fe\u3002\u6e05\u6670\u5730\u7406\u89e3\u8f93\u5165\u00a0x_t\u00a0\u548c\u00a0h_{t-1}\u00a0\u662f\u5982\u4f55\u901a\u8fc7\u4e09\u4e2a\u95e8\u548c\u7ec6\u80de\u72b6\u6001&#xff0c;\u6700\u7ec8\u8ba1\u7b97\u51fa\u00a0h_t\u00a0\u548c\u00a0C_t\u00a0\u7684\u3002\u8fd9\u662f\u540e\u7eed\u6240\u6709\u5b66\u4e60\u7684\u57fa\u7840\u3002<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u4f7f\u7528Keras\u6216PyTorch&#xff0c;\u642d\u5efa\u4e00\u4e2a\u5b57\u7b26\u7ea7\u7684RNN\/LSTM\u8bed\u8a00\u6a21\u578b\u3002\u5728\u4e00\u6bb5\u6587\u672c&#xff08;\u5982\u838e\u58eb\u6bd4\u4e9a\u7684\u8457\u4f5c&#xff09;\u4e0a\u8fdb\u884c\u8bad\u7ec3&#xff0c;\u7136\u540e\u8ba9\u5b83\u4ece\u4e00\u4e2a\u79cd\u5b50\u5b57\u7b26\u5f00\u59cb&#xff0c;\u81ea\u52a8\u751f\u6210\u65b0\u7684\u6587\u672c\u3002\u89c2\u5bdf\u5b83\u662f\u5426\u80fd\u5b66\u4e60\u5230\u5355\u8bcd\u62fc\u5199\u3001\u7a7a\u683c\u3001\u6362\u884c\u7b49\u8bed\u6cd5\u89c4\u5219&#xff0c;\u8fd9\u662f\u68c0\u9a8c\u4f60\u662f\u5426\u771f\u6b63\u7406\u89e3\u5e8f\u5217\u5efa\u6a21\u7684\u201c\u8bd5\u91d1\u77f3\u201d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e8c&#xff1a;\u5e8f\u5217\u5230\u5e8f\u5217&#xff08;Seq2Seq&#xff09;\u4e0e\u6ce8\u610f\u529b\u673a\u5236<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u300aSequence to Sequence Learning with Neural Networks\u300b\u548c\u300aNeural Machine Translation by Jointly Learning to Align and Translate\u300b\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\n<ul>\n<li>Seq2Seq\u67b6\u6784&#xff1a;\u7406\u89e3\u5176\u7ecf\u5178\u7684**\u7f16\u7801\u5668-\u89e3\u7801\u5668&#xff08;Encoder-Decoder&#xff09;**\u7ed3\u6784\u3002\u7f16\u7801\u5668&#xff08;\u4e00\u4e2aRNN\/LSTM&#xff09;\u5c06\u6574\u4e2a\u8f93\u5165\u5e8f\u5217\u538b\u7f29\u6210\u4e00\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u4e0a\u4e0b\u6587\u5411\u91cf&#xff08;Context Vector&#xff09;&#xff0c;\u89e3\u7801\u5668&#xff08;\u53e6\u4e00\u4e2aRNN\/LSTM&#xff09;\u5219\u4ee5\u8fd9\u4e2a\u5411\u91cf\u4e3a\u521d\u59cb\u72b6\u6001&#xff0c;\u9010\u4e2a\u751f\u6210\u8f93\u51fa\u5e8f\u5217\u7684\u5143\u7d20\u3002<\/li>\n<li>\u74f6\u9888&#xff1a;\u8fd9\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u4e0a\u4e0b\u6587\u5411\u91cf\u6210\u4e3a\u4e86\u4fe1\u606f\u74f6\u9888&#xff0c;\u96be\u4ee5\u627f\u8f7d\u957f\u8f93\u5165\u5e8f\u5217\u7684\u5168\u90e8\u4fe1\u606f\u3002<\/li>\n<li>\u6ce8\u610f\u529b\u673a\u5236&#xff08;Attention&#xff09;&#xff1a;\u8fd9\u662f\u89e3\u51b3\u74f6\u9888\u7684\u5929\u624d\u4e4b\u4e3e\u3002\u5b83\u5141\u8bb8\u89e3\u7801\u5668\u5728\u751f\u6210\u6bcf\u4e00\u4e2a\u8f93\u51fa\u8bcd\u65f6&#xff0c;\u4e0d\u518d\u53ea\u4f9d\u8d56\u90a3\u4e2a\u56fa\u5b9a\u7684\u4e0a\u4e0b\u6587\u5411\u91cf&#xff0c;\u800c\u662f\u53ef\u4ee5\u201c\u56de\u987e\u201d\u7f16\u7801\u5668\u7684\u6240\u6709\u9690\u85cf\u72b6\u6001&#xff0c;\u5e76\u4e3a\u5b83\u4eec\u8ba1\u7b97\u4e00\u4e2a\u201c\u6ce8\u610f\u529b\u6743\u91cd\u201d&#xff0c;\u7136\u540e\u5bf9\u8fd9\u4e9b\u9690\u85cf\u72b6\u6001\u8fdb\u884c\u52a0\u6743\u6c42\u548c\u3002\u8fd9\u6837&#xff0c;\u89e3\u7801\u5668\u5728\u6bcf\u4e00\u6b65\u90fd\u80fd\u52a8\u6001\u5730\u3001\u6709\u9009\u62e9\u5730\u805a\u7126\u4e8e\u8f93\u5165\u5e8f\u5217\u4e2d\u6700\u76f8\u5173\u7684\u90e8\u5206\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u5b9e\u73b0\u4e00\u4e2a\u5e26\u6ce8\u610f\u529b\u673a\u5236\u7684Seq2Seq\u6a21\u578b&#xff0c;\u7528\u4e8e\u5b8c\u6210\u4e00\u4e2a\u7b80\u5355\u7684\u4efb\u52a1&#xff0c;\u5982\u65e5\u671f\u683c\u5f0f\u8f6c\u6362&#xff08;\u201c2024-07-21\u201d -&gt; \u201cJuly 21, 2024\u201d&#xff09;\u6216\u7b80\u5355\u7684\u673a\u5668\u7ffb\u8bd1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e09&#xff1a;Transformer\u7684\u5d1b\u8d77&#xff08;\u8be6\u89c1\u4e0b\u4e00\u8282&#xff09;\u00a0RNN\u53ca\u5176\u53d8\u4f53\u867d\u7136\u5f3a\u5927&#xff0c;\u4f46\u5176\u56fa\u6709\u7684\u987a\u5e8f\u8ba1\u7b97\u7279\u6027\u4f7f\u5176\u96be\u4ee5\u5728\u73b0\u4ee3GPU\u4e0a\u9ad8\u6548\u5e76\u884c\u5316&#xff0c;\u9650\u5236\u4e86\u5176\u5904\u7406\u8d85\u957f\u5e8f\u5217\u548c\u6784\u5efa\u8d85\u5927\u89c4\u6a21\u6a21\u578b\u7684\u80fd\u529b\u3002\u8fd9\u76f4\u63a5\u50ac\u751f\u4e86\u4e0b\u4e00\u4ee3\u9769\u547d\u6027\u67b6\u6784\u7684\u8bde\u751f\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h5>13.1.3 \u6ce8\u610f\u529b\u673a\u5236\u4e0eTransformer&#xff1a;\u5e76\u884c\u65f6\u4ee3\u7684NLP\u738b\u8005<\/h5>\n<p>1. \u52a8\u673a\u4e0e\u54f2\u5b66&#xff1a;\u4e3a\u4f55\u629b\u5f03\u5faa\u73af&#xff1f;<\/p>\n<ul>\n<li>\n<p>\u56f0\u5883&#xff1a;RNN\u7684\u201c\u5faa\u73af\u201d\u65e2\u662f\u5176\u4f18\u70b9&#xff08;\u8bb0\u5fc6&#xff09;&#xff0c;\u4e5f\u662f\u5176\u81f4\u547d\u5f31\u70b9\u3002t\u65f6\u523b\u7684\u8ba1\u7b97\u5fc5\u987b\u7b49\u5f85t-1\u65f6\u523b\u5b8c\u6210&#xff0c;\u8fd9\u79cd\u987a\u5e8f\u4f9d\u8d56\u4f7f\u5176\u65e0\u6cd5\u5229\u7528GPU\u5f3a\u5927\u7684\u5e76\u884c\u8ba1\u7b97\u80fd\u529b\u3002\u5728\u5904\u7406\u957f\u6587\u6863\u65f6&#xff0c;\u8fd9\u79cd\u4e32\u884c\u8ba1\u7b97\u7684\u6548\u7387\u4f4e\u4e0b\u95ee\u9898\u5c24\u4e3a\u7a81\u51fa\u3002\u6b64\u5916&#xff0c;\u5373\u4f7f\u6709LSTM\/GRU&#xff0c;\u4fe1\u606f\u5728\u5e8f\u5217\u4e2d\u4f20\u9012\u7684\u8def\u5f84\u4f9d\u7136\u5f88\u957f&#xff0c;\u6355\u6349\u8d85\u957f\u8ddd\u79bb\u4f9d\u8d56\u4ecd\u7136\u662f\u4e00\u4e2a\u6311\u6218\u3002<\/p>\n<\/li>\n<li>\n<p>\u54f2\u5b66\u7a81\u7834&#xff1a;\u5c06\u201c\u91cd\u8981\u6027\u201d\u7684\u8ba1\u7b97\u5e76\u884c\u5316\u00a0\u6ce8\u610f\u529b\u673a\u5236\u7684\u6210\u529f\u542f\u53d1\u4e86\u7814\u7a76\u8005\u4eec&#xff1a;\u5982\u679c\u6a21\u578b\u53ef\u4ee5\u76f4\u63a5\u8ba1\u7b97\u51fa\u5e8f\u5217\u4e2d\u4efb\u610f\u4e24\u4e2a\u4f4d\u7f6e\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb&#xff0c;\u800c\u65e0\u9700\u901a\u8fc7\u5faa\u73af\u7ed3\u6784\u9010\u6b65\u4f20\u9012\u4fe1\u606f&#xff0c;\u90a3\u4e48\u662f\u5426\u53ef\u4ee5\u5b8c\u5168\u629b\u5f03\u5faa\u73af&#xff1f;Transformer\u7684\u56de\u7b54\u662f&#xff1a;\u53ef\u4ee5&#xff01;\u00a0\u5b83\u7684\u6838\u5fc3\u54f2\u5b66\u662f&#xff0c;\u5e8f\u5217\u4e2d\u4e00\u4e2a\u5143\u7d20\u7684\u8868\u793a&#xff0c;\u5e94\u8be5\u7531\u6574\u4e2a\u5e8f\u5217\u4e2d\u6240\u6709\u5143\u7d20\u6839\u636e\u5176\u91cd\u8981\u6027\u8fdb\u884c\u52a0\u6743\u6c42\u548c\u6765\u5b9a\u4e49\u3002<\/p>\n<\/li>\n<\/ul>\n<p>2. \u6838\u5fc3\u6b66\u5668\u5e93&#xff1a;\u81ea\u6ce8\u610f\u529b\u673a\u5236<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b&#xff08;Scaled Dot-Product Attention&#xff09;\u00a0\u8fd9\u662fTransformer\u7684\u7075\u9b42\u3002\u5bf9\u4e8e\u8f93\u5165\u5e8f\u5217\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20&#xff08;Token&#xff09;&#xff0c;\u6211\u4eec\u90fd\u901a\u8fc7\u7ebf\u6027\u53d8\u6362\u4e3a\u5176\u751f\u6210\u4e09\u4e2a\u53ef\u5b66\u4e60\u7684\u5411\u91cf&#xff1a;\n<li>\u67e5\u8be2&#xff08;Query, Q&#xff09;&#xff1a;\u4ee3\u8868\u4e86\u5f53\u524d\u5143\u7d20\u4e3a\u4e86\u7406\u89e3\u81ea\u5df1&#xff0c;\u9700\u8981\u53bb\u201c\u67e5\u8be2\u201d\u5176\u4ed6\u5143\u7d20\u7684\u4fe1\u606f\u3002<\/li>\n<li>\u952e&#xff08;Key, K&#xff09;&#xff1a;\u4ee3\u8868\u4e86\u5e8f\u5217\u4e2d\u6bcf\u4e2a\u5143\u7d20\u6240\u643a\u5e26\u7684\u3001\u53ef\u4f9b\u201c\u67e5\u8be2\u201d\u7684\u201c\u6807\u7b7e\u201d\u4fe1\u606f\u3002<\/li>\n<li>\u503c&#xff08;Value, V&#xff09;&#xff1a;\u4ee3\u8868\u4e86\u5e8f\u5217\u4e2d\u6bcf\u4e2a\u5143\u7d20\u5b9e\u9645\u5305\u542b\u7684\u201c\u5185\u5bb9\u201d\u4fe1\u606f\u3002 \u8ba1\u7b97\u8fc7\u7a0b\u5206\u4e3a\u4e09\u6b65&#xff1a;<\/li>\n<li>\u8ba1\u7b97\u6ce8\u610f\u529b\u5206\u6570&#xff1a;\u5c06\u5f53\u524d\u5143\u7d20\u7684Q\u5411\u91cf&#xff0c;\u4e0e\u6240\u6709\u5143\u7d20\u7684K\u5411\u91cf\u8fdb\u884c\u70b9\u79ef\u3002\u8fd9\u4e2a\u5206\u6570\u76f4\u89c2\u5730\u8861\u91cf\u4e86\u201c\u67e5\u8be2\u201d\u4e0e\u201c\u952e\u201d\u7684\u5339\u914d\u7a0b\u5ea6\u3002<\/li>\n<li>\u7f29\u653e\u4e0e\u5f52\u4e00\u5316&#xff1a;\u5c06\u5f97\u5230\u7684\u5206\u6570\u9664\u4ee5\u4e00\u4e2a\u7f29\u653e\u56e0\u5b50&#xff08;\u901a\u5e38\u662fK\u5411\u91cf\u7ef4\u5ea6\u7684\u5e73\u65b9\u6839&#xff09;&#xff0c;\u4ee5\u9632\u6b62\u68af\u5ea6\u8fc7\u5c0f&#xff0c;\u7136\u540e\u901a\u8fc7Softmax\u51fd\u6570\u5c06\u5176\u5f52\u4e00\u5316\u4e3a\u548c\u4e3a1\u7684\u6982\u7387\u5206\u5e03\u3002\u8fd9\u5c31\u662f\u201c\u6ce8\u610f\u529b\u6743\u91cd\u201d\u3002<\/li>\n<li>\u52a0\u6743\u6c42\u548c&#xff1a;\u7528\u5f97\u5230\u7684\u6ce8\u610f\u529b\u6743\u91cd&#xff0c;\u53bb\u52a0\u6743\u6c42\u548c\u6240\u6709\u5143\u7d20\u7684V\u5411\u91cf\u3002\u6700\u7ec8\u7684\u7ed3\u679c&#xff0c;\u5c31\u662f\u5f53\u524d\u5143\u7d20\u878d\u5408\u4e86\u5168\u5c40\u4e0a\u4e0b\u6587\u4fe1\u606f\u540e\u7684\u65b0\u8868\u793a\u3002<\/li>\n<\/li>\n<li>\u5173\u952e\u589e\u5f3a&#xff1a;\n<ul>\n<li>\u591a\u5934\u6ce8\u610f\u529b&#xff08;Multi-Head Attention&#xff09;&#xff1a;\u5e76\u884c\u5730\u8fd0\u884c\u591a\u6b21\u72ec\u7acb\u7684\u81ea\u6ce8\u610f\u529b\u8ba1\u7b97\u3002\u6bcf\u4e00\u201c\u5934\u201d\u90fd\u5b66\u4e60\u5c06Q, K, V\u6295\u5f71\u5230\u4e0d\u540c\u7684\u8868\u793a\u5b50\u7a7a\u95f4\u4e2d&#xff0c;\u4ece\u800c\u8ba9\u6a21\u578b\u80fd\u591f\u540c\u65f6\u5173\u6ce8\u6765\u81ea\u4e0d\u540c\u65b9\u9762\u3001\u4e0d\u540c\u4f4d\u7f6e\u7684\u4fe1\u606f\u3002\u8fd9\u5c31\u50cf\u6211\u4eec\u8bfb\u4e66\u65f6&#xff0c;\u53ef\u4ee5\u540c\u65f6\u5173\u6ce8\u4e00\u53e5\u8bdd\u7684\u8bed\u6cd5\u7ed3\u6784\u3001\u8bed\u4e49\u5185\u6db5\u548c\u60c5\u611f\u8272\u5f69\u3002<\/li>\n<li>\u4f4d\u7f6e\u7f16\u7801&#xff08;Positional Encoding&#xff09;&#xff1a;\u7531\u4e8e\u81ea\u6ce8\u610f\u529b\u673a\u5236\u672c\u8eab\u4e0d\u5305\u542b\u4efb\u4f55\u5173\u4e8e\u987a\u5e8f\u7684\u4fe1\u606f&#xff08;\u5b83\u662f\u4e00\u4e2a\u201c\u96c6\u5408\u201d\u64cd\u4f5c&#xff09;&#xff0c;\u6211\u4eec\u9700\u8981\u663e\u5f0f\u5730\u4e3a\u8f93\u5165\u5e8f\u5217\u6dfb\u52a0\u201c\u4f4d\u7f6e\u7f16\u7801\u201d\u5411\u91cf&#xff0c;\u5c06\u8bcd\u7684\u4f4d\u7f6e\u4fe1\u606f\u6ce8\u5165\u6a21\u578b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>3. \u67b6\u6784\u6f14\u5316\u4e0e\u8fdb\u9636\u8def\u5f84<\/p>\n<ul>\n<li>\n<p>\u9636\u6bb5\u4e00&#xff1a;\u5960\u57fa\u4e0e\u7406\u89e3<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u300aAttention Is All You Need\u300b\u3002\u8fd9\u7bc7\u8bba\u6587\u7b80\u6d01\u3001\u6709\u529b&#xff0c;\u662f\u73b0\u4ee3NLP\u7684\u201c\u65b0\u7ea6\u5723\u7ecf\u201d\u3002\u6bcf\u4e00\u4e2a\u6709\u5fd7\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u4eba\u90fd\u5e94\u8be5\u53cd\u590d\u7cbe\u8bfb\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u5f7b\u5e95\u7406\u89e3\u81ea\u6ce8\u610f\u529b\u673a\u5236\u7684\u77e9\u9635\u8fd0\u7b97\u5f62\u5f0f\u3002\u660e\u767dQ, K, V\u77e9\u9635\u7684\u7ef4\u5ea6\u53d8\u5316\u3002\u7406\u89e3\u4e3a\u4f55\u9700\u8981\u4f4d\u7f6e\u7f16\u7801&#xff0c;\u4ee5\u53ca\u6b8b\u5dee\u8fde\u63a5\u548c\u5c42\u5f52\u4e00\u5316&#xff08;Layer Normalization&#xff09;\u5728Transformer\u5757\u4e2d\u7684\u5173\u952e\u4f5c\u7528\u3002<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u4f7f\u7528PyTorch\u6216TensorFlow&#xff0c;\u4ece\u96f6\u5f00\u59cb\u5b9e\u73b0\u4e00\u4e2a\u5b8c\u6574\u7684\u3001\u5305\u542b\u591a\u5934\u81ea\u6ce8\u610f\u529b\u548c\u524d\u9988\u7f51\u7edc&#xff08;Feed-Forward Network&#xff09;\u7684Transformer\u7f16\u7801\u5668\u5757\u3002\u8fd9\u662f\u68c0\u9a8c\u4f60\u662f\u5426\u771f\u6b63\u7406\u89e3\u5176\u5185\u90e8\u5de5\u4f5c\u539f\u7406\u7684\u7ec8\u6781\u6d4b\u8bd5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e8c&#xff1a;\u9884\u8bad\u7ec3\u8bed\u8a00\u6a21\u578b&#xff08;Pre-trained Language Models, PLMs&#xff09;<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u8bba\u6587&#xff1a;\u300aBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding\u300b\u548cOpenAI\u5173\u4e8eGPT\u7cfb\u5217\u6a21\u578b\u7684\u535a\u5ba2\u6587\u7ae0\u6216\u8bba\u6587\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u7406\u89e3\u8fc1\u79fb\u5b66\u4e60\u5728NLP\u9886\u57df\u7684\u5e94\u7528&#xff0c;\u5373\u201c\u9884\u8bad\u7ec3-\u5fae\u8c03&#xff08;Pre-train, Fine-tune&#xff09;\u201d\u8303\u5f0f\u3002\n<ul>\n<li>BERT&#xff1a;\u5b66\u4e60\u5176\u6838\u5fc3\u7684**\u63a9\u7801\u8bed\u8a00\u6a21\u578b&#xff08;Masked Language Model, MLM&#xff09;**\u9884\u8bad\u7ec3\u4efb\u52a1&#xff0c;\u4ee5\u53ca\u5b83\u5982\u4f55\u901a\u8fc7\u53cc\u5411Transformer\u7f16\u7801\u5668\u5b9e\u73b0\u5bf9\u4e0a\u4e0b\u6587\u7684\u6df1\u5ea6\u53cc\u5411\u7406\u89e3\u3002<\/li>\n<li>GPT&#xff1a;\u5b66\u4e60\u5176\u7ecf\u5178\u7684**\u81ea\u56de\u5f52\u8bed\u8a00\u6a21\u578b&#xff08;Autoregressive LM&#xff09;**\u9884\u8bad\u7ec3\u4efb\u52a1&#xff0c;\u4ee5\u53ca\u5b83\u5982\u4f55\u901a\u8fc7\u5355\u5411Transformer\u89e3\u7801\u5668\u7ed3\u6784&#xff0c;\u5728\u6587\u672c\u751f\u6210\u4efb\u52a1\u4e0a\u8868\u73b0\u51fa\u8272\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u719f\u7ec3\u638c\u63e1Hugging Face\u7684transformers\u5e93\u3002\u52a0\u8f7d\u4e00\u4e2a\u9884\u8bad\u7ec3\u7684BERT\u6a21\u578b&#xff0c;\u5e76\u5c06\u5176\u5728\u4e00\u4e2a\u4e0b\u6e38\u6587\u672c\u5206\u7c7b\u4efb\u52a1&#xff08;\u5982GLUE\u57fa\u51c6\u6d4b\u8bd5\u4e2d\u7684\u4e00\u4e2a&#xff09;\u4e0a\u8fdb\u884c\u5fae\u8c03\u3002\u7136\u540e&#xff0c;\u52a0\u8f7d\u4e00\u4e2a\u9884\u8bad\u7ec3\u7684GPT-2\u6a21\u578b&#xff0c;\u4f53\u9a8c\u5176\u5f3a\u5927\u7684\u6587\u672c\u751f\u6210\u548c\u96f6\u6837\u672c\/\u5c11\u6837\u672c\u5b66\u4e60\u80fd\u529b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e09&#xff1a;\u6548\u7387\u4e0e\u672a\u6765<\/p>\n<ul>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u6807\u51c6Transformer\u7684\u8ba1\u7b97\u548c\u5185\u5b58\u590d\u6742\u5ea6\u4e0e\u5e8f\u5217\u957f\u5ea6\u7684\u5e73\u65b9\u6210\u6b63\u6bd4&#xff0c;\u8fd9\u9650\u5236\u4e86\u5176\u5904\u7406\u957f\u6587\u6863\u6216\u9ad8\u5206\u8fa8\u7387\u56fe\u50cf\u3002\u56e0\u6b64&#xff0c;\u5927\u91cf\u7684\u7814\u7a76\u5de5\u4f5c\u81f4\u529b\u4e8e\u9ad8\u6548Transformer&#xff0c;\u5982Longformer, Reformer, Linformer\u7b49&#xff0c;\u5b83\u4eec\u901a\u8fc7\u5404\u79cd\u7a00\u758f\u6ce8\u610f\u529b\u6216\u4f4e\u79e9\u8fd1\u4f3c\u7684\u65b9\u6cd5\u6765\u964d\u4f4e\u590d\u6742\u5ea6\u3002<\/li>\n<li>\u524d\u6cbf\u65b9\u5411&#xff1a;\n<ul>\n<li>\u591a\u6a21\u6001\u878d\u5408&#xff1a;CLIP, DALL-E\u7b49\u6a21\u578b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Transformer\u67b6\u6784\u6765\u8054\u5408\u7406\u89e3\u56fe\u50cf\u548c\u6587\u672c&#xff0c;\u5b9e\u73b0\u4e86\u60ca\u4eba\u7684\u8de8\u6a21\u6001\u751f\u6210\u548c\u7406\u89e3\u80fd\u529b\u3002<\/li>\n<li>\u6a21\u578b\u5373\u670d\u52a1&#xff1a;\u968f\u7740\u6a21\u578b\u89c4\u6a21&#xff08;\u5982GPT-3\/4&#xff09;\u53d8\u5f97\u8d8a\u6765\u8d8a\u5e9e\u5927&#xff0c;\u666e\u901a\u7814\u7a76\u8005\u548c\u5f00\u53d1\u8005\u96be\u4ee5\u81ea\u884c\u8bad\u7ec3\u6216\u90e8\u7f72\u3002\u5b66\u4e60\u5982\u4f55\u901a\u8fc7API\u6765\u8c03\u7528\u8fd9\u4e9b\u8d85\u5927\u89c4\u6a21\u6a21\u578b&#xff0c;\u5e76\u5c06\u5176\u4f5c\u4e3a\u4e00\u79cd\u5f3a\u5927\u7684\u201cAI\u5373\u670d\u52a1\u201d\u6765\u6784\u5efa\u5e94\u7528&#xff0c;\u6b63\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002<\/li>\n<li>\u67b6\u6784\u7edf\u4e00&#xff1a;Transformer\u67b6\u6784\u6b63\u4eceNLP\u9886\u57df\u201c\u6ea2\u51fa\u201d&#xff0c;\u5728\u8ba1\u7b97\u673a\u89c6\u89c9&#xff08;Vision Transformer, ViT&#xff09;\u3001\u8bed\u97f3\u5904\u7406\u3001\u751a\u81f3\u5f3a\u5316\u5b66\u4e60\u4e2d\u90fd\u53d6\u5f97\u4e86\u5de8\u5927\u6210\u529f&#xff0c;\u5c55\u73b0\u51fa\u6210\u4e3a\u4e00\u79cd\u201c\u901a\u7528\u667a\u80fd\u8ba1\u7b97\u67b6\u6784\u201d\u7684\u6f5c\u529b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>13.2 \u5f3a\u5316\u5b66\u4e60&#xff1a;\u5728\u201c\u8bd5\u9519\u201d\u4e2d\u5b66\u4e60\u6700\u4f18\u51b3\u7b56\u7684\u667a\u80fd\u4f53<\/h4>\n<h5>13.2.1. \u52a8\u673a\u4e0e\u54f2\u5b66&#xff1a;\u8d85\u8d8a\u201c\u6807\u7b7e\u201d\u7684\u667a\u6167<\/h5>\n<ul>\n<li>\n<p>\u56f0\u5883&#xff1a;\u76d1\u7763\u5b66\u4e60\u9700\u8981\u5927\u91cf\u7684\u3001\u9ad8\u8d28\u91cf\u7684\u6807\u6ce8\u6570\u636e&#xff0c;\u8fd9\u5728\u8bb8\u591a\u73b0\u5b9e\u573a\u666f\u4e2d\u662f\u6602\u8d35\u751a\u81f3\u4e0d\u53ef\u80fd\u83b7\u5f97\u7684&#xff08;\u5982\u4e0b\u68cb\u3001\u673a\u5668\u4eba\u63a7\u5236&#xff09;\u3002\u65e0\u76d1\u7763\u5b66\u4e60\u64c5\u957f\u53d1\u73b0\u6570\u636e\u4e2d\u7684\u6a21\u5f0f&#xff0c;\u4f46\u901a\u5e38\u4e0d\u76f4\u63a5\u5bfc\u5411\u4e00\u4e2a\u6700\u4f18\u7684\u201c\u51b3\u7b56\u201d\u6216\u201c\u884c\u4e3a\u201d\u3002\u5f53\u6211\u4eec\u7684\u95ee\u9898\u6838\u5fc3\u662f\u5e8f\u8d2f\u51b3\u7b56&#xff08;Sequential Decision Making&#xff09;&#xff0c;\u5373\u9700\u8981\u5728\u4e00\u7cfb\u5217\u65f6\u95f4\u6b65\u9aa4\u4e2d\u505a\u51fa\u6700\u4f18\u9009\u62e9\u4ee5\u8fbe\u6210\u4e00\u4e2a\u957f\u671f\u76ee\u6807\u65f6&#xff0c;\u8fd9\u4e24\u79cd\u8303\u5f0f\u90fd\u663e\u5f97\u529b\u4e0d\u4ece\u5fc3\u3002<\/p>\n<\/li>\n<li>\n<p>\u54f2\u5b66\u7a81\u7834&#xff1a;\u4ece\u201c\u4ea4\u4e92\u201d\u4e2d\u6d8c\u73b0\u667a\u80fd\u00a0\u5f3a\u5316\u5b66\u4e60&#xff08;RL&#xff09;\u7684\u54f2\u5b66\u6839\u690d\u4e8e\u751f\u7269\u5fc3\u7406\u5b66\u7684\u884c\u4e3a\u4e3b\u4e49\u3002\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u4e00\u4e2a\u201c\u6559\u5e08\u201d\u7ed9\u51fa\u7684\u6b63\u786e\u7b54\u6848&#xff0c;\u800c\u662f\u8ba9\u4e00\u4e2a\u667a\u80fd\u4f53&#xff08;Agent&#xff09;\u76f4\u63a5\u4e0e\u4e00\u4e2a\u73af\u5883&#xff08;Environment&#xff09;\u8fdb\u884c\u4ea4\u4e92\u3002\u667a\u80fd\u4f53\u901a\u8fc7\u201c\u8bd5\u9519&#xff08;Trial-and-Error&#xff09;\u201d\u6765\u63a2\u7d22\u73af\u5883&#xff0c;\u73af\u5883\u5219\u901a\u8fc7\u4e00\u4e2a\u5956\u52b1\u4fe1\u53f7&#xff08;Reward Signal&#xff09;\u6765\u53cd\u9988\u667a\u80fd\u4f53\u884c\u4e3a\u7684\u597d\u574f\u3002\u667a\u80fd\u4f53\u7684\u552f\u4e00\u76ee\u6807&#xff0c;\u5c31\u662f\u5b66\u4e60\u4e00\u4e2a\u7b56\u7565&#xff08;Policy&#xff09;&#xff0c;\u4ee5\u6700\u5927\u5316\u5176\u5728\u751f\u547d\u5468\u671f\u5185\u83b7\u5f97\u7684\u7d2f\u79ef\u5956\u52b1\u3002\u8fd9\u79cd\u4ece\u7a00\u758f\u3001\u5ef6\u8fdf\u7684\u5956\u52b1\u4fe1\u53f7\u4e2d\u5b66\u4e60\u590d\u6742\u884c\u4e3a\u7684\u80fd\u529b&#xff0c;\u662fRL\u6700\u8ff7\u4eba\u3001\u4e5f\u6700\u5177\u6311\u6218\u6027\u7684\u5730\u65b9\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>13.2.2. \u6838\u5fc3\u6b66\u5668\u5e93&#xff1a;\u4ef7\u503c\u3001\u7b56\u7565\u4e0e\u6a21\u578b<\/h5>\n<p>RL\u7b97\u6cd5\u7684\u6c6a\u6d0b\u5927\u6d77&#xff0c;\u53ef\u4ee5\u4ece\u4e09\u4e2a\u6838\u5fc3\u89c6\u89d2\u6765\u5212\u5206&#xff1a;\u5bf9**\u4ef7\u503c&#xff08;Value&#xff09;\u7684\u4f30\u8ba1\u3001\u5bf9\u7b56\u7565&#xff08;Policy&#xff09;\u7684\u76f4\u63a5\u5b66\u4e60&#xff0c;\u4ee5\u53ca\u5bf9\u73af\u5883\u6a21\u578b&#xff08;Model&#xff09;**\u7684\u6784\u5efa\u3002<\/p>\n<ul>\n<li>\n<p>\u57fa\u77f3\u4e00&#xff1a;\u4ef7\u503c\u51fd\u6570&#xff08;Value Function&#xff09;\u2014\u2014\u8861\u91cf\u201c\u597d\u574f\u201d\u7684\u6807\u5c3a<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;\u4ef7\u503c\u51fd\u6570\u662fRL\u7684\u57fa\u77f3\u3002\u5b83\u4e0d\u53bb\u76f4\u63a5\u56de\u7b54\u201c\u8be5\u505a\u4ec0\u4e48\u201d&#xff0c;\u800c\u662f\u56de\u7b54\u201c\u5f53\u524d\u72b6\u6001\u6216\u884c\u4e3a\u6709\u591a\u597d\u201d\u3002\n<ul>\n<li>\u72b6\u6001\u4ef7\u503c\u51fd\u6570\u00a0V(s)&#xff1a;\u8868\u793a\u4ece\u72b6\u6001\u00a0s\u00a0\u51fa\u53d1&#xff0c;\u9075\u5faa\u5f53\u524d\u7b56\u7565\u00a0\u03c0&#xff0c;\u672a\u6765\u80fd\u83b7\u5f97\u7684\u671f\u671b\u7d2f\u79ef\u5956\u52b1\u3002<\/li>\n<li>\u52a8\u4f5c\u4ef7\u503c\u51fd\u6570\u00a0Q(s, a)&#xff08;Q-function&#xff09;&#xff1a;\u8868\u793a\u5728\u72b6\u6001\u00a0s\u00a0\u4e0b&#xff0c;\u6267\u884c\u52a8\u4f5c\u00a0a&#xff0c;\u7136\u540e\u9075\u5faa\u5f53\u524d\u7b56\u7565\u00a0\u03c0&#xff0c;\u672a\u6765\u80fd\u83b7\u5f97\u7684\u671f\u671b\u7d2fd\u79ef\u5956\u52b1\u3002Q\u51fd\u6570\u6bd4V\u51fd\u6570\u66f4\u76f4\u63a5\u5730\u6307\u5bfc\u51b3\u7b56&#xff0c;\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u5728\u5f53\u524d\u72b6\u6001\u4e0b\u9009\u62e9\u80fd\u5e26\u6765\u6700\u5927Q\u503c\u7684\u52a8\u4f5c\u5373\u53ef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6838\u5fc3\u7b97\u6cd5&#xff1a;Q-Learning \u4e0e DQN\u00a0Q-Learning\u662f\u4e00\u79cd\u7ecf\u5178\u7684\u79bb\u7b56\u7565&#xff08;Off-policy&#xff09;\u65f6\u95f4\u5dee\u5206&#xff08;TD&#xff09;\u5b66\u4e60\u7b97\u6cd5\u3002\u5b83\u901a\u8fc7\u4e0d\u65ad\u8fed\u4ee3\u8d1d\u5c14\u66fc\u6700\u4f18\u65b9\u7a0b\u00a0Q(s, a) &#061; R &#043; \u03b3 * max_{a&#039;} Q(s&#039;, a&#039;)\u00a0\u6765\u76f4\u63a5\u903c\u8fd1\u6700\u4f18\u7684\u52a8\u4f5c\u4ef7\u503c\u51fd\u6570Q*&#xff0c;\u800c\u65e0\u9700\u77e5\u9053\u73af\u5883\u7684\u5177\u4f53\u6a21\u578b\u3002 **\u6df1\u5ea6Q\u7f51\u7edc&#xff08;Deep Q-Network, DQN&#xff09;\u662f\u5176\u91cc\u7a0b\u7891\u5f0f\u7684\u5ef6\u4f38\u3002\u5b83\u4f7f\u7528\u4e00\u4e2a\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc\u6765\u8fd1\u4f3cQ\u51fd\u6570&#xff0c;\u4ece\u800c\u80fd\u5904\u7406\u9ad8\u7ef4\u7684\u72b6\u6001\u8f93\u5165&#xff08;\u5982\u6e38\u620f\u753b\u9762\u50cf\u7d20&#xff09;\u3002DQN\u901a\u8fc7\u5f15\u5165\u7ecf\u9a8c\u56de\u653e&#xff08;Experience Replay&#xff09;\u548c\u76ee\u6807\u7f51\u7edc&#xff08;Target Network&#xff09;**\u4e24\u5927\u6280\u5de7&#xff0c;\u6210\u529f\u5730\u89e3\u51b3\u4e86\u4f7f\u7528\u975e\u7ebf\u6027\u51fd\u6570\u8fd1\u4f3c\u5668\u5e26\u6765\u7684\u8bad\u7ec3\u4e0d\u7a33\u5b9a\u6027\u95ee\u9898&#xff0c;\u5f00\u542f\u4e86\u6df1\u5ea6\u5f3a\u5316\u5b66\u4e60\u7684\u65f6\u4ee3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u57fa\u77f3\u4e8c&#xff1a;\u7b56\u7565\u51fd\u6570&#xff08;Policy Function&#xff09;\u2014\u2014\u76f4\u63a5\u6307\u5bfc\u201c\u884c\u52a8\u201d\u7684\u6307\u5357<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;\u57fa\u4e8e\u4ef7\u503c\u7684\u65b9\u6cd5\u5728\u5904\u7406\u8fde\u7eed\u52a8\u4f5c\u7a7a\u95f4\u6216\u968f\u673a\u7b56\u7565\u65f6\u4f1a\u9047\u5230\u56f0\u96be\u3002\u57fa\u4e8e\u7b56\u7565\u7684\u65b9\u6cd5\u5219\u9009\u62e9\u76f4\u63a5\u53c2\u6570\u5316\u7b56\u7565\u672c\u8eab&#xff0c;\u5373\u5b66\u4e60\u4e00\u4e2a\u51fd\u6570\u00a0\u03c0(a|s; \u03b8)&#xff0c;\u8f93\u5165\u72b6\u6001\u00a0s&#xff0c;\u76f4\u63a5\u8f93\u51fa\u6267\u884c\u6bcf\u4e2a\u52a8\u4f5c\u00a0a\u00a0\u7684\u6982\u7387\u5206\u5e03\u3002<\/li>\n<li>\u6838\u5fc3\u7b97\u6cd5&#xff1a;\u7b56\u7565\u68af\u5ea6&#xff08;Policy Gradient&#xff09;\u00a0\u5176\u6838\u5fc3\u601d\u60f3\u975e\u5e38\u76f4\u89c2&#xff1a;\u5982\u679c\u4e00\u4e2a\u52a8\u4f5c\u6700\u7ec8\u5bfc\u5411\u4e86\u597d\u7684\u7ed3\u679c&#xff08;\u9ad8\u5956\u52b1&#xff09;&#xff0c;\u90a3\u4e48\u5c31\u8c03\u6574\u53c2\u6570\u00a0\u03b8&#xff0c;\u589e\u5927\u8fd9\u4e2a\u52a8\u4f5c\u88ab\u9009\u4e2d\u7684\u6982\u7387&#xff1b;\u53cd\u4e4b\u5219\u51cf\u5c0f\u3002REINFORCE\u7b97\u6cd5\u662f\u5176\u6700\u57fa\u7840\u7684\u5f62\u5f0f\u3002\u7136\u800c&#xff0c;\u7b56\u7565\u68af\u5ea6\u65b9\u6cd5\u901a\u5e38\u5177\u6709\u9ad8\u65b9\u5dee&#xff0c;\u6536\u655b\u8f83\u6162\u3002 **\u884c\u52a8\u8005-\u8bc4\u8bba\u5bb6&#xff08;Actor-Critic, A-C&#xff09;**\u67b6\u6784\u662f\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u4e3b\u6d41\u65b9\u6848\u3002\u5b83\u7ed3\u5408\u4e86\u4ef7\u503c\u548c\u7b56\u7565\u5b66\u4e60&#xff1a;\n<ul>\n<li>\u884c\u52a8\u8005&#xff08;Actor&#xff09;&#xff1a;\u5373\u7b56\u7565\u7f51\u7edc&#xff0c;\u8d1f\u8d23\u8f93\u51fa\u52a8\u4f5c\u3002<\/li>\n<li>\u8bc4\u8bba\u5bb6&#xff08;Critic&#xff09;&#xff1a;\u5373\u4ef7\u503c\u7f51\u7edc&#xff0c;\u8d1f\u8d23\u8bc4\u4f30\u884c\u52a8\u8005\u6240\u9009\u52a8\u4f5c\u7684\u597d\u574f&#xff0c;\u5e76\u63d0\u4f9b\u4e00\u4e2a\u66f4\u4f4e\u65b9\u5dee\u7684\u68af\u5ea6\u4fe1\u53f7\u6765\u6307\u5bfc\u884c\u52a8\u8005\u7684\u66f4\u65b0\u3002A2C (Advantage Actor-Critic)\u00a0\u548c\u5176\u5f02\u6b65\u7248\u672c\u00a0A3C\u00a0\u662f\u5176\u4e2d\u7684\u6770\u51fa\u4ee3\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u57fa\u77f3\u4e09&#xff1a;\u73af\u5883\u6a21\u578b&#xff08;Environment Model&#xff09;\u2014\u2014\u5728\u201c\u60f3\u8c61\u201d\u4e2d\u89c4\u5212\u672a\u6765<\/p>\n<ul>\n<li>\u673a\u5236&#xff1a;\u4e0a\u8ff0\u4e24\u7c7b\u65b9\u6cd5\u90fd\u5c5e\u4e8e\u65e0\u6a21\u578b&#xff08;Model-Free&#xff09;RL&#xff0c;\u5b83\u4eec\u76f4\u63a5\u4ece\u4e0e\u771f\u5b9e\u73af\u5883\u7684\u4ea4\u4e92\u4e2d\u5b66\u4e60\u3002\u800c\u6709\u6a21\u578b&#xff08;Model-Based&#xff09;RL\u5219\u8bd5\u56fe\u5148\u5b66\u4e60\u4e00\u4e2a\u73af\u5883\u7684\u6a21\u578b&#xff0c;\u5373\u5b66\u4e60\u72b6\u6001\u8f6c\u79fb\u51fd\u6570\u00a0P(s&#039;|s, a)\u00a0\u548c\u5956\u52b1\u51fd\u6570\u00a0R(s, a)\u3002\u4e00\u65e6\u6709\u4e86\u6a21\u578b&#xff0c;\u667a\u80fd\u4f53\u5c31\u53ef\u4ee5\u5728\u201c\u8111\u5185\u201d\u8fdb\u884c\u6a21\u62df\u548c\u89c4\u5212&#xff0c;\u800c\u65e0\u9700\u4e0e\u771f\u5b9e\u73af\u5883\u8fdb\u884c\u6602\u8d35\u751a\u81f3\u5371\u9669\u7684\u4ea4\u4e92\u3002<\/li>\n<li>\u4f18\u52bf\u4e0e\u6311\u6218&#xff1a;\u6709\u6a21\u578b\u65b9\u6cd5\u901a\u5e38\u5177\u6709\u66f4\u9ad8\u7684\u6837\u672c\u6548\u7387&#xff08;Sample Efficiency&#xff09;\u3002\u7136\u800c&#xff0c;\u5b66\u4e60\u4e00\u4e2a\u8db3\u591f\u7cbe\u786e\u7684\u73af\u5883\u6a21\u578b\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5de8\u5927\u7684\u6311\u6218&#xff0c;\u6a21\u578b\u8bef\u5dee\u53ef\u80fd\u4f1a\u88ab\u89c4\u5212\u8fc7\u7a0b\u653e\u5927\u3002AlphaGo\u53ca\u5176\u540e\u7ee7\u8005AlphaZero\u662f\u7ed3\u5408\u4e86\u65e0\u6a21\u578b\u5b66\u4e60&#xff08;\u8499\u7279\u5361\u6d1b\u6811\u641c\u7d22&#xff09;\u548c\u6709\u6a21\u578b\u5b66\u4e60&#xff08;\u4ef7\u503c\/\u7b56\u7565\u7f51\u7edc&#xff09;\u7684\u5dc5\u5cf0\u4e4b\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>13.3.3. \u8fdb\u9636\u8def\u5f84<\/h5>\n<ul>\n<li>\n<p>\u9636\u6bb5\u4e00&#xff1a;\u5960\u57fa\u4e0e\u6838\u5fc3\u6982\u5ff5<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u6587\u732e&#xff1a;Richard Sutton \u548c Andrew Barto \u7684\u300aReinforcement Learning: An Introduction (2nd Edition)\u300b\u3002\u8fd9\u672c\u4e66\u662fRL\u9886\u57df\u7684\u201c\u5723\u7ecf\u201d&#xff0c;\u5176\u5730\u4f4d\u65e0\u53ef\u64bc\u52a8\u3002\u524d\u4e24\u90e8\u5206\u5173\u4e8eMDP\u3001\u52a8\u6001\u89c4\u5212\u3001\u8499\u7279\u5361\u6d1b\u548cTD\u5b66\u4e60\u7684\u5185\u5bb9\u662f\u7406\u89e3\u4e00\u5207\u540e\u7eed\u7b97\u6cd5\u7684\u57fa\u7840\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\u6df1\u523b\u7406\u89e3\u63a2\u7d22\u4e0e\u5229\u7528\u7684\u6743\u8861&#xff08;Exploration vs. Exploitation Trade-off&#xff09;\u3002\u533a\u5206**\u540c\u7b56\u7565&#xff08;On-policy&#xff09;\u4e0e\u79bb\u7b56\u7565&#xff08;Off-policy&#xff09;**\u5b66\u4e60\u7684\u672c\u8d28\u533a\u522b\u3002\u638c\u63e1\u8d1d\u5c14\u66fc\u65b9\u7a0b\u7684\u63a8\u5bfc\u548c\u610f\u4e49\u3002<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u4f7f\u7528Python\u548cNumPy&#xff0c;\u5728\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u683c\u4e16\u754c&#xff08;Gridworld&#xff09;\u73af\u5883\u4e2d&#xff0c;\u4eb2\u624b\u5b9e\u73b0Q-Learning\u548cSARSA\u7b97\u6cd5\u3002\u7136\u540e&#xff0c;\u8fdb\u5165OpenAI Gym\u7684\u201c\u7ecf\u5178\u63a7\u5236\u201d\u73af\u5883&#xff0c;\u4f7f\u7528PyTorch\u6216TensorFlow\u5b9e\u73b0\u4e00\u4e2aDQN\u6765\u89e3\u51b3\u201c\u8f66\u6746&#xff08;CartPole-v1&#xff09;\u201d\u95ee\u9898\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e8c&#xff1a;\u73b0\u4ee3\u6df1\u5ea6RL\u7b97\u6cd5<\/p>\n<ul>\n<li>\u5fc5\u8bfb\u6587\u732e&#xff1a;DQN\u3001A3C\u3001TRPO\/PPO\u3001DDPG\/TD3\u3001SAC\u7684\u539f\u59cb\u8bba\u6587\u3002\u8fd9\u4e9b\u662f\u73b0\u4ee3\u6df1\u5ea6RL\u7b97\u6cd5\u7684\u57fa\u77f3\u3002<\/li>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\n<ul>\n<li>\u7b56\u7565\u68af\u5ea6&#xff1a;\u6df1\u5165\u7406\u89e3REINFORCE\u7b97\u6cd5\u7684\u63a8\u5bfc&#xff0c;\u660e\u767d\u4e3a\u4f55\u9700\u8981\u5f15\u5165\u57fa\u7ebf&#xff08;Baseline&#xff09;\u6765\u51cf\u5c0f\u65b9\u5dee\u3002<\/li>\n<li>Actor-Critic&#xff1a;\u7406\u89e3A2C\/A3C\u5982\u4f55\u901a\u8fc7\u4f18\u52bf\u51fd\u6570&#xff08;Advantage Function&#xff09;\u6765\u7a33\u5b9a\u8bad\u7ec3\u3002<\/li>\n<li>\u4fe1\u4efb\u533a\u57df\/\u8fd1\u7aef\u7b56\u7565\u4f18\u5316&#xff08;TRPO\/PPO&#xff09;&#xff1a;\u7406\u89e3\u5176\u5982\u4f55\u901a\u8fc7\u9650\u5236\u7b56\u7565\u66f4\u65b0\u7684\u6b65\u957f\u6765\u4fdd\u8bc1\u5b66\u4e60\u8fc7\u7a0b\u7684\u7a33\u5b9a\u6027&#xff0c;PPO\u662f\u76ee\u524d\u5e94\u7528\u6700\u5e7f\u6cdb\u3001\u6700\u9c81\u68d2\u7684\u7b97\u6cd5\u4e4b\u4e00\u3002<\/li>\n<li>\u8fde\u7eed\u63a7\u5236&#xff1a;\u5b66\u4e60DDPG\/TD3\/SAC\u7b49\u7b97\u6cd5\u662f\u5982\u4f55\u5c06DQN\u548cActor-Critic\u601d\u60f3\u6269\u5c55\u5230\u8fde\u7eed\u52a8\u4f5c\u7a7a\u95f4\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b9e\u8df5\u9879\u76ee&#xff1a;\u5728OpenAI Gym\u7684MuJoCo\u6216PyBullet\u7269\u7406\u4eff\u771f\u73af\u5883\u4e2d&#xff0c;\u4f7f\u7528\u4e00\u4e2a\u6210\u719f\u7684RL\u5e93&#xff08;\u5982Stable Baselines3&#xff09;\u6765\u8bad\u7ec3PPO\u6216SAC\u7b97\u6cd5&#xff0c;\u8ba9\u4e00\u4e2a\u6a21\u62df\u673a\u5668\u4eba\u5b66\u4f1a\u884c\u8d70\u6216\u5b8c\u6210\u7279\u5b9a\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9636\u6bb5\u4e09&#xff1a;\u524d\u6cbf\u4e0e\u6311\u6218<\/p>\n<ul>\n<li>\u5b66\u4e60\u8981\u70b9&#xff1a;\n<ul>\n<li>\u79bb\u7ebf\u5f3a\u5316\u5b66\u4e60&#xff08;Offline RL&#xff09;&#xff1a;\u5982\u4f55\u4ece\u4e00\u4e2a\u56fa\u5b9a\u7684\u3001\u5386\u53f2\u4ea4\u4e92\u6570\u636e\u96c6\u4e2d\u5b66\u4e60\u7b56\u7565&#xff0c;\u800c\u65e0\u9700\u4e0e\u73af\u5883\u8fdb\u884c\u65b0\u7684\u4ea4\u4e92&#xff1f;\u8fd9\u5728\u533b\u7597\u3001\u91d1\u878d\u7b49\u65e0\u6cd5\u81ea\u7531\u63a2\u7d22\u7684\u9886\u57df\u81f3\u5173\u91cd\u8981\u3002<\/li>\n<li>\u591a\u667a\u80fd\u4f53\u5f3a\u5316\u5b66\u4e60&#xff08;Multi-Agent RL, MARL&#xff09;&#xff1a;\u5f53\u73af\u5883\u4e2d\u5b58\u5728\u591a\u4e2a\u76f8\u4e92\u5f71\u54cd\u7684\u667a\u80fd\u4f53\u65f6&#xff0c;\u5982\u4f55\u5b66\u4e60\u5408\u4f5c\u6216\u7ade\u4e89\u7684\u7b56\u7565&#xff1f;<\/li>\n<li>\u57fa\u4e8e\u6a21\u578b\u7684RL&#xff1a;\u5b66\u4e60Dreamer\u7b49\u7b97\u6cd5&#xff0c;\u770b\u5b83\u4eec\u5982\u4f55\u901a\u8fc7\u5728\u201c\u60f3\u8c61\u201d\u4e2d\u5b66\u4e60&#xff0c;\u5b9e\u73b0\u60ca\u4eba\u7684\u6837\u672c\u6548\u7387\u3002<\/li>\n<li>\u63a2\u7d22\u95ee\u9898&#xff1a;\u5982\u4f55\u8bbe\u8ba1\u66f4\u6709\u6548\u7684\u5185\u5728\u6fc0\u52b1&#xff08;Intrinsic Motivation&#xff09;\u673a\u5236&#xff0c;\u6765\u9f13\u52b1\u667a\u80fd\u4f53\u5728\u7a00\u758f\u5956\u52b1\u73af\u5883\u4e2d\u8fdb\u884c\u6709\u610f\u4e49\u7684\u63a2\u7d22&#xff1f;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>13.3 \u65b0\u5174\u524d\u6cbf&#xff1a;\u91cd\u5851AI\u8fb9\u754c\u7684\u65b0\u8303\u5f0f<\/h4>\n<h5>13.3.1 \u56fe\u795e\u7ecf\u7f51\u7edc&#xff08;GNN&#xff09;&#xff1a;\u89e3\u9501\u5173\u7cfb\u6570\u636e\u7684\u529b\u91cf<\/h5>\n<ul>\n<li>\u6df1\u5ea6\u5256\u6790&#xff1a;GNN\u7684\u6838\u5fc3\u601d\u60f3\u662f\u6d88\u606f\u4f20\u9012&#xff08;Message Passing&#xff09;&#xff0c;\u5b83\u662f\u4e00\u4e2a\u8fed\u4ee3\u7684\u8fc7\u7a0b\u3002\u5728\u6bcf\u4e00\u8f6e\u8fed\u4ee3\u4e2d&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a&#xff1a;1)\u00a0\u6536\u96c6\u5176\u6240\u6709\u90bb\u5c45\u8282\u70b9\u7684\u7279\u5f81\u8868\u793a&#xff1b;2) \u901a\u8fc7\u4e00\u4e2a\u53ef\u5b66\u4e60\u7684\u51fd\u6570&#xff08;\u5982\u4e00\u4e2a\u5c0f\u578bMLP&#xff09;\u5c06\u8fd9\u4e9b\u4fe1\u606f\u8fdb\u884c\u805a\u5408&#xff1b;3) \u5c06\u805a\u5408\u540e\u7684\u4fe1\u606f\u4e0e\u81ea\u5df1\u4e0a\u4e00\u8f6e\u7684\u8868\u793a\u76f8\u7ed3\u5408&#xff0c;\u66f4\u65b0\u4e3a\u81ea\u5df1\u672c\u8f6e\u7684\u65b0\u8868\u793a\u3002\u7ecf\u8fc7\u00a0k\u00a0\u8f6e\u8fed\u4ee3&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u7684\u6700\u7ec8\u8868\u793a\u5c31\u7f16\u7801\u4e86\u5176k\u8df3\u90bb\u5c45\u5185\u7684\u5168\u90e8\u7ed3\u6784\u4fe1\u606f\u3002GCN\u3001GraphSAGE\u3001GAT\u7b49\u6a21\u578b\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u5b83\u4eec\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u805a\u5408\u548c\u66f4\u65b0\u51fd\u6570\u3002<\/li>\n<li>\u8fdb\u9636\u8def\u5f84&#xff1a;\u5b66\u4e60PyTorch Geometric (PyG) \u6216 Deep Graph Library (DGL) \u8fd9\u4e24\u4e2a\u4e3b\u6d41\u7684GNN\u5e93\u3002\u4ece\u5728\u4e00\u4e2a\u793e\u4ea4\u7f51\u7edc\u6570\u636e\u96c6&#xff08;\u5982Cora&#xff09;\u4e0a\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684GCN\u8fdb\u884c\u8282\u70b9\u5206\u7c7b\u5f00\u59cb\u3002<\/li>\n<\/ul>\n<h5>13.3.2 \u8054\u90a6\u5b66\u4e60&#xff08;Federated Learning&#xff09;&#xff1a;\u6570\u636e\u9690\u79c1\u65f6\u4ee3\u7684\u534f\u540c\u667a\u80fd<\/h5>\n<ul>\n<li>\u6df1\u5ea6\u5256\u6790&#xff1a;\u5176\u6807\u51c6\u6d41\u7a0b&#xff08;FedAvg\u7b97\u6cd5&#xff09;\u4e3a&#xff1a;1)\u00a0\u5206\u53d1&#xff1a;\u4e2d\u592e\u670d\u52a1\u5668\u5c06\u5168\u5c40\u6a21\u578b\u5206\u53d1\u7ed9\u6240\u6709\u53c2\u4e0e\u7684\u5ba2\u6237\u7aef\u30022)\u00a0\u672c\u5730\u8bad\u7ec3&#xff1a;\u6bcf\u4e2a\u5ba2\u6237\u7aef\u4f7f\u7528\u81ea\u5df1\u7684\u672c\u5730\u6570\u636e&#xff0c;\u5bf9\u6a21\u578b\u8fdb\u884c\u591a\u8f6e\u68af\u5ea6\u4e0b\u964d\u8bad\u7ec3\u30023)\u00a0\u4e0a\u4f20&#xff1a;\u5ba2\u6237\u7aef\u5c06\u8bad\u7ec3\u540e\u7684\u6a21\u578b\u6743\u91cd\u66f4\u65b0&#xff08;\u800c\u975e\u539f\u59cb\u6570\u636e&#xff09;\u52a0\u5bc6\u540e\u4e0a\u4f20\u7ed9\u670d\u52a1\u5668\u30024)\u00a0\u805a\u5408&#xff1a;\u670d\u52a1\u5668\u5c06\u6536\u96c6\u5230\u7684\u6240\u6709\u66f4\u65b0\u8fdb\u884c\u52a0\u6743\u5e73\u5747&#xff0c;\u7528\u6765\u66f4\u65b0\u5168\u5c40\u6a21\u578b\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5faa\u73af\u5f80\u590d\u3002\u5176\u6838\u5fc3\u6311\u6218\u5728\u4e8e\u5982\u4f55\u5904\u7406\u5ba2\u6237\u7aef\u4e4b\u95f4\u7684\u6570\u636e\u5f02\u6784\u6027&#xff08;Non-IID data&#xff09;\u3001\u901a\u4fe1\u5f00\u9500\u4ee5\u53ca\u5b89\u5168\u6027\u95ee\u9898\u3002<\/li>\n<li>\u8fdb\u9636\u8def\u5f84&#xff1a;\u4e86\u89e3FedAvg\u7b97\u6cd5\u7684\u7406\u8bba\u57fa\u7840\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528Flower\u6216PySyft\u7b49\u8054\u90a6\u5b66\u4e60\u6846\u67b6&#xff0c;\u6a21\u62df\u4e00\u4e2a\u7b80\u5355\u7684\u8054\u90a6\u5b66\u4e60\u73af\u5883\u3002<\/li>\n<\/ul>\n<h5>13.3.3 \u81ea\u76d1\u7763\u5b66\u4e60&#xff08;Self-supervised Learning, SSL&#xff09;&#xff1a;\u65e0\u6807\u7b7e\u6570\u636e\u4e2d\u7684\u201c\u70bc\u91d1\u672f\u201d<\/h5>\n<ul>\n<li>\u6df1\u5ea6\u5256\u6790&#xff1a;SSL\u662f\u8fd1\u5e74\u6765\u6df1\u5ea6\u5b66\u4e60\u9886\u57df\u6700\u6fc0\u52a8\u4eba\u5fc3\u7684\u7a81\u7834\u4e4b\u4e00&#xff0c;\u5b83\u6781\u5927\u5730\u964d\u4f4e\u4e86\u5bf9\u4eba\u5de5\u6807\u6ce8\u6570\u636e\u7684\u4f9d\u8d56\u3002\u5176\u6210\u529f\u7684\u5173\u952e\u5728\u4e8e\u8bbe\u8ba1\u7cbe\u5de7\u7684\u4ee3\u7406\u4efb\u52a1&#xff08;Pretext Task&#xff09;\u3002SSL\u53ef\u4ee5\u5206\u4e3a\u4e24\u5927\u6d41\u6d3e&#xff1a;\n<li>\u751f\u6210\u5f0f&#xff08;Generative&#xff09;&#xff1a;\u5982BERT\u7684\u63a9\u7801\u8bed\u8a00\u6a21\u578b\u548c\u56fe\u50cf\u4fee\u590d&#xff08;Image Inpainting&#xff09;&#xff0c;\u5b83\u4eec\u5b66\u4e60\u6062\u590d\u88ab\u7834\u574f\u7684\u90e8\u5206\u8f93\u5165\u3002<\/li>\n<li>\u5bf9\u6bd4\u5f0f&#xff08;Contrastive&#xff09;&#xff1a;\u5982SimCLR, MoCo&#xff0c;\u5b83\u4eec\u7684\u6838\u5fc3\u601d\u60f3\u662f\u201c\u5c06\u76f8\u4f3c\u7684\u6837\u672c\u5728\u8868\u793a\u7a7a\u95f4\u4e2d\u62c9\u8fd1&#xff0c;\u5c06\u4e0d\u76f8\u4f3c\u7684\u6837\u672c\u63a8\u8fdc\u201d\u3002\u901a\u8fc7\u5bf9\u540c\u4e00\u4e2a\u6837\u672c\u8fdb\u884c\u4e0d\u540c\u7684\u6570\u636e\u589e\u5f3a&#xff08;\u5982\u65cb\u8f6c\u3001\u88c1\u526a&#xff09;\u6765\u6784\u9020\u201c\u6b63\u6837\u672c\u5bf9\u201d&#xff0c;\u800c\u5c06\u5176\u4ed6\u6837\u672c\u89c6\u4e3a\u201c\u8d1f\u6837\u672c\u5bf9\u201d&#xff0c;\u7136\u540e\u901a\u8fc7\u4e00\u4e2a\u5bf9\u6bd4\u635f\u5931\u51fd\u6570&#xff08;\u5982InfoNCE Loss&#xff09;\u6765\u5b66\u4e60\u8868\u793a\u3002<\/li>\n<\/li>\n<li>\u8fdb\u9636\u8def\u5f84&#xff1a;\u7cbe\u8bfbSimCLR\u548cBERT\u7684\u8bba\u6587&#xff0c;\u7406\u89e3\u5bf9\u6bd4\u5b66\u4e60\u548c\u63a9\u7801\u5efa\u6a21\u7684\u7cbe\u9ad3\u3002\u5728\u5b9e\u8df5\u4e2d&#xff0c;\u5b66\u4e60\u5982\u4f55\u4f7f\u7528\u5728ImageNet\u4e0a\u901a\u8fc7\u81ea\u76d1\u7763\u5b66\u4e60\u9884\u8bad\u7ec3\u597d\u7684\u89c6\u89c9\u6a21\u578b&#xff08;\u5982MoCo, DINO&#xff09;&#xff0c;\u5e76\u5c06\u5176\u7528\u4e8e\u4e0b\u6e38\u4efb\u52a1\u7684\u8fc1\u79fb\u5b66\u4e60\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>13.4 \u201c\u77e5\u884c\u5408\u4e00\u201d&#xff1a;\u4ece\u4f18\u79c0\u5230\u5353\u8d8a\u7684\u7ec8\u8eab\u6210\u957f\u4e4b\u9053<\/h4>\n<p>\u6280\u672f\u7684\u5b66\u4e60\u6c38\u65e0\u6b62\u5883&#xff0c;\u4f46\u6210\u957f\u4e4b\u9053\u6709\u6cd5\u53ef\u5faa\u3002<\/p>\n<li>\n<p>\u6784\u5efa\u201c\u53cd\u8106\u5f31\u201d\u7684\u77e5\u8bc6\u4f53\u7cfb&#xff1a;\u4e0d\u8981\u53ea\u6ee1\u8db3\u4e8e\u5b66\u4e60\u5f53\u524d\u6700\u201c\u706b\u201d\u7684\u6a21\u578b\u3002\u66f4\u8981\u53bb\u7406\u89e3\u90a3\u4e9b\u8de8\u8d8a\u65f6\u95f4\u3001\u66f4\u52a0\u672c\u8d28\u7684\u601d\u60f3&#xff0c;\u5982\u8d1d\u53f6\u65af\u63a8\u65ad\u3001\u4fe1\u606f\u8bba\u3001\u4f18\u5316\u7406\u8bba\u3001\u56e0\u679c\u63a8\u65ad\u3002\u8fd9\u4e9b\u662f\u7406\u89e3\u548c\u521b\u9020\u65b0\u6a21\u578b\u7684\u57fa\u7840\u3002\u5728\u6784\u5efaT\u578b\u77e5\u8bc6\u7ed3\u6784\u65f6&#xff0c;\u8ba9\u8fd9\u4e9b\u57fa\u7840\u7406\u8bba\u6210\u4e3a\u4f60\u201cT\u201d\u5b57\u90a3\u575a\u5b9e\u7684\u6a2a\u6881\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ece\u201c\u590d\u73b0\u201d\u5230\u201c\u6279\u5224\u201d\u7684\u601d\u7ef4\u5347\u7ea7&#xff1a;<\/p>\n<ul>\n<li>\u590d\u73b0\u662f\u5b66\u4e60\u7684\u57fa\u77f3&#xff0c;\u4f46\u6279\u5224\u662f\u521b\u65b0\u7684\u5f00\u59cb\u3002\u5728\u9605\u8bfb\u8bba\u6587\u65f6&#xff0c;\u4e0d\u8981\u5168\u76d8\u63a5\u53d7\u3002\u8981\u4e3b\u52a8\u601d\u8003&#xff1a;\u4f5c\u8005\u7684\u6838\u5fc3\u5047\u8bbe\u662f\u4ec0\u4e48&#xff1f;\u8fd9\u4e2a\u5047\u8bbe\u5728\u54ea\u4e9b\u573a\u666f\u4e0b\u53ef\u80fd\u4e0d\u6210\u7acb&#xff1f;\u5b9e\u9a8c\u90e8\u5206\u662f\u5426\u516c\u5e73&#xff1f;\u6709\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u80fd\u8fbe\u5230\u7c7b\u4f3c\u7684\u6548\u679c&#xff1f;\u8fd9\u4e2a\u601d\u60f3\u80fd\u5426\u88ab\u8fc1\u79fb\u5230\u6211\u81ea\u5df1\u7684\u95ee\u9898\u4e2d&#xff1f;<\/li>\n<li>\u201cAblation Study\u201d&#xff08;\u6d88\u878d\u7814\u7a76&#xff09;\u662f\u8bba\u6587\u4e2d\u6700\u503c\u5f97\u5173\u6ce8\u7684\u90e8\u5206\u3002\u5b83\u901a\u8fc7\u79fb\u9664\u6216\u66ff\u6362\u6a21\u578b\u7684\u67d0\u4e2a\u7ec4\u4ef6\u6765\u89c2\u5bdf\u6027\u80fd\u53d8\u5316&#xff0c;\u8fd9\u63ed\u793a\u4e86\u6a21\u578b\u6210\u529f\u7684\u771f\u6b63\u539f\u56e0\u3002\u5728\u81ea\u5df1\u7684\u9879\u76ee\u4e2d&#xff0c;\u4e5f\u8981\u517b\u6210\u8fdb\u884c\u4e25\u8c28\u6d88\u878d\u7814\u7a76\u7684\u4e60\u60ef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6253\u9020\u4f60\u7684\u201c\u4ee3\u8868\u4f5c\u201d&#xff1a;<\/p>\n<ul>\n<li>\u4e0e\u5176\u505a\u5341\u4e2a\u6d45\u5c1d\u8f84\u6b62\u7684\u8bfe\u7a0b\u9879\u76ee&#xff0c;\u4e0d\u5982\u96c6\u4e2d\u7cbe\u529b&#xff0c;\u7528\u534a\u5e74\u751a\u81f3\u4e00\u5e74\u7684\u65f6\u95f4&#xff0c;\u6253\u9020\u4e00\u4e2a\u5b8c\u6574\u3001\u6df1\u5165\u3001\u6709\u5f71\u54cd\u529b\u7684\u4e2a\u4eba\u9879\u76ee\u3002\u8fd9\u4e2a\u9879\u76ee\u5e94\u8be5\u80fd\u4f53\u73b0\u4f60\u7684\u6280\u672f\u6df1\u5ea6\u3001\u5de5\u7a0b\u80fd\u529b\u548c\u5bf9\u67d0\u4e2a\u9886\u57df\u7684\u72ec\u7279\u601d\u8003\u3002\u5b83\u53ef\u4ee5\u662f\u4e00\u4e2a\u6027\u80fd\u4f18\u5f02\u7684Kaggle\u7ade\u8d5b\u65b9\u6848&#xff0c;\u4e00\u4e2a\u88ab\u4ed6\u4eba\u4f7f\u7528\u7684\u5f00\u6e90\u5de5\u5177&#xff0c;\u6216\u662f\u4e00\u7bc7\u53d1\u8868\u5728\u9876\u4f1aWorkshop\u4e0a\u7684\u8bba\u6587\u3002\u8fd9\u4e2a\u201c\u4ee3\u8868\u4f5c\u201d\u5c06\u6210\u4e3a\u4f60\u6700\u95ea\u4eae\u7684\u540d\u7247\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5efa\u7acb\u4f60\u7684\u201c\u77e5\u8bc6\u590d\u5229\u201d\u7cfb\u7edf&#xff1a;<\/p>\n<ul>\n<li>\u8d39\u66fc\u5b66\u4e60\u6cd5&#xff1a;\u5c06\u590d\u6742\u7684\u6982\u5ff5\u7528\u6700\u7b80\u5355\u7684\u8bed\u8a00\u89e3\u91ca\u7ed9\u4e0d\u61c2\u884c\u7684\u4eba\u542c\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u5f3a\u8feb\u4f60\u76f4\u9762\u81ea\u5df1\u7406\u89e3\u7684\u6a21\u7cca\u4e4b\u5904\u3002\u5199\u6280\u672f\u535a\u5ba2\u3001\u505a\u5185\u90e8\u6280\u672f\u5206\u4eab\u90fd\u662f\u7edd\u4f73\u7684\u5b9e\u8df5\u3002<\/li>\n<li>\u5efa\u7acb\u8fde\u63a5&#xff1a;\u77e5\u8bc6\u7684\u4ef7\u503c\u5728\u8fde\u63a5\u4e2d\u653e\u5927\u3002\u79ef\u6781\u53c2\u4e0e\u7ebf\u4e0a&#xff08;Twitter, Reddit&#xff09;\u548c\u7ebf\u4e0b&#xff08;Meetup, \u5b66\u672f\u4f1a\u8bae&#xff09;\u7684\u8ba8\u8bba\u3002\u5411\u4f60\u5c0a\u656c\u7684\u5b66\u8005\u6216\u5de5\u7a0b\u5e08\u793c\u8c8c\u5730\u63d0\u95ee&#xff0c;\u4e0e\u5fd7\u540c\u9053\u5408\u7684\u4f19\u4f34\u7ec4\u6210\u5b66\u4e60\u5c0f\u7ec4\u3002\u5728\u4ea4\u6d41\u3001\u5206\u4eab\u3001\u8fa9\u8bba\u4e2d&#xff0c;\u4f60\u7684\u8ba4\u77e5\u4f1a\u4ee5\u6307\u6570\u65b9\u5f0f\u6210\u957f\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u7ed3\u8bed<\/p>\n<p>\u4eb2\u7231\u7684\u8bfb\u8005&#xff0c;\u6211\u4eec\u5171\u540c\u7684\u65c5\u7a0b\u81f3\u6b64\u771f\u6b63\u5730\u753b\u4e0a\u4e86\u4e00\u4e2a\u53e5\u53f7&#xff0c;\u4f46\u5b83\u66f4\u50cf\u662f\u4e00\u4e2a\u7701\u7565\u53f7&#xff0c;\u9884\u793a\u7740\u65e0\u9650\u7684\u53ef\u80fd\u3002\u6211\u4eec\u4ecePython\u7684\u57fa\u7840\u8bed\u6cd5\u51fa\u53d1&#xff0c;\u4e00\u8def\u62ab\u8346\u65a9\u68d8&#xff0c;\u7a7f\u8d8a\u4e86\u7ecf\u5178\u673a\u5668\u5b66\u4e60\u7684\u5d07\u5c71\u5cfb\u5cad&#xff0c;\u6df1\u5165\u4e86\u6df1\u5ea6\u5b66\u4e60\u7684\u5947\u8be1\u6d1e\u5929&#xff0c;\u6700\u7ec8\u62b5\u8fbe\u4e86\u4eba\u5de5\u667a\u80fd\u672a\u6765\u7684\u6d77\u5cb8\u3002<\/p>\n<p>\u8fd9\u672c\u4e66\u503e\u6ce8\u4e86\u6211\u4eec\u5bf9\u77e5\u8bc6\u7684\u656c\u754f&#xff0c;\u5bf9\u5b9e\u8df5\u7684\u5c0a\u91cd&#xff0c;\u4ee5\u53ca\u5bf9\u672a\u6765\u7684\u70ed\u671b\u3002\u5982\u679c\u5b83\u80fd\u5728\u60a8\u7684\u4e66\u67b6\u4e0a\u5360\u636e\u4e00\u5e2d\u4e4b\u5730&#xff0c;\u5728\u60a8\u63a2\u7d22\u7684\u9053\u8def\u4e0a\u5076\u5c14\u4e3a\u60a8\u7167\u4eae\u4e00\u5c0f\u7247\u524d\u8def&#xff0c;\u90a3\u5c06\u662f\u6211\u4eec\u6700\u5927\u7684\u8363\u5e78\u3002<\/p>\n<p>\u8bb0\u4f4f&#xff0c;\u771f\u6b63\u7684\u201c\u7cbe\u901a\u201d&#xff0c;\u4e0d\u662f\u65e0\u6240\u4e0d\u77e5&#xff0c;\u800c\u662f\u6c38\u8fdc\u4fdd\u6709\u4e00\u9897\u5b66\u5f92\u7684\u5fc3\u3002<\/p>\n<p>The journey is the reward.<\/p>\n<hr \/>\n<h3>\u9644\u5f55\u00a0<\/h3>\n<ul>\n<li>A. \u6570\u5b66\u57fa\u7840\u56de\u987e&#xff08;\u7ebf\u6027\u4ee3\u6570\u3001\u5fae\u79ef\u5206\u3001\u6982\u7387\u8bba\u6838\u5fc3\u6982\u5ff5&#xff09;<\/li>\n<li>B. \u5e38\u7528\u5de5\u5177\u4e0e\u5e93\u901f\u67e5\u624b\u518c<\/li>\n<li>C. \u672f\u8bed\u8868&#xff08;\u4e2d\u82f1\u5bf9\u7167&#xff09;<\/li>\n<li>D. \u63a8\u8350\u9605\u8bfb\u4e0e\u8d44\u6e90\u5217\u8868<\/li>\n<\/ul>\n<h4>A. \u6570\u5b66\u57fa\u7840\u56de\u987e<\/h4>\n<p>\u672c\u9644\u5f55\u5e76\u975e\u4e00\u672c\u8be6\u5c3d\u7684\u6570\u5b66\u6559\u79d1\u4e66&#xff0c;\u800c\u662f\u4e3a\u673a\u5668\u5b66\u4e60\u5b9e\u8df5\u8005\u91cf\u8eab\u6253\u9020\u7684\u201c\u6025\u6551\u5305\u201d\u4e0e\u201c\u6982\u5ff5\u5730\u56fe\u201d\u3002\u6211\u4eec\u805a\u7126\u4e8e\u90a3\u4e9b\u5728\u7406\u89e3\u548c\u5b9e\u73b0\u7b97\u6cd5\u65f6\u6700\u6838\u5fc3\u3001\u6700\u5e38\u7528\u7684\u6570\u5b66\u6982\u5ff5&#xff0c;\u65e8\u5728\u5e2e\u52a9\u60a8\u5feb\u901f\u56de\u987e\u3001\u5efa\u7acb\u76f4\u89c9&#xff0c;\u5e76\u5c06\u62bd\u8c61\u7684\u6570\u5b66\u7b26\u53f7\u4e0e\u5177\u4f53\u7684\u7b97\u6cd5\u884c\u4e3a\u8054\u7cfb\u8d77\u6765\u3002<\/p>\n<p>A.1 \u7ebf\u6027\u4ee3\u6570&#xff1a;\u63cf\u8ff0\u7a7a\u95f4\u4e0e\u53d8\u6362\u7684\u8bed\u8a00<\/p>\n<ul>\n<li>\u6838\u5fc3\u5730\u4f4d&#xff1a;\u5728\u673a\u5668\u5b66\u4e60\u4e2d&#xff0c;\u6570\u636e\u88ab\u8868\u793a\u4e3a\u5411\u91cf&#xff0c;\u6570\u636e\u96c6\u662f\u77e9\u9635&#xff0c;\u7b97\u6cd5\u662f\u4f5c\u7528\u4e8e\u8fd9\u4e9b\u5411\u91cf\u548c\u77e9\u9635\u7684\u53d8\u6362\u3002\u7ebf\u6027\u4ee3\u6570\u662f\u8fd9\u4e00\u5207\u7684\u5e95\u5c42\u8bed\u8a00\u3002<\/li>\n<li>\u6838\u5fc3\u6982\u5ff5\u56de\u987e&#xff1a;\n<ul>\n<li>\u6807\u91cf\u3001\u5411\u91cf\u3001\u77e9\u9635\u3001\u5f20\u91cf&#xff1a;\u4ece0\u7ef4\u5230n\u7ef4\u7684\u6570\u636e\u5bb9\u5668\u3002\u7406\u89e3\u5b83\u4eec\u5728NumPy\u4e2d\u7684\u5bf9\u5e94&#xff08;scalar,\u00a01D-array,\u00a02D-array,\u00a0nD-array&#xff09;\u3002<\/li>\n<li>\u77e9\u9635\u8fd0\u7b97&#xff1a;\n<ul>\n<li>\u52a0\u6cd5\u4e0e\u6570\u4e58&#xff1a;\u5bf9\u5e94\u56fe\u50cf\u7684\u4eae\u5ea6\u8c03\u6574\u7b49\u3002<\/li>\n<li>\u77e9\u9635\u4e58\u6cd5&#xff08;Matrix Multiplication&#xff09;&#xff1a;\u6838\u5fc3\u4e2d\u7684\u6838\u5fc3\u3002\u7406\u89e3\u5176\u201c\u884c\u5bf9\u5217\u201d\u7684\u8ba1\u7b97\u89c4\u5219&#xff0c;\u4ee5\u53ca\u5b83\u4ee3\u8868\u7684\u7ebf\u6027\u53d8\u6362\u3002\u795e\u7ecf\u7f51\u7edc\u7684\u6bcf\u4e00\u5c42\u672c\u8d28\u4e0a\u90fd\u662f\u4e00\u6b21\u77e9\u9635\u4e58\u6cd5\u52a0\u4e00\u4e2a\u975e\u7ebf\u6027\u6fc0\u6d3b\u3002A * B\u3002<\/li>\n<li>\u54c8\u8fbe\u739b\u79ef&#xff08;Hadamard Product&#xff09;\/ \u9010\u5143\u7d20\u4e58\u79ef&#xff1a;\u4e24\u4e2a\u5f62\u72b6\u76f8\u540c\u7684\u77e9\u9635\u5bf9\u5e94\u5143\u7d20\u76f8\u4e58\u3002\u5728NumPy\u4e2d\u662f\u00a0A * B&#xff0c;\u800c\u77e9\u9635\u4e58\u6cd5\u662f\u00a0A &#064; B\u00a0\u6216\u00a0np.dot(A, B)\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7279\u6b8a\u77e9\u9635&#xff1a;\n<ul>\n<li>\u5355\u4f4d\u77e9\u9635&#xff08;Identity Matrix&#xff09;&#xff1a;\u7ebf\u6027\u53d8\u6362\u4e2d\u7684\u201c\u4e0d\u53d8\u201d\u64cd\u4f5c\u3002<\/li>\n<li>\u8f6c\u7f6e\u77e9\u9635&#xff08;Transpose Matrix&#xff09;&#xff1a;A^T&#xff0c;\u884c\u5217\u4e92\u6362\u3002\u5728\u8ba1\u7b97\u68af\u5ea6\u3001\u53d8\u6362\u5411\u91cf\u7a7a\u95f4\u65f6\u6781\u5176\u5e38\u7528\u3002<\/li>\n<li>\u9006\u77e9\u9635&#xff08;Inverse Matrix&#xff09;&#xff1a;A\u207b\u00b9&#xff0c;\u7ebf\u6027\u53d8\u6362\u7684\u201c\u64a4\u9500\u201d\u64cd\u4f5c\u3002\u7528\u4e8e\u6c42\u89e3\u7ebf\u6027\u65b9\u7a0b\u7ec4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7ebf\u6027\u65b9\u7a0b\u7ec4\u00a0Ax &#061; b&#xff1a;\u7406\u89e3\u5176\u5728\u6700\u5c0f\u4e8c\u4e58\u6cd5&#xff08;Normal Equation&#xff09;\u4e2d\u7684\u5e94\u7528\u3002<\/li>\n<li>\u8303\u6570&#xff08;Norm&#xff09;&#xff1a;\u8861\u91cf\u5411\u91cf\u6216\u77e9\u9635\u7684\u201c\u5927\u5c0f\u201d\u3002\n<ul>\n<li>L1\u8303\u6570&#xff1a;\u5411\u91cf\u5143\u7d20\u7edd\u5bf9\u503c\u4e4b\u548c\u3002\u503e\u5411\u4e8e\u4ea7\u751f\u7a00\u758f\u89e3&#xff08;Lasso\u56de\u5f52&#xff09;\u3002<\/li>\n<li>L2\u8303\u6570&#xff1a;\u5411\u91cf\u5143\u7d20\u5e73\u65b9\u548c\u7684\u5e73\u65b9\u6839&#xff08;\u6b27\u51e0\u91cc\u5f97\u8ddd\u79bb&#xff09;\u3002\u6b63\u5219\u5316\u7684\u5e38\u7528\u5de5\u5177&#xff08;Ridge\u56de\u5f52&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7279\u5f81\u503c\u4e0e\u7279\u5f81\u5411\u91cf&#xff08;Eigenvalues and Eigenvectors&#xff09;&#xff1a;Av &#061; \u03bbv\u3002\u77e9\u9635A\u4f5c\u7528\u4e8e\u5176\u7279\u5f81\u5411\u91cfv&#xff0c;\u6548\u679c\u7b49\u540c\u4e8e\u5bf9v\u8fdb\u884c\u7f29\u653e&#xff0c;\u7f29\u653e\u6bd4\u4f8b\u5373\u7279\u5f81\u503c\u03bb\u3002\u8fd9\u662f**\u4e3b\u6210\u5206\u5206\u6790&#xff08;PCA&#xff09;**\u7684\u7075\u9b42&#xff0c;\u7279\u5f81\u5411\u91cf\u5b9a\u4e49\u4e86\u6570\u636e\u53d8\u5316\u7684\u4e3b\u65b9\u5411&#xff0c;\u7279\u5f81\u503c\u8861\u91cf\u4e86\u8be5\u65b9\u5411\u4e0a\u7684\u65b9\u5dee\u5927\u5c0f\u3002<\/li>\n<li>\u5947\u5f02\u503c\u5206\u89e3&#xff08;SVD&#xff09;&#xff1a;A &#061; U\u03a3V^T\u3002\u4e00\u79cd\u66f4\u901a\u7528\u7684\u77e9\u9635\u5206\u89e3\u65b9\u6cd5&#xff0c;\u53ef\u7528\u4e8e\u4efb\u610f\u77e9\u9635\u3002PCA\u3001\u63a8\u8350\u7cfb\u7edf\u3001\u56fe\u50cf\u538b\u7f29\u7b49\u9886\u57df\u7684\u6838\u5fc3\u6280\u672f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A.2 \u5fae\u79ef\u5206&#xff1a;\u63cf\u8ff0\u53d8\u5316\u4e0e\u4f18\u5316\u7684\u8bed\u8a00<\/p>\n<ul>\n<li>\u6838\u5fc3\u5730\u4f4d&#xff1a;\u673a\u5668\u5b66\u4e60\u7684\u201c\u5b66\u4e60\u201d\u8fc7\u7a0b&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u4f18\u5316\u8fc7\u7a0b&#xff0c;\u5373\u5bfb\u627e\u4e00\u7ec4\u6a21\u578b\u53c2\u6570&#xff0c;\u4f7f\u5f97\u635f\u5931\u51fd\u6570\u6700\u5c0f\u3002\u5fae\u79ef\u5206&#xff0c;\u7279\u522b\u662f\u5fae\u5206\u5b66&#xff0c;\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u552f\u4e00\u5de5\u5177\u3002<\/li>\n<li>\u6838\u5fc3\u6982\u5ff5\u56de\u987e&#xff1a;\n<ul>\n<li>\u5bfc\u6570&#xff08;Derivative&#xff09;&#xff1a;f&#039;(x)&#xff0c;\u8861\u91cf\u4e00\u5143\u51fd\u6570\u5728\u67d0\u4e00\u70b9\u7684\u77ac\u65f6\u53d8\u5316\u7387\u3002\u5728\u4f18\u5316\u4e2d&#xff0c;\u5b83\u6307\u660e\u4e86\u51fd\u6570\u503c\u4e0a\u5347\u6700\u5feb\u7684\u65b9\u5411\u3002<\/li>\n<li>\u504f\u5bfc\u6570&#xff08;Partial Derivative&#xff09;&#xff1a;\u2202f\/\u2202x_i&#xff0c;\u591a\u5143\u51fd\u6570\u4e2d&#xff0c;\u56fa\u5b9a\u5176\u4ed6\u53d8\u91cf&#xff0c;\u5bf9\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u6c42\u5bfc\u3002\u5b83\u8861\u91cf\u4e86\u51fd\u6570\u5728\u67d0\u4e2a\u5750\u6807\u8f74\u65b9\u5411\u4e0a\u7684\u53d8\u5316\u7387\u3002<\/li>\n<li>\u68af\u5ea6&#xff08;Gradient&#xff09;&#xff1a;\u2207f&#xff0c;\u7531\u6240\u6709\u504f\u5bfc\u6570\u7ec4\u6210\u7684\u5411\u91cf\u3002\u5b83\u6307\u5411\u51fd\u6570\u5728\u5f53\u524d\u70b9\u4e0a\u5347\u6700\u5feb\u7684\u65b9\u5411\u3002\u56e0\u6b64&#xff0c;\u8d1f\u68af\u5ea6\u65b9\u5411\u5c31\u662f\u51fd\u6570\u4e0b\u964d\u6700\u5feb\u7684\u65b9\u5411\u3002<\/li>\n<li>\u68af\u5ea6\u4e0b\u964d\u6cd5&#xff08;Gradient Descent&#xff09;&#xff1a;\u03b8 &#061; \u03b8 &#8211; \u03b7 * \u2207J(\u03b8)\u3002\u8fd9\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u6700\u6838\u5fc3\u7684\u4f18\u5316\u7b97\u6cd5\u3002\u6211\u4eec\u6cbf\u7740\u8d1f\u68af\u5ea6\u65b9\u5411&#xff0c;\u4ee5\u5b66\u4e60\u7387\u03b7\u4e3a\u6b65\u957f&#xff0c;\u8fed\u4ee3\u5730\u66f4\u65b0\u53c2\u6570\u03b8&#xff0c;\u4ee5\u671f\u627e\u5230\u635f\u5931\u51fd\u6570J(\u03b8)\u7684\u6700\u5c0f\u503c\u3002<\/li>\n<li>\u94fe\u5f0f\u6cd5\u5219&#xff08;Chain Rule&#xff09;&#xff1a;dy\/dx &#061; dy\/du * du\/dx\u3002\u8fd9\u662f**\u53cd\u5411\u4f20\u64ad\u7b97\u6cd5&#xff08;Backpropagation&#xff09;**\u7684\u6570\u5b66\u57fa\u77f3\u3002\u5b83\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u8ba1\u7b97\u4e00\u4e2a\u6df1\u5ea6\u3001\u590d\u6742\u7684\u795e\u7ecf\u7f51\u7edc\u4e2d&#xff0c;\u6700\u7ec8\u7684\u635f\u5931\u5bf9\u4e8e\u7f51\u7edc\u4e2d\u4efb\u610f\u4e00\u5c42\u53c2\u6570\u7684\u68af\u5ea6\u3002<\/li>\n<li>\u96c5\u53ef\u6bd4\u77e9\u9635&#xff08;Jacobian Matrix&#xff09;\u4e0e\u6d77\u68ee\u77e9\u9635&#xff08;Hessian Matrix&#xff09;&#xff1a;\n<ul>\n<li>\u96c5\u53ef\u6bd4&#xff1a;\u4e00\u9636\u504f\u5bfc\u6570\u7ec4\u6210\u7684\u77e9\u9635&#xff0c;\u662f\u68af\u5ea6\u7684\u63a8\u5e7f\u3002<\/li>\n<li>\u6d77\u68ee&#xff1a;\u4e8c\u9636\u504f\u5bfc\u6570\u7ec4\u6210\u7684\u77e9\u9635\u3002\u5b83\u63cf\u8ff0\u4e86\u51fd\u6570\u7684\u5c40\u90e8\u66f2\u7387&#xff0c;\u53ef\u7528\u4e8e\u5224\u65ad\u4e34\u754c\u70b9\u662f\u6781\u5927\u3001\u6781\u5c0f\u8fd8\u662f\u978d\u70b9\u3002\u725b\u987f\u6cd5\u7b49\u4e8c\u9636\u4f18\u5316\u65b9\u6cd5\u4f1a\u7528\u5230\u5b83\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A.3 \u6982\u7387\u8bba&#xff1a;\u63cf\u8ff0\u4e0d\u786e\u5b9a\u6027\u7684\u8bed\u8a00<\/p>\n<ul>\n<li>\u6838\u5fc3\u5730\u4f4d&#xff1a;\u4e16\u754c\u662f\u5145\u6ee1\u4e0d\u786e\u5b9a\u6027\u7684&#xff0c;\u6570\u636e\u662f\u6709\u566a\u58f0\u7684&#xff0c;\u6a21\u578b\u662f\u6982\u7387\u6027\u7684\u3002\u6982\u7387\u8bba\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u5957\u4e25\u8c28\u7684\u6846\u67b6\u6765\u91cf\u5316\u3001\u5efa\u6a21\u548c\u63a8\u7406\u8fd9\u79cd\u4e0d\u786e\u5b9a\u6027\u3002<\/li>\n<li>\u6838\u5fc3\u6982\u5ff5\u56de\u987e&#xff1a;\n<ul>\n<li>\u968f\u673a\u53d8\u91cf&#xff08;Random Variable&#xff09;&#xff1a;\u79bb\u6563\u578b\u4e0e\u8fde\u7eed\u578b\u3002<\/li>\n<li>\u6982\u7387\u5206\u5e03&#xff08;Probability Distribution&#xff09;&#xff1a;\n<ul>\n<li>\u6982\u7387\u8d28\u91cf\u51fd\u6570&#xff08;PMF&#xff09;&#xff08;\u79bb\u6563&#xff09;\u4e0e\u6982\u7387\u5bc6\u5ea6\u51fd\u6570&#xff08;PDF&#xff09;&#xff08;\u8fde\u7eed&#xff09;\u3002<\/li>\n<li>\u5e38\u89c1\u5206\u5e03&#xff1a;\u4f2f\u52aa\u5229&#xff08;\u5355\u6b21\u786c\u5e01&#xff09;\u3001\u4e8c\u9879&#xff08;\u591a\u6b21\u786c\u5e01&#xff09;\u3001\u5206\u7c7b&#xff08;\u5355\u6b21\u9ab0\u5b50&#xff09;\u3001\u591a\u9879&#xff08;\u591a\u6b21\u9ab0\u5b50&#xff09;\u3001\u9ad8\u65af&#xff08;\u6b63\u6001\u5206\u5e03&#xff0c;\u81ea\u7136\u754c\u6700\u5e38\u89c1&#xff09;\u3001\u6cca\u677e&#xff08;\u5355\u4f4d\u65f6\u95f4\u4e8b\u4ef6\u53d1\u751f\u6b21\u6570&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u671f\u671b&#xff08;Expectation&#xff09;&#xff1a;E[X]&#xff0c;\u968f\u673a\u53d8\u91cf\u7684\u957f\u671f\u5e73\u5747\u503c\u3002<\/li>\n<li>\u65b9\u5dee&#xff08;Variance&#xff09;&#xff1a;Var(X)&#xff0c;\u8861\u91cf\u968f\u673a\u53d8\u91cf\u53d6\u503c\u504f\u79bb\u5176\u671f\u671b\u7684\u7a0b\u5ea6\u3002<\/li>\n<li>\u6761\u4ef6\u6982\u7387&#xff08;Conditional Probability&#xff09;&#xff1a;P(A|B)&#xff0c;\u5728\u4e8b\u4ef6B\u53d1\u751f\u7684\u6761\u4ef6\u4e0b&#xff0c;\u4e8b\u4ef6A\u53d1\u751f\u7684\u6982\u7387\u3002\u8fd9\u662f\u6240\u6709\u6982\u7387\u6a21\u578b\u7684\u57fa\u7840\u3002<\/li>\n<li>\u8d1d\u53f6\u65af\u5b9a\u7406&#xff08;Bayes&#039; Theorem&#xff09;&#xff1a;P(H|D) &#061; [P(D|H) * P(H)] \/ P(D)\u3002\n<ul>\n<li>\u540e\u9a8c\u6982\u7387\u00a0P(H|D)\u00a0&#061; (\u00a0\u4f3c\u7136\u00a0P(D|H)\u00a0*\u00a0\u5148\u9a8c\u00a0P(H)\u00a0) \/\u00a0\u8bc1\u636e\u00a0P(D)<\/li>\n<li>\u8fd9\u662f\u6734\u7d20\u8d1d\u53f6\u65af\u5206\u7c7b\u5668\u3001\u8d1d\u53f6\u65af\u63a8\u65ad\u548c\u8bb8\u591a\u73b0\u4ee3\u751f\u6210\u6a21\u578b\u7684\u7406\u8bba\u6838\u5fc3\u3002\u5b83\u544a\u8bc9\u6211\u4eec\u5982\u4f55\u6839\u636e\u89c2\u6d4b\u5230\u7684\u6570\u636e&#xff08;\u8bc1\u636e&#xff09;&#xff0c;\u6765\u66f4\u65b0\u6211\u4eec\u5bf9\u4e00\u4e2a\u5047\u8bbe&#xff08;\u6a21\u578b\u53c2\u6570&#xff09;\u7684\u4fe1\u5ff5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6700\u5927\u4f3c\u7136\u4f30\u8ba1&#xff08;Maximum Likelihood Estimation, MLE&#xff09;&#xff1a;\u4e00\u79cd\u53c2\u6570\u4f30\u8ba1\u65b9\u6cd5\u3002\u5bfb\u627e\u4e00\u7ec4\u53c2\u6570&#xff0c;\u4f7f\u5f97\u5f53\u524d\u89c2\u6d4b\u5230\u7684\u8fd9\u6279\u6570\u636e\u51fa\u73b0\u7684\u6982\u7387\u6700\u5927\u3002\u8fd9\u662f\u9891\u7387\u5b66\u6d3e\u7684\u6838\u5fc3\u601d\u60f3\u3002<\/li>\n<li>\u6700\u5927\u540e\u9a8c\u6982\u7387\u4f30\u8ba1&#xff08;Maximum A Posteriori, MAP&#xff09;&#xff1a;\u8d1d\u53f6\u65af\u5b66\u6d3e\u7684\u53c2\u6570\u4f30\u8ba1\u65b9\u6cd5\u3002\u5b83\u5728\u6700\u5927\u4f3c\u7136\u7684\u57fa\u7840\u4e0a&#xff0c;\u989d\u5916\u8003\u8651\u4e86\u53c2\u6570\u672c\u8eab\u7684\u5148\u9a8c\u5206\u5e03&#xff0c;\u5373argmax_\u03b8 P(D|\u03b8)P(\u03b8)\u3002\u6b63\u5219\u5316\u9879&#xff08;\u5982L1, L2&#xff09;\u901a\u5e38\u53ef\u4ee5\u88ab\u89e3\u91ca\u4e3a\u5bf9\u53c2\u6570\u5f15\u5165\u4e86\u67d0\u79cd\u5148\u9a8c\u5206\u5e03\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>B. \u5e38\u7528\u5de5\u5177\u4e0e\u5e93\u901f\u67e5\u624b\u518c<\/h4>\n<ul>\n<li>\n<p>Jupyter Notebook \/ Lab<\/p>\n<ul>\n<li>Shift &#043; Enter: \u8fd0\u884c\u5f53\u524d\u5355\u5143\u683c\u5e76\u8df3\u8f6c\u5230\u4e0b\u4e00\u4e2a<\/li>\n<li>Ctrl &#043; Enter: \u8fd0\u884c\u5f53\u524d\u5355\u5143\u683c<\/li>\n<li>Esc\u00a0-&gt;\u00a0M: \u5207\u6362\u5230Markdown\u6a21\u5f0f<\/li>\n<li>Esc\u00a0-&gt;\u00a0Y: \u5207\u6362\u5230\u4ee3\u7801\u6a21\u5f0f<\/li>\n<li>Esc\u00a0-&gt;\u00a0A\u00a0\/\u00a0B: \u5728\u4e0a\u65b9\/\u4e0b\u65b9\u63d2\u5165\u5355\u5143\u683c<\/li>\n<li>%matplotlib inline: \u5728Notebook\u4e2d\u663e\u793aMatplotlib\u56fe\u50cf<\/li>\n<li>!pip install [package]: \u5728Notebook\u4e2d\u6267\u884cShell\u547d\u4ee4<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>NumPy<\/p>\n<ul>\n<li>np.array([list]): \u521b\u5efa\u6570\u7ec4<\/li>\n<li>np.arange(start, stop, step): \u521b\u5efa\u7b49\u5dee\u5e8f\u5217<\/li>\n<li>np.linspace(start, stop, num): \u521b\u5efa\u7b49\u5206\u5e8f\u5217<\/li>\n<li>arr.shape,\u00a0arr.ndim,\u00a0arr.size: \u67e5\u770b\u5f62\u72b6\u3001\u7ef4\u5ea6\u3001\u5143\u7d20\u6570<\/li>\n<li>arr.reshape(new_shape): \u91cd\u5851\u6570\u7ec4<\/li>\n<li>arr[slice]: \u7d22\u5f15\u4e0e\u5207\u7247<\/li>\n<li>arr.T: \u8f6c\u7f6e<\/li>\n<li>np.dot(a, b)\u00a0or\u00a0a &#064; b: \u77e9\u9635\u4e58\u6cd5<\/li>\n<li>np.sum(),\u00a0np.mean(),\u00a0np.std(): \u805a\u5408\u51fd\u6570&#xff08;\u53ef\u6307\u5b9aaxis&#xff09;<\/li>\n<li>np.linalg.inv(A): \u6c42\u9006\u77e9\u9635<\/li>\n<li>np.linalg.eig(A): \u6c42\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Pandas<\/p>\n<ul>\n<li>pd.read_csv(filepath): \u8bfb\u53d6CSV<\/li>\n<li>df.head(),\u00a0df.tail(),\u00a0df.info(),\u00a0df.describe(): \u6570\u636e\u901f\u89c8<\/li>\n<li>df[&#039;column_name&#039;]\u00a0or\u00a0df.column_name: \u9009\u62e9\u5217&#xff08;Series&#xff09;<\/li>\n<li>df[[&#039;col1&#039;, &#039;col2&#039;]]: \u9009\u62e9\u591a\u5217&#xff08;DataFrame&#xff09;<\/li>\n<li>df.loc[row_label, col_label]: \u57fa\u4e8e\u6807\u7b7e\u7684\u7d22\u5f15<\/li>\n<li>df.iloc[row_index, col_index]: \u57fa\u4e8e\u4f4d\u7f6e\u7684\u7d22\u5f15<\/li>\n<li>df.isnull().sum(): \u67e5\u770b\u6bcf\u5217\u7684\u7f3a\u5931\u503c\u6570\u91cf<\/li>\n<li>df.fillna(value): \u586b\u5145\u7f3a\u5931\u503c<\/li>\n<li>df.dropna(): \u5220\u9664\u6709\u7f3a\u5931\u503c\u7684\u884c\/\u5217<\/li>\n<li>df.groupby(&#039;key_column&#039;).agg({&#039;data_col&#039;: &#039;mean&#039;}): \u5206\u7ec4\u805a\u5408<\/li>\n<li>pd.concat([df1, df2]): \u62fc\u63a5<\/li>\n<li>pd.merge(df1, df2, on&#061;&#039;key&#039;): \u5408\u5e76<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Matplotlib \/ Seaborn<\/p>\n<ul>\n<li>import matplotlib.pyplot as plt<\/li>\n<li>import seaborn as sns<\/li>\n<li>plt.figure(figsize&#061;(w, h)): \u521b\u5efa\u753b\u5e03<\/li>\n<li>plt.plot(x, y): \u6298\u7ebf\u56fe<\/li>\n<li>plt.scatter(x, y): \u6563\u70b9\u56fe<\/li>\n<li>plt.hist(data, bins&#061;n): \u76f4\u65b9\u56fe<\/li>\n<li>sns.heatmap(corr_matrix, annot&#061;True): \u70ed\u529b\u56fe<\/li>\n<li>sns.pairplot(df, hue&#061;&#039;category_col&#039;): \u53d8\u91cf\u5173\u7cfb\u5bf9\u56fe<\/li>\n<li>plt.title(),\u00a0plt.xlabel(),\u00a0plt.ylabel(),\u00a0plt.legend(): \u6dfb\u52a0\u56fe\u8868\u5143\u7d20<\/li>\n<li>plt.show(): \u663e\u793a\u56fe\u50cf<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Scikit-learn\u00a0(\u901a\u7528API\u6a21\u5f0f)<\/p>\n<li>from sklearn.module import Model<\/li>\n<li>model &#061; Model(hyperparameters)<\/li>\n<li>model.fit(X_train, y_train)<\/li>\n<li>predictions &#061; model.predict(X_test)<\/li>\n<li>score &#061; model.score(X_test, y_test)<\/li>\n<ul>\n<li>\u9884\u5904\u7406:\u00a0StandardScaler,\u00a0MinMaxScaler,\u00a0OneHotEncoder,\u00a0LabelEncoder<\/li>\n<li>\u6a21\u578b\u9009\u62e9:\u00a0train_test_split,\u00a0GridSearchCV,\u00a0cross_val_score<\/li>\n<li>\u8bc4\u4f30:\u00a0confusion_matrix,\u00a0classification_report,\u00a0mean_squared_error,\u00a0r2_score<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>C. \u672f\u8bed\u8868&#xff08;\u4e2d\u82f1\u5bf9\u7167&#xff09;<\/h4>\n<ul>\n<li>\u4eba\u5de5\u667a\u80fd (Artificial Intelligence, AI)<\/li>\n<li>\u673a\u5668\u5b66\u4e60 (Machine Learning, ML)<\/li>\n<li>\u6df1\u5ea6\u5b66\u4e60 (Deep Learning, DL)<\/li>\n<li>\u76d1\u7763\u5b66\u4e60 (Supervised Learning)<\/li>\n<li>\u65e0\u76d1\u7763\u5b66\u4e60 (Unsupervised Learning)<\/li>\n<li>\u5f3a\u5316\u5b66\u4e60 (Reinforcement Learning)<\/li>\n<li>\u7279\u5f81 (Feature)<\/li>\n<li>\u6807\u7b7e (Label)<\/li>\n<li>\u8bad\u7ec3\u96c6 (Training Set)<\/li>\n<li>\u9a8c\u8bc1\u96c6 (Validation Set)<\/li>\n<li>\u6d4b\u8bd5\u96c6 (Test Set)<\/li>\n<li>\u8fc7\u62df\u5408 (Overfitting)<\/li>\n<li>\u6b20\u62df\u5408 (Underfitting)<\/li>\n<li>\u504f\u5dee-\u65b9\u5dee\u6743\u8861 (Bias-Variance Trade-off)<\/li>\n<li>\u635f\u5931\u51fd\u6570 (Loss Function) \/ \u6210\u672c\u51fd\u6570 (Cost Function)<\/li>\n<li>\u68af\u5ea6\u4e0b\u964d (Gradient Descent)<\/li>\n<li>\u5b66\u4e60\u7387 (Learning Rate)<\/li>\n<li>\u53cd\u5411\u4f20\u64ad (Backpropagation)<\/li>\n<li>\u6b63\u5219\u5316 (Regularization) (L1, L2)<\/li>\n<li>\u5206\u7c7b (Classification)<\/li>\n<li>\u56de\u5f52 (Regression)<\/li>\n<li>\u805a\u7c7b (Clustering)<\/li>\n<li>\u964d\u7ef4 (Dimensionality Reduction)<\/li>\n<li>\u903b\u8f91\u56de\u5f52 (Logistic Regression)<\/li>\n<li>\u652f\u6491\u5411\u91cf\u673a (Support Vector Machine, SVM)<\/li>\n<li>\u51b3\u7b56\u6811 (Decision Tree)<\/li>\n<li>\u968f\u673a\u68ee\u6797 (Random Forest)<\/li>\n<li>\u68af\u5ea6\u63d0\u5347 (Gradient Boosting) (GBDT, XGBoost, LightGBM)<\/li>\n<li>K-\u5747\u503c (K-Means)<\/li>\n<li>\u4e3b\u6210\u5206\u5206\u6790 (Principal Component Analysis, PCA)<\/li>\n<li>\u795e\u7ecf\u7f51\u7edc (Neural Network, NN)<\/li>\n<li>\u5377\u79ef\u795e\u7ecf\u7f51\u7edc (Convolutional Neural Network, CNN)<\/li>\n<li>\u5faa\u73af\u795e\u7ecf\u7f51\u7edc (Recurrent Neural Network, RNN)<\/li>\n<li>\u957f\u77ed\u671f\u8bb0\u5fc6\u7f51\u7edc (Long Short-Term Memory, LSTM)<\/li>\n<li>\u6ce8\u610f\u529b\u673a\u5236 (Attention Mechanism)<\/li>\n<li>\u53d8\u6362\u5668 (Transformer)<\/li>\n<li>\u51c6\u786e\u7387 (Accuracy)<\/li>\n<li>\u7cbe\u786e\u7387 (Precision)<\/li>\n<li>\u53ec\u56de\u7387 (Recall)<\/li>\n<li>F1\u5206\u6570 (F1-Score)<\/li>\n<li>ROC\u66f2\u7ebf (Receiver Operating Characteristic Curve)<\/li>\n<li>\u66f2\u7ebf\u4e0b\u9762\u79ef (Area Under the Curve, AUC)<\/li>\n<li>\u8d85\u53c2\u6570 (Hyperparameter)<\/li>\n<li>\u6279\u5904\u7406 (Batch)<\/li>\n<li>\u5468\u671f (Epoch)<\/li>\n<\/ul>\n<hr \/>\n<h4>D. \u63a8\u8350\u9605\u8bfb\u4e0e\u8d44\u6e90\u5217\u8868<\/h4>\n<p>\u7ecf\u5178\u4e66\u7c4d<\/p>\n<li>\u300a\u6df1\u5ea6\u5b66\u4e60\u300b(Deep Learning)\u00a0by Ian Goodfellow, Yoshua Bengio, and Aaron Courville.\n<ul>\n<li>\u4fd7\u79f0\u201c\u82b1\u4e66\u201d\u3002\u7406\u8bba\u6df1\u5ea6\u65e0\u51fa\u5176\u53f3&#xff0c;\u662f\u7cfb\u7edf\u6027\u7406\u89e3\u6df1\u5ea6\u5b66\u4e60\u6570\u5b66\u539f\u7406\u7684\u5fc5\u8bfb\u4e4b\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u300a\u673a\u5668\u5b66\u4e60\u300b(Machine Learning)\u00a0by \u5468\u5fd7\u534e.\n<ul>\n<li>\u4fd7\u79f0\u201c\u897f\u74dc\u4e66\u201d\u3002\u5185\u5bb9\u5168\u9762&#xff0c;\u8986\u76d6\u5e7f\u6cdb&#xff0c;\u662f\u56fd\u5185\u6700\u7ecf\u5178\u7684\u673a\u5668\u5b66\u4e60\u6559\u6750\u4e4b\u4e00\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u5728\u7ebf\u8bfe\u7a0b<\/p>\n<li>Coursera &#8211; Machine Learning by Andrew Ng (\u5434\u6069\u8fbe)\n<ul>\n<li>\u673a\u5668\u5b66\u4e60\u7684\u201c\u542f\u8499\u5723\u7ecf\u201d&#xff0c;\u65e0\u6570\u4eba\u7684AI\u5165\u95e8\u7b2c\u4e00\u8bfe\u3002\u76f4\u89c2\u3001\u6613\u61c2\u3002<\/li>\n<\/ul>\n<\/li>\n<li>Coursera &#8211; Deep Learning Specialization by Andrew Ng\n<ul>\n<li>\u5434\u6069\u8fbe\u8001\u5e08\u7684\u6df1\u5ea6\u5b66\u4e60\u7cfb\u5217\u8bfe\u7a0b&#xff0c;\u7cfb\u7edf\u6027\u5730\u4ecb\u7ecd\u4e86\u6df1\u5ea6\u5b66\u4e60\u7684\u5404\u9879\u6280\u672f\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u5b9e\u7528\u7f51\u7ad9\u4e0e\u5de5\u5177<\/p>\n<li>Kaggle: \u5168\u7403\u6700\u5927\u7684\u6570\u636e\u79d1\u5b66\u7ade\u8d5b\u5e73\u53f0\u3002\u662f\u5b9e\u8df5\u3001\u5b66\u4e60\u3001\u4ea4\u6d41\u548c\u6c42\u804c\u7684\u7edd\u4f73\u573a\u6240\u3002<\/li>\n<li>Papers with Code: \u5c06\u5b66\u672f\u8bba\u6587\u3001\u4ee3\u7801\u5b9e\u73b0\u3001\u6570\u636e\u96c6\u548cSOTA&#xff08;State-of-the-art&#xff09;\u6392\u884c\u699c\u5b8c\u7f8e\u7ed3\u5408\u7684\u7f51\u7ad9&#xff0c;\u662f\u8ffd\u8e2a\u9886\u57df\u524d\u6cbf\u7684\u5229\u5668\u3002<\/li>\n<li>Hugging Face: \u63d0\u4f9b\u4e86transformers\u5e93&#xff0c;\u662fNLP\u9886\u57df\u4e8b\u5b9e\u4e0a\u7684\u6807\u51c6\u5de5\u5177\u5e93\u3002\u5176\u6a21\u578b\u4e2d\u5fc3&#xff08;Model Hub&#xff09;\u548c\u6570\u636e\u96c6&#xff08;Datasets&#xff09;\u5e93\u4e5f\u6781\u4e3a\u5f3a\u5927\u3002<\/li>\n<p>\u6280\u672f\u535a\u5ba2<\/p>\n<li>Chris Olah&#039;s Blog: \u5bf9LSTM\u3001\u6ce8\u610f\u529b\u673a\u5236\u7b49\u590d\u6742\u6982\u5ff5\u7684\u56fe\u6587\u89e3\u91ca\u5df2\u6210\u7ecf\u5178\u3002<\/li>\n<li>Jay Alammar&#039;s Blog (The Illustrated Transformer\/BERT): \u7528\u6781\u5176\u7cbe\u7f8e\u7684\u56fe\u793a&#xff0c;\u5c06Transformer\u7b49\u590d\u6742\u6a21\u578b\u8bb2\u89e3\u5f97\u4e00\u6e05\u4e8c\u695a\u3002<\/li>\n<li>Lilian Weng&#039;s Blog: OpenAI\u7814\u7a76\u5458\u7684\u535a\u5ba2&#xff0c;\u5bf9RL\u3001LLM\u7b49\u524d\u6cbf\u9886\u57df\u6709\u7cfb\u7edf\u6027\u3001\u9ad8\u8d28\u91cf\u7684\u603b\u7ed3\u3002<\/li>\n<hr \/>\n<h3>\u540e\u8bb0<\/h3>\n<p>\u4eb2\u7231\u7684\u8bfb\u8005\u670b\u53cb\u4eec&#xff1a;<\/p>\n<p>\u5f53\u60a8\u8bfb\u5230\u8fd9\u91cc\u65f6&#xff0c;\u6211\u4eec\u5171\u540c\u7684\u65c5\u7a0b\u5df2\u7136\u753b\u4e0a\u4e86\u4e00\u4e2a\u53e5\u70b9\u3002\u6211\u4eff\u4f5b\u80fd\u770b\u5230&#xff0c;\u706f\u5149\u4e0b&#xff0c;\u60a8\u8f7b\u8f7b\u5408\u4e0a\u4e66\u5377&#xff0c;\u957f\u8212\u4e00\u53e3\u6c14\u3002\u60a8\u7684\u76ee\u5149\u6216\u8bb8\u4f1a\u671b\u5411\u7a97\u5916&#xff0c;\u90a3\u7247\u7531\u6570\u636e\u3001\u4ee3\u7801\u548c\u7b97\u6cd5\u4ea4\u7ec7\u800c\u6210\u7684\u3001\u65e2\u719f\u6089\u53c8\u5d2d\u65b0\u7684\u4e16\u754c&#xff0c;\u5728\u60a8\u773c\u4e2d&#xff0c;\u5df2\u7136\u5448\u73b0\u51fa\u4e0e\u521d\u89c1\u65f6\u622a\u7136\u4e0d\u540c\u7684\u98ce\u666f\u3002<\/p>\n<p>\u6211\u4eec\u4e00\u540c\u8d70\u8fc7\u4e86\u8fd9\u6bb5\u4e0d\u5e73\u51e1\u7684\u9053\u8def\u3002<\/p>\n<p>\u6211\u4eec\u59cb\u4e8e\u201c\u4ef0\u671b\u661f\u7a7a\u201d\u3002\u5728\u7b2c\u4e00\u7ae0&#xff0c;\u6211\u4eec\u63a2\u8ba8\u4e86\u4f55\u4e3a\u5b66\u4e60&#xff0c;\u4f55\u4e3a\u667a\u80fd&#xff0c;\u6211\u4eec\u8ffd\u6eaf\u4e86\u673a\u5668\u5b66\u4e60\u90a3\u6ce2\u6f9c\u58ee\u9614\u7684\u601d\u60f3\u53f2&#xff0c;\u4e5f\u6821\u51c6\u4e86\u6211\u4eec\u4f5c\u4e3a\u63a2\u7d22\u8005\u7684\u201c\u5fc3\u6cd5\u201d\u2014\u2014\u4ee5\u201c\u51fa\u4e16\u201d\u4e4b\u5fc3&#xff0c;\u505a\u201c\u5165\u4e16\u201d\u4e4b\u4e8b\u3002\u6211\u4eec\u7ea6\u5b9a&#xff0c;\u6280\u672f\u662f\u201c\u5668\u201d&#xff0c;\u800c\u9a7e\u9a6d\u5b83\u7684&#xff0c;\u5fc5\u987b\u662f\u4e00\u9897\u6e05\u660e\u3001\u5ba1\u614e\u4e14\u5145\u6ee1\u4eba\u6587\u5173\u6000\u7684\u5fc3\u3002<\/p>\n<p>\u968f\u540e&#xff0c;\u6211\u4eec\u5f00\u59cb\u4e86\u201c\u811a\u8e0f\u5b9e\u5730\u201d\u7684\u7b51\u57fa\u4e4b\u65c5\u3002\u5728\u7b2c\u4e8c\u7ae0&#xff0c;\u6211\u4eec\u78e8\u5229\u4e86\u624b\u4e2d\u7684\u201c\u795e\u5175\u201d\u2014\u2014Python\u3001NumPy\u3001Pandas\u3001Matplotlib\u3002\u5b83\u4eec\u4e0d\u518d\u662f\u51b0\u51b7\u7684\u5e93&#xff0c;\u800c\u662f\u6211\u4eec\u611f\u77e5\u6570\u636e\u3001\u7406\u89e3\u6570\u636e\u3001\u4e0e\u6570\u636e\u5bf9\u8bdd\u7684\u5ef6\u4f38\u3002\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u4e3a\u6570\u636e\u201c\u76f8\u9762\u201d&#xff0c;\u5982\u4f55\u4e3a\u5b83\u4eec\u201c\u51c0\u8eab\u201d&#xff0c;\u5982\u4f55\u5728\u829c\u6742\u4e2d\u201c\u70b9\u77f3\u6210\u91d1\u201d\u3002\u7b2c\u4e09\u7ae0\u7684\u9884\u5904\u7406\u4e0e\u7279\u5f81\u5de5\u7a0b&#xff0c;\u662f\u6211\u4eec\u4ece\u201c\u5de5\u5320\u201d\u8d70\u5411\u201c\u827a\u672f\u5bb6\u201d\u7684\u7b2c\u4e00\u6b65&#xff0c;\u6211\u4eec\u61c2\u5f97\u4e86&#xff0c;\u597d\u7684\u6a21\u578b\u59cb\u4e8e\u597d\u7684\u6570\u636e&#xff0c;\u800c\u597d\u7684\u6570\u636e&#xff0c;\u6e90\u4e8e\u6df1\u523b\u7684\u7406\u89e3\u4e0e\u7cbe\u5fc3\u7684\u96d5\u7422\u3002<\/p>\n<p>\u63a5\u7740&#xff0c;\u6211\u4eec\u8fdb\u5165\u4e86\u7b97\u6cd5\u7684\u201c\u6838\u5fc3\u6bbf\u5802\u201d\u3002\u6211\u4eec\u624b\u6301\u5728\u7b2c\u56db\u7ae0\u7cbe\u5fc3\u6253\u78e8\u7684\u201c\u5ea6\u91cf\u8861\u201d\u2014\u2014\u90a3\u4e9b\u8bc4\u4f30\u6a21\u578b\u597d\u574f\u7684\u6807\u5c3a&#xff0c;\u5f00\u59cb\u7cfb\u7edf\u5730\u5b66\u4e60\u5404\u7c7b\u4e3b\u6d41\u7b97\u6cd5\u3002\u4ece\u76d1\u7763\u5b66\u4e60\u7684\u201c\u5224\u522b\u201d\u4e0e\u201c\u9884\u6d4b\u201d&#xff08;\u7b2c\u4e94\u3001\u516d\u7ae0&#xff09;&#xff0c;\u5230\u65e0\u76d1\u7763\u5b66\u4e60\u7684\u201c\u5f52\u7eb3\u201d\u4e0e\u201c\u53d1\u73b0\u201d&#xff08;\u7b2c\u4e03\u7ae0&#xff09;&#xff0c;\u6211\u4eec\u50cf\u4e00\u4f4d\u7ecf\u9a8c\u4e30\u5bcc\u7684\u5c06\u519b&#xff0c;\u68c0\u9605\u4e86\u903b\u8f91\u56de\u5f52\u7684\u7b80\u7ea6\u3001\u652f\u6491\u5411\u91cf\u673a\u7684\u7cbe\u5de7\u3001\u51b3\u7b56\u6811\u7684\u76f4\u89c2\u3001K-\u5747\u503c\u7684\u6734\u7d20\u3001PCA\u7684\u6df1\u523b\u3002\u6211\u4eec\u4e0d\u518d\u6ee1\u8db3\u4e8emodel.fit()\u7684\u8868\u8c61&#xff0c;\u800c\u662f\u6df1\u5165\u5230\u6bcf\u4e2a\u7b97\u6cd5\u7684\u5047\u8bbe\u3001\u8fb9\u754c\u548c\u6570\u5b66\u539f\u7406\u4e4b\u4e2d\u3002<\/p>\n<p>\u5f53\u5355\u4e00\u6a21\u578b\u7684\u667a\u6167\u7565\u663e\u5355\u8584\u65f6&#xff0c;\u6211\u4eec\u9886\u609f\u4e86\u201c\u96c6\u814b\u6210\u88d8\u201d\u7684\u96c6\u6210\u601d\u60f3\u3002\u7b2c\u516b\u7ae0\u7684Bagging\u4e0eBoosting&#xff0c;\u8ba9\u6211\u4eec\u770b\u5230\u4e86\u201c\u4e09\u4e2a\u81ed\u76ae\u5320\u201d\u5982\u4f55\u901a\u8fc7\u534f\u4f5c\u4e0e\u8fed\u4ee3&#xff0c;\u6700\u7ec8\u8d85\u8d8a\u201c\u8bf8\u845b\u4eae\u201d\u3002\u6211\u4eec\u89c1\u8bc1\u4e86XGBoost\u4e0eLightGBM\u8fd9\u4e9b\u5de5\u4e1a\u754c\u201c\u5927\u6740\u5668\u201d\u7684\u5a01\u529b&#xff0c;\u4e5f\u7406\u89e3\u4e86\u5176\u80cc\u540e\u6df1\u523b\u7684\u7edf\u8ba1\u5b66\u4e0e\u4f18\u5316\u601d\u60f3\u3002<\/p>\n<p>\u7136\u540e&#xff0c;\u6211\u4eec\u52c7\u6562\u5730\u53e9\u54cd\u4e86\u201c\u672a\u6765\u4e4b\u95e8\u201d\u3002\u7b2c\u4e5d\u7ae0\u7684\u795e\u7ecf\u7f51\u7edc&#xff0c;\u4e3a\u6211\u4eec\u642d\u5efa\u4e86\u901a\u5f80\u6df1\u5ea6\u5b66\u4e60\u7684\u6865\u6881\u3002\u6211\u4eec\u4ece\u751f\u7269\u795e\u7ecf\u5143\u7684\u542f\u53d1\u5f00\u59cb&#xff0c;\u4eb2\u624b\u6784\u5efa\u4e86\u591a\u5c42\u611f\u77e5\u673a&#xff0c;\u7406\u89e3\u4e86\u53cd\u5411\u4f20\u64ad\u7684\u7cbe\u9ad3\u3002\u8fd9\u6247\u95e8\u80cc\u540e&#xff0c;\u662fCNN\u5bf9\u7a7a\u95f4\u7684\u6d1e\u5bdf&#xff0c;\u662fRNN\u5bf9\u65f6\u95f4\u7684\u8bb0\u5fc6&#xff0c;\u662fTransformer\u5bf9\u8bed\u8a00\u7684\u91cd\u5851\u3002<\/p>\n<p>\u7406\u8bba\u7684\u6df1\u5ea6&#xff0c;\u6700\u7ec8\u8981\u5728\u5b9e\u8df5\u7684\u571f\u58e4\u4e2d\u5f00\u82b1\u7ed3\u679c\u3002\u6211\u4eec\u6295\u8eab\u4e8e\u4e24\u4e2a\u201c\u771f\u5b9e\u6218\u573a\u201d\u3002\u5728\u7b2c\u5341\u7ae0\u7684\u91d1\u878d\u98ce\u63a7\u4e2d&#xff0c;\u6211\u4eec\u76f4\u9762\u4e86\u6570\u636e\u4e0d\u5e73\u8861\u7684\u6311\u6218&#xff0c;\u5b66\u4f1a\u4e86\u7528SMOTE\u521b\u9020\u667a\u6167&#xff0c;\u7528SHAP\u6d1e\u5bdf\u6a21\u578b\u7684\u201c\u5185\u5fc3\u201d\u3002\u5728\u7b2c\u5341\u4e00\u7ae0\u7684\u6587\u672c\u60c5\u611f\u5206\u6790\u4e2d&#xff0c;\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u5c06\u975e\u7ed3\u6784\u5316\u7684\u8bed\u8a00&#xff0c;\u8f6c\u5316\u4e3a\u673a\u5668\u53ef\u4ee5\u7406\u89e3\u7684\u5411\u91cf&#xff0c;\u5e76\u6316\u6398\u5176\u80cc\u540e\u7684\u60c5\u611f\u4e0e\u4e3b\u9898\u3002\u8fd9\u4e0d\u518d\u662f\u73a9\u5177\u9879\u76ee&#xff0c;\u800c\u662f\u5145\u6ee1\u7ea6\u675f\u3001\u59a5\u534f\u4e0e\u521b\u9020\u6027\u89e3\u51b3\u95ee\u9898\u7684\u771f\u5b9e\u6f14\u7ec3\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u6211\u4eec\u5b8c\u6210\u4e86\u4ece\u201c\u70bc\u4e39\u5e08\u201d\u5230\u201c\u5de5\u7a0b\u5e08\u201d\u4e0e\u201c\u601d\u60f3\u5bb6\u201d\u7684\u6700\u540e\u4e00\u8dc3\u3002\u7b2c\u5341\u4e8c\u7ae0\u8ba9\u6211\u4eec\u5b66\u4f1a\u4e86\u5982\u4f55\u5c06\u6a21\u578b\u5c01\u88c5\u3001\u90e8\u7f72&#xff0c;\u8ba9\u5b83\u8d70\u51fa\u5b9e\u9a8c\u5ba4&#xff0c;\u201c\u6d3b\u201d\u5728\u771f\u5b9e\u4e16\u754c\u91cc&#xff0c;\u670d\u52a1\u4e8e\u4eba\u3002\u800c\u7b2c\u5341\u4e09\u7ae0&#xff0c;\u6211\u4eec\u518d\u6b21\u62ac\u5934&#xff0c;\u5c06\u76ee\u5149\u6295\u5411\u4e86\u66f4\u8fdc\u7684\u5730\u5e73\u7ebf\u2014\u2014\u5f3a\u5316\u5b66\u4e60\u7684\u4ea4\u4e92\u667a\u6167\u3001\u56fe\u795e\u7ecf\u7f51\u7edc\u7684\u5173\u7cfb\u6d1e\u5bdf\u3001\u81ea\u76d1\u7763\u5b66\u4e60\u7684\u65e0\u5c3d\u6f5c\u529b\u3002\u6211\u4eec\u7ed8\u5236\u4e86\u4e00\u5f20\u6301\u7eed\u6210\u957f\u7684\u5730\u56fe&#xff0c;\u56e0\u4e3a\u6211\u4eec\u6df1\u77e5&#xff0c;\u5728\u8fd9\u7247\u9886\u57df&#xff0c;\u201c\u6bd5\u4e1a\u201d\u5373\u662f\u201c\u843d\u540e\u201d\u7684\u5f00\u59cb\u3002<\/p>\n<p>\u56de\u987e\u8fd9\u6bb5\u65c5\u7a0b&#xff0c;\u6211\u5e0c\u671b\u60a8\u6536\u83b7\u7684&#xff0c;\u4e0d\u4ec5\u4ec5\u662f\u4e00\u5957\u201c\u5c60\u9f99\u4e4b\u6280\u201d\u3002\u5982\u679c\u662f\u90a3\u6837&#xff0c;\u5976\u5976\u5c31\u5931\u8d25\u4e86\u3002<\/p>\n<p>\u6211\u66f4\u5e0c\u671b\u60a8\u6536\u83b7\u7684&#xff0c;\u662f\u4e00\u79cd\u201c\u601d\u7ef4\u8303\u5f0f\u201d\u7684\u8f6c\u53d8\u3002\u60a8\u5b66\u4f1a\u4e86\u5982\u4f55\u5c06\u4e00\u4e2a\u6a21\u7cca\u7684\u73b0\u5b9e\u95ee\u9898&#xff0c;\u89e3\u6784\u3001\u62bd\u8c61\u4e3a\u4e00\u4e2a\u53ef\u4ee5\u88ab\u6570\u5b66\u5b9a\u4e49\u7684\u673a\u5668\u5b66\u4e60\u95ee\u9898&#xff1b;\u60a8\u5b66\u4f1a\u4e86\u5728\u9762\u5bf9\u4e00\u5806\u770b\u4f3c\u6742\u4e71\u65e0\u7ae0\u7684\u6570\u636e\u65f6&#xff0c;\u5982\u4f55\u901a\u8fc7\u63a2\u7d22\u3001\u6e05\u6d17\u3001\u8f6c\u6362&#xff0c;\u53d1\u73b0\u5176\u5185\u5728\u7684\u7ed3\u6784\u4e0e\u4ef7\u503c&#xff1b;\u60a8\u5b66\u4f1a\u4e86\u5728\u4f17\u591a\u6a21\u578b\u4e2d&#xff0c;\u5982\u4f55\u6839\u636e\u95ee\u9898\u7684\u7279\u6027\u3001\u6570\u636e\u7684\u5f62\u6001\u548c\u4e1a\u52a1\u7684\u76ee\u6807&#xff0c;\u505a\u51fa\u6743\u8861\u4e0e\u9009\u62e9&#xff1b;\u60a8\u66f4\u5b66\u4f1a\u4e86\u5982\u4f55\u6279\u5224\u6027\u5730\u770b\u5f85\u6a21\u578b\u7684\u8f93\u51fa&#xff0c;\u7406\u89e3\u5176\u80fd\u529b\u8fb9\u754c&#xff0c;\u5e76\u8b66\u60d5\u5176\u6f5c\u5728\u7684\u504f\u89c1\u4e0e\u98ce\u9669\u3002<\/p>\n<p>\u6211\u5e0c\u671b\u60a8\u6536\u83b7\u7684&#xff0c;\u662f\u4e00\u79cd\u201c\u5b66\u4e60\u80fd\u529b\u201d\u7684\u5185\u5316\u3002\u6211\u4eec\u4e0d\u53ef\u80fd\u5728\u4e00\u672c\u4e66\u91cc\u7a77\u5c3d\u6240\u6709\u77e5\u8bc6\u3002\u4f46\u901a\u8fc7\u5bf9\u51e0\u4e2a\u6838\u5fc3\u7b97\u6cd5\u8fdb\u884c\u201c\u89e3\u5256\u9ebb\u96c0\u201d\u5f0f\u7684\u6df1\u5ea6\u6316\u6398&#xff0c;\u60a8\u5e94\u8be5\u5df2\u7ecf\u638c\u63e1\u4e86\u5b66\u4e60\u4efb\u4f55\u65b0\u6a21\u578b\u7684\u65b9\u6cd5\u8bba&#xff1a;\u8ffd\u6eaf\u5176\u52a8\u673a&#xff0c;\u7406\u89e3\u5176\u6838\u5fc3\u5047\u8bbe&#xff0c;\u5256\u6790\u5176\u6570\u5b66\u539f\u7406&#xff0c;\u8fdb\u884c\u4ee3\u7801\u5b9e\u8df5&#xff0c;\u5e76\u63a2\u7d22\u5176\u5e94\u7528\u8fb9\u754c\u3002\u8fd9\u5957\u65b9\u6cd5&#xff0c;\u5c06\u662f\u60a8\u672a\u6765\u9762\u5bf9\u5c42\u51fa\u4e0d\u7a77\u7684\u65b0\u6280\u672f\u65f6&#xff0c;\u6700\u53ef\u9760\u7684\u6b66\u5668\u3002<\/p>\n<p>\u6211\u6700\u5e0c\u671b\u60a8\u6536\u83b7\u7684&#xff0c;\u662f\u4e00\u79cd\u201c\u77e5\u884c\u5408\u4e00\u201d\u7684\u4fe1\u5ff5\u3002\u77e5\u8bc6\u82e5\u4e0d\u5316\u4e3a\u884c\u52a8&#xff0c;\u4fbf\u5982\u9526\u8863\u591c\u884c&#xff1b;\u884c\u52a8\u82e5\u65e0\u77e5\u8bc6\u6307\u5f15&#xff0c;\u5219\u6613\u9677\u5165\u8ff7\u9014\u3002\u8bf7\u52a1\u5fc5\u5c06\u4e66\u4e2d\u6240\u5b66&#xff0c;\u5e94\u7528\u5230\u60a8\u6240\u70ed\u7231\u7684\u9886\u57df\u4e2d\u53bb\u3002\u53bb\u89e3\u51b3\u4e00\u4e2a\u5b9e\u9645\u7684\u95ee\u9898&#xff0c;\u54ea\u6015\u5b83\u5f88\u5c0f&#xff1b;\u53bb\u53c2\u52a0\u4e00\u573aKaggle\u7ade\u8d5b&#xff0c;\u54ea\u6015\u540d\u6b21\u4e0d\u4f73&#xff1b;\u53bb\u5199\u4e00\u7bc7\u6280\u672f\u535a\u5ba2&#xff0c;\u54ea\u6015\u8bfb\u8005\u5be5\u5be5&#xff1b;\u53bb\u4e3a\u5f00\u6e90\u793e\u533a\u8d21\u732e\u4e00\u884c\u4ee3\u7801&#xff0c;\u54ea\u6015\u53ea\u662f\u4fee\u6b63\u4e00\u4e2a\u62fc\u5199\u9519\u8bef\u3002\u6bcf\u4e00\u6b21\u5fae\u5c0f\u7684\u5b9e\u8df5&#xff0c;\u90fd\u662f\u5728\u4e3a\u60a8\u5185\u5fc3\u7684\u77e5\u8bc6\u5927\u53a6&#xff0c;\u6dfb\u4e0a\u4e00\u5757\u575a\u5b9e\u7684\u7816\u74e6\u3002<\/p>\n<p>\u4eb2\u7231\u7684\u670b\u53cb&#xff0c;\u4eba\u5de5\u667a\u80fd\u7684\u65f6\u4ee3\u6d2a\u6d41\u5df2\u81f3&#xff0c;\u5b83\u6b63\u4ee5\u524d\u6240\u672a\u6709\u7684\u529b\u91cf&#xff0c;\u91cd\u5851\u7740\u6211\u4eec\u4e16\u754c\u7684\u6bcf\u4e00\u4e2a\u89d2\u843d\u3002\u8fd9\u80a1\u529b\u91cf&#xff0c;\u65e2\u53ef\u4ee5\u521b\u9020\u5de8\u5927\u7684\u798f\u7949&#xff0c;\u4e5f\u53ef\u80fd\u5e26\u6765\u524d\u6240\u672a\u6709\u7684\u6311\u6218\u3002\u800c\u60a8&#xff0c;\u4f5c\u4e3a\u638c\u63e1\u4e86\u8fd9\u80a1\u529b\u91cf\u6838\u5fc3\u6280\u672f\u7684\u4eba&#xff0c;\u60a8\u7684\u6bcf\u4e00\u6b21\u9009\u62e9&#xff0c;\u6bcf\u4e00\u6b21\u521b\u9020&#xff0c;\u90fd\u5c06\u662f\u8fd9\u80a1\u6d2a\u6d41\u4e2d\u4e00\u6735\u91cd\u8981\u7684\u6d6a\u82b1\u3002<\/p>\n<p>\u8bf7\u6c38\u8fdc\u4fdd\u6301\u90a3\u4efd\u597d\u5947\u5fc3\u3002\u5bf9\u672a\u77e5\u4fdd\u6301\u656c\u754f&#xff0c;\u5bf9\u95ee\u9898\u7a77\u6839\u7a76\u5e95\u3002<\/p>\n<p>\u8bf7\u6c38\u8fdc\u6000\u6709\u90a3\u4efd\u540c\u7406\u5fc3\u3002\u8bb0\u4f4f\u6280\u672f\u6700\u7ec8\u662f\u4e3a\u4eba\u670d\u52a1\u7684&#xff0c;\u53bb\u7406\u89e3\u7528\u6237\u7684\u75db\u70b9&#xff0c;\u53bb\u5173\u6000\u6280\u672f\u53ef\u80fd\u5f71\u54cd\u5230\u7684\u6bcf\u4e00\u4e2a\u4eba\u3002<\/p>\n<p>\u8bf7\u6c38\u8fdc\u575a\u5b88\u90a3\u4efd\u8d23\u4efb\u5fc3\u3002\u786e\u4fdd\u4f60\u7684\u6a21\u578b\u662f\u516c\u5e73\u7684\u3001\u900f\u660e\u7684\u3001\u53ef\u9760\u7684&#xff0c;\u7528\u4f60\u7684\u667a\u6167\u53bb\u201c\u4f5c\u5584\u201d&#xff0c;\u800c\u975e\u201c\u4f5c\u6076\u201d\u3002<\/p>\n<p>\u5728\u53e4\u8001\u7684\u7985\u5b97\u6545\u4e8b\u91cc&#xff0c;\u5f1f\u5b50\u95ee\u7985\u5e08&#xff1a;\u201c\u5e08\u7236&#xff0c;\u5f00\u609f\u4e4b\u540e&#xff0c;\u60a8\u505a\u4ec0\u4e48&#xff1f;\u201d\u7985\u5e08\u7b54&#xff1a;\u201c\u5f00\u609f\u524d&#xff0c;\u780d\u67f4&#xff0c;\u62c5\u6c34&#xff1b;\u5f00\u609f\u540e&#xff0c;\u780d\u67f4&#xff0c;\u62c5\u6c34\u3002\u201d<\/p>\n<p>\u90a3\u4e48&#xff0c;\u5728\u8bfb\u5b8c\u8fd9\u672c\u4e66&#xff0c;\u638c\u63e1\u4e86\u673a\u5668\u5b66\u4e60\u7684\u79cd\u79cd\u201c\u6cd5\u95e8\u201d\u4e4b\u540e&#xff0c;\u6211\u4eec\u8be5\u505a\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<p>\u7b54\u6848\u6216\u8bb8\u4e5f\u662f\u4e00\u6837&#xff1a;\u56de\u5230\u4f60\u7684\u751f\u6d3b&#xff0c;\u56de\u5230\u4f60\u7684\u5de5\u4f5c&#xff0c;\u56de\u5230\u4f60\u5173\u5fc3\u7684\u95ee\u9898\u4e2d\u53bb\u3002\u53ea\u662f\u8fd9\u4e00\u6b21&#xff0c;\u4f60\u7684\u201c\u65a7\u5934\u201d\u66f4\u950b\u5229\u4e86&#xff0c;\u4f60\u7684\u201c\u6241\u62c5\u201d\u66f4\u575a\u56fa\u4e86&#xff0c;\u4f60\u770b\u5f85\u201c\u67f4\u201d\u4e0e\u201c\u6c34\u201d\u7684\u773c\u5149&#xff0c;\u4e5f\u53d8\u5f97\u66f4\u52a0\u6df1\u9083\u3001\u66f4\u52a0\u667a\u6167\u4e86\u3002<\/p>\n<p>\u611f\u8c22\u60a8&#xff0c;\u9009\u62e9\u4e0e\u6211\u4eec\u4e00\u540c\u8d70\u8fc7\u8fd9\u6bb5\u65c5\u7a0b\u3002\u524d\u8def\u6f2b\u6f2b&#xff0c;\u4ea6\u707f\u707f\u3002\u73b0\u5728&#xff0c;\u8bf7\u5408\u4e0a\u4e66&#xff0c;\u8d70\u51fa\u4e66\u658b&#xff0c;\u53bb\u90a3\u7247\u5e7f\u9614\u7684\u667a\u6167\u8352\u539f\u4e0a&#xff0c;\u70b9\u71c3\u5c5e\u4e8e\u60a8\u81ea\u5df1\u7684\u3001\u90a3\u72ec\u4e00\u65e0\u4e8c\u7684\u706b\u628a\u3002<\/p>\n<p>\u613f\u667a\u6167\u4e4b\u5149&#xff0c;\u6c38\u8fdc\u7167\u4eae\u60a8\u524d\u884c\u7684\u9053\u8def&#xff0c;\u518d\u4f1a&#xff01;<\/p>\n<p><span style=\"color:#000000;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal\">\u200b<\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b\u76ee\u5f55\u7b2c\u4e00\u90e8\u5206&#xff1a;\u601d\u60f3\u4e0e\u57fa\u77f3\u2014\u2014\u4e07\u6cd5\u5f52\u5b97&#xff0c;\u7b51\u57fa\u95ee\u9053\u7b2c1\u7ae0&#xff1a;\u521d\u63a2\u667a\u6167\u4e4b\u5883\u2014\u2014\u673a\u5668\u5b66\u4e60\u4e16\u754c\u89c21.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f21.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;\u7b2c2\u7ae0&#xff1a;\u5de5\u6b32\u5584\u5176\u4e8b\u2014\u2014Python\u73af\u5883\u4e0e\u6838\u5fc3\u5de5\u5177\u94fe2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&amp;#xff1<\/p>\n","protected":false},"author":2,"featured_media":64355,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81],"topic":[],"class_list":["post-64356","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \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\/64356.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u200b\u76ee\u5f55\u7b2c\u4e00\u90e8\u5206&#xff1a;\u601d\u60f3\u4e0e\u57fa\u77f3\u2014\u2014\u4e07\u6cd5\u5f52\u5b97&#xff0c;\u7b51\u57fa\u95ee\u9053\u7b2c1\u7ae0&#xff1a;\u521d\u63a2\u667a\u6167\u4e4b\u5883\u2014\u2014\u673a\u5668\u5b66\u4e60\u4e16\u754c\u89c21.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f21.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;\u7b2c2\u7ae0&#xff1a;\u5de5\u6b32\u5584\u5176\u4e8b\u2014\u2014Python\u73af\u5883\u4e0e\u6838\u5fc3\u5de5\u5177\u94fe2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&amp;#xff1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64356.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-23T04:24:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260123042446-6972f80e4b1fc.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=\"101 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64356.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64356.html\",\"name\":\"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-23T04:24:47+00:00\",\"dateModified\":\"2026-01-23T04:24:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64356.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64356.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64356.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\"}]},{\"@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":"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \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\/64356.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u200b\u76ee\u5f55\u7b2c\u4e00\u90e8\u5206&#xff1a;\u601d\u60f3\u4e0e\u57fa\u77f3\u2014\u2014\u4e07\u6cd5\u5f52\u5b97&#xff0c;\u7b51\u57fa\u95ee\u9053\u7b2c1\u7ae0&#xff1a;\u521d\u63a2\u667a\u6167\u4e4b\u5883\u2014\u2014\u673a\u5668\u5b66\u4e60\u4e16\u754c\u89c21.1 \u4f55\u4e3a\u5b66\u4e60&#xff1f;\u4ece\u4eba\u7c7b\u5b66\u4e60\u5230\u673a\u5668\u667a\u80fd1.2 \u673a\u5668\u5b66\u4e60\u7684\u201c\u524d\u4e16\u4eca\u751f\u201d&#xff1a;\u4e00\u90e8\u601d\u60f3\u4e0e\u6280\u672f\u7684\u6f14\u8fdb\u53f21.3 \u4e3a\u4f55\u662fPython&#xff1f;\u2014\u2014\u6570\u636e\u79d1\u5b66\u7684\u201c\u901a\u7528\u8bed\u201d1.4 \u7834\u9664\u8ff7\u601d&#xff1a;AI\u662f\u201c\u795e\u201d\u8fd8\u662f\u201c\u5668\u201d&#xff1f;\u7b2c2\u7ae0&#xff1a;\u5de5\u6b32\u5584\u5176\u4e8b\u2014\u2014Python\u73af\u5883\u4e0e\u6838\u5fc3\u5de5\u5177\u94fe2.1 \u201c\u4e7e\u5764\u5728\u63e1\u201d&amp;#xff1","og_url":"https:\/\/www.wsisp.com\/helps\/64356.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-23T04:24:47+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260123042446-6972f80e4b1fc.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"101 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64356.html","url":"https:\/\/www.wsisp.com\/helps\/64356.html","name":"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-23T04:24:47+00:00","dateModified":"2026-01-23T04:24:47+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64356.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64356.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64356.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u673a\u5668\u5b66\u4e60\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a"}]},{"@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\/64356","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=64356"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64356\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/64355"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64356"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}