{"id":1394,"date":"2024-02-08T10:53:00","date_gmt":"2024-02-08T02:53:00","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1394"},"modified":"2025-02-14T11:39:10","modified_gmt":"2025-02-14T03:39:10","slug":"3-1-linear-regression","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/3-1-linear-regression\/","title":{"rendered":"3.1 \u7ebf\u6027\u56de\u5f52"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<p>\u7ebf\u6027\u56de\u5f52\u8f93\u51fa\u7684\u662f\u8fde\u7eed\u503c\uff0c\u9002\u7528\u4e8e\u5982\u9884\u6d4b\u623f\u5c4b\u4ef7\u683c\u3001\u6c14\u6e29\u3001\u9500\u552e\u989d\u7b49\u8fde\u7eed\u503c\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ebf\u6027\u56de\u5f52\u7684\u57fa\u672c\u8981\u7d20<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u6a21\u578b\u5b9a\u4e49<\/h3>\n\n\n\n<p>\u5047\u8bbe\u8f93\u5165\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u4e3a$x_1$\u548c$x_2$\uff0c\u8f93\u51fa\u4e3a\u4e00\u4e2a\u6570$y$\u3002\u5efa\u7acb\u4e00\u4e2a\u57fa\u4e8e\u8f93\u5165$x_1$\u548c$x_2$\u6765\u8ba1\u7b97\u8f93\u51fa$y$\u7684\u8868\u8fbe\u5f0f\uff0c\u4e5f\u5c31\u662f\u6a21\u578b(model)\u3002<\/p>\n\n\n\n<p>\u7ebf\u6027\u56de\u5f52\u5047\u8bbe\u8f93\u51fa\u4e0e\u5404\u8f93\u5165\u4e4b\u95f4\u662f\u7ebf\u6027\u5173\u7cfb\uff1a<\/p>\n\n\n\n<p>$$\\hat{y}=x_1 w_1+x_2 w_2+b$$<\/p>\n\n\n\n<p>\u5176\u4e2d$w_1$\u548c$w_2$\u662f\u6743\u91cd\uff08weight\uff09\uff0c$b$\u662f\u504f\u5dee\uff08bisa\uff09\uff0c\u5747\u4e3a\u6807\u91cf\u3002\u5b83\u4eec\u662f\u7ebf\u6027\u56de\u5f52\u6a21\u578b\u7684\u53c2\u6570\uff08parameter\uff09\u3002$\\hat{y}$\u662f\u6a21\u578b\u7684\u8f93\u51fa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8bad\u7ec3\u6a21\u578b<\/h3>\n\n\n\n<p>\u901a\u8fc7\u6a21\u578b\u8bad\u7ec3\uff08model training\uff09\uff0c\u6839\u636e\u6570\u636e\u5bfb\u627e\u5230\u7279\u5b9a\u7684\u6a21\u578b\u53c2\u6570\u503c\uff0c\u4f7f\u5f97\u6a21\u578b\u7684\u8f93\u51fa\u5c3d\u53ef\u80fd\u63a5\u8fd1\u6b63\u786e\u7684\u7b54\u6848\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u8bad\u7ec3\u6570\u636e<\/h4>\n\n\n\n<p>\u5c06\u6536\u96c6\u5230\u7684\u4e00\u7cfb\u5217\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\u7684\u771f\u5b9e\u6570\u636e\u79f0\u4e4b\u4e3a\u8bad\u7ec3\u6570\u636e\u96c6\uff08training data set\uff09\u6216\u8bad\u7ec3\u96c6\uff08training set\uff09\uff0c\u5176\u4e2d\u7684\u4e00\u5957\u6570\u636e\u79f0\u4e3a\u4e00\u4e2a\u6837\u672c\uff08sample\uff09\uff0c\u4e00\u5957\u6570\u636e\u4e2d\u7684$x_1$\u3001$x_2$\u79f0\u4e3a\u7279\u5f81\uff08feature\uff09\uff0c$y$\u88ab\u79f0\u4e3a\u6807\u7b7e\uff08label\uff09\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u91c7\u96c6\u7684\u6837\u672c\u6570\u4e3a$n$\uff0c\u7d22\u5f15\u4e3a$i$\u7684\u6837\u672c\u7279\u5f81\u5199\u4f5c$x_1^{(i)}$\u548c$x_2^{(i)}$\uff0c\u6807\u7b7e\u5199\u4f5c$y^{(i)}$\u3002\u5bf9\u4e8e\u7d22\u5f15\u4e3a$i$\u7684\u6837\u672c\uff0c\u5176\u7ebf\u6027\u6a21\u578b\u7684\u9884\u6d4b\u503c\u8868\u8fbe\u5f0f\u4e3a\uff1a<\/p>\n\n\n\n<p>$$\\hat{y}^{(i)}=x_1^{(i)} w_1+x_2^{(i)} w_2+b$$<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u635f\u5931\u51fd\u6570<\/h4>\n\n\n\n<p>\u5728\u6a21\u578b\u8bad\u7ec3\u4e2d\uff0c\u9700\u8981\u8861\u91cf\u9884\u6d4b\u4e0e\u771f\u5b9e\u503c\u7684\u8bef\u5dee\u3002\u901a\u5e38\u4f1a\u9009\u62e9\u4e00\u4e2a\u975e\u8d1f\u6570\u4f5c\u4e3a\u8bef\u5dee\uff0c\u4e14\u6570\u503c\u8d8a\u5c0f\u8bef\u5dee\u8d8a\u5c0f\u3002\u4e00\u4e2a\u5e38\u7528\u7684\u9009\u62e9\u662f\u5e73\u65b9\u51fd\u6570\u3002\u7d22\u5f15\u4e3a$i$\u7684\u6837\u672c\u8bef\u5dee\u7684\u8868\u8fbe\u5f0f\u4e3a\uff1a<\/p>\n\n\n\n<p>$$\\ell^{(i)}\\left(w_1, w_2, b\\right)=\\frac{1}{2}\\left(\\hat{y}^{(i)}-y^{(i)}\\right)^2$$<\/p>\n\n\n\n<p>\u5c06\u6a21\u578b\u8f93\u51fa\u7684\u9884\u6d4b\u503c$\\hat{y}^{(i)}$\u4e0e\u6807\u7b7e\uff08\u5373\u6807\u51c6\u7b54\u6848\uff09\u76f8\u51cf\uff0c\u518d\u4e58\u65b9\u6765\u5c06\u53ef\u80fd\u51fa\u73b0\u7684\u8d1f\u6570\u8f6c\u6362\u4e3a\u6b63\u6570\u3002\u5e38\u6570$\\frac{1}{2}$\u4f7f\u5bf9\u5e73\u65b9\u9879\u6c42\u5bfc\u540e\u7684\u5e38\u6570\u7cfb\u6570\u4e3a1\uff0c\u8fd9\u6837\u5728\u4f1a\u8ba9\u540e\u7eed\u6c42\u5bfc\u540e\u7684\u7ed3\u679c\u5728\u5f62\u5f0f\u4e0a\u7a0d\u5fae\u7b80\u5355\u4e00\u4e9b\u3002<\/p>\n\n\n\n<p>\u7ed9\u5b9a\u8bad\u7ec3\u96c6\uff0c\u8fd9\u4e2a\u8bef\u5dee\u53ea\u4e0e\u6a21\u578b\u53c2\u6570\u6709\u5173\uff0c\u56e0\u6b64\u5c06\u5b83\u8bb0\u4e3a\u4ee5\u6a21\u578b\u53c2\u6570\u4e3a\u53c2\u6570\u7684\u51fd\u6570\u3002\u8be5\u51fd\u6570\u88ab\u79f0\u4e3a\u635f\u5931\u51fd\u6570\uff08loss function\uff09\uff0c\u5728\u8fd9\u91cc\u7528$\\ell^{(i)}\\left(w_1, w_2, b\\right)$\u6765\u8868\u793a\u7d22\u5f15\u4e3a$i$\u7684\u6837\u672c\u7684\u635f\u5931\u51fd\u6570\u3002\u8fd9\u91cc\u4f7f\u7528\u7684\u5e73\u65b9\u8bef\u5dee\u51fd\u6570\u4e5f\u79f0\u4e3a\u5e73\u65b9\u635f\u5931\uff08square loss\uff09\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\uff0c\u7528\u8bad\u7ec3\u6570\u636e\u96c6\u4e2d\u6240\u6709\u6837\u672c\u8bef\u5dee\u7684\u5e73\u5747\u6765\u8861\u91cf\u6a21\u578b\u9884\u6d4b\u7684\u8d28\u91cf\uff0c\u5373<\/p>\n\n\n\n<p>$$\\ell\\left(w_1, w_2, b\\right)=\\frac{1}{n} \\sum_{i=1}^n \\ell^{(i)}\\left(w_1, w_2, b\\right)=\\frac{1}{n} \\sum_{i=1}^n \\frac{1}{2}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right)^2$$<\/p>\n\n\n\n<p>\u7528\u6c42\u548c\u51fd\u6570\u5c06\u8bad\u7ec3\u6570\u636e\u96c6\u4e2d\u6bcf\u4e2a\u6837\u672c\u7684\u8bef\u5dee\u76f8\u52a0\uff0c\u968f\u540e\u9664\u4ee5n\u5f97\u5230\u8bad\u7ec3\u6570\u636e\u96c6\u7684\u5e73\u5747\u8bef\u5dee\u3002<\/p>\n\n\n\n<p>\u5728\u6a21\u578b\u8bad\u7ec3\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u51fa\u4e00\u7ec4\u6a21\u578b\u53c2\u6570\uff0c\u8bb0\u4e3a $w_1^*$, $w_2^*$, $b^*$ \uff0c\u6765\u4f7f\u8bad\u7ec3\u6837\u672c\u5e73\u5747\u635f\u5931\u6700\u5c0f: <\/p>\n\n\n\n<p>$$ w_1^*, w_2^*, b^*=\\underset{w_1, w_2, b}{\\arg \\min } \\ell\\left(w_1, w_2, b\\right)$$<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f18\u5316\u7b97\u6cd5<\/h4>\n\n\n\n<p>\u5f53\u6a21\u578b\u548c\u635f\u5931\u51fd\u6570\u5f62\u5f0f\u8f83\u4e3a\u7b80\u5355\u65f6\uff0c\u4e0a\u9762\u7684\u8bef\u5dee\u6700\u5c0f\u5316\u95ee\u9898\u7684\u89e3\u53ef\u4ee5\u76f4\u63a5\u7528\u516c\u5f0f\u8868\u8fbe\u51fa\u6765\u3002\u8fd9\u7c7b\u89e3\u53eb\u4f5c\u89e3\u6790\u89e3\uff08analytical solution\uff09\u3002\u672c\u8282\u4f7f\u7528\u7684\u7ebf\u6027\u56de\u5f52\u548c\u5e73\u65b9\u8bef\u5dee\u521a\u597d\u5c5e\u4e8e\u8fd9\u4e2a\u8303\u7574\u3002\u7136\u800c\uff0c\u5927\u591a\u6570\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u5e76\u6ca1\u6709\u89e3\u6790\u89e3\uff0c\u53ea\u80fd\u901a\u8fc7\u4f18\u5316\u7b97\u6cd5\u6709\u9650\u6b21\u8fed\u4ee3\u6a21\u578b\u53c2\u6570\u6765\u5c3d\u53ef\u80fd\u964d\u4f4e\u635f\u5931\u51fd\u6570\u7684\u503c\u3002\u8fd9\u7c7b\u89e3\u53eb\u4f5c\u6570\u503c\u89e3\uff08numerical solution\uff09\u3002<\/p>\n\n\n\n<p>\u5728\u6c42\u6570\u503c\u89e3\u7684\u4f18\u5316\u7b97\u6cd5\u4e2d\uff0c\u6df1\u5ea6\u5b66\u4e60\u4e2d\u901a\u5e38\u4f7f\u7528\u5c0f\u6279\u91cf\u968f\u673a\u68af\u5ea6\u4e0b\u964d\uff08mini-batch stochastic gradient descent\uff09\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u9009\u53d6\u4e00\u7ec4\u6a21\u578b\u53c2\u6570\u7684\u521d\u59cb\u503c\uff08\u5982\u968f\u673a\u9009\u53d6\uff09\uff1b\u63a5\u4e0b\u6765\u5bf9\u53c2\u6570\u8fdb\u884c\u591a\u6b21\u8fed\u4ee3\uff0c\u4f7f\u6bcf\u6b21\u8fed\u4ee3\u90fd\u53ef\u80fd\u964d\u4f4e\u635f\u5931\u51fd\u6570\u7684\u503c\u3002\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d\uff0c\u5148\u968f\u673a\u5747\u5300\u91c7\u6837\u4e00\u4e2a\u7531\u56fa\u5b9a\u6570\u76ee\u8bad\u7ec3\u6570\u636e\u6837\u672c\u6240\u7ec4\u6210\u7684\u5c0f\u6279\u91cf\uff08mini-batch\uff09$\\mathcal{B}$\uff0c\u7136\u540e\u6c42\u5c0f\u6279\u91cf\u4e2d\u6570\u636e\u6837\u672c\u7684\u5e73\u5747\u635f\u5931\u6709\u5173\u6a21\u578b\u53c2\u6570\u7684\u5bfc\u6570\uff08\u68af\u5ea6\uff09\uff0c\u6700\u540e\u7528\u6b64\u7ed3\u679c\u4e0e\u9884\u5148\u8bbe\u5b9a\u7684\u4e00\u4e2a\u6b63\u6570\u7684\u4e58\u79ef\u4f5c\u4e3a\u6a21\u578b\u53c2\u6570\u5728\u672c\u6b21\u8fed\u4ee3\u7684\u51cf\u5c0f\u91cf\u3002<\/p>\n\n\n\n<p>\u68af\u5ea6\u5373\u4e3a\u635f\u5931\u51fd\u6570\u7684\u5bfc\u6570\uff0c\u4e4b\u6240\u4ee5\u5728\u8fed\u4ee3\u4e2d\u9700\u8981\u4e58\u4ee5\u68af\u5ea6\uff0c\u662f\u56e0\u4e3a\u5bfc\u6570\u53cd\u5e94\u4e86\u6a21\u578b\u7684\u9884\u6d4b\u503c\u4e0e\u6807\u7b7e\u4e4b\u95f4\u7684\u5dee\u8ddd\u7684\u5927\u5c0f\uff0c\u5dee\u8ddd\u8d8a\u5927\u8be5\u5bfc\u6570\u8d8a\u5927\uff0c\u4e5f\u5c31\u662f\u68af\u5ea6\u8d8a\u5927\u3002\u4e3a\u4e86\u505a\u5230\u6a21\u578b\u53c2\u6570\u7684\u51cf\u5c0f\u91cf\u968f\u7740\u9884\u6d4b\u503c\u4e0e\u6807\u7b7e\u4e4b\u95f4\u7684\u5927\u5c0f\u6539\u53d8\u800c\u6539\u53d8\uff0c\u6240\u4ee5\u5728\u8ba1\u7b97\u51cf\u5c0f\u503c\u65f6\u91c7\u7528\u68af\u5ea6\uff0c\u5dee\u8ddd\u8d8a\u5927\uff0c\u6a21\u578b\u53c2\u6570\u6539\u53d8\u7684\u8d8a\u5927\uff0c\u5dee\u8ddd\u8d8a\u5c0f\uff0c\u6a21\u578b\u53c2\u6570\u6539\u53d8\u7684\u8d8a\u5c0f\u3002<\/p>\n\n\n\n<p>\u540c\u4e0a\uff0c\u5047\u8bbe\u6a21\u578b\u4ec5\u6709\u4e24\u4e2a\u53c2\u6570$x_1$\uff0c$x_2$\u548c\u4e00\u4e2a\u8f93\u51fa$y$\uff0c\u5219\u6bcf\u4e2a\u53c2\u6570\u5c06\u505a\u5982\u4e0b\u8fed\u4ee3\uff1a<\/p>\n\n\n\n<p>$$<br>w_1 \\leftarrow w_1-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} \\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial w_1}=w_1-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} x_1^{(i)}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right)<br>$$<\/p>\n\n\n\n<p>$$<br>w_2 \\leftarrow w_2-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} \\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial w_2}=w_2-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} x_2^{(i)}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right)<br>$$<\/p>\n\n\n\n<p>$$<br>b \\leftarrow b-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} \\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial b}=b-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right)<br>$$<\/p>\n\n\n\n<p>\u5728\u4e0a\u5f0f\u4e2d\uff0c$|\\mathcal{B}|$&nbsp;\u4ee3\u8868\u6bcf\u4e2a\u5c0f\u6279\u91cf\u4e2d\u7684\u6837\u672c\u4e2a\u6570\uff08\u6279\u91cf\u5927\u5c0f\uff0cbatch size\uff09\uff0c$\\eta$&nbsp;\u79f0\u4f5c\u5b66\u4e60\u7387\uff08learning rate\uff09\u5e76\u53d6\u6b63\u6570\u3002\u8fd9\u91cc\u7684\u6279\u91cf\u5927\u5c0f\u548c\u5b66\u4e60\u7387\u7684\u503c\u662f\u4eba\u4e3a\u8bbe\u5b9a\u7684\uff0c\u5e76\u4e0d\u662f\u901a\u8fc7\u6a21\u578b\u8bad\u7ec3\u5b66\u51fa\u7684\uff0c\u56e0\u6b64\u53eb\u4f5c\u8d85\u53c2\u6570\uff08hyperparameter\uff09\u3002<\/p>\n\n\n\n<p>\u5728\u6c42\u53c2\u6570$w_1$\u7684\u51cf\u5c0f\u91cf\u65f6\uff0c\u6c42\u51fa\u5c0f\u6279\u91cf$\\mathcal{B}$\u4e2d\u6bcf\u4e2a\u6837\u672c\u7684\u635f\u5931\u51fd\u6570\u5bf9\u4e8e\u53c2\u6570$w_1$\u7684\u504f\u5bfc\u6570\u5e76\u5e26\u5165\u6570\u503c\uff0c\u7136\u540e\u5c06\u6bcf\u4e2a\u6837\u672c\u7684\u504f\u5bfc\u6570\u76f8\u52a0\uff0c\u9664\u4ee5\u5c0f\u6279\u91cf\u7684\u6837\u672c\u4e2a\u6570$|\\mathcal{B}|$\u5f97\u5230\u8be5\u5c0f\u6279\u91cf\u7684\u5e73\u5747\u8bef\u5dee\uff0c\u7136\u540e\u518d\u4e58\u4ee5\u5b66\u4e60\u7387$\\eta$\uff0c\u5c31\u5f97\u5230\u4e86\u8be5\u51fd\u6570\u7684\u51cf\u5c0f\u91cf\u3002\u7136\u540e\u5c06\u8be5\u53c2\u6570\u51cf\u53bb\u8fd9\u4e2a\u51cf\u5c0f\u91cf\uff0c\u5c31\u5f97\u5230\u4e86\u8c03\u6574\u540e\u7684\u53c2\u6570\u503c\u3002<br>\u6bcf\u4e00\u4e2a\u53c2\u6570\u7684\u8c03\u6574\u8fc7\u7a0b\uff0c\u90fd\u4e0e$w_1$\u4e00\u6837\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6a21\u578b\u9884\u6d4b<\/h3>\n\n\n\n<p>\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c06\u6a21\u578b\u53c2\u6570$w_1$\uff0c$w_2$\uff0c$b$&nbsp;\u5728\u4f18\u5316\u7b97\u6cd5\u505c\u6b62\u65f6\u7684\u503c\u5206\u522b\u8bb0\u4f5c$\\hat{w}1$\uff0c$\\hat{w}_2$\uff0c$\\hat{b}$\u3002\u8fd9\u91cc\u5f97\u5230\u7684\u5e76\u4e0d\u4e00\u5b9a\u662f\u6700\u5c0f\u5316\u635f\u5931\u51fd\u6570\u7684\u6700\u4f18\u89e3 $w_1^*$, $w_2^*$, $b^*$ \uff0c\u800c\u662f\u5bf9\u6700\u4f18\u89e3\u7684\u4e00\u4e2a\u8fd1\u4f3c\u3002\u7136\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5b66\u51fa\u7684\u7ebf\u6027\u56de\u5f52\u6a21\u578b$x_1\\hat{w}_1+x_2\\hat{w}_2+\\hat{b}$\u6765\u4f30\u7b97\u8bad\u7ec3\u6570\u636e\u96c6\u7684\u6570\u636e\u4e86\u3002\u8fd9\u91cc\u7684\u4f30\u7b97\u4e5f\u53eb\u4f5c\u6a21\u578b\u9884\u6d4b\u3001\u6a21\u578b\u63a8\u65ad\u6216\u6a21\u578b\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ebf\u6027\u56de\u5f52\u7684\u8868\u793a\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u795e\u7ecf\u7f51\u7edc\u56fe<\/h3>\n\n\n\n<p>\u795e\u7ecf\u7f51\u7edc\u56fe\u9690\u53bb\u4e86\u6a21\u578b\u53c2\u6570\u6743\u91cd\u548c\u504f\u5dee\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/02\/image.png\" src=\"https:\/\/cdn.forillusion.com\/moezx\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" class=\"wp-image-1405\" width=\"262\" height=\"129\"\/><\/figure >\n<noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cos.forillusion.top\/wp-content\/uploads\/2024\/02\/image.png\" alt=\"\" class=\"wp-image-1405\" width=\"262\" height=\"129\"\/><\/figure><\/noscript>\n\n\n\n<p>\u56fe\u4e2d\u6240\u793a\u7684\u795e\u7ecf\u7f51\u7edc\u4e2d\uff0c\u8f93\u5165\u4e3a$x_1$\uff0c$x_2$\uff0c\u56e0\u6b64\u8f93\u5165\u5c42\u7684\u8f93\u5165\u4e2a\u6570\u4e3a2\u3002\u8f93\u5165\u4e2a\u6570\u4e5f\u53eb\u7279\u5f81\u6570\u6216\u7279\u5f81\u5411\u91cf\u7ef4\u5ea6\u3002<\/p>\n\n\n\n<p>\u56fe\u4e2d\u7f51\u7edc\u7684\u8f93\u51fa\u4e3a$o$\uff0c\u8f93\u51fa\u5c42\u4e2a\u6570\u4e3a1\u3002\u5728\u8fd9\u91cc\uff0c\u76f4\u63a5\u5c06\u795e\u7ecf\u7f51\u7edc\u7684\u8f93\u51fa$o$\u4f5c\u4e3a\u7ebf\u6027\u56de\u5f52\u7684\u8f93\u51fa\uff0c\u5373$\\hat{y}=o$\u3002\u7531\u4e8e\u8f93\u5165\u5c42\u4e0d\u6d89\u53ca\u8ba1\u7b97\uff0c\u56fe\u793a\u4e2d\u7684\u795e\u7ecf\u7f51\u7edc\u7684\u5c42\u6570\u4e3a1.<\/p>\n\n\n\n<p>\u6240\u4ee5\uff0c\u7ebf\u6027\u56de\u5f52\u662f\u4e00\u4e2a\u5355\u5c42\u795e\u7ecf\u7f51\u7edc\u3002\u8f93\u51fa\u5c42\u4e2d\u8d1f\u8d23\u8ba1\u7b97$o$\u7684\u5355\u5143\u53c8\u53eb\u795e\u7ecf\u5143\u3002\u5728\u7ebf\u6027\u56de\u5f52\u4e2d\uff0c$o$\u7684\u8ba1\u7b97\u4f9d\u8d56$x_1$\u548c$x_2$\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8f93\u51fa\u5c42\u4e2d\u7684\u795e\u7ecf\u5143\u548c\u8f93\u5165\u5c42\u4e2d\u5404\u4e2a\u8f93\u5165\u5b8c\u5168\u8fde\u63a5\u3002\u56e0\u6b64\uff0c\u8fd9\u91cc\u7684\u8f93\u51fa\u5c42\u53c8\u53eb\u5168\u8fde\u63a5\u5c42\uff08fully-connected layer\uff09\u6216\u7a20\u5bc6\u5c42\uff08dense layer\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u77e2\u91cf\u8ba1\u7b97\u8868\u8fbe\u5f0f<\/h3>\n\n\n\n<p>\u5728\u6a21\u578b\u8bad\u7ec3\u6216\u9884\u6d4b\u65f6\uff0c\u6211\u4eec\u5e38\u5e38\u4f1a\u540c\u65f6\u5904\u7406\u591a\u4e2a\u6570\u636e\u6837\u672c\u5e76\u7528\u5230\u77e2\u91cf\u8ba1\u7b97\u3002\u7531\u4e8e\u77e2\u91cf\u8ba1\u7b97\u6bd4\u4e00\u4e2a\u4e2a\u5143\u7d20\u5355\u72ec\u8fd0\u7b97\u66f4\u5feb\uff0c\u6240\u4ee5\u5e94\u8be5\u5c3d\u53ef\u80fd\u91c7\u7528\u77e2\u91cf\u8ba1\u7b97\uff0c\u4ee5\u63d0\u5347\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u4f9d\u7136\u91c7\u7528\u4e0a\u6587\u4e2d\u4e24\u4e2a\u8f93\u5165\u53c2\u6570\u7684\u6a21\u578b\u3002\u5982\u679c\u53d6\u51fa\u8bad\u7ec3\u96c6\u4e2d\u76843\u4e2a\u6837\u672c\u8fdb\u884c\u8ba1\u7b97\uff0c\u5219\u4f1a\u6709\u4e0b\u5217\u516c\u5f0f\uff1a<\/p>\n\n\n\n<p>$$\\hat{y}^{(1)}=x_1^{(1)} w_1+x_2^{(1)} w_2+b$$<br>$$\\hat{y}^{(2)}=x_1^{(2)} w_1+x_2^{(2)} w_2+b$$<br>$$\\hat{y}^{(3)}=x_1^{(3)} w_1+x_2^{(3)} w_2+b$$<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u4e09\u4e2a\u7b49\u5f0f\u53ef\u4ee5\u8f6c\u5316\u4e3a\u77e2\u91cf\u8ba1\u7b97\uff1a<\/p>\n\n\n\n<p>$$<br>\\hat{\\mathbf{y}}=\\left[\\begin{array}{l}<br>\\hat{y}^{(1)} \\\\<br>\\hat{y}^{(2)} \\\\<br>\\hat{y}^{(3)}<br>\\end{array}\\right], \\quad \\mathbf{X}=\\left[\\begin{array}{ll}<br>x_1^{(1)} &amp; x_2^{(1)} \\\\<br>x_1^{(2)} &amp; x_2^{(2)} \\\\<br>x_1^{(3)} &amp; x_2^{(3)}<br>\\end{array}\\right], \\quad \\mathbf{w}=\\left[\\begin{array}{l}<br>w_1 \\\\<br>w_2<br>\\end{array}\\right]<br>$$<\/p>\n\n\n\n<p>\u5bf9\u8fd9\u4e09\u4e2a\u6837\u672c\u9884\u6d4b\u503c\u7684\u77e2\u91cf\u8ba1\u7b97\u8868\u8fbe\u5f0f\u4e3a$\\hat{\\mathbf{y}}=\\mathbf{X} \\mathbf{w}+b$\uff0c\u5176\u4e2d\u7684\u52a0\u6cd5\u8fd0\u7b97\u4f7f\u7528\u4e86\u5e7f\u64ad\u673a\u5236\u3002<\/p>\n\n\n\n<p>\u5e7f\u4e49\u4e0a\uff0c\u5f53\u6570\u636e\u6837\u672c\u6570\u4e3a$n$\uff0c\u7279\u5f81\u6570\u4e3a$d$\u65f6\uff0c\u7ebf\u6027\u56de\u5f52\u7684\u77e2\u91cf\u8ba1\u7b97\u8868\u8fbe\u5f0f\u4e3a<\/p>\n\n\n\n<p>$$\\hat{\\mathbf{y}}=\\mathbf{X} \\mathbf{w}+b$$<\/p>\n\n\n\n<p>\u5176\u4e2d\u6a21\u578b\u8f93\u51fa$ \\hat{\\mathbf{y}} \\in \\mathbb{R}^{n \\times 1} $\u6279\u91cf\u6570\u636e\u6837\u672c\u7279\u5f81$\\mathbf{X} \\in \\mathbb{R}^{n \\times d}$\uff0c\u6743\u91cd$\\mathbf{w} \\in \\mathbb{R}^{d \\times 1}$ \uff0c\u504f\u5dee$b \\in \\mathbb{R}$\u3002\u76f8\u5e94\u5730\uff0c\u6279\u91cf\u6570\u636e\u6837\u672c\u6807\u7b7e$\\mathbf{y} \\in \\mathbb{R}^{n \\times 1}$\u3002\u8bbe\u6a21\u578b\u53c2\u6570$\\mathbf{\\theta}=\\left[w_1, w_2, b\\right]^{\\top}$\uff08$\\mathbb{R}$\u53ef\u4ee5\u7406\u89e3\u4e3a\u77e9\u5f62\u7684\u5f62\u72b6\uff09\u3002\u6211\u4eec\u53ef\u4ee5\u91cd\u5199\u635f\u5931\u51fd\u6570\u4e3a\uff1a<\/p>\n\n\n\n<p>$$<br>\\ell(\\mathbf{\\theta})=\\frac{1}{2 n}(\\hat{\\mathbf{y}}-\\mathbf{y})^{\\top}(\\hat{\\mathbf{y}}-\\mathbf{y})<br>$$<\/p>\n\n\n\n<p>\u5176\u4e2d$(\\hat{\\mathbf{y}}-\\mathbf{y})^{\\top}(\\hat{\\mathbf{y}}-\\mathbf{y})$\u8868\u793a$\\left(\\hat{y}-y\\right)^2$<\/p>\n\n\n\n<p>\u5c0f\u6279\u91cf\u968f\u673a\u68af\u5ea6\u4e0b\u964d\u7684\u8fed\u4ee3\u6b65\u9aa4\u5c06\u76f8\u5e94\u5730\u6539\u5199\u4e3a\uff1a<\/p>\n\n\n\n<p>$$<br>\\mathbf{\\theta} \\leftarrow \\mathbf{\\theta}-\\frac{\\eta}{|\\mathcal{B}|} \\sum_{i \\in \\mathcal{B}} \\nabla_{\\mathbf{\\theta}} \\ell^{(i)}(\\mathbf{\\theta})<br>$$<\/p>\n\n\n\n<p>\u5176\u4e2d\u68af\u5ea6\u662f\u635f\u5931\u6709\u51733\u4e2a\u4e3a\u6807\u91cf\u7684\u6a21\u578b\u53c2\u6570\u7684\u504f\u5bfc\u6570\u7ec4\u6210\u7684\u5411\u91cf\uff1a<\/p>\n\n\n\n<p>$$<br>\\nabla_{\\mathbf{\\theta}} \\ell^{(i)}(\\mathbf{\\theta})=\\left[\\begin{array}{c}<br>\\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial w_1} \\\\<br>\\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial w_2} \\\\<br>\\frac{\\partial \\ell^{(i)}\\left(w_1, w_2, b\\right)}{\\partial b}<br>\\end{array}\\right]=\\left[\\begin{array}{c}<br>x_1^{(i)}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right) \\\\<br>x_2^{(i)}\\left(x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}\\right) \\\\<br>x_1^{(i)} w_1+x_2^{(i)} w_2+b-y^{(i)}<br>\\end{array}\\right]=\\left[\\begin{array}{c}<br>x_1^{(i)} \\\\<br>x_2^{(i)} \\\\<br>1<br>\\end{array}\\right]\\left(\\hat{y}^{(i)}-y^{(i)}\\right)<br>$$<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ebf\u6027\u56de\u5f52\u8f93\u51fa\u7684\u662f\u8fde\u7eed\u503c\uff0c\u9002\u7528\u4e8e\u5982\u9884\u6d4b\u623f\u5c4b\u4ef7\u683c\u3001\u6c14\u6e29\u3001\u9500\u552e\u989d\u7b49\u8fde\u7eed\u503c\u7684\u95ee\u9898\u3002 \u7ebf\u6027\u56de\u5f52\u7684\u57fa\u672c\u8981\u7d20 \u6a21\u578b\u5b9a\u4e49 \u5047\u8bbe\u8f93\u5165\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5206\u522b &#8230;<\/p>","protected":false},"author":1,"featured_media":1396,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,3],"tags":[45,44,12,22],"class_list":["post-1394","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-46","category-3","tag-45","tag-44","tag-12","tag-22"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1394"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1394\/revisions"}],"predecessor-version":[{"id":1728,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1394\/revisions\/1728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1396"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}