{"id":8894,"date":"2024-05-22T23:01:01","date_gmt":"2024-05-22T15:01:01","guid":{"rendered":""},"modified":"2024-05-22T23:01:01","modified_gmt":"2024-05-22T15:01:01","slug":"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8894.html","title":{"rendered":"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d"},"content":{"rendered":"<p><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"display: none;\"> \n <path stroke-linecap=\"round\" d=\"M5,0 0,2.5 5,5z\" id=\"raphael-marker-block\" style=\"-webkit-tap-highlight-color: rgba(0, 0, 0, 0);\"><\/path> \n<\/svg> <\/p>\n<p><strong>\u8bad\u7ec3\u6570\u636e\u4ee5\u53ca\u6e90\u4ee3\u7801\u5728\u6211\u7684Github\uff1a<\/strong><code>https:\/\/github.com\/taw19960426\/DeepLearning\/tree\/master\/%E4%BD%9C%E4%B8%9A\/%E4%BD%9C%E4%B8%9A2%E6%95%B0%E6%8D%AE<\/code><\/p>\n<h4>\u4e00\u3001\u4f5c\u4e1a\u8bf4\u660e<\/h4>\n<p>\u7ed9\u5b9a\u8bad\u7ec3\u96c6spam_train.csv\uff0c\u8981\u6c42\u6839\u636e\u6bcf\u4e2aID\u5404\u79cd\u5c5e\u6027\u503c\u6765\u5224\u65ad\u8be5ID\u5bf9\u5e94\u89d2\u8272\u662fWinner\u8fd8\u662fLosser(\u6536\u5165\u662f\u5426\u5927\u4e8e50K)\uff0c\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u4e8c\u5206\u7c7b\u95ee\u9898\u3002<\/p>\n<ul>\n<li>\n<p>CSV\u6587\u4ef6\uff0c\u5927\u5c0f\u4e3a4000\u884cX59\u5217;<\/p>\n<\/li>\n<li>\n<p>4000\u884c\u6570\u636e\u5bf9\u5e94\u77404000\u4e2a\u89d2\u8272\uff0cID\u7f16\u53f7\u4ece1\u52304001;<\/p>\n<\/li>\n<li>\n<p>59\u5217\u6570\u636e\u4e2d\uff0c \u7b2c\u4e00\u5217\u4e3a\u89d2\u8272ID\uff0c\u6700\u540e\u4e00\u5217\u4e3a\u5206\u7c7b\u7ed3\u679c\uff0c\u5373label(0\u30011\u4e24\u79cd)\uff0c\u4e2d\u95f4\u768457\u5217\u4e3a\u89d2\u8272\u5bf9\u5e94\u768457\u79cd\u5c5e\u6027\u503c\uff1b<\/p>\n<\/li>\n<\/ul>\n<h4>\u4e8c\u3001\u601d\u8def\u5206\u6790<\/h4>\n<h5>2.1 \u601d\u8def\u5206\u6790<\/h5>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u7ed3\u5408\u8bfe\u4e0a\u6240\u5b66\u5185\u5bb9\uff0c\u51b3\u5b9a\u91c7\u7528Logistic\u56de\u5f52\u7b97\u6cd5\u3002<\/p>\n<p>\u4e0e\u7ebf\u6027\u56de\u5f52\u7528\u4e8e\u9884\u6d4b\u4e0d\u540c\uff0cLogistic\u56de\u5f52\u5219\u5e38\u7528\u4e8e\u5206\u7c7b(\u901a\u5e38\u662f\u4e8c\u5206\u7c7b\u95ee\u9898)\u3002Logistic\u56de\u5f52\u5b9e\u8d28\u4e0a\u5c31\u662f\u5728\u666e\u901a\u7684\u7ebf\u6027\u56de\u5f52\u540e\u9762\u52a0\u4e0a\u4e86\u4e00\u4e2asigmoid\u51fd\u6570\uff0c\u628a\u7ebf\u6027\u56de\u5f52\u9884\u6d4b\u5230\u7684\u6570\u503c\u538b\u7f29\u6210\u4e3a\u4e00\u4e2a\u6982\u7387\uff0c\u8fdb\u800c\u5b9e\u73b0\u4e8c\u5206\u7c7b\uff08\u5173\u4e8e\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff0c\u53ef\u53c2\u8003\u4e0a\u4e00\u6b21\u4f5c\u4e1a\uff09\u3002<\/p>\n<p>\u5728\u635f\u5931\u51fd\u6570\u65b9\u9762\uff0cLogistic\u56de\u5f52\u5e76\u6ca1\u6709\u4f7f\u7528\u4f20\u7edf\u7684\u6b27\u5f0f\u8ddd\u79bb\u6765\u5ea6\u91cf\u8bef\u5dee\uff0c\u800c\u4f7f\u7528\u4e86\u4ea4\u53c9\u71b5(\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u7684\u76f8\u4f3c\u7a0b\u5ea6)\u3002<br \/> \u3000\u3000<img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/3fd420bdf38a4461aee2779331018da7.png\" =\"\" =\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" alt=\"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d (https:\/\/mushiming.com\/) \u7b2c1\u5f20\" title=\"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d \u7b2c1\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><\/p>\n<h5>2.2 \u6570\u636e\u9884\u5904\u7406<\/h5>\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6570\u636e\u7684\u9884\u5904\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u73af\uff0c\u80fd\u76f4\u63a5\u5f71\u54cd\u5230\u6a21\u578b\u6548\u679c\u7684\u597d\u574f\u3002\u672c\u6b21\u4f5c\u4e1a\u7684\u6570\u636e\u76f8\u5bf9\u7b80\u5355\u7eaf\u51c0\uff0c\u5728\u6570\u636e\u9884\u5904\u7406\u65b9\u9762\u5e76\u4e0d\u9700\u8981\u82b1\u592a\u591a\u7cbe\u529b\u3002<\/p>\n<p>\u9996\u5148\u662f\u7a7a\u503c\u5904\u7406(\u5c3d\u7ba1\u6ca1\u770b\u5230\u7a7a\u503c\uff0c\u4f46\u4e3a\u4e86\u4ee5\u9632\u4e07\u4e00\uff0c\u8fd8\u662f\u505a\u4e00\u4e0b)\uff0c\u6240\u6709\u7a7a\u503c\u75280\u586b\u5145(\u4e5f\u53ef\u4ee5\u7528\u5e73\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u7b49\uff0c\u89c6\u5177\u4f53\u60c5\u51b5\u800c\u5b9a)\u3002<\/p>\n<p>\u63a5\u7740\u5c31\u662f\u628a\u6570\u636e\u8303\u56f4\u5c3d\u91cfscale\u5230\u540c\u4e00\u4e2a\u6570\u91cf\u7ea7\u4e0a\uff0c\u89c2\u5bdf\u6570\u636e\u540e\u53d1\u73b0\uff0c\u591a\u6570\u6570\u636e\u503c\u4e3a0\uff0c\u975e0\u503c\u4e5f\u90fd\u57281\u9644\u8fd1\uff0c\u53ea\u6709\u5012\u6570\u7b2c\u4e8c\u5217\u548c\u5012\u6570\u7b2c\u4e09\u5217\u6570\u636e\u503c\u8f83\u5927\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e24\u5217\u5206\u522b\u9664\u4e0a\u6bcf\u5217\u7684\u5e73\u5747\u503c\uff0c\u628a\u6570\u503c\u8303\u56f4\u62c9\u52301\u9644\u8fd1\u3002<\/p>\n<p>\u7531\u4e8e\u5e76\u6ca1\u6709\u7ed9\u51fa\u8fd957\u4e2a\u5c5e\u6027\u5177\u4f53\u662f\u4ec0\u4e48\u5c5e\u6027\uff0c\u56e0\u6b64\u65e0\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u6316\u6398\u5e94\u7528\u3002<\/p>\n<p>\u4e0a\u8ff0\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u5c06\u8868\u683c\u7684\u7b2c2\u5217\u81f358\u5217\u53d6\u51fa\u4e3ax(shape\u4e3a4000X57)\uff0c\u5c06\u6700\u540e\u4e00\u5217\u53d6\u51fa\u505alabel y(shape\u4e3a4000X1)\u3002\u8fdb\u4e00\u6b65\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u9a8c\u8bc1\u96c6\uff0c\u5206\u522b\u53d6x\u3001y\u4e2d\u524d3500\u4e2a\u6837\u672c\u4e3a\u8bad\u7ec3\u96c6x_test(shape\u4e3a3500X57)\uff0cy_test(shape\u4e3a3500X1)\uff0c\u540e500\u4e2a\u6837\u672c\u4e3a\u9a8c\u8bc1\u96c6x_val(shape\u4e3a500X57)\uff0cy_val(shape\u4e3a500X1)\u3002<\/p>\n<p>\u6570\u636e\u9884\u5904\u7406\u5230\u6b64\u7ed3\u675f\u3002<\/p>\n<pre class=\"language-java prettyprint linenums\"><code class=\"prism language-python\"><span class=\"token comment\">#\u6570\u636e\u7684\u9884\u5904\u7406<\/span>\n df<span class=\"token operator\">=<\/span>pd<span class=\"token punctuation\">.<\/span>read_csv<span class=\"token punctuation\">(<\/span><span class=\"token string\">'spam_train.csv'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u8bfb\u6587\u4ef6<\/span>\n df<span class=\"token operator\">=<\/span>df<span class=\"token punctuation\">.<\/span>fillna<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u7a7a\u503c\u75280\u586b\u5145<\/span>\n array<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>array<span class=\"token punctuation\">(<\/span>df<span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u8f6c\u5316\u4e3a\u5bf9\u8c61\uff084000\uff0c49\uff09<\/span>\n x<span class=\"token operator\">=<\/span>array<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token comment\">#\u629b\u5f03\u7b2c\u4e00\u5217\u548c\u6700\u540e\u4e00\u5217shape(4000,47)<\/span>\n y<span class=\"token operator\">=<\/span>array<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token comment\">#\u6700\u540e\u4e00\u5217label<\/span>\n <span class=\"token comment\">#\u5c06\u5012\u6570\u7b2c\u4e8c\u5217\u548c\u7b2c\u4e09\u5217\u9664\u4ee5\u5e73\u5747\u503c<\/span>\n x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">\/<\/span>np<span class=\"token punctuation\">.<\/span>mean<span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>\n x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">=<\/span> x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">\/<\/span> np<span class=\"token punctuation\">.<\/span>mean<span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>\n\n <span class=\"token comment\">#\u5212\u5206\u6d4b\u8bd5\u96c6\u548c\u9a8c\u8bc1\u96c6<\/span>\n x_train<span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span>\n y_train <span class=\"token operator\">=<\/span> y<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">]<\/span>\n x_val<span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">4001<\/span><span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span>\n y_val<span class=\"token operator\">=<\/span>y<span class=\"token punctuation\">[<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">4001<\/span><span class=\"token punctuation\">]<\/span>\n<\/code><\/pre>\n<h4>2.3 \u6a21\u578b\u5efa\u7acb<\/h4>\n<h5>2.3.1 \u7ebf\u6027\u56de\u5f52<\/h5>\n<p>\u5148\u5bf9\u6570\u636e\u505a\u7ebf\u6027\u56de\u5f52\uff0c\u5f97\u51fa\u6bcf\u4e2a\u6837\u672c\u5bf9\u5e94\u7684\u56de\u5f52\u503c\u3002\u4e0b\u5f0f\u4e3a\u5bf9\u7b2cn\u4e2a\u6837\u672c<span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\"> x n x^{n} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.664392em; vertical-align: 0em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.664392em;\"><span class=\"\" style=\"top: -3.063em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u7684\u56de\u5f52\uff0c\u56de\u5f52\u7ed3\u679c\u4e3a<span class=\"katex--inline\"><span class=\"katex\"><span class=\"katex-mathml\"> y n y^{n} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.858832em; vertical-align: -0.19444em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.664392em;\"><span class=\"\" style=\"top: -3.063em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002<\/p>\n<p><span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> y n = \u2211 i = 1 57 w i x i n + b \\mathrm{y}^{n}=\\sum_{i=1}^{57} w_{i} x_{i}^{n}+b <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.908832em; vertical-align: -0.19444em;\"><\/span><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathrm\" style=\"margin-right: 0.01389em;\">y<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 3.07878em; vertical-align: -1.27767em;\"><\/span><span class=\"mop op-limits\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.80111em;\"><span class=\"\" style=\"top: -1.87233em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><span class=\"mrel mtight\">=<\/span><span class=\"mord mtight\">1<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.05001em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"\"><span class=\"mop op-symbol large-op\">\u2211<\/span><\/span><\/span><span class=\"\" style=\"top: -4.30001em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">5<\/span><span class=\"mord mtight\">7<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.27767em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.02691em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -2.453em; margin-left: 0em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.247em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.69444em; vertical-align: 0em;\"><\/span><span class=\"mord mathdefault\">b<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<h5>2.3.2 sigmoid\u51fd\u6570\u538b\u7f29\u56de\u5f52\u503c<\/h5>\n<p>\u4e4b\u540e\u5c06\u56de\u5f52\u7ed3\u679c\u9001\u8fdbsigmoid\u51fd\u6570\uff0c\u5f97\u5230\u6982\u7387\u503c\u3002<br \/> <span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> p n = 1 1 + e \u2212 y n p^{n}=\\frac{1}{1+e^{-y^{n}}} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.908832em; vertical-align: -0.19444em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 2.09077em; vertical-align: -0.76933em;\"><\/span><span class=\"mord\"><span class=\"mopen nulldelimiter\"><\/span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.32144em;\"><span class=\"\" style=\"top: -2.314em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">e<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.70448em;\"><span class=\"\" style=\"top: -2.989em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">\u2212<\/span><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.03588em;\">y<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.593543em;\"><span class=\"\" style=\"top: -2.786em; margin-right: 0.0714286em;\"><span class=\"pstrut\" style=\"height: 2.5em;\"><\/span><span class=\"sizing reset-size3 size1 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.23em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"frac-line\" style=\"border-bottom-width: 0.04em;\"><\/span><\/span><span class=\"\" style=\"top: -3.677em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\">1<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.76933em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mclose nulldelimiter\"><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<h5>2.3.3 \u8bef\u5dee\u53cd\u5411\u4f20\u64ad<\/h5>\n<p>\u63a5\u7740\u5c31\u5230\u91cd\u5934\u620f\u4e86\u3002\u4f17\u6240\u5468\u77e5\uff0c\u4e0d\u7ba1\u7ebf\u6027\u56de\u5f52\u8fd8\u662fLogistic\u56de\u5f52\uff0c\u5176\u5173\u952e\u548c\u6838\u5fc3\u5c31\u5728\u4e8e\u901a\u8fc7\u8bef\u5dee\u7684\u53cd\u5411\u4f20\u64ad\u6765\u66f4\u65b0\u53c2\u6570\uff0c\u8fdb\u800c\u4f7f\u6a21\u578b\u4e0d\u65ad\u4f18\u5316\u3002\u56e0\u6b64\uff0c\u635f\u5931\u51fd\u6570\u7684\u786e\u5b9a\u53ca\u5bf9\u5404\u53c2\u6570\u7684\u6c42\u5bfc\u5c31\u6210\u4e86\u91cd\u4e2d\u4e4b\u91cd\u3002\u5728\u5206\u7c7b\u95ee\u9898\u4e2d\uff0c\u6a21\u578b\u4e00\u822c\u9488\u5bf9\u5404\u7c7b\u522b\u8f93\u51fa\u4e00\u4e2a\u6982\u7387\u5206\u5e03\uff0c\u56e0\u6b64\u5e38\u7528\u4ea4\u53c9\u71b5\u4f5c\u4e3a\u635f\u5931\u51fd\u6570\u3002\u4ea4\u53c9\u71b5\u53ef\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u7684\u76f8\u4f3c\u3001\u7edf\u4e00\u7a0b\u5ea6\uff0c\u4e24\u4e2a\u6982\u7387\u5206\u5e03\u8d8a\u76f8\u4f3c\u3001\u8d8a\u7edf\u4e00\uff0c\u5219\u4ea4\u53c9\u71b5\u8d8a\u5c0f\uff1b\u53cd\u4e4b\uff0c\u4e24\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u5dee\u5f02\u8d8a\u5927\u3001\u8d8a\u6df7\u4e71\uff0c\u5219\u4ea4\u53c9\u71b5\u8d8a\u5927\u3002<\/p>\n<p>\u4e0b\u5f0f\u8868\u793ak\u5206\u7c7b\u95ee\u9898\u7684\u4ea4\u53c9\u71b5\uff0cP\u4e3alabel\uff0c\u662f\u4e00\u4e2a\u6982\u7387\u5206\u5e03\uff0c\u5e38\u7528one_hot\u7f16\u7801\u3002\u4f8b\u5982\u9488\u5bf93\u5206\u7c7b\u95ee\u9898\u800c\u8a00\uff0c\u82e5\u6837\u672c\u5c5e\u4e8e\u7b2c\u4e00\u7c7b\uff0c\u5219P\u4e3a(1,0,0)\uff0c\u82e5\u5c5e\u4e8e\u7b2c\u4e8c\u7c7b\uff0c\u5219P\u4e3a(0,1,0)\uff0c\u82e5\u5c5e\u4e8e\u7b2c\u4e09\u7c7b\uff0c\u5219\u4e3a(0,0,1)\u3002\u5373\u6240\u5c5e\u7684\u7c7b\u6982\u7387\u503c\u4e3a1\uff0c\u5176\u4ed6\u7c7b\u6982\u7387\u503c\u4e3a0\u3002Q\u4e3a\u6a21\u578b\u5f97\u51fa\u7684\u6982\u7387\u5206\u5e03\uff0c\u53ef\u4ee5\u662f(0.1,0.8,0.1)\u7b49\u3002<br \/> \u3000\u3000<span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> Loss \u2061 n = \u2212 \u2211 1 k P n ln \u2061 Q n \\operatorname{Loss}^{n}=-\\sum_{1}^{k} P^{n} \\ln Q^{n} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.737622em; vertical-align: 0em;\"><\/span><span class=\"mop\"><span class=\"mop\"><span class=\"mord mathrm\">L<\/span><span class=\"mord mathrm\">o<\/span><span class=\"mord mathrm\">s<\/span><span class=\"mord mathrm\">s<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.737622em;\"><span class=\"\" style=\"top: -3.13623em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 3.10323em; vertical-align: -1.26711em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop op-limits\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.83611em;\"><span class=\"\" style=\"top: -1.88289em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.05001em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"\"><span class=\"mop op-symbol large-op\">\u2211<\/span><\/span><\/span><span class=\"\" style=\"top: -4.30001em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.03148em;\">k<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.26711em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.13889em;\">P<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">Q<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><br \/> \u9488\u5bf9\u672c\u6b21\u4f5c\u4e1a\u800c\u8a00\uff0c\u867d\u7136\u6a21\u578b\u53ea\u8f93\u51fa\u4e86\u4e00\u4e2a\u6982\u7387\u503cp\uff0c\u4f46\u7531\u4e8e\u5904\u7406\u7684\u662f\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u56e0\u6b64\u53ef\u4ee5\u5f88\u5feb\u6c42\u51fa\u53e6\u4e00\u6982\u7387\u503c\u4e3a1-p\uff0c\u5373\u53ef\u89c6\u4e3a\u6a21\u578b\u8f93\u51fa\u7684\u6982\u7387\u5206\u5e03\u4e3aQ(p\uff0c1-p)\u3002\u5c06\u672c\u6b21\u7684label\u89c6\u4e3a\u6982\u7387\u5206\u5e03P(y,1-y)\uff0c\u5373Winner(label\u4e3a1)\u7684\u6982\u7387\u5206\u5e03\u4e3a(1,0)\uff0c\u5206\u7c7b\u4e3aLosser(label\u4e3a0)\u7684\u6982\u7387\u5206\u5e03\u4e3a(0,1)\u3002<br \/> <span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> Loss \u2061 n = \u2212 [ y ^ n ln \u2061 p n + ( 1 \u2212 y ^ n ) ln \u2061 ( 1 \u2212 p n ) ] \\operatorname{Loss}^{n}=-\\left[\\hat{y}^{n} \\ln p^{n}+\\left(1-\\hat{y}^{n}\\right) \\ln \\left(1-p^{n}\\right)\\right] <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.737622em; vertical-align: 0em;\"><\/span><span class=\"mop\"><span class=\"mop\"><span class=\"mord mathrm\">L<\/span><span class=\"mord mathrm\">o<\/span><span class=\"mord mathrm\">s<\/span><span class=\"mord mathrm\">s<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.737622em;\"><span class=\"\" style=\"top: -3.13623em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 1em; vertical-align: -0.25em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">[<\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">]<\/span><\/span><\/span><\/span><\/span><\/span><\/span><br \/> \u635f\u5931\u51fd\u6570\u5bf9\u6743\u91cdw\u6c42\u504f\u5bfc\uff0c\u53ef\u5f97\uff1a<br \/> <span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> \u2202 L o s s n \u2202 w i = \u2212 x i [ y ^ n \u2212 p n ] \\frac{\\partial L o s s^{n}}{\\partial w_{i}}=-x_{i}\\left[\\hat{y}^{n}-p^{n}\\right] <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 2.20744em; vertical-align: -0.836em;\"><\/span><span class=\"mord\"><span class=\"mopen nulldelimiter\"><\/span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.37144em;\"><span class=\"\" style=\"top: -2.314em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\" style=\"margin-right: 0.05556em;\">\u2202<\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.02691em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.23em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"frac-line\" style=\"border-bottom-width: 0.04em;\"><\/span><\/span><span class=\"\" style=\"top: -3.677em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\" style=\"margin-right: 0.05556em;\">\u2202<\/span><span class=\"mord mathdefault\">L<\/span><span class=\"mord mathdefault\">o<\/span><span class=\"mord mathdefault\">s<\/span><span class=\"mord\"><span class=\"mord mathdefault\">s<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.664392em;\"><span class=\"\" style=\"top: -3.063em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.836em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mclose nulldelimiter\"><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 1em; vertical-align: -0.25em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: 0em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">[<\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">]<\/span><\/span><\/span><\/span><\/span><\/span><\/span><br \/> \u540c\u7406\uff0c\u635f\u5931\u51fd\u6570\u5bf9\u504f\u7f6eb\u6c42\u504f\u5bfc\uff0c\u53ef\u5f97\uff1a<br \/> <span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> \u2202 L o s s n \u2202 b = \u2212 [ y ^ n \u2212 p n ] \\frac{\\partial L o s s^{n}}{\\partial b}=-\\left[\\hat{y}^{n}-p^{n}\\right] <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 2.05744em; vertical-align: -0.686em;\"><\/span><span class=\"mord\"><span class=\"mopen nulldelimiter\"><\/span><span class=\"mfrac\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.37144em;\"><span class=\"\" style=\"top: -2.314em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\" style=\"margin-right: 0.05556em;\">\u2202<\/span><span class=\"mord mathdefault\">b<\/span><\/span><\/span><span class=\"\" style=\"top: -3.23em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"frac-line\" style=\"border-bottom-width: 0.04em;\"><\/span><\/span><span class=\"\" style=\"top: -3.677em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\" style=\"margin-right: 0.05556em;\">\u2202<\/span><span class=\"mord mathdefault\">L<\/span><span class=\"mord mathdefault\">o<\/span><span class=\"mord mathdefault\">s<\/span><span class=\"mord\"><span class=\"mord mathdefault\">s<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.664392em;\"><span class=\"\" style=\"top: -3.063em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.686em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mclose nulldelimiter\"><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 1em; vertical-align: -0.25em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">[<\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">]<\/span><\/span><\/span><\/span><\/span><\/span><\/span><br \/> <strong>\u8bfe\u4ef6\u4e0a\u7684\u516c\u5f0f\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u52a0\u6b63\u5219\u5316<span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> Loss \u2061 n = \u2212 \u2211 1 k p n ln \u2061 Q n + \u03bb ( w i ) 2 \\operatorname{Loss}^{n}=-\\sum_{1}^{k} p^{n} \\ln Q^{n}+\\lambda\\left(w_{i}\\right)^{2} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.737622em; vertical-align: 0em;\"><\/span><span class=\"mop\"><span class=\"mop\"><span class=\"mord mathrm\">L<\/span><span class=\"mord mathrm\">o<\/span><span class=\"mord mathrm\">s<\/span><span class=\"mord mathrm\">s<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.737622em;\"><span class=\"\" style=\"top: -3.13623em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 3.10323em; vertical-align: -1.26711em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop op-limits\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.83611em;\"><span class=\"\" style=\"top: -1.88289em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">1<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.05001em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"\"><span class=\"mop op-symbol large-op\">\u2211<\/span><\/span><\/span><span class=\"\" style=\"top: -4.30001em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.03148em;\">k<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.26711em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">p<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\">Q<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 1.20401em; vertical-align: -0.25em;\"><\/span><span class=\"mord mathdefault\">\u03bb<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.02691em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.954008em;\"><span class=\"\" style=\"top: -3.2029em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mtight\">2<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> Loss \u2061 n = \u2211 n \u2212 [ y ^ n ln \u2061 f w , b ( x n ) + ( 1 \u2212 y ^ n ) ln \u2061 ( 1 \u2212 f w , b ( x n ) ) ] \\operatorname{Loss}^{n}=\\sum_{n}-\\left[\\hat{y}^{n} \\ln f_{w, b}\\left(x^{n}\\right)+\\left(1-\\hat{y}^{n}\\right) \\ln \\left(1-f_{w, b}\\left(x^{n}\\right)\\right)\\right] <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.737622em; vertical-align: 0em;\"><\/span><span class=\"mop\"><span class=\"mop\"><span class=\"mord mathrm\">L<\/span><span class=\"mord mathrm\">o<\/span><span class=\"mord mathrm\">s<\/span><span class=\"mord mathrm\">s<\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.737622em;\"><span class=\"\" style=\"top: -3.13623em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 2.30001em; vertical-align: -1.25001em;\"><\/span><span class=\"mop op-limits\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.05001em;\"><span class=\"\" style=\"top: -1.89999em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.05em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"\"><span class=\"mop op-symbol large-op\">\u2211<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.25001em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">[<\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.10764em;\">f<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.336108em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.10764em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"mpunct mtight\">,<\/span><span class=\"mord mathdefault mtight\">b<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.286108em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord accent\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.69444em;\"><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">y<\/span><\/span><\/span><span class=\"\" style=\"top: -3em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"accent-body\" style=\"left: -0.19444em;\">^<\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.19444em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mop\">ln<\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u2212<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.10764em;\">f<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.336108em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.10764em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"mpunct mtight\">,<\/span><span class=\"mord mathdefault mtight\">b<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.286108em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"minner\"><span class=\"mopen delimcenter\" style=\"top: 0em;\">(<\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.714392em;\"><span class=\"\" style=\"top: -3.113em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">)<\/span><\/span><span class=\"mclose delimcenter\" style=\"top: 0em;\">]<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> f w , b ( x ) = \u03c3 ( z ) = 1 \/ 1 + exp \u2061 ( \u2212 z ) \\begin{array}{l}{f_{w, b}(x)=\\sigma(z)} {=1 \/ 1+\\exp (-z)}\\end{array} <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 1.2em; vertical-align: -0.35em;\"><\/span><span class=\"mord\"><span class=\"mtable\"><span class=\"arraycolsep\" style=\"width: 0.5em;\"><\/span><span class=\"col-align-l\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.85em;\"><span class=\"\" style=\"top: -3.01em;\"><span class=\"pstrut\" style=\"height: 3em;\"><\/span><span class=\"mord\"><span class=\"mord\"><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.10764em;\">f<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.336108em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.10764em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"mpunct mtight\">,<\/span><span class=\"mord mathdefault mtight\">b<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.286108em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mopen\">(<\/span><span class=\"mord mathdefault\">x<\/span><span class=\"mclose\">)<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mord mathdefault\" style=\"margin-right: 0.03588em;\">\u03c3<\/span><span class=\"mopen\">(<\/span><span class=\"mord mathdefault\" style=\"margin-right: 0.04398em;\">z<\/span><span class=\"mclose\">)<\/span><\/span><span class=\"mord\"><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mord\">1<\/span><span class=\"mord\">\/<\/span><span class=\"mord\">1<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mop\">exp<\/span><span class=\"mopen\">(<\/span><span class=\"mord\">\u2212<\/span><span class=\"mord mathdefault\" style=\"margin-right: 0.04398em;\">z<\/span><span class=\"mclose\">)<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.35em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"arraycolsep\" style=\"width: 0.5em;\"><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<\/li>\n<li>\n<p><span class=\"katex--display\"><span class=\"katex-display\"><span class=\"katex\"><span class=\"katex-mathml\"> z = w \u22c5 x + b = \u2211 i w i x i + b \\quad z=w \\cdot x+b=\\sum_{i} w_{i} x_{i}+b <\/span><span class=\"katex-html\"><span class=\"base\"><span class=\"strut\" style=\"height: 0.43056em; vertical-align: 0em;\"><\/span><span class=\"mspace\" style=\"margin-right: 1em;\"><\/span><span class=\"mord mathdefault\" style=\"margin-right: 0.04398em;\">z<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.44445em; vertical-align: 0em;\"><\/span><span class=\"mord mathdefault\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">\u22c5<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.66666em; vertical-align: -0.08333em;\"><\/span><span class=\"mord mathdefault\">x<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.69444em; vertical-align: 0em;\"><\/span><span class=\"mord mathdefault\">b<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><span class=\"mrel\">=<\/span><span class=\"mspace\" style=\"margin-right: 0.277778em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 2.32767em; vertical-align: -1.27767em;\"><\/span><span class=\"mop op-limits\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.05001em;\"><span class=\"\" style=\"top: -1.87233em; margin-left: 0em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><span class=\"\" style=\"top: -3.05001em;\"><span class=\"pstrut\" style=\"height: 3.05em;\"><\/span><span class=\"\"><span class=\"mop op-symbol large-op\">\u2211<\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 1.27767em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.166667em;\"><\/span><span class=\"mord\"><span class=\"mord mathdefault\" style=\"margin-right: 0.02691em;\">w<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: -0.02691em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mord\"><span class=\"mord mathdefault\">x<\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.311664em;\"><span class=\"\" style=\"top: -2.55em; margin-left: 0em; margin-right: 0.05em;\"><span class=\"pstrut\" style=\"height: 2.7em;\"><\/span><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\"><span class=\"mord mathdefault mtight\">i<\/span><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height: 0.15em;\"><span class=\"\"><\/span><\/span><\/span><\/span><\/span><\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><span class=\"mbin\">+<\/span><span class=\"mspace\" style=\"margin-right: 0.222222em;\"><\/span><\/span><span class=\"base\"><span class=\"strut\" style=\"height: 0.69444em; vertical-align: 0em;\"><\/span><span class=\"mord mathdefault\">b<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<h5>2.3.4 \u53c2\u6570\u66f4\u65b0<\/h5>\n<p>\u6c42\u51fa\u68af\u5ea6\u540e\uff0c\u518d\u62ff\u539f\u53c2\u6570\u51cf\u53bb\u68af\u5ea6\u4e0e\u5b66\u4e60\u7387\u7684\u4e58\u79ef\uff0c\u5373\u53ef\u5b9e\u73b0\u53c2\u6570\u7684\u66f4\u65b0\u3002<\/p>\n<pre class=\"language-java prettyprint linenums\"><code class=\"prism language-python\"><span class=\"token comment\">#\u5e73\u5747\u6570<\/span>\n b_g<span class=\"token operator\">\/=<\/span>num\n w_g<span class=\"token operator\">\/=<\/span>num\n\n <span class=\"token comment\">#adagrad<\/span>\n bg2_sum<span class=\"token operator\">+=<\/span>b_g<span class=\"token operator\">**<\/span><span class=\"token number\">2<\/span>\n wg2_sum<span class=\"token operator\">+=<\/span>w_g<span class=\"token operator\">**<\/span><span class=\"token number\">2<\/span>\n <span class=\"token comment\">#\u66f4\u65b0w\u548cb<\/span>\n weights<span class=\"token operator\">-=<\/span>Learning_rate<span class=\"token operator\">\/<\/span>wg2_sum<span class=\"token operator\">**<\/span><span class=\"token number\">0.5<\/span><span class=\"token operator\">*<\/span>w_g\n bias<span class=\"token operator\">-=<\/span>Learning_rate<span class=\"token operator\">\/<\/span>bg2_sum<span class=\"token operator\">**<\/span><span class=\"token number\">0.5<\/span><span class=\"token operator\">*<\/span>b_g\n<\/code><\/pre>\n<h4>\u4e09\u3001\u4ee3\u7801\u5206\u4eab\u4e0e\u7ed3\u679c\u663e\u793a<\/h4>\n<h5>3.1 \u6e90\u4ee3\u7801<\/h5>\n<pre class=\"language-java prettyprint linenums\"><code class=\"prism language-python\"><span class=\"token keyword\">import<\/span> numpy <span class=\"token keyword\">as<\/span> np\n<span class=\"token keyword\">import<\/span> pandas <span class=\"token keyword\">as<\/span> pd\n\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">train<\/span><span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">,<\/span>y_train<span class=\"token punctuation\">,<\/span>epoch<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n num<span class=\"token operator\">=<\/span>x_train<span class=\"token punctuation\">.<\/span>shape<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span>\n <span class=\"token triple-quoted-string string\">'''y.shape \u8fd4\u56de\u7684\u4e00\u4e2a\u5143\u7ec4\uff0c\u4ee3\u8868 y \u6570\u636e\u96c6\u7684\u4fe1\u606f\u5982\uff08\u884c\uff0c\u5217\uff09 y.shape[0], \u610f\u601d\u662f\uff1a\u8fd4\u56de y \u4e2d\u884c\u7684\u603b\u6570\u3002\u8fd9\u4e2a\u503c\u5728 y \u662f\u5355\u7279\u5f81\u7684\u60c5\u51b5\u4e0b \u548c len(y) \u662f\u7b49\u4ef7\u7684\uff0c \u5373\u6570\u636e\u96c6\u4e2d\u6570\u636e\u70b9\u7684\u603b\u6570\u3002'''<\/span>\n dim<span class=\"token operator\">=<\/span>x_train<span class=\"token punctuation\">.<\/span>shape<span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span>\n bias<span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span><span class=\"token comment\">#\u504f\u7f6e\u521d\u59cb\u5316<\/span>\n weights<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>ones<span class=\"token punctuation\">(<\/span>dim<span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u6743\u91cd\u521d\u59cb\u5316<\/span>\n Learning_rate<span class=\"token operator\">=<\/span><span class=\"token number\">1<\/span><span class=\"token comment\">#\u5b66\u4e60\u7387\u548c\u6b63\u5219\u9879\u7cfb\u6570\u521d\u59cb\u5316<\/span>\n Regular_coefficient<span class=\"token operator\">=<\/span><span class=\"token number\">0.001<\/span>\n <span class=\"token comment\">#\u7528\u4e8e\u5b58\u653e\u504f\u7f6e\u503c\u7684\u68af\u5ea6\u5e73\u65b9\u548c,adagrad\u7528\u5230<\/span>\n bg2_sum<span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span>\n wg2_sum<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>zeros<span class=\"token punctuation\">(<\/span>dim<span class=\"token punctuation\">)<\/span>\n\n <span class=\"token comment\">#\u8fed\u4ee3\u6c42w,b<\/span>\n <span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>epoch<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n b_g<span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span><span class=\"token comment\">#\u521d\u59cb\u5316<\/span>\n w_g<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>zeros<span class=\"token punctuation\">(<\/span>dim<span class=\"token punctuation\">)<\/span>\n <span class=\"token comment\"># \u8ba1\u7b97\u68af\u5ea6\uff0c\u68af\u5ea6\u8ba1\u7b97\u65f6\u9488\u5bf9\u635f\u5931\u51fd\u6570\u6c42\u5bfc,\u5728\u6240\u6709\u6570\u636e\u4e0a<\/span>\n <span class=\"token keyword\">for<\/span> j <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n z<span class=\"token operator\">=<\/span>weights<span class=\"token punctuation\">.<\/span>dot<span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">+<\/span>bias<span class=\"token comment\">#Z\u51fd\u6570\u8868\u8fbe\u5f0f<\/span>\n sigmoid<span class=\"token operator\">=<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">\/<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">+<\/span>np<span class=\"token punctuation\">.<\/span>exp<span class=\"token punctuation\">(<\/span><span class=\"token operator\">-<\/span>z<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token comment\">#sigmoid function<\/span>\n <span class=\"token comment\">#\u635f\u5931\u51fd\u6570\u5bf9b\u6c42\u5bfc<\/span>\n b_g<span class=\"token operator\">+=<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span>y_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token operator\">-<\/span>sigmoid<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>\n <span class=\"token comment\"># \u635f\u5931\u51fd\u6570\u5bf9w\u6c42\u5bfc,\u5e76\u4e14\u6709\u6b63\u5219\u5316\uff08\u9632overfitting)<\/span>\n\n <span class=\"token keyword\">for<\/span> k <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>dim<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n w_g<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token operator\">+=<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span>y_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token operator\">-<\/span>sigmoid<span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span>x_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">,<\/span>k<span class=\"token punctuation\">]<\/span><span class=\"token operator\">+<\/span><span class=\"token number\">2<\/span><span class=\"token operator\">*<\/span>Regular_coefficient<span class=\"token operator\">*<\/span>weights<span class=\"token punctuation\">[<\/span>k<span class=\"token punctuation\">]<\/span>\n <span class=\"token comment\">#\u5e73\u5747\u6570<\/span>\n b_g<span class=\"token operator\">\/=<\/span>num\n w_g<span class=\"token operator\">\/=<\/span>num\n\n <span class=\"token comment\">#adagrad<\/span>\n bg2_sum<span class=\"token operator\">+=<\/span>b_g<span class=\"token operator\">**<\/span><span class=\"token number\">2<\/span>\n wg2_sum<span class=\"token operator\">+=<\/span>w_g<span class=\"token operator\">**<\/span><span class=\"token number\">2<\/span>\n <span class=\"token comment\">#\u66f4\u65b0w\u548cb<\/span>\n weights<span class=\"token operator\">-=<\/span>Learning_rate<span class=\"token operator\">\/<\/span>wg2_sum<span class=\"token operator\">**<\/span><span class=\"token number\">0.5<\/span><span class=\"token operator\">*<\/span>w_g\n bias<span class=\"token operator\">-=<\/span>Learning_rate<span class=\"token operator\">\/<\/span>bg2_sum<span class=\"token operator\">**<\/span><span class=\"token number\">0.5<\/span><span class=\"token operator\">*<\/span>b_g\n\n <span class=\"token comment\"># \u6bcf\u8bad\u7ec33\u8f6e\uff0c\u8f93\u51fa\u4e00\u6b21\u5728\u8bad\u7ec3\u96c6\u4e0a\u7684\u6b63\u786e\u7387<\/span>\n <span class=\"token comment\"># \u5728\u8ba1\u7b97loss\u65f6\uff0c\u7531\u4e8e\u6d89\u53cag()\u8fd0\u5230lo\u7b97\uff0c\u56e0\u6b64\u53ef\u80fd\u51fa\u73b0\u65e0\u7a77\u5927\uff0c\u8ba1\u7b97\u5e76\u6253\u5370\u51fa\u6765\u7684loss\u4e3anan<\/span>\n <span class=\"token comment\"># \u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u628a\u4e0b\u9762\u6d89\u53ca\u5230loss\u8fd0\u7b97\u7684\u6ce8\u91ca\u53bb\u6389\uff0c\u89c2\u5bdf\u4e00\u6ce2\u6253\u5370\u51fa\u7684loss<\/span>\n <span class=\"token keyword\">if<\/span> i<span class=\"token operator\">%<\/span><span class=\"token number\">3<\/span><span class=\"token operator\">==<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span>\n Correct_quantity<span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span>\n result<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>zeros<span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span>\n <span class=\"token comment\">#loss=0<\/span>\n <span class=\"token keyword\">for<\/span> j <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n z <span class=\"token operator\">=<\/span> weights<span class=\"token punctuation\">.<\/span>dot<span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">+<\/span> bias <span class=\"token comment\"># Z\u51fd\u6570\u8868\u8fbe\u5f0f<\/span>\n sigmoid <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">\/<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span> <span class=\"token operator\">+<\/span> np<span class=\"token punctuation\">.<\/span>exp<span class=\"token punctuation\">(<\/span><span class=\"token operator\">-<\/span>z<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># sigmoid function<\/span>\n <span class=\"token keyword\">if<\/span> sigmoid<span class=\"token operator\">>=<\/span><span class=\"token number\">0.5<\/span><span class=\"token punctuation\">:<\/span>\n result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token operator\">=<\/span><span class=\"token number\">1<\/span>\n <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span>\n result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span>\n <span class=\"token keyword\">if<\/span> result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token operator\">==<\/span>y_train<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span>\n Correct_quantity<span class=\"token operator\">+=<\/span><span class=\"token number\">1.0<\/span>\n <span class=\"token comment\">#loss += (-1) * (y_train[j] * np.ln(sigmoid) + (1 - y_train[j]) * np.ln(1 - sigmoid))<\/span>\n <span class=\"token comment\">#print(f\"epoch{0},the loss on train data is::{1}\", i, loss \/ num)<\/span>\n <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"epoch{0},the Correct rate on train data is:{1}\"<\/span><span class=\"token punctuation\">,<\/span>i<span class=\"token punctuation\">,<\/span>Correct_quantity<span class=\"token operator\">\/<\/span>num<span class=\"token punctuation\">)<\/span>\n <span class=\"token keyword\">return<\/span> weights<span class=\"token punctuation\">,<\/span>bias\n\n<span class=\"token comment\">#\u5bf9\u6c42\u51fa\u6765\u7684W\u548cb\u9a8c\u8bc1\u4e00\u4e0b\u6548\u679c<\/span>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">validate<\/span><span class=\"token punctuation\">(<\/span>x_val<span class=\"token punctuation\">,<\/span>y_val<span class=\"token punctuation\">,<\/span>weights<span class=\"token punctuation\">,<\/span>bias<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n num<span class=\"token operator\">=<\/span>x_val<span class=\"token punctuation\">.<\/span>shape<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span>\n Correct_quantity <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span>\n result <span class=\"token operator\">=<\/span> np<span class=\"token punctuation\">.<\/span>zeros<span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span>\n loss<span class=\"token operator\">=<\/span><span class=\"token number\">0<\/span>\n <span class=\"token keyword\">for<\/span> j <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n z <span class=\"token operator\">=<\/span> weights<span class=\"token punctuation\">.<\/span>dot<span class=\"token punctuation\">(<\/span>x_val<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">+<\/span> bias <span class=\"token comment\"># Z\u51fd\u6570\u8868\u8fbe\u5f0f<\/span>\n sigmoid <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">\/<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span> <span class=\"token operator\">+<\/span> np<span class=\"token punctuation\">.<\/span>exp<span class=\"token punctuation\">(<\/span><span class=\"token operator\">-<\/span>z<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># sigmoid function<\/span>\n <span class=\"token keyword\">if<\/span> sigmoid <span class=\"token operator\">>=<\/span> <span class=\"token number\">0.5<\/span><span class=\"token punctuation\">:<\/span>\n result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span>\n <span class=\"token keyword\">if<\/span> sigmoid <span class=\"token operator\"><<\/span> <span class=\"token number\">0.5<\/span><span class=\"token punctuation\">:<\/span>\n result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span>\n <span class=\"token keyword\">if<\/span> result<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">==<\/span> y_val<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span>\n Correct_quantity <span class=\"token operator\">+=<\/span> <span class=\"token number\">1.0<\/span>\n <span class=\"token comment\">#\u9a8c\u8bc1\u96c6\u4e0a\u7684\u635f\u5931\u51fd\u6570<\/span>\n <span class=\"token comment\">#loss += (-1) * (y_val[j] * np.log(sigmoid) + (1 - y_val[j]) * np.ln(1 - sigmoid))<\/span>\n\n <span class=\"token keyword\">return<\/span> Correct_quantity<span class=\"token operator\">\/<\/span>num\n\n\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>\n <span class=\"token comment\">#\u6570\u636e\u7684\u9884\u5904\u7406<\/span>\n df<span class=\"token operator\">=<\/span>pd<span class=\"token punctuation\">.<\/span>read_csv<span class=\"token punctuation\">(<\/span><span class=\"token string\">'spam_train.csv'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u8bfb\u6587\u4ef6<\/span>\n df<span class=\"token operator\">=<\/span>df<span class=\"token punctuation\">.<\/span>fillna<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u7a7a\u503c\u75280\u586b\u5145<\/span>\n array<span class=\"token operator\">=<\/span>np<span class=\"token punctuation\">.<\/span>array<span class=\"token punctuation\">(<\/span>df<span class=\"token punctuation\">)<\/span><span class=\"token comment\">#\u8f6c\u5316\u4e3a\u5bf9\u8c61\uff084000\uff0c49\uff09<\/span>\n x<span class=\"token operator\">=<\/span>array<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token comment\">#\u629b\u5f03\u7b2c\u4e00\u5217\u548c\u6700\u540e\u4e00\u5217shape(4000,47)<\/span>\n y<span class=\"token operator\">=<\/span>array<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token comment\">#\u6700\u540e\u4e00\u5217label<\/span>\n <span class=\"token comment\">#\u5c06\u5012\u6570\u7b2c\u4e8c\u5217\u548c\u7b2c\u4e09\u5217\u9664\u4ee5\u5e73\u5747\u503c<\/span>\n x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">\/<\/span>np<span class=\"token punctuation\">.<\/span>mean<span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>\n x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">=<\/span> x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">\/<\/span> np<span class=\"token punctuation\">.<\/span>mean<span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span>\n\n <span class=\"token comment\">#\u5212\u5206\u6d4b\u8bd5\u96c6\u548c\u9a8c\u8bc1\u96c6<\/span>\n x_train<span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span>\n y_train <span class=\"token operator\">=<\/span> y<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">]<\/span>\n x_val<span class=\"token operator\">=<\/span>x<span class=\"token punctuation\">[<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">4001<\/span><span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">:<\/span><span class=\"token punctuation\">]<\/span>\n y_val<span class=\"token operator\">=<\/span>y<span class=\"token punctuation\">[<\/span><span class=\"token number\">3500<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">4001<\/span><span class=\"token punctuation\">]<\/span>\n\n <span class=\"token comment\">#\u8fed\u4ee3\u6b21\u6570\u4e3a30\u6b21<\/span>\n epoch<span class=\"token operator\">=<\/span><span class=\"token number\">30<\/span>\n w<span class=\"token punctuation\">,<\/span>b<span class=\"token operator\">=<\/span>train<span class=\"token punctuation\">(<\/span>x_train<span class=\"token punctuation\">,<\/span>y_train<span class=\"token punctuation\">,<\/span>epoch<span class=\"token punctuation\">)<\/span>\n <span class=\"token comment\">#\u9a8c\u8bc1\u96c6\u4e0a\u7684\u7ed3\u679c<\/span>\n Correct_rate<span class=\"token operator\">=<\/span>validate<span class=\"token punctuation\">(<\/span>x_val<span class=\"token punctuation\">,<\/span>y_val<span class=\"token punctuation\">,<\/span>w<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span>\n <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"The Correct rate on val data is:{0}\"<\/span><span class=\"token punctuation\">,<\/span>Correct_rate<span class=\"token punctuation\">)<\/span>\n\n<span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">==<\/span> <span class=\"token string\">'__main__'<\/span><span class=\"token punctuation\">:<\/span>\n main<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\n<\/code><\/pre>\n<h5>3.2 \u7ed3\u679c\u663e\u793a<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/img.mushiming.top\/app\/mushiming_com\/b5fe4c40120a4058a3f618105003f2dd.jpg\" =\"\" =\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" alt=\"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d (https:\/\/mushiming.com\/) \u7b2c2\u5f20\" title=\"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d \u7b2c2\u5f20-\u7a46\u4e16\u660e\u535a\u5ba2\" ><br \/> \u53ef\u4ee5\u770b\u51fa\uff0c\u5728\u8bad\u7ec330\u8f6e\u540e\uff0c\u5206\u7c7b\u6b63\u786e\u7387\u80fd\u8fbe\u523094%\u5de6\u53f3\u3002<\/p>\n<h4>\u53c2\u8003\u8d44\u6599\uff1a<\/h4>\n<ul>\n<li>https:\/\/www.cnblogs.com\/HL-space\/p\/10785225.html<\/li>\n<li>http:\/\/www.luyixian.cn\/news_show_4755.aspx<\/li>\n<li>https:\/\/www.cnblogs.com\/luhuan\/p\/7925790.html<\/li>\n<li>https:\/\/blog.csdn.net\/u013541048\/article\/details\/81335256<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u674e\u5b8f\u6bc5\u673a\u5668\u5b66\u4e60\u4f5c\u4e1a2:Winner\u8fd8\u662fLosser\uff08\u542b\u8bad\u7ec3\u6570\u636e\uff09\u300c\u5efa\u8bae\u6536\u85cf\u300d\u8bad\u7ec3\u6570\u636e\u4ee5\u53ca\u6e90\u4ee3\u7801\u5728\u6211\u7684Github\uff1ahttps:\/\/github.com\/taw1...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8894"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8894"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8894\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}