{"id":20110,"date":"2026-01-19T10:09:36","date_gmt":"2026-01-19T02:09:36","guid":{"rendered":"https:\/\/92it.top\/?p=20110"},"modified":"2026-01-19T10:09:36","modified_gmt":"2026-01-19T02:09:36","slug":"%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0_%e6%8d%9f%e5%a4%b1%e5%87%bd%e6%95%b0%e4%b8%8e%e6%a2%af%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=20110","title":{"rendered":"\u673a\u5668\u5b66\u4e60_\u635f\u5931\u51fd\u6570\u4e0e\u68af\u5ea6"},"content":{"rendered":"\n<p><strong>\u524d\u8a00\u200b\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u672c\u7ae0\u8282\u6211\u4eec\u5c06\u4e00\u8d77\u63a2\u7d22\u4e24\u4e2a\u81f3\u5173\u91cd\u8981\u7684\u6838\u5fc3\u6982\u5ff5\uff1a<strong>\u635f\u5931\u51fd\u6570<\/strong>&nbsp;\u548c&nbsp;<strong>\u68af\u5ea6<\/strong>\uff0c\u5b83\u4eec\u662f\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u80fd\u591f<strong>\u5b66\u4e60<\/strong>\u548c<strong>\u6539\u8fdb<\/strong>\u7684\u57fa\u77f3\u3002<\/p>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u5728\u5b66\u4e60\u6295\u7bee\uff0c\u6bcf\u6b21\u6295\u7403\u540e\uff0c\u4f60\u90fd\u4f1a\u89c2\u5bdf\u7403\u662f\u8fdb\u4e86\u3001\u504f\u5de6\u4e86\u8fd8\u662f\u504f\u53f3\u4e86\u3002\u8fd9\u4e2a\u89c2\u5bdf\u7ed3\u679c\u4e0e\u5b8c\u7f8e\u8fdb\u7403\u4e4b\u95f4\u7684\u5dee\u8ddd\uff0c\u5c31\u662f\u4f60\u7684<strong>\u635f\u5931<\/strong>\u3002\u800c\u4e3a\u4e86\u4e0b\u6b21\u6295\u5f97\u66f4\u51c6\uff0c\u4f60\u4f1a\u6839\u636e\u8fd9\u6b21\u504f\u5dee\u7684\u65b9\u5411\u548c\u5927\u5c0f\u6765\u8c03\u6574\u4f60\u7684\u59ff\u52bf\u548c\u529b\u5ea6\uff0c\u8fd9\u4e2a<strong>\u8c03\u6574\u7684\u65b9\u5411\u548c\u5927\u5c0f<\/strong>\u5c31\u7c7b\u4f3c\u4e8e<strong>\u68af\u5ea6<\/strong>\u3002<\/p>\n\n\n\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6a21\u578b\u5c31\u662f\u90a3\u4e2a<strong>\u5b66\u4e60\u8005<\/strong>\uff0c\u635f\u5931\u51fd\u6570\u8861\u91cf\u5b83\u7684<strong>\u9519\u8bef\u7a0b\u5ea6<\/strong>\uff0c\u800c\u68af\u5ea6\u5219\u544a\u8bc9\u5b83<strong>\u5982\u4f55\u6539\u8fdb<\/strong>\u3002\u7406\u89e3\u5b83\u4eec\uff0c\u4f60\u5c31\u638c\u63e1\u4e86\u673a\u5668\u5b66\u4e60\u5982\u4f55\u5de5\u4f5c\u7684\u6838\u5fc3\u903b\u8f91\u3002<\/p>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u635f\u5931\u51fd\u6570\uff1a\u6a21\u578b\u7684\u6210\u7ee9\u5355\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\ud83d\udd391 .1 \u4ec0\u4e48\u662f\u635f\u5931\u51fd\u6570\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u635f\u5931\u51fd\u6570<\/strong>\uff0c\u6709\u65f6\u4e5f\u53eb<strong>\u4ee3\u4ef7\u51fd\u6570<\/strong>\u6216<strong>\u76ee\u6807\u51fd\u6570<\/strong>\uff0c\u662f\u4e00\u4e2a\u7528\u6765<strong>\u91cf\u5316\u6a21\u578b\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u5dee\u5f02<\/strong>\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u6838\u5fc3\u4f5c\u7528<\/strong>\uff1a\u5b83\u7ed9\u6a21\u578b\u7684\u9884\u6d4b\u8868\u73b0\u6253\u4e86\u4e00\u4e2a\u5177\u4f53\u7684&#8221;\u5206\u6570&#8221;\u3002\u8fd9\u4e2a\u5206\u6570\u8d8a\u4f4e\uff0c\u8bf4\u660e\u6a21\u578b\u9884\u6d4b\u5f97\u8d8a\u51c6\u786e\uff1b\u5206\u6570\u8d8a\u9ad8\uff0c\u8bf4\u660e\u9884\u6d4b\u8bef\u5dee\u8d8a\u5927\u3002<\/li>\n\n\n\n<li><strong>\u7c7b\u6bd4\u7406\u89e3<\/strong>\uff1a\u5c31\u50cf\u8003\u8bd5\u4e00\u6837\uff0c\u635f\u5931\u51fd\u6570\u7684&#8221;\u5206\u6570&#8221;\u5c31\u662f\u6a21\u578b\u7684\u8003\u8bd5\u6210\u7ee9\u3002\u6211\u4eec\u7684\u7ec8\u6781\u76ee\u6807\u5c31\u662f\u901a\u8fc7&#8221;\u5b66\u4e60&#8221;\uff08\u8c03\u6574\u6a21\u578b\u53c2\u6570\uff09\uff0c\u8ba9\u8fd9\u4e2a\u5206\u6570\uff08\u635f\u5931\uff09\u8d8a\u6765\u8d8a\u4f4e\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\ud83d\udd391.2 \u5e38\u89c1\u635f\u5931\u51fd\u6570\u4e3e\u4f8b<\/strong><\/p>\n\n\n\n<p>\u4e0d\u540c\u7684\u4efb\u52a1\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684<strong>\u8bc4\u5206\u6807\u51c6<\/strong>\uff0c\u4ee5\u4e0b\u662f\u4e24\u4e2a\u6700\u57fa\u7840\u7684\u635f\u5931\u51fd\u6570\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u5747\u65b9\u8bef\u5dee<\/strong>&nbsp;&#8211; \u9002\u7528\u4e8e\u56de\u5f52\u95ee\u9898\uff08\u9884\u6d4b\u8fde\u7eed\u503c\uff0c\u5982\u623f\u4ef7\u3001\u6e29\u5ea6\uff09<\/h4>\n\n\n\n<p>\u5747\u65b9\u8bef\u5dee\u8ba1\u7b97\u7684\u662f\u6240\u6709\u6837\u672c\u7684<strong>\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u5dee\u7684\u5e73\u65b9\u7684\u5e73\u5747\u503c<\/strong>\u3002<\/p>\n\n\n\n<p>\u516c\u5f0f\uff1a\u00a0<code>MSE = (1\/n) * \u03a3(\u771f\u5b9e\u503c\u1d62 - \u9884\u6d4b\u503c\u1d62)\u00b2<\/code><\/p>\n\n\n\n<ul>\n<li><code>n<\/code>\uff1a\u6837\u672c\u6570\u91cf<\/li>\n\n\n\n<li><code>\u03a3<\/code>\uff1a\u6c42\u548c\u7b26\u53f7<\/li>\n\n\n\n<li><code>\u771f\u5b9e\u503c\u1d62<\/code>\uff1a\u7b2c i \u4e2a\u6837\u672c\u7684\u771f\u5b9e\u503c<\/li>\n\n\n\n<li><code>\u9884\u6d4b\u503c\u1d62<\/code>\uff1a\u6a21\u578b\u5bf9\u7b2c i \u4e2a\u6837\u672c\u7684\u9884\u6d4b\u503c<\/li>\n<\/ul>\n\n\n\n<p>\u7279\u70b9\uff1a\u7531\u4e8e\u4f7f\u7528\u4e86\u5e73\u65b9\uff0c\u5b83\u5bf9\u8f83\u5927\u7684\u8bef\u5dee\u60e9\u7f5a\u66f4\u91cd\uff08\u8bef\u5dee\u4e3a 2 \u65f6\uff0c\u5e73\u65b9\u540e\u8d21\u732e\u4e3a 4\uff1b\u8bef\u5dee\u4e3a 10 \u65f6\uff0c\u5e73\u65b9\u540e\u8d21\u732e\u9ad8\u8fbe 100\uff09\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import numpy as np\n\n# \u5047\u8bbe\u6211\u4eec\u6709 5 \u4e2a\u6837\u672c\u7684\u771f\u5b9e\u503c\u548c\u9884\u6d4b\u503c\ny_true = np.array([3, -0.5, 2, 7, 4])      # \u771f\u5b9e\u503c\ny_pred = np.array([2.5, 0.0, 2, 8, 5])     # \u9884\u6d4b\u503c\n\n# \u624b\u52a8\u8ba1\u7b97 MSE\nn = len(y_true)\nsquared_errors = (y_true - y_pred) ** 2    # \u8ba1\u7b97\u6bcf\u4e2a\u6837\u672c\u7684\u5e73\u65b9\u8bef\u5dee\nmse_manual = np.sum(squared_errors) \/ n    # \u6c42\u548c\u5e76\u53d6\u5e73\u5747\nprint(f\"\u624b\u52a8\u8ba1\u7b97\u7684 MSE: {mse_manual}\")\n\n# \u4f7f\u7528 sklearn \u5e93\u51fd\u6570\u9a8c\u8bc1\nfrom sklearn.metrics import mean_squared_error\nmse_sklearn = mean_squared_error(y_true, y_pred)\nprint(f\"Sklearn \u8ba1\u7b97\u7684 MSE: {mse_sklearn}\")<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u624b\u52a8\u8ba1\u7b97\u7684 MSE: 0.5\nSklearn \u8ba1\u7b97\u7684 MSE: 0.5<\/pre>\n\n\n\n<p><strong>\u4ea4\u53c9\u71b5\u635f\u5931<\/strong>&nbsp;&#8211; \u9002\u7528\u4e8e\u5206\u7c7b\u95ee\u9898\uff08\u9884\u6d4b\u7c7b\u522b\uff0c\u5982\u56fe\u7247\u662f\u732b\u8fd8\u662f\u72d7\uff09<\/p>\n\n\n\n<p>\u4ea4\u53c9\u71b5\u8861\u91cf\u7684\u662f\u6a21\u578b\u9884\u6d4b\u7684\u6982\u7387\u5206\u5e03\u4e0e\u771f\u5b9e\u7684\u6982\u7387\u5206\u5e03\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u5728\u4e8c\u5206\u7c7b\u4e2d\uff0c\u771f\u5b9e\u5206\u5e03\u901a\u5e38\u662f\u00a0<code>[1, 0]<\/code>\uff08\u662f\u7c7b\u522b A\uff09\u6216\u00a0<code>[0, 1]<\/code>\uff08\u662f\u7c7b\u522b B\uff09\u3002<\/p>\n\n\n\n<p>\u4e8c\u5206\u7c7b\u516c\u5f0f\uff08\u5bf9\u6570\u635f\u5931\uff09\uff1a\u00a0<code>Log Loss = - (1\/n) * \u03a3 [\u771f\u5b9e\u503c\u1d62 * log(\u9884\u6d4b\u6982\u7387\u1d62) + (1 - \u771f\u5b9e\u503c\u1d62) * log(1 - \u9884\u6d4b\u6982\u7387\u1d62)]<\/code><\/p>\n\n\n\n<p>\u76f4\u89c2\u7406\u89e3\uff1a\u5f53\u771f\u5b9e\u6807\u7b7e\u4e3a 1 \u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u6a21\u578b\u9884\u6d4b\u7684\u6982\u7387\u4e5f\u63a5\u8fd1 1\u3002\u5982\u679c\u6b64\u65f6\u6a21\u578b\u9884\u6d4b\u4e86\u4e00\u4e2a\u5f88\u4f4e\u7684\u6982\u7387\uff08\u6bd4\u5982 0.1\uff09\uff0c\u90a3\u4e48\u00a0<code>log(0.1)<\/code>\u00a0\u4f1a\u662f\u4e00\u4e2a\u5f88\u5927\u7684\u8d1f\u6570\uff0c\u518d\u4e58\u4ee5\u524d\u9762\u7684\u8d1f\u53f7\uff0c\u5c31\u4f1a\u5bfc\u81f4\u635f\u5931\u503c\u53d8\u5f97\u5f88\u5927\uff0c\u8868\u793a\u60e9\u7f5a\u5f88\u91cd\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import numpy as np\nfrom sklearn.metrics import log_loss\n\n# \u4e8c\u5206\u7c7b\u793a\u4f8b\uff1a\u771f\u5b9e\u6807\u7b7e\uff081\u4ee3\u8868\"\u662f\"\uff0c0\u4ee3\u8868\"\u5426\"\uff09\ny_true_binary = np.array([1, 0, 0, 1]) # \u771f\u5b9e\u7c7b\u522b\uff1a\u662f\uff0c\u5426\uff0c\u5426\uff0c\u662f\n# \u6a21\u578b\u9884\u6d4b\u4e3a\"\u662f\"\u8fd9\u4e2a\u7c7b\u522b\u7684\u6982\u7387\ny_pred_prob = np.array([0.9, 0.1, 0.2, 0.8]) # \u9884\u6d4b\u6982\u7387\uff1a0.9, 0.1, 0.2, 0.8\n\n# \u4f7f\u7528 sklearn \u8ba1\u7b97\u4ea4\u53c9\u71b5\u635f\u5931\uff08\u5bf9\u6570\u635f\u5931\uff09\nce_loss = log_loss(y_true_binary, y_pred_prob)\nprint(f\"\u4ea4\u53c9\u71b5\u635f\u5931 (Log Loss): {ce_loss}\")<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u4ea4\u53c9\u71b5\u635f\u5931 (Log Loss): 0.164252033486018\n<\/pre>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u68af\u5ea6\uff1a\u6307\u5f15\u4f18\u5316\u65b9\u5411\u7684&#8221;\u6307\u5357\u9488&#8221;\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u77e5\u9053\u4e86\u5982\u4f55\u7ed9\u6a21\u578b\u6253\u5206\uff08\u635f\u5931\u51fd\u6570\uff09\uff0c\u63a5\u4e0b\u6765\u6700\u5173\u952e\u7684\u95ee\u9898\u662f\uff1a<strong>\u6a21\u578b\u5982\u4f55\u6839\u636e\u8fd9\u4e2a\u5206\u6570\u6765\u6539\u8fdb\u81ea\u5df1\uff1f<\/strong>&nbsp;\u7b54\u6848\u5c31\u662f\u901a\u8fc7<strong>\u68af\u5ea6<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\ud83d\udd392.1 \u4ec0\u4e48\u662f\u68af\u5ea6\uff1f<\/strong><\/p>\n\n\n\n<p>\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6a21\u578b\u901a\u5e38\u7531\u8bb8\u591a<strong>\u53c2\u6570<\/strong>\uff08\u6216\u53eb<strong>\u6743\u91cd<\/strong>\uff09\u6784\u6210\u3002\u6211\u4eec\u53ef\u4ee5\u628a<strong>\u635f\u5931\u51fd\u6570 L<\/strong>&nbsp;\u770b\u4f5c\u662f\u6240\u6709\u8fd9\u4e9b\u53c2\u6570\u7684\u51fd\u6570\uff1a<code>L(w1, w2, ..., wn)<\/code>\u3002<\/p>\n\n\n\n<ul>\n<li>\u68af\u5ea6\u00a0\u5c31\u662f\u635f\u5931\u51fd\u6570\u5bf9\u6bcf\u4e2a\u53c2\u6570\u7684\u504f\u5bfc\u6570\u6240\u6784\u6210\u7684\u5411\u91cf\u3002<\/li>\n\n\n\n<li>\u6570\u5b66\u8868\u793a\uff1a<code>\u2207L = [\u2202L\/\u2202w1, \u2202L\/\u2202w2, ..., \u2202L\/\u2202wn]<\/code><\/li>\n\n\n\n<li>\u6838\u5fc3\u610f\u4e49\uff1a\n<ol>\n<li>\u65b9\u5411\uff1a\u68af\u5ea6\u5411\u91cf\u6240\u6307\u7684\u65b9\u5411\uff0c\u662f\u635f\u5931\u51fd\u6570\u5728\u8be5\u70b9\u4e0a\u5347\u6700\u5feb\u7684\u65b9\u5411\u3002<\/li>\n\n\n\n<li>\u5927\u5c0f\uff1a\u6bcf\u4e2a\u504f\u5bfc\u6570\u7684\u7edd\u5bf9\u503c\u5927\u5c0f\uff0c\u8868\u793a\u635f\u5931\u51fd\u6570\u5bf9\u8be5\u53c2\u6570\u53d8\u5316\u7684\u654f\u611f\u5ea6\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\ud83d\udd392.2 \u4e3a\u4ec0\u4e48\u68af\u5ea6\u80fd\u6307\u5f15\u4f18\u5316\uff1f<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f<strong>\u6700\u5c0f\u5316\u635f\u5931\u51fd\u6570<\/strong>\u3002\u65e2\u7136\u68af\u5ea6\u6307\u5411\u4e86\u635f\u5931\u4e0a\u5347\u6700\u5feb\u7684\u65b9\u5411\uff0c\u90a3\u4e48\u5b83\u7684\u53cd\u65b9\u5411&nbsp;<code>-\u2207L<\/code>&nbsp;\u81ea\u7136\u5c31\u662f\u635f\u5931<strong>\u4e0b\u964d\u6700\u5feb<\/strong>\u7684\u65b9\u5411\u3002<\/p>\n\n\n\n<p>\u4f18\u5316\u8fc7\u7a0b\uff08\u68af\u5ea6\u4e0b\u964d\uff09\u53ef\u4ee5\u5f62\u8c61\u5730\u7406\u89e3\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4f60\u7ad9\u5728\u4e00\u5ea7\u5c71\u8c37\uff08\u635f\u5931\u66f2\u9762\uff09\u7684\u67d0\u4e2a\u5c71\u5761\u4e0a\uff0c\u8499\u7740\u773c\u775b\u60f3\u8981\u8d70\u5230\u8c37\u5e95\uff08\u635f\u5931\u6700\u5c0f\u70b9\uff09\u3002\u4f60\u6bcf\u8d70\u4e00\u6b65\u524d\uff0c\u90fd\u7528\u811a\u611f\u53d7\u4e00\u4e0b\u56db\u5468\u54ea\u4e2a\u65b9\u5411\u6700\u9661\u5ced\uff08\u8ba1\u7b97\u68af\u5ea6\uff09\uff0c\u7136\u540e\u671d\u7740\u6700\u9661\u5ced\u7684\u4e0b\u5761\u65b9\u5411\uff08\u8d1f\u68af\u5ea6\u65b9\u5411\uff09\u8fc8\u51fa\u4e00\u6b65\uff08\u66f4\u65b0\u53c2\u6570\uff09\u3002\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u4f60\u6700\u7ec8\u5c31\u80fd\u5230\u8fbe\u8c37\u5e95\u3002<br><br><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u6d41\u7a0b\u56fe\u6982\u62ec\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"953\" height=\"1024\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-953x1024.png\" alt=\"\" class=\"wp-image-20111\" style=\"width:416px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-953x1024.png 953w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-279x300.png 279w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-768x825.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-830x892.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-230x247.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-350x376.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71-480x516.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-71.png 1089w\" sizes=\"(max-width: 953px) 100vw, 953px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\ud83d\udd392.3 \u68af\u5ea6\u4e0b\u964d\u7684\u7b80\u5355\u793a\u4f8b<\/strong><\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u7528\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4f8b\u5b50\u2014\u2014\u53ea\u6709\u4e00\u4e2a\u53c2\u6570&nbsp;<code>w<\/code>&nbsp;\u7684\u7ebf\u6027\u6a21\u578b\uff0c\u6765\u6f14\u793a\u68af\u5ea6\u4e0b\u964d\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u7684\u635f\u5931\u51fd\u6570\u662f&nbsp;<code>L(w) = w\u00b2<\/code>\u3002\u663e\u7136\uff0c\u5f53&nbsp;<code>w = 0<\/code>&nbsp;\u65f6\uff0c\u635f\u5931\u6700\u5c0f\u3002<\/p>\n\n\n\n<ul>\n<li>\u68af\u5ea6\u8ba1\u7b97\uff1a<code>\u2207L = dL\/dw = 2w<\/code><\/li>\n\n\n\n<li>\u53c2\u6570\u66f4\u65b0\u516c\u5f0f\uff1a<code>w_new = w_old - \u03b7 * (2 * w_old)<\/code>\n<ul>\n<li><code>\u03b7<\/code>\u00a0\u662f\u5b66\u4e60\u7387\uff0c\u63a7\u5236\u6bcf\u4e00\u6b65\u8fc8\u591a\u5927\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import numpy as np\nimport matplotlib.pyplot as plt\n\n# \u5b9a\u4e49\u635f\u5931\u51fd\u6570 L(w) = w^2\ndef loss(w):\n    return w ** 2\n\n# \u5b9a\u4e49\u68af\u5ea6 dL\/dw = 2*w\ndef gradient(w):\n    return 2 * w\n\n# \u68af\u5ea6\u4e0b\u964d\u7b97\u6cd5\ndef gradient_descent(start_w, learning_rate, iterations):\n    w = start_w\n    w_history = [w]  # \u8bb0\u5f55 w \u7684\u53d8\u5316\u5386\u53f2\n    loss_history = [loss(w)]  # \u8bb0\u5f55\u635f\u5931\u7684\u53d8\u5316\u5386\u53f2\n\n    for i in range(iterations):\n        grad = gradient(w)  # \u8ba1\u7b97\u5f53\u524d\u70b9\u7684\u68af\u5ea6\n        w = w - learning_rate * grad  # \u6cbf\u8d1f\u68af\u5ea6\u65b9\u5411\u66f4\u65b0\u53c2\u6570\n        w_history.append(w)\n        loss_history.append(loss(w))\n\n    return w_history, loss_history\n\n# \u6267\u884c\u68af\u5ea6\u4e0b\u964d\uff1a\u4ece w=5 \u5f00\u59cb\uff0c\u5b66\u4e60\u7387 0.1\uff0c\u8fed\u4ee3 20 \u6b21\nw_start = 5.0\nlr = 0.1\niters = 20\nw_hist, loss_hist = gradient_descent(w_start, lr, iters)\n\nprint(f\"\u521d\u59cb w: {w_hist[0]:.4f}, \u521d\u59cb\u635f\u5931: {loss_hist[0]:.4f}\")\nprint(f\"\u6700\u7ec8 w: {w_hist[-1]:.4f}, \u6700\u7ec8\u635f\u5931: {loss_hist[-1]:.4f}\")\n\n# \u53ef\u89c6\u5316\u4f18\u5316\u8fc7\u7a0b\nplt.figure(figsize=(12, 4))\n\n# \u56fe1\uff1a\u635f\u5931\u51fd\u6570\u66f2\u7ebf\u53ca\u4f18\u5316\u8def\u5f84\nplt.subplot(1, 2, 1)\nw_vals = np.linspace(-6, 6, 100)\nplt.plot(w_vals, loss(w_vals), label='L(w) = w\u00b2')\nplt.scatter(w_hist, loss_hist, c='red', s=20, label='Gradient Descent Steps')\nplt.plot(w_hist, loss_hist, 'r--', alpha=0.5)\nplt.xlabel('Parameter w')\nplt.ylabel('Loss L(w)')\nplt.title('Gradient Descent on L(w)=w\u00b2')\nplt.legend()\nplt.grid(True)\n\n# \u56fe2\uff1a\u635f\u5931\u503c\u968f\u8fed\u4ee3\u6b21\u6570\u7684\u4e0b\u964d\u66f2\u7ebf\nplt.subplot(1, 2, 2)\nplt.plot(range(len(loss_hist)), loss_hist, 'b-o')\nplt.xlabel('Iteration')\nplt.ylabel('Loss')\nplt.title('Loss Reduction Over Iterations')\nplt.grid(True)\n\nplt.tight_layout()\nplt.show()<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\u521d\u59cb w: 5.0000, \u521d\u59cb\u635f\u5931: 25.0000\n\u6700\u7ec8 w: 0.0576, \u6700\u7ec8\u635f\u5931: 0.0033\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"353\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-1024x353.png\" alt=\"\" class=\"wp-image-20112\" style=\"width:588px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-1024x353.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-300x103.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-768x265.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-1536x530.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-830x286.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-230x79.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-350x121.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72-480x166.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-72.png 1658w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u4f60\u4f1a\u770b\u5230\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5de6\u8fb9\u7684\u56fe\u5c55\u793a\u4e86\u53c2\u6570\u00a0<code>w<\/code>\u00a0\u5982\u4f55\u4ece 5.0 \u5f00\u59cb\uff0c\u4e00\u6b65\u6b65&#8221;\u6eda\u4e0b&#8221;\u629b\u7269\u7ebf\uff0c\u6700\u7ec8\u63a5\u8fd1\u6700\u5c0f\u503c\u70b9 0\u3002<\/li>\n\n\n\n<li>\u53f3\u8fb9\u7684\u56fe\u5c55\u793a\u4e86\u635f\u5931\u503c\u5982\u4f55\u968f\u7740\u8fed\u4ee3\u6b21\u6570\u7684\u589e\u52a0\u800c\u8fc5\u901f\u4e0b\u964d\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u00a0\u6838\u5fc3\u8981\u70b9\u4e0e\u8054\u7cfb\u603b\u7ed3\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>\u6982\u5ff5<\/th><th>\u6bd4\u55bb<\/th><th>\u6838\u5fc3\u4f5c\u7528<\/th><th>\u5173\u952e\u70b9<\/th><\/tr><\/thead><tbody><tr><td><strong>\u635f\u5931\u51fd\u6570<\/strong><\/td><td><strong>\u6210\u7ee9\u5355\/\u8bef\u5dee\u6d4b\u91cf\u5c3a<\/strong><\/td><td>\u5b9a\u91cf\u8bc4\u4f30\u6a21\u578b\u9884\u6d4b\u7684\u597d\u574f\u3002<\/td><td>1. \u4e0d\u540c\u7c7b\u578b\u4efb\u52a1\uff08\u56de\u5f52\u3001\u5206\u7c7b\uff09\u4f7f\u7528\u4e0d\u540c\u7684\u635f\u5931\u51fd\u6570\u3002<br>2. \u635f\u5931\u503c\u8d8a\u5c0f\uff0c\u6a21\u578b\u6027\u80fd\u8d8a\u597d\u3002<\/td><\/tr><tr><td><strong>\u68af\u5ea6<\/strong><\/td><td><strong>\u6307\u5357\u9488\/\u6700\u9661\u4e0b\u5761\u65b9\u5411<\/strong><\/td><td>\u6307\u51fa\u4e3a\u4e86\u6700\u5feb\u964d\u4f4e\u635f\u5931\uff0c\u6bcf\u4e2a\u6a21\u578b\u53c2\u6570\u5e94\u8be5\u5982\u4f55\u8c03\u6574\u3002<\/td><td>1. \u662f\u635f\u5931\u51fd\u6570\u5bf9\u6240\u6709\u53c2\u6570\u7684\u504f\u5bfc\u6570\u5411\u91cf\u3002<br>2.&nbsp;<strong>\u8d1f\u68af\u5ea6\u65b9\u5411<\/strong>\u662f\u635f\u5931\u4e0b\u964d\u6700\u5feb\u7684\u65b9\u5411\u3002<\/td><\/tr><tr><td><strong>\u68af\u5ea6\u4e0b\u964d<\/strong><\/td><td><strong>\u8499\u773c\u4e0b\u5c71\u6cd5<\/strong><\/td><td>\u5229\u7528\u68af\u5ea6\u4fe1\u606f\uff0c\u8fed\u4ee3\u5730\u66f4\u65b0\u53c2\u6570\u4ee5\u6700\u5c0f\u5316\u635f\u5931\u3002<\/td><td>1.&nbsp;<strong>\u5b66\u4e60\u7387<\/strong>\u662f\u5173\u952e\u8d85\u53c2\u6570\uff0c\u592a\u5c0f\u5219\u5b66\u4e60\u6162\uff0c\u592a\u5927\u53ef\u80fd\u65e0\u6cd5\u6536\u655b\u3002<br>2. \u662f\u5927\u591a\u6570\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8bad\u7ec3\u7684\u5e95\u5c42\u4f18\u5316\u7b97\u6cd5\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\u94fe\u662f\uff1a\u00a0\u6a21\u578b\u505a\u51fa\u9884\u6d4b \u2192 \u635f\u5931\u51fd\u6570\u8ba1\u7b97\u8bef\u5dee \u2192 \u8ba1\u7b97\u8bef\u5dee\u76f8\u5bf9\u4e8e\u5404\u53c2\u6570\u7684\u68af\u5ea6 \u2192 \u6cbf\u8d1f\u68af\u5ea6\u65b9\u5411\u66f4\u65b0\u53c2\u6570 \u2192 \u6a21\u578b\u6539\u8fdb \u2192 \u91cd\u590d&#8230;<a href=\"https:\/\/www.runoob.com\/ml\/ml-probabilistic-thinking.html\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\u200b\ud83d\udd16 \u672c\u7ae0\u8282\u6211\u4eec\u5c06\u4e00\u8d77\u63a2\u7d22\u4e24\u4e2a\u81f3\u5173\u91cd\u8981\u7684\u6838\u5fc3\u6982\u5ff5\uff1a\u635f\u5931\u51fd\u6570&nbsp;\u548c&nbsp;\u68af\u5ea6\uff0c\u5b83\u4eec\u662f\u673a\u5668\u5b66\u4e60\u7b97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20110"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20110"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20110\/revisions"}],"predecessor-version":[{"id":20113,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20110\/revisions\/20113"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}