{"id":3253,"date":"2022-02-27T13:56:07","date_gmt":"2022-02-27T05:56:07","guid":{"rendered":"https:\/\/egonlin.com\/?p=3253"},"modified":"2022-02-27T14:17:38","modified_gmt":"2022-02-27T06:17:38","slug":"%e7%ac%ac%e4%ba%8c%e8%8a%82%ef%bc%9a%e9%80%9a%e8%bf%87%e7%ba%bf%e6%80%a7%e5%9b%9e%e5%bd%92%e5%b8%a6%e4%bd%a0%e4%ba%86%e8%a7%a3%e7%ae%97%e6%b3%95%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=3253","title":{"rendered":"\u7b2c\u4e8c\u8282\uff1a\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u5e26\u4f60\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b"},"content":{"rendered":"<h1>\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u5e26\u4f60\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b<\/h1>\n<h1>1. 1 \u7ebf\u6027\u56de\u5f52\u5f15\u5165<\/h1>\n<p>&emsp;&emsp;\u76f8\u4fe1\u6211\u4eec\u5f88\u591a\u4eba\u53ef\u80fd\u90fd\u6709\u53bb\u552e\u697c\u5904\u4e70\u623f\u800c\u65e0\u5948\u56de\u5bb6\u7684\u884c\u4e3a\uff0c\u5c31\u7b97\u4f60\u6ca1\u53bb\u8fc7\u552e\u697c\u5904\uff0c\u76f8\u4fe1\u4f60\u4e5f\u5e94\u8be5\u542c\u8bf4\u8fc7\u90a3\u4ee4\u4eba\u53f9\u800c\u60ca\u6b62\u7684\u623f\u4ef7\u5427\uff1f\u5bf9\u4e8e\u9ad8\u623f\u4ef7\u4f60\u6ca1\u6709\u60f3\u8fc7\u8fd9\u623f\u4ef7\u662f\u600e\u4e48\u7b97\u51fa\u6765\u7684\u5462\uff1f\u96be\u9053\u5c31\u662f\u623f\u5730\u4ea7\u5546\u62cd\u62cd\u8111\u95e8\uff0c\u5317\u4eac\u7684\u4e00\u69821000\u4e07\uff0c\u4e0a\u6d77\u7684\u4e00\u6982800\u4e07\uff0c\u676d\u5dde\u7684\u4e00\u6982600\u4e07\u5417\uff1f\u770b\u5230\u8fd9\u76f8\u4fe1\u4f60\u5e94\u8be5\u6709\u52a8\u529b\u60f3\u8981\u5b66\u597d\u673a\u5668\u5b66\u4e60\u8d70\u5411\u4eba\u751f\u5dc5\u5cf0\u4e86\u3002<\/p>\n<p>&emsp;&emsp;\u5176\u5b9e\u4ed4\u7ec6\u60f3\u60f3\u8fd9\u623f\u4ef7\u5927\u6709\u6765\u5934\uff0c\u9996\u5148\u623f\u4ef7\u4e0d\u53ef\u80fd\u53ea\u548c\u5730\u533a\u6709\u5173\uff0c\u5317\u4eac\u67091000\u4e07\u7684\u623f\u5b50\uff0c\u53c8\u4f1a\u6709800\u4e07\u3001600\u4e07\u7684\u623f\u5b50\uff0c\u90a3\u8fd9\u4e9b\u623f\u4ef7\u4e0d\u548c\u5730\u533a\u6709\u5173\u8fd8\u548c\u4ec0\u4e48\u6709\u5173\u5462\uff1f\u5982\u679c\u4f60\u771f\u7684\u4e70\u8fc7\u623f\u5c31\u77e5\u9053\uff0c\u623f\u5b50\u7684\u4ef7\u683c\u9996\u5148\u548c\u5730\u533a\u662f\u6709\u7740\u6bd4\u8f83\u5927\u7684\u8054\u7cfb\u7684\uff0c\u5317\u4eac\u4e94\u73af\u5916\u7684\u623f\u5b50\u53ef\u80fd\u90fd\u9ad8\u4e8e\u676d\u5dde\u4efb\u4f55\u5730\u533a\u7684\u623f\u5b50\uff0c\u5728\u540c\u4e00\u4e2a\u5730\u533a\u5185\uff0c\u623f\u5b50\u7684\u4ef7\u683c\u5927\u591a\u548c\u623f\u5b50\u7684\u5360\u5730\u9762\u79ef\u3001\u6237\u578b\u3001\u91c7\u5149\u5ea6\u7b49\u7b49\u56e0\u7d20\u6709\u5173\u7cfb\u3002<\/p>\n<p>&emsp;&emsp;\u8fd9\u4e2a\u65f6\u5019\u5c31\u6709\u67d0\u4f4d\u806a\u660e\u7684\u6295\u673a\u8005\u60f3\u5230\u4e86\uff0c\u6211\u662f\u4e0d\u662f\u53ef\u4ee5\u627e\u5230\u4e00\u4e2a\u65b9\u6cd5\u6765\u9884\u6d4b\u623f\u4ef7\u5462\uff1f\u5982\u679c\u8fd9\u4e2a\u623f\u5b50\u7684\u623f\u4ef7\u660e\u663e\u5c0f\u4e8e\u8fd9\u6240\u623f\u5b50\u8be5\u6709\u7684\u623f\u4ef7(\u6ce8\uff1a\u623f\u4ef7\u53ef\u80fd\u5728\u67d0\u6bb5\u65f6\u95f4\u7531\u4e8e\u67d0\u79cd\u4e0d\u4e3a\u4eba\u77e5\u7684\u56e0\u7d20\u6709\u5c0f\u5e45\u6ce2\u52a8)\uff0c\u5c31\u628a\u90a3\u6240\u4e70\u8fc7\u6765\u4e86\uff0c\u7b49\u623f\u4ef7\u6da8\u56de\u53bb\u4e86\u518d\u5356\u51fa\u53bb\uff0c\u8fd9\u6837\u770b\u8d77\u6765\u4e5f\u662f\u751f\u8d22\u4e4b\u9053\u3002(\u6ce8\uff1a\u7eaf\u5c5e\u865a\u6784)<\/p>\n<p>&emsp;&emsp;\u53ef\u662f\u5982\u679c\u53bb\u9884\u6d4b\u623f\u4ef7\u5462\uff1f\u4e0a\u9762\u8bb2\u5230\u4e86\u623f\u4ef7\u548c\u623f\u5b50\u6240\u5728\u5730\u533a$x_1$\u3001\u5360\u5730\u9762\u79ef$x_2$\u3001\u6237\u578b$x_3$\u548c\u91c7\u5149\u5ea6$x_4$\u6709\u5173\uff0c\u90a3\u4e48\u6211\u662f\u4e0d\u662f\u53ef\u4ee5\u628a\u8fd9\u4e9b\u56e0\u7d20\u5047\u60f3\u6210\u623f\u5b50\u7684\u7279\u5f81\uff0c\u7136\u540e\u7ed9\u8fd9\u4e9b\u6bcf\u4e2a\u7279\u5f81\u90fd\u52a0\u4e0a\u4e00\u4e2a\u76f8\u5e94\u7684\u6743\u91cd$\\omega$\uff0c\u65e2\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u7684\u51b3\u7b56\u51fd\u6570<br \/>\n$$<br \/>\n\\hat{Y} = \\omega_1x_1 + \\omega_2x_2 + \\omega_3x_3 + \\omega_4x_4 + b<br \/>\n$$<br \/>\n\u5176\u4e2d$b$\u53ef\u4ee5\u7406\u89e3\u4e3a\u504f\u5dee\uff0c\u4f60\u4e5f\u53ef\u4ee5\u60f3\u6210\u623f\u5b50\u7684\u8fd9\u4e9b\u7279\u5f81\u518d\u5dee\u4e5f\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u5e95\u4ef7\u3002<\/p>\n<p>&emsp;&emsp;\u57fa\u4e8e\u4e0a\u8ff0\u7ed9\u51fa\u623f\u4ef7\u7684\u51b3\u7b56\u51fd\u6570\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u67d0\u4e2a\u4e0d\u77e5\u540d\u7684\u623f\u5b50\u8f93\u5165\u5b83\u7684\u8fd9\u4e9b\u7279\u5f81\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5f97\u5230\u8fd9\u6240\u623f\u5b50\u7684\u9884\u6d4b\u4ef7\u683c\u4e86\u3002<\/p>\n<p>&emsp;&emsp;\u7406\u60f3\u603b\u662f\u7f8e\u597d\u7684\uff0c\u5373\u4e00\u6761\u751f\u8d22\u4e4b\u9053\u5c31\u5728\u773c\u524d\uff0c\u4f46\u662f\u6211\u4eec\u5982\u4f55\u53bb\u5f97\u5230\u8fd9\u4e2a\u51b3\u7b56\u51fd\u6570\u5462\uff1f\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u8fd9\u4e2a\u7279\u5f81\u503c\uff0c\u4f46\u662f\u8fd9\u4e2a$\\omega$\u600e\u4e48\u5f97\u5230\u5462\uff1f\u8fd9\u5c31\u662f\u6211\u4eec\u7684\u7ebf\u6027\u56de\u5f52\u9700\u8981\u89e3\u51b3\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u8ba9\u6211\u4eec\u4e00\u8d77\u8d70\u5411\u8fd9\u6761\u751f\u8d22\u4e4b\u9053\u5427\uff01<\/p>\n<h1>1. 2 \u51b3\u7b56\u51fd\u6570<\/h1>\n<p>&emsp;&emsp;\u4f60\u53ef\u4ee5\u7b80\u5355\u7684\u8ba4\u4e3a\u7ebf\u6027\u56de\u5f52\u5c31\u662f\u627e\u5230\u4e00\u6761\u66f2\u7ebf\u53bb\u62df\u5408\u6240\u6709\u6837\u672c\u70b9\uff0c\u4e0a\u9762\u63d0\u53ca\u4e70\u623f\u7684\u95ee\u9898\u6709\u56db\u4e2a\u7279\u5f81\uff0c\u56e0\u6b64\u6211\u4eec\u5f97\u5230\u7684\u51b3\u7b56\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\n\\hat{Y} = \\omega_1x_1 + \\omega_2x_2 + \\omega_3x_3 + \\omega_4x_4 + b<br \/>\n$$<\/p>\n<p>&emsp;&emsp;\u5bf9\u4e8e$n$\u4e2a\u7279\u5f81\u7684\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u627e\u5230\u4e00\u6761\u66f2\u7ebf\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u6210\u662f\u4e00\u4e2a\u51b3\u7b56\u51fd\u6570<br \/>\n$$<br \/>\n\\hat{Y}=f_\\theta(X)=\\theta_1x_1+\\theta_2x_2+\\cdots+\\theta_nx_n+b=\\theta^TX+b<br \/>\n$$<br \/>\n\u62df\u5408\u6240\u6709\u6837\u672c\u70b9\u3002\u5176\u4e2d$b$\u4e3a\u672a\u77e5\u53c2\u6570\u504f\u7f6e\uff08bias\uff09\uff1b$\\theta$\u4e3a\u672a\u77e5\u53c2\u6570\u5411\u91cf$[\\theta_1,\\theta_2,\\cdots,\\theta_n]$\uff1b$X$\u4e3a\u6837\u672c\u5728\u5404\u4e2a\u7279\u5f81\u4e0a\u7684\u7279\u5f81\u503c\uff0c\u7528\u5411\u91cf\u8868\u793a\u4e3a$[x_1,x_2,\\cdots,x_n]$\uff1b$\\theta^T$\u4e3a\u5411\u91cf$\\theta$\u7684\u8f6c\u7f6e<br \/>\n$$<br \/>\n\\begin{bmatrix}<br \/>\n\\theta_1 \\<br \/>\n\\theta_2 \\<br \/>\n\\vdots \\<br \/>\n\\theta_n<br \/>\n\\end{bmatrix}<br \/>\n$$<br \/>\n\uff1b<br \/>\n$$<br \/>\n\\theta^TX=<br \/>\n\\begin{bmatrix}<br \/>\n\\theta_1 \\<br \/>\n\\theta_2 \\<br \/>\n\\vdots \\<br \/>\n\\theta_n<br \/>\n\\end{bmatrix}<\/p>\n<ul>\n<li>[x_1,x_2,\\cdots,x_n] = \\theta_1x_1+\\theta_2x_2+\\cdots+\\theta_nx<em>n<br \/>\n$$<br \/>\n\u5982\u679c\u4f60\u5bf9\u77e9\u9635\u8fd0\u7b97\u4e0d\u719f\u6089\uff0c\u7262\u8bb0$f<\/em>\\theta(X)=\\theta_1x_1+\\theta_2x_2+\\cdots+\\theta_nx_n+b=\\theta^TX+b$\u5373\u53ef\u3002<\/li>\n<\/ul>\n<p>&emsp;&emsp;\u5982\u679c\u628a\u672a\u77e5\u53c2\u6570$b$\u770b\u6210$\\theta<em>0$\uff0c\u66f2\u7ebf\u4e3a<br \/>\n$$<br \/>\n\\hat{Y}=f<\/em>\\theta(X)=\\theta_0x_0+\\theta_1x_1+\\theta_2x_2+\\cdots+\\theta_nx_n+b=\\theta^TX<br \/>\n$$<br \/>\n\u5176\u4e2d$x_0=1$\u3002<\/p>\n<p>&emsp;&emsp;\u867d\u7136\u5176\u4ed6\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u7684\u51b3\u7b56\u51fd\u6570\u4e0d\u4e00\u5b9a\u662f\u7ebf\u6027\u56de\u5f52\u7684$f_\\theta(X)=\\theta^T{X}$\uff0c\u4f46\u662f\u51b3\u7b56\u51fd\u6570\u4e2d\u4e00\u822c\u90fd\u4f1a\u6709\u4e00\u4e2a\u672a\u77e5\u53c2\u6570$\\theta$\uff0c\u4ee5\u540e\u5bf9\u4e8e\u6240\u6709\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u90fd\u4f1a\u9010\u4e00\u8bb2\u89e3\u4e3a\u4ec0\u4e48\u4f1a\u6709\u8fd9\u4e2a\u53c2\u6570\u3002<\/p>\n<h1>1. 3 \u635f\u5931\u51fd\u6570<\/h1>\n<pre><code class=\"language-python\"># \u635f\u5931\u51fd\u6570\u56fe\u4f8b\nimport matplotlib.pyplot as plt\nfrom matplotlib.font_manager import FontProperties\nfrom sklearn.datasets.samples_generator import make_regression\n%matplotlib inline\nfont = FontProperties(fname=&#039;\/Library\/Fonts\/Heiti.ttc&#039;)\n\n# \u751f\u6210\u968f\u673a\u6570\u636e\n# X\u4e3a\u6837\u672c\u7279\u5f81\uff0cy\u4e3a\u6837\u672c\u8f93\u51fa\uff0ccoef\u4e3a\u56de\u5f52\u7cfb\u6570\uff0c\u5171100\u4e2a\u6837\u672c\uff0c5\u4e2a\u566a\u58f0\uff0c\u6bcf\u4e2a\u6837\u672c1\u4e2a\u7279\u5f81\uff0c\u6570\u636e\u96c6\u968f\u673a\u79cd\u5b50\u4e3a1\nX, y, coef = make_regression(\n    n_samples=100, n_features=1, noise=50, coef=True, random_state=1)\n\n# \u6563\u70b9\u56fe+\u76f4\u7ebf\nplt.scatter(X, y, color=&#039;g&#039;, s=50, label=&#039;\u623f\u5b50\u4fe1\u606f&#039;)\nplt.plot(X, X*coef, color=&#039;r&#039;, linewidth=2)\n\nplt.xlabel(&#039;\u623f\u5b50\u9762\u79ef&#039;, fontproperties=font, fontsize=15)\nplt.ylabel(&#039;\u623f\u4ef7&#039;, fontproperties=font, fontsize=15)\nplt.title(&#039;\u623f\u5b50\u9762\u79ef-\u623f\u4ef7&#039;, fontproperties=font, fontsize=20)\n# \u53bb\u6389x,y\u8f74\u5c3a\u5ea6\nplt.xticks(())\nplt.yticks(())\nplt.legend(prop=font)\nplt.show()<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_6_0.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_6_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>&emsp;&emsp;\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u4e0a\u56fe\u5047\u8bbe\u6bcf\u4e00\u4e2a\u7eff\u70b9\u8868\u793a\u4e00\u6240\u623f\u5b50\u7684\u4fe1\u606f\uff0c\u7ea2\u8272\u7684\u76f4\u7ebf\u4e3a\u6211\u4eec\u901a\u8fc7\u67d0\u79cd\u65b9\u6cd5\u5f97\u5230\u4e00\u4e2a\u51b3\u7b56\u51fd\u6570$\\hat{Y}=f_\\theta(X)=\\theta^T{X}+b=\\theta_1x+b$\u3002\u5bf9\u4e8e\u76d1\u7763\u6a21\u578b\u4e2d\u7684\u901a\u8fc7\u623f\u5b50\u9762\u79ef\u9884\u6d4b\u623f\u4ef7\u4f8b\u5b50\uff0c\u6211\u4eec\u662f\u5047\u8bbe\u5df2\u77e5$\\theta_1=10,b=0$\u3002<\/p>\n<p>&emsp;&emsp;\u4f46\u662f\u5982\u679c\u4f60\u773c\u529b\u52b2\u8fd8\u4e0d\u9519\uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u6211\u4eec\u7684\u8fd9\u4e2a\u51b3\u7b56\u51fd\u6570\u5e76\u6ca1\u6709\u5b8c\u5168\u7ecf\u8fc7\u8fd9\u4e9b\u6570\u636e\u70b9\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u662f\u6ca1\u6709\u5b8c\u5168\u62df\u5408\u8fd9\u4e9b\u6570\u636e\u70b9\u3002\u4e00\u822c\u6211\u4eec\u7684\u51b3\u7b56\u51fd\u6570\u90fd\u662f\u65e0\u6cd5\u7ecf\u8fc7\u6240\u6709\u70b9\u7684\uff0c\u4f60\u8981\u77e5\u9053\u673a\u5668\u5b66\u4e60\u662f\u4e0d\u53ef\u80fd\u505a\u5230\u9884\u8a00\u7684\uff0c\u800c\u53ea\u80fd\u505a\u5230\u9884\u6d4b\uff0c\u9884\u8a00\u6709\u65f6\u5019\u90fd\u4f1a\u4e0d\u51c6\u786e\uff0c\u66f4\u522b\u8bf4\u9884\u6d4b\u4e86\uff0c\u4e5f\u5c31\u662f\u8bf4\u673a\u5668\u5b66\u4e60\u5bf9\u65b0\u6570\u636e\u7684\u9884\u6d4b\u662f\u6709\u8bef\u5dee\u7684\u3002\u901a\u5e38\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u635f\u5931\u51fd\u6570\uff08loss function\uff09\u6216\u4ee3\u4ef7\u51fd\u6570\uff08cost function\uff09\u5ea6\u91cf\u6a21\u578b\u9884\u6d4b\u9519\u8bef\u7684\u7a0b\u5ea6<br \/>\n$$<br \/>\nL(Y-\\hat{Y})=L(Y-f_\\theta(X))<br \/>\n$$<br \/>\n\u5176\u4e2d$Y$\u4e3a\u6837\u672c\u7684\u771f\u5b9e\u503c\uff0c$\\hat{Y}$\u4e3a\u6837\u672c\u7684\u9884\u6d4b\u503c\u3002<\/p>\n<p>\u56db\u79cd\u5e38\u7528\u7684\u635f\u5931\u51fd\u6570\uff1a<\/p>\n<ol>\n<li>\u5e73\u65b9\u635f\u5931\u51fd\u6570\uff08quadratic loss function\uff09<br \/>\n$$<br \/>\nL(Y,f<em>\\theta(X))=(Y-f<\/em>\\theta(X))^2<br \/>\n$$<\/li>\n<li>\u7edd\u5bf9\u503c\u635f\u5931\u51fd\u6570\uff08absolute loss fuction\uff09<br \/>\n$$<br \/>\nL(Y,f<em>\\theta(X))=|Y-f<\/em>\\theta(X)|<br \/>\n$$<\/li>\n<li>0-1\u635f\u5931\u51fd\u6570\uff080-1 loss function\uff09<br \/>\n$$<br \/>\nL(Y,f<em>\\theta(X))<br \/>\n\\begin{cases}<br \/>\n1,&amp;Y\\neq{f<\/em>\\theta(X)} \\<br \/>\n0,&amp;Y=f_\\theta(X)<br \/>\n\\end{cases}<br \/>\n$$<\/li>\n<li>\u5bf9\u6570\u635f\u5931\u51fd\u6570\uff08logarithmic loss function\uff09\u6216\u5bf9\u6570\u4f3c\u7136\u635f\u5931\u51fd\u6570\uff08log-likelihood loss function\uff09<br \/>\n$$<br \/>\nL(Y,f_\\theta(X))=-\\log{P(Y|X)}<br \/>\n$$<\/li>\n<\/ol>\n<h1>1. 4 \u76ee\u6807\u51fd\u6570<\/h1>\n<p>&emsp;&emsp;\u635f\u5931\u51fd\u6570\u4e00\u822c\u662f\u5bf9\u67d0\u4e2a\u6837\u672c\u635f\u5931\u7684\u8ba1\u7b97\uff0c\u4f46\u662f\u6211\u4eec\u7684\u6a21\u578b\u5f88\u660e\u663e\u4e0d\u662f\u7531\u4e00\u4e2a\u6837\u672c\u751f\u6210\u7684\uff0c\u800c\u662f\u7531\u4e00\u7ec4\u6837\u672c\u751f\u6210\u7684\u3002\u7531\u4e8e$X$\u548c$Y$\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6570\u636e\u83b7\u5f97\uff0c\u4f46\u662f\u672a\u77e5\u53c2\u6570$\\theta$\u662f\u672a\u77e5\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u5728\u8fd9\u91cc\u7ed9\u51fa\u5173\u4e8e$\\theta$\u7684\u76ee\u6807\u51fd\u6570\uff08objective function\uff09\uff0c\u5373\u6240\u6709\u6837\u672c\u7684\u8bef\u5dee\u52a0\u548c\u53d6\u5e73\u5747<br \/>\n$$<br \/>\nJ(\\theta)= \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x<em>i))<br \/>\n$$<br \/>\n\u5176\u4e2d$m$\u662f\u6837\u672c\u603b\u6570\uff0c$\\sum<\/em>{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i))= L(y<em>1,f<\/em>{\\theta_1}(x_1))+L(y<em>2,f<\/em>{\\theta_2}(x_2))+\\cdots+L(y<em>m,f<\/em>{\\theta_m}(x_m))$<\/p>\n<h1>1. 5 \u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316<\/h1>\n<p>&emsp;&emsp;\u5047\u8bbe\u6211\u4eec\u5f97\u5230\u4e86\u76ee\u6807\u51fd\u6570\uff0c\u90a3\u4e48\u6211\u4eec\u63a5\u4e0b\u6765\u8981\u5e72\u4ec0\u4e48\u5462\uff1f\u76ee\u6807\u51fd\u6570\u662f\u6240\u6709\u6837\u672c\u7684\u8bef\u5dee\u52a0\u548c\u53d6\u5e73\u5747\uff0c\u90a3\u4e48\u662f\u4e0d\u662f\u8fd9\u4e2a\u8bef\u5dee\u8d8a\u5c0f\u8d8a\u597d\u5462\uff1f\u5bf9\uff0c\u4f60\u6682\u65f6\u53ef\u4ee5\u8fd9\u6837\u60f3\uff0c\u8bef\u5dee\u8d8a\u5c0f\uff0c\u5219\u6211\u4eec\u7684\u9884\u6d4b\u503c\u4f1a\u8d8a\u6765\u8d8a\u63a5\u8fd1\u771f\u5b9e\u503c\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u662f\u9700\u8981\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\uff0c\u7531\u4e8e\u76ee\u6807\u51fd\u6570\u5728\u7edf\u8ba1\u5b66\u4e2d\u88ab\u79f0\u4e3a\u7ecf\u9a8c\u98ce\u9669\uff08empirical risk\uff09\uff0c\u6240\u4ee5\u6709\u65f6\u5019\u4e5f\u4f1a\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u4e5f\u4f1a\u88ab\u79f0\u4e3a\u7ecf\u9a8c\u98ce\u9669\u6700\u5c0f\u5316\uff08empirical risk minimization\uff09\u3002<br \/>\n$$<br \/>\n\\min{J(\\theta)} = \\min \\frac{1}{m}\\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i))<br \/>\n$$<br \/>\n\u5176\u4e2d$\\min{J(\\theta)}$\u8868\u793a\u6700\u5c0f\u5316$J(\\theta)$\u51fd\u6570\u3002<\/p>\n<p>&emsp;&emsp;\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e3e\u4f8b\uff0c\u7531\u4e8e$f<em>{\\theta}(X)=\\theta^TX$\uff0c\u5219\u5b83\u7684\u635f\u5931\u51fd\u6570\u662f<br \/>\n$$<br \/>\nL(Y,f<\/em>\\theta(X)) = L(Y,\\theta^TX)<br \/>\n$$<br \/>\n\u5b83\u7684\u76ee\u6807\u51fd\u6570\u662f<br \/>\n$$<br \/>\nJ(\\theta)=\\frac{1}{m} \\sum_{i=1}^m L(y_i,\\theta_i{x_i})<br \/>\n$$<\/p>\n<p>&emsp;&emsp;\u5047\u8bbe\u4e0a\u8ff0\u76ee\u6807\u51fd\u6570\u4f7f\u7528\u4e86\u5e73\u65b9\u635f\u5931\u51fd\u6570\uff0c\u5219\u76ee\u6807\u51fd\u6570\u53d8\u6210<br \/>\n$$<br \/>\nJ(\\theta) = \\frac{1}{m} \\sum_{i=1}^m (y_i-\\theta_i{x<em>i})^2<br \/>\n$$<br \/>\n\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\n\\begin{align}<br \/>\n\\min{J(\\theta)} &amp; = \\min \\frac{1}{m} \\sum<\/em>{i=1}^m (y_i-\\theta_i{x_i})^2 \\<br \/>\n&amp; = \\min \\frac{1}{m} [(y_1-\\theta_1{x_1})^2+(y_2-\\theta_2{x_2})^2+\\cdots+(y_m-\\theta_m{x_m})^2]<br \/>\n\\end{align}<br \/>\n$$<br \/>\n\u5176\u4e2d${x_1,x_2,\\cdots,x_m}$\u3001${y_1,y_2,\\cdots,y_m}$\u3001$m$\u90fd\u662f\u5df2\u77e5\u7684\uff0c\u5373\u6211\u4eec\u53ef\u4ee5\u628a\u4ed6\u4eec\u770b\u6210\u4e00\u4e2a\u5e38\u6570\u3002<\/p>\n<p>&emsp;&emsp;\u5982\u679c\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u6781\u7aef\u60c5\u51b5\uff0c\u5373\u5047\u8bbe$x_i=1,\\,(i=1,2,\\cdots,m)$\u3001$y_i=2,\\,(y=1,2,\\cdots,m)$\u3001$m=100$\u3001$\\theta_1=\\theta_2=\\cdots=\\theta_m=\\theta_j$\uff0c\u5219\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u53d8\u4e3a<br \/>\n$$<br \/>\n\\begin{align}<br \/>\n\\min{J(\\theta)} &amp; = \\min \\frac{1}{100} \\underbrace{[(2-\\theta_j<em>1)^2+(2-\\theta_j<\/em>1)^2+\\cdots+(2-\\theta<em>j*1)^2]}<\/em>{100} \\<br \/>\n&amp; = \\min \\frac{1}{100} 100<em>[(2-\\theta_j<\/em>1)^2] \\<br \/>\n&amp; = \\min (2-\\theta_j*1)^2<br \/>\n\\end{align}<br \/>\n$$<\/p>\n<pre><code class=\"language-python\"># \u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316\u56fe\u4f8b\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\n# \u751f\u6210\u4e00\u4e2a\u6570\u7ec4(-4.98,-4.96,...,4.98,5)\ntheta_j = np.arange(-5, 5, 0.02)\n# \u6784\u9020J_theta\u66f2\u7ebf\nJ_theta_j = (2-theta_j)**2\n\n# \u63cf\u7ed8\u66f2\u7ebf\nplt.plot(theta_j, J_theta_j, color=&#039;r&#039;, linewidth=2)\n\nplt.xlabel(&#039;$\u03b8$&#039;, fontproperties=font, fontsize=15)\nplt.ylabel(&#039;$min{J(\u03b8)}$&#039;, fontproperties=font, fontsize=15)\nplt.title(&#039;$\\min{J(\u03b8)}=(2-\u03b8_j*1)^2$&#039;, fontproperties=font, fontsize=20)\nplt.show()<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_12_0.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_12_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>&emsp;&emsp;\u4e0a\u56fe\u5373\u6211\u4eec\u5047\u8bbe\u7684\u76ee\u6807\u51fd\u6570\u7684\u56fe\u50cf\uff0c\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u5982\u679c\u8981\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u5219\u9700\u8981\u627e\u5230\u80fd\u4f7f\u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316\u7684\u53c2\u6570\u5411\u91cf$\\theta$\uff0c\u901a\u8fc7\u516c\u5f0f\u53ef\u4ee5\u8868\u793a\u4e3a<br \/>\n$$<br \/>\n\\underbrace{arg\\,\\min}<em>\\theta{J(\\theta)}=\\frac{1}{m}\\sum<\/em>{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x<em>i))<br \/>\n$$<br \/>\n\u5176\u4e2d$\\underbrace{arg\\,\\min}<\/em>\\theta{J(\\theta)}$\u8868\u793a\u627e\u5230\u80fd\u4f7f$J(\\theta)$\u6700\u5c0f\u5316\u7684\u53c2\u6570\u5411\u91cf$\\theta$\u3002<\/p>\n<p>&emsp;&emsp;\u7531\u4e8e\u8fd9\u91cc\u53ea\u4ecb\u7ecd\u76ee\u6807\u51fd\u548c\u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316\u95ee\u9898\uff0c\u600e\u4e48\u627e\u80fd\u4f7f\u5f97\u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316\u7684$\\theta$\u4e0d\u5728\u6b64\u5904\u4ecb\u7ecd\u8303\u56f4\uff0c\u4ee5\u540e\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u3002\u76f8\u4fe1\u4f60\u5bf9\u76ee\u6807\u51fd\u6570\u7684\u6784\u9020\u3001\u76ee\u6807\u51fd\u6570\u6700\u5c0f\u5316\uff08\u76ee\u6807\u51fd\u6570\u4f18\u5316\u95ee\u9898\uff09\u6709\u4e86\u4e00\u4e2a\u660e\u786e\u7684\u8ba4\u77e5\uff0c\u81f3\u4e8e\u76ee\u6807\u51fd\u6570\u4e2d\u57cb\u4e0b\u7684\u51e0\u5904\u4f0f\u7b14\uff0c\u4ee5\u540e\u90fd\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u76ee\u524d\u7684\u4f60\u53ea\u9700\u8981\u4e86\u89e3\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u4ee5\u540e\u6211\u4eec\u4f1a\u901a\u8fc7\u5177\u4f53\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u6765\u518d\u4e00\u6b21\u89e3\u91ca\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u5e76\u4e14\u4ee5\u540e\u4f60\u4f1a\u53d1\u73b0\u5176\u5b9e\u6211\u4eec\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684\u6240\u6709\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u90fd\u662f\u57fa\u4e8e\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u6240\u4ee5\u4f60\u4f1a\u53cd\u590d\u518d\u53cd\u590d\u63a5\u89e6\u8fd9\u4e2a\u6d41\u7a0b\uff0c\u5982\u679c\u73b0\u5728\u80fd\u6709\u4e2a\u660e\u786e\u7684\u8ba4\u77e5\u5f88\u597d\uff0c\u5982\u679c\u4e0d\u53ef\u4ee5\u7b49\u628a\u8fd9\u4e2a\u6d41\u7a0b\u4e0e\u67d0\u4e2a\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u8054\u7cfb\u5728\u4e00\u8d77\u7684\u65f6\u5019\u76f8\u4fe1\u4f60\u80fd\u7406\u89e3\u4ed6\u3002<\/p>\n<h1>1. 6 \u8fc7\u62df\u5408<\/h1>\n<p>&emsp;&emsp;\u5728\u8fd9\u91cc\u6211\u5fc5\u987b\u5f97\u660e\u786e\u544a\u8bc9\u4f60\uff0c\u7406\u8bba\u4e0a\u6a21\u578b\u53ef\u80fd\u662f\u8d8a\u5c0f\u8d8a\u597d\uff0c\u4f46\u662f\u5728\u5de5\u4e1a\u4e0a\u6a21\u578b\u5e76\u4e0d\u662f\u8bef\u5dee\u8d8a\u5c0f\u8d8a\u597d\u3002\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3\u60f3\uff0c\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u6570\u636e\u96c6\uff0c\u8fd9\u4e2a\u6570\u636e\u96c6\u96be\u9053\u4e0d\u4f1a\u6709\u566a\u97f3\uff08noise\uff09\u6216\u566a\u58f0\u5417\uff1f\u9996\u5148\u6211\u53ef\u4ee5\u5f88\u660e\u786e\u7684\u544a\u8bc9\u4f60\uff0c\u4e00\u822c\u7684\u5de5\u4e1a\u4e0a\u7684\u6570\u636e\u90fd\u4f1a\u6709\u566a\u58f0\uff0c\u5982\u679c\u6211\u4eec\u7684\u6a21\u578b\u7ecf\u8fc7\u4e86\u5305\u62ec\u566a\u58f0\u7684\u6240\u6709\u6837\u672c\u70b9\uff0c\u4e5f\u5c31\u662f\u8bf4\u6a21\u578b\u5bf9\u6211\u4eec\u7684\u8bad\u7ec3\u96c6\u505a\u5230\u4e86\u5b8c\u7f8e\u62df\u5408\uff0c\u8fd9\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u8fc7\u62df\u5408\uff08over-fitting\uff09\uff0c\u5e76\u4e14\u8fc7\u62df\u5408\u65f6\u6a21\u578b\u4e5f\u4f1a\u53d8\u5f97\u76f8\u5bf9\u590d\u6742\u3002<\/p>\n<p>\u4ea7\u751f\u566a\u58f0\u7684\u539f\u56e0\uff1a<\/p>\n<ol>\n<li>\u8bad\u7ec3\u6570\u636e\u7684\u6807\u7b7e\u9519\u8bef\uff0c\u5373A\u7c7b\u7684\u6570\u636e\u6807\u8bb0\u4e3aB\u7c7b\uff1bB\u7c7b\u7684\u6570\u636e\u6807\u8bb0\u4e3aA\u7c7b<\/li>\n<li>\u8f93\u5165\u6570\u636e\u67d0\u4e00\u7ef4\u7279\u5f81\u503c\u4e0d\u51c6\u786e\u7684\uff0c\u4e0b\u56fe\u6240\u793a\u7684\u7ea2\u70b9<\/li>\n<\/ol>\n<pre><code class=\"language-python\"># \u8fc7\u62df\u5408\u56fe\u4f8b\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib.font_manager import FontProperties\nfrom sklearn.preprocessing import PolynomialFeatures\nfrom sklearn.linear_model import LinearRegression\nfont = FontProperties(fname=&#039;\/Library\/Fonts\/Heiti.ttc&#039;)\n%matplotlib inline\n\n# \u81ea\u5b9a\u4e49\u6570\u636e\u5e76\u5904\u7406\u6570\u636e\ndata_frame = {&#039;x&#039;: [2, 1.5, 3, 3.2, 4.22, 5.2, 6, 6.7],\n              &#039;y&#039;: [0.5, 3.5, 5.5, 5.2, 5.5, 5.7, 5.5, 6.25]}\ndf = pd.DataFrame(data_frame)\nX, y = df.iloc[:, 0].values.reshape(-1, 1), df.iloc[:, 1].values.reshape(-1, 1)\n\n# \u7ebf\u6027\u56de\u5f52\nlr = LinearRegression()\nlr.fit(X, y)\n\ndef poly_lr(degree):\n    &quot;&quot;&quot;\u591a\u9879\u5f0f\u56de\u5f52&quot;&quot;&quot;\n    poly = PolynomialFeatures(degree=degree)\n    X_poly = poly.fit_transform(X)\n    lr_poly = LinearRegression()\n    lr_poly.fit(X_poly, y)\n    y_pred_poly = lr_poly.predict(X_poly)\n\n    return y_pred_poly\n\ndef plot_lr():\n    &quot;&quot;&quot;\u5bf9\u7ebf\u6027\u56de\u5f52\u751f\u6210\u7684\u56fe\u7ebf\u753b\u56fe&quot;&quot;&quot;\n    plt.scatter(X, y, c=&#039;k&#039;, edgecolors=&#039;white&#039;, s=50)\n    plt.plot(X, lr.predict(X), color=&#039;r&#039;, label=&#039;lr&#039;)\n    # \u566a\u58f0\n    plt.scatter(2, 0.5, c=&#039;r&#039;)\n    plt.text(2, 0.5, s=&#039;$(2,0.5)$&#039;)\n\n    plt.xlim(0, 7)\n    plt.ylim(0, 8)\n    plt.xlabel(&#039;x&#039;)\n    plt.ylabel(&#039;y&#039;)\n    plt.legend()\n\ndef plot_poly(degree, color):\n    &quot;&quot;&quot;\u5bf9\u591a\u9879\u5f0f\u56de\u5f52\u751f\u6210\u7684\u56fe\u7ebf\u753b\u56fe&quot;&quot;&quot;\n    plt.scatter(X, y, c=&#039;k&#039;, edgecolors=&#039;white&#039;, s=50)\n    plt.plot(X, poly_lr(degree), color=color, label=&#039;m={}&#039;.format(degree))\n    # \u566a\u58f0\n    plt.scatter(2, 0.5, c=&#039;r&#039;)\n    plt.text(2, 0.5, s=&#039;$(2,0.5)$&#039;)\n\n    plt.xlim(0, 7)\n    plt.ylim(0, 8)\n    plt.xlabel(&#039;x&#039;)\n    plt.ylabel(&#039;y&#039;)\n    plt.legend()\n\ndef run():\n    plt.figure()\n    plt.subplot(231)\n    plt.title(&#039;\u56fe1(\u7ebf\u6027\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_lr()\n    plt.subplot(232)\n    plt.title(&#039;\u56fe2(\u4e00\u9636\u591a\u9879\u5f0f\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_poly(1, &#039;orange&#039;)\n    plt.subplot(233)\n    plt.title(&#039;\u56fe3(\u4e09\u9636\u591a\u9879\u5f0f\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_poly(3, &#039;gold&#039;)\n    plt.subplot(234)\n    plt.title(&#039;\u56fe4(\u4e94\u9636\u591a\u9879\u5f0f\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_poly(5, &#039;green&#039;)\n    plt.subplot(235)\n    plt.title(&#039;\u56fe5(\u4e03\u9636\u591a\u9879\u5f0f\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_poly(7, &#039;blue&#039;)\n    plt.subplot(236)\n    plt.title(&#039;\u56fe6(\u5341\u9636\u591a\u9879\u5f0f\u56de\u5f52)&#039;, fontproperties=font, color=&#039;r&#039;, fontsize=12)\n    plot_poly(10, &#039;violet&#039;)\n    plt.show()\n\nrun()<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_16_0.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/08-01-\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b_16_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>&emsp;&emsp;\u5982\u4e0a\u56fe\u6240\u793a\u6bcf\u5f20\u56fe\u90fd\u6709\u76f8\u540c\u5206\u5e03\u76848\u4e2a\u6837\u672c\u70b9\uff0c\u7ea2\u70b9\u660e\u663e\u662f\u4e00\u4e2a\u566a\u58f0\u70b9\uff0c\u63a5\u4e0b\u6765\u5c06\u8bb2\u89e3\u4e0a\u8ff08\u5f20\u56fe\u3002\u6682\u65f6\u4e0d\u7528\u592a\u5173\u5fc3\u7ebf\u6027\u56de\u5f52\u548c\u591a\u9879\u5f0f\u56de\u5f52\u662f\u4ec0\u4e48\uff0c\u8fd9\u4e24\u4e2a\u4ee5\u540e\u4f60\u90fd\u4f1a\u5b66\u4e60\u5230\uff0c\u6b64\u5904\u5f15\u7528\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u4e3e\u4f8b\u3002<\/p>\n<ul>\n<li>\u56fe1\uff1a\u7ebf\u6027\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u53ef\u4ee5\u53d1\u73b0\u6837\u672c\u70b9\u8ddd\u79bb\u62df\u5408\u66f2\u7ebf\u5f88\u8fdc\uff0c\u8fd9\u4e2a\u65f6\u5019\u4e00\u822c\u79f0\u4f5c\u6b20\u62df\u5408\uff08underfitting\uff09<\/li>\n<li>\u56fe2\uff1a\u4e00\u9636\u591a\u9879\u5f0f\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u7b49\u540c\u4e8e\u7ebf\u6027\u56de\u5f52<\/li>\n<li>\u56fe3\uff1a\u4e09\u9636\u591a\u9879\u5f0f\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u8868\u73b0\u8fd8\u4e0d\u9519<\/li>\n<li>\u56fe4\uff1a\u4e94\u9636\u591a\u9879\u5f0f\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u660e\u663e\u8fc7\u62df\u5408<\/li>\n<li>\u56fe5\uff1a\u4e03\u9636\u591a\u9879\u5f0f\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u5df2\u7ecf\u62df\u5408\u4e86\u6240\u6709\u7684\u6837\u672c\u70b9\uff0c\u6bcb\u5eb8\u7f6e\u7591\u7684\u8fc7\u62df\u5408<\/li>\n<li>\u56fe7\uff1a\u5341\u9636\u591a\u9879\u5f0f\u56de\u5f52\u62df\u5408\u6837\u672c\u70b9\uff0c\u62df\u5408\u6837\u672c\u70b9\u7684\u66f2\u7ebf\u548c\u4e03\u9636\u591a\u9879\u5f0f\u5df2\u7ecf\u6ca1\u6709\u4e86\u533a\u522b\uff0c\u53ef\u4ee5\u60f3\u8c61\u5341\u9636\u4e4b\u540e\u7684\u66f2\u7ebf\u4e5f\u7c7b\u4f3c\u4e8e\u4e03\u9636\u591a\u9879\u5f0f\u7684\u62df\u5408\u66f2\u7ebf<\/li>\n<\/ul>\n<p>&emsp;&emsp;\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u8fc7\u62df\u5408\u6a21\u578b\u5c06\u4f1a\u53d8\u5f97\u590d\u6742\uff0c\u5bf9\u4e8e\u7ebf\u6027\u56de\u5f52\u800c\u8a00\uff0c\u5b83\u53ef\u80fd\u9700\u8981\u66f4\u9ad8\u9636\u7684\u591a\u9879\u5f0f\u53bb\u62df\u5408\u6837\u672c\u70b9\uff0c\u5bf9\u4e8e\u5176\u4ed6\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\uff0c\u4e5f\u662f\u5982\u6b64\u3002\u8fd9\u4e2a\u65f6\u5019\u4f60\u4e5f\u53ef\u4ee5\u60f3\u8c61\uff0c\u8fc7\u62df\u5408\u867d\u7136\u5bf9\u62df\u5408\u7684\u6837\u672c\u70b9\u7684\u8bef\u5dee\u63a5\u8fd10\uff0c\u4f46\u662f\u5bf9\u4e8e\u672a\u6765\u65b0\u6570\u636e\u800c\u8a00\uff0c\u5982\u679c\u65b0\u6570\u636e\u7684$x=2$\uff0c\u5982\u679c\u4f7f\u7528\u8fc7\u62df\u5408\u7684\u66f2\u7ebf\u8fdb\u884c\u62df\u5408\u65b0\u6570\u636e\uff0c\u90a3\u4e48\u4f1a\u7ed9\u51fa$y=0.5$\u7684\u9884\u6d4b\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\u628a\u566a\u58f0\u7684\u503c\u7ed9\u4e86\u65b0\u6570\u636e\uff0c\u8fd9\u6837\u660e\u663e\u662f\u4e0d\u5408\u7406\u7684\u3002<\/p>\n<h1>1. 7 \u6b63\u5219\u5316<\/h1>\n<p>&emsp;&emsp;\u4e0a\u9762\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e86\u673a\u5668\u5b66\u4e60\u4e2d\u907f\u4e0d\u5f00\u7684\u4e00\u4e2a\u8bdd\u9898\uff0c\u5373\u6a21\u578b\u5f88\u6709\u53ef\u80fd\u51fa\u73b0\u8fc7\u62df\u5408\u73b0\u8c61\uff0c\u51fa\u73b0\u4e86\u95ee\u9898\u5c31\u5e94\u8be5\u89e3\u51b3\uff0c\u6211\u8bb2\u8bb2\u673a\u5668\u5b66\u4e60\u4e2d\u6700\u5e38\u7528\u7684\u89e3\u51b3\u8fc7\u62df\u5408\u95ee\u9898\u7684\u65b9\u6cd5\u2014\u2014\u6b63\u5219\u5316\uff08regularization\uff09\u3002\u7ed9\u76ee\u6807\u51fd\u6570\u52a0\u4e0a\u6b63\u5219\u5316\u9879\uff08regularizer\uff09\u6216\u60e9\u7f5a\u9879\uff08penalty term\uff09\uff0c\u5373\u65b0\u7684\u76ee\u6807\u51fd\u6570\u53d8\u6210<br \/>\n$$<br \/>\nJ(\\theta)=\\frac{1}{m} \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i)) + \\lambda(R(f))<br \/>\n$$<br \/>\n\u5176\u4e2d$\\lambda\\geq0$\u4e3a\u8d85\u53c2\u6570\uff0c\u7c7b\u4f3c\u4e8e\u53c2\u6570\uff0c\u4f46\u662f\u53c2\u6570\u53ef\u4ee5\u901a\u8fc7\u7b97\u6cd5\u6c42\u89e3\uff0c\u8d85\u53c2\u6570\u9700\u8981\u4eba\u5de5\u624b\u52a8\u8c03\u6574\uff1b$\\lambda(R(f))$\u4e3a\u6b63\u5219\u5316\u9879\u3002<\/p>\n<p>&emsp;&emsp;\u8fd9\u4e2a\u65f6\u5019\u4f60\u53ef\u80fd\u5728\u60f3\u4e3a\u4ec0\u4e48\u52a0\u4e0a\u6b63\u5219\u5316\u9879\u5c31\u53ef\u4ee5\u89e3\u51b3\u8fc7\u62df\u5408\u95ee\u9898\u5462\uff1f\u5bf9\u4e8e\u7ebf\u6027\u56de\u5f52\u800c\u8a00\uff0c\u7531\u4e8e\u6d89\u53ca\u7ebf\u6027\u56de\u5f52\u3001\u68af\u5ea6\u4e0b\u964d\u6cd5\u3001\u6700\u5c0f\u89d2\u56de\u5f52\u6cd5\u7b49\u6982\u5ff5\uff0c\u6b64\u5904\u4e0d\u591a\u8d58\u8ff0\uff0c\u8bb2\u7ebf\u6027\u56de\u5f52\u65f6\u4f1a\u8be6\u7ec6\u8bb2\u8ff0\u3002\u4e0b\u9762\u5c06\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4e2d\u6b63\u5219\u5316\u7684\u4e24\u79cd\u5f62\u5f0fL1\u6b63\u5219\u5316\u548cL2\u6b63\u5219\u5316\u505a\u7b80\u5355\u89e3\u91ca\u3002<\/p>\n<h2>1. 7.1 L1\u6b63\u5219\u5316<\/h2>\n<p>&emsp;&emsp;L1\u6b63\u5219\u5316\uff08Lasso\uff09\u662f\u5728\u76ee\u6807\u51fd\u6570\u4e0a\u52a0\u4e0aL1\u6b63\u5219\u5316\u9879\uff0c\u5373\u65b0\u7684\u76ee\u6807\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\nJ(\\theta) =\\frac{1}{m} \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i)) + \\lambda||\\theta||_1<br \/>\n$$<br \/>\n\u5176\u4e2d$||\\theta||_1$\u4e3a\u53c2\u6570\u5411\u91cf$\\theta$\u76841\u8303\u6570\u3002<\/p>\n<p>&emsp;&emsp;\u5047\u8bbe\u6837\u672c\u6709$n$\u7279\u5f81\uff0c\u5219$\\theta$\u4e3a$n$\u7ef4\u5411\u91cf\uff0c1\u8303\u6570\u4e3a<br \/>\n$$<br \/>\n||\\theta||<em>1=\\sum<\/em>{j=1}^n|\\theta_j|<br \/>\n$$<\/p>\n<h2>1. 7.2 L2\u6b63\u5219\u5316<\/h2>\n<p>&emsp;&emsp;L2\u6b63\u5219\u5316\uff08Ridge\uff09\u662f\u5728\u76ee\u6807\u51fd\u6570\u4e0a\u52a0\u4e0aL2\u6b63\u5219\u5316\u9879\uff0c\u5373\u65b0\u7684\u76ee\u6807\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\nJ(\\theta)=\\frac{1}{m} \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i)) + \\frac{\\lambda}{2}||\\theta||_2^2<br \/>\n$$<br \/>\n\u5176\u4e2d$||\\theta||_2^2$\u4e3a\u53c2\u6570\u5411\u91cf$\\theta$\u76842\u8303\u6570\u7684\u5e73\u65b9\u3002<\/p>\n<p>&emsp;&emsp;\u5047\u8bbe\u6837\u672c\u6709$n$\u7279\u5f81\uff0c\u5219$\\theta$\u4e3a$n$\u7ef4\u5411\u91cf\uff0c2\u8303\u6570\u4e3a<br \/>\n$$<br \/>\n||\\theta||<em>2=\\sqrt{\\sum<\/em>{j=1}^n{\\theta_j}^2}<br \/>\n$$<\/p>\n<p>&emsp;&emsp;\u591a\u8bf4\u4e00\u5634\uff0c\u5047\u8bbe\u6837\u672c\u6709$n$\u7279\u5f81\uff0c\u5219$\\theta$\u4e3a$n$\u7ef4\u5411\u91cf\uff0cp\u8303\u6570\u4e3a<br \/>\n$$<br \/>\n||\\theta||<em>p=\\sqrt[p]{\\sum<\/em>{j=1}^n{\\theta_j}^p}<br \/>\n$$<\/p>\n<h1>1. 8 \u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u3001\u6d4b\u8bd5\u96c6<\/h1>\n<p>&emsp;&emsp;\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u4e0d\u4f1a\u4f7f\u7528\u6570\u636e\u96c6\u4e2d\u7684\u6240\u6709\u6570\u636e\u4f5c\u4e3a\u8bad\u7ec3\u6570\u636e\u8bad\u7ec3\u6a21\u578b\uff0c\u800c\u662f\u4f1a\u6309\u7167\u67d0\u79cd\u6bd4\u4f8b\uff0c\u5c06\u6570\u636e\u96c6\u4e2d\u7684\u6570\u636e\u968f\u673a\u5206\u6210\u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u3001\u6d4b\u8bd5\u96c6\u5b66\u5f97\u4e00\u4e2a\u8f83\u4f18\u6a21\u578b\uff0c\u5982\u53ef\u4ee5\u628a\u6570\u636e\u96c6\u6309\u71677\uff1a2\uff1a1\u7684\u6bd4\u4f8b\u5206\u6210\u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u3001\u6d4b\u8bd5\u96c6\uff0c\u5bf9\u4e8e\u4e0d\u540c\u7684\u95ee\u9898\u4e00\u822c\u5206\u914d\u7684\u6bd4\u4f8b\u4e0d\u540c\uff0c\u4e0b\u9762\u5c06\u4ecb\u7ecd\u8fd9\u4e09\u8005\u5404\u81ea\u7684\u4f5c\u7528\u3002<\/p>\n<h2>1. 8.1 \u8bad\u7ec3\u96c6<\/h2>\n<p>&emsp;&emsp;\u4e00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528\u5e26\u6709\u6b63\u5219\u9879\u7684\u76ee\u6807\u51fd\u6570\u53bb\u6784\u5efa\u6a21\u578b\uff0c\u5373\u6211\u4eec\u7684\u76ee\u6807\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\nJ(\\theta)=\\frac{1}{m} \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i)) + \\lambda(R(f))<br \/>\n$$<br \/>\n\u4e00\u822c\u4f1a\u901a\u8fc7\u8bad\u7ec3\u96c6\u5f97\u5230\u53c2\u6570$\\theta$\u3002\u5982\u7ebf\u6027\u56de\u5f52\u7684\u76ee\u6807\u51fd\u6570\u4e2d\u6709\u4e24\u4e2a\u53c2\u6570$\\theta$\u548c$b$\uff0c\u4e00\u822c\u4f1a\u901a\u8fc7\u8bad\u7ec3\u96c6\u5f97\u5230\u8fd9\u4e24\u4e2a\u53c2\u6570$\\theta$\u548c$b$\u3002<\/p>\n<h2>1. 8.2 \u9a8c\u8bc1\u96c6<\/h2>\n<p>&emsp;&emsp;\u4e00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528\u5e26\u6709\u6b63\u5219\u9879\u7684\u76ee\u6807\u51fd\u6570\u53bb\u6784\u5efa\u6a21\u578b\uff0c\u5373\u6211\u4eec\u7684\u76ee\u6807\u51fd\u6570\u4e3a<br \/>\n$$<br \/>\nJ(\\theta)=\\frac{1}{m} \\sum_{i=1}^m L(y<em>i,f<\/em>{\\theta_i}(x_i)) + \\lambda(R(f))<br \/>\n$$<br \/>\n&emsp;&emsp;\u4e00\u822c\u4f1a\u901a\u8fc7\u7ed9\u5b9a\u4e00\u7ec4\u8d85\u53c2\u6570\uff0c\u7136\u540e\u901a\u8fc7\u9a8c\u8bc1\u96c6\u5f97\u5230\u6700\u4f18\u8d85\u53c2\u6570$\\lambda$\uff0c\u6709\u65f6\u5019\u4f1a\u628a\u9a8c\u8bc1\u96c6\u5f97\u5230\u8d85\u53c2\u6570\u7684\u6b65\u9aa4\u5212\u5206\u5230\u8bad\u7ec3\u96c6\u4e2d\u3002\u5982\u7ebf\u6027\u56de\u5f52\u7684\u76ee\u6807\u51fd\u6570\u6709\u4e00\u4e2a\u8d85\u53c2\u6570$\\lambda$\uff0c\u4e00\u822c\u4f1a\u901a\u8fc7\u9a8c\u8bc1\u96c6\u5f97\u5230\u8be5\u8d85\u53c2\u6570$\\lambda$\u3002<\/p>\n<h2>1. 8.3 \u6d4b\u8bd5\u96c6<\/h2>\n<p>&emsp;&emsp;\u6d4b\u8bd5\u96c6\u4e00\u822c\u88ab\u5f53\u505a\u672a\u6765\u65b0\u6570\u636e\u96c6\uff0c\u7136\u540e\u901a\u8fc7\u5ea6\u91cf\u6a21\u578b\u6027\u80fd\u7684\u5de5\u5177\u6d4b\u8bd5\u6a21\u578b\u7684\u8bef\u5dee\u5927\u5c0f\u3002<\/p>\n<h1>1. 9 \u672c\u7ae0\u5c0f\u7ed3<\/h1>\n<p>&emsp;&emsp;\u672c\u7ae0\u4e3b\u8981\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u4ecb\u7ecd\u4e86\u51b3\u7b56\u51fd\u6570\u3001\u56db\u79cd\u635f\u5931\u51fd\u6570\u3001\u76ee\u6807\u51fd\u6570\u53ca\u76ee\u6807\u51fd\u6570\u7684\u95ee\u9898\uff0c\u5176\u5b9e\u5176\u4ed6\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u4e5f\u662f\u8fd9\u6837\u7684\u5957\u8def\uff0c\u5728\u5728\u4e00\u90e8\u5206\u7b97\u6cd5\u539f\u7406\u65f6\u6211\u4eec\u4f1a\u7ec6\u8bb2\uff0c\u6b64\u5904\u4f60\u6709\u4e00\u4e2a\u5927\u6982\u7684\u6982\u5ff5\u5373\u53ef\u3002<\/p>\n<p>&emsp;&emsp;\u6700\u5c0f\u5316\u76ee\u6807\u51fd\u6570\u6211\u4eec\u5047\u8bbe\u8bef\u5dee\u8d8a\u5c0f\u8d8a\u597d\uff0c\u7136\u800c\u5de5\u4e1a\u4e0a\u6570\u636e\u603b\u662f\u4f1a\u6709\u566a\u58f0\uff0c\u4e5f\u5c31\u662f\u8bf4$0$\u8bef\u5dee\u4e5f\u8bb8\u5e76\u4e0d\u662f\u6700\u597d\u7684\uff0c\u56e0\u6b64\u5f15\u51fa\u4e86\u6211\u4eec\u7684\u8fc7\u62df\u5408\u95ee\u9898\uff0c\u4e4b\u540e\u8bb2\u89e3\u4e86\u89e3\u51b3\u8fc7\u62df\u5408\u95ee\u9898\u7684\u4e24\u4e2a\u65b9\u6cd5\uff0c\u4e00\u4e2a\u662f\u5728\u76ee\u6807\u51fd\u6570\u4e0a\u52a0\u4e0a\u6b63\u5219\u5316\u9879\uff0c\u53e6\u4e00\u4e2a\u5219\u628a\u8bad\u7ec3\u96c6\u5206\u6210\u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u7ebf\u6027\u56de\u5f52\u5e26\u4f60\u4e86\u89e3\u7b97\u6cd5\u6d41\u7a0b 1. 1 \u7ebf\u6027\u56de\u5f52\u5f15\u5165 &emsp;&emsp;\u76f8\u4fe1\u6211\u4eec\u5f88\u591a\u4eba\u53ef\u80fd\u90fd\u6709\u53bb\u552e\u697c\u5904\u4e70 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3275,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[301],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3253"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3253"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3253\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/3275"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}