{"id":1326,"date":"2025-05-15T00:06:47","date_gmt":"2025-05-14T15:06:47","guid":{"rendered":"https:\/\/www.dogrow.net\/nnet\/?p=1326"},"modified":"2025-05-15T01:03:17","modified_gmt":"2025-05-14T16:03:17","slug":"blog41-python-matplotlib%e3%81%a7%e6%b4%bb%e6%80%a7%e5%8c%96%e9%96%a2%e6%95%b0%e3%81%ae%e3%82%b0%e3%83%a9%e3%83%95%e3%82%92%e6%8f%8f%e3%81%8f%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/nnet\/blog41-python-matplotlib%e3%81%a7%e6%b4%bb%e6%80%a7%e5%8c%96%e9%96%a2%e6%95%b0%e3%81%ae%e3%82%b0%e3%83%a9%e3%83%95%e3%82%92%e6%8f%8f%e3%81%8f%e3%80%82\/","title":{"rendered":"(41) Python matplotlib\u3067\u6d3b\u6027\u5316\u95a2\u6570\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u304f\u3002"},"content":{"rendered":"<h1 class=\"my_h\">\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>Python\u306e\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b Matplotlib\u3092\u4f7f\u3063\u3066\u3001\u6d3b\u6027\u5316\u95a2\u6570\u3092\u30b0\u30e9\u30d5\u306b\u3057\u3066\u307f\u305f\u3044\u3002<\/p>\n<h1 class=\"my_h\">\u3084\u3063\u3066\u307f\u305f<\/h1>\n<h3 class=\"my_h\">(1) sigmoid, tanh<\/h3>\n<p>\u30b0\u30e9\u30d5\u3092\u898b\u308b\u3068\u4e00\u76ee\u77ad\u7136\u3060\u304c\u3001<br \/>\n\u5165\u529b\u5024\u306e\u7d76\u5bfe\u5024\u304c\u5927\u304d\u3044\u6642\u306b\u51fa\u529b\u5024\u304c\u98fd\u548c\u3059\u308b\uff08\uff1d\u51fa\u529b\u5024\u304c\u307b\u307c\u4e00\u5b9a\u306b\u306a\u308b\uff09<br \/>\n\u3000\u2193<br \/>\n\u9006\u4f1d\u64ad\u3092\u5b9f\u884c\u6642\u306b\u5fae\u5206\u5024\uff08\uff1d\u50be\u304d\u3001\u52fe\u914d\uff09\u304c\u307b\u307c 0\u306b\u306a\u308b\u3002<br \/>\n\u3000\u2193<br \/>\n<span class=\"my_fc_redBBig\">\u52fe\u914d\u6d88\u5931\u554f\u984c\uff08Vanishing Gradient Problem\uff09<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/05\/i001.jpg\" alt=\"\" \/><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# \u5165\u529b\u5024\u306e\u7bc4\u56f2\r\nx = np.linspace(-10, 10, 400)\r\n\r\n# \u6d3b\u6027\u5316\u95a2\u6570\r\nsigmoid = 1 \/ (1 + np.exp(-x))\r\ntanh    = np.tanh(x)\r\n\r\n# \u30b0\u30e9\u30d5\u63cf\u753b\r\nplt.figure(figsize=(8, 5))\r\nplt.plot(x, sigmoid, label=&#039;sigmoid&#039;, linestyle=&#039;-&#039;, linewidth=2)\r\nplt.plot(x, tanh,    label=&#039;tanh&#039;,    linestyle=&#039;-&#039;, linewidth=2)\r\nplt.title(&#039;Activation Functions&#039;)\r\nplt.xlabel(&#039;x&#039;)\r\nplt.ylabel(&#039;y&#039;)\r\nplt.grid(True)\r\nplt.legend()\r\nplt.axhline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.axvline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.tight_layout()\r\nplt.show()\r\n<\/pre>\n<h3 class=\"my_h\">(2) ReLU<\/h3>\n<p>\u5165\u529b\u5024\u304c\u8ca0\u306e\u5024\uff08x &lt; 0\uff09\u306e\u5834\u5408\u306b\u51fa\u529b\u304c 0\u306b\u56fa\u5b9a\u3055\u308c\u308b\u3002<br \/>\n\u3000\u2193<br \/>\n<span class=\"my_fc_redBBig\">\u6b7b\u3093\u3060\u30cb\u30e5\u30fc\u30ed\u30f3\u554f\u984c\uff08Dead Neuron Problem\uff09<br \/>\n\u6b7b\u3093\u3060ReLU\u554f\u984c\uff08Dying ReLU Problem\uff09<\/span><\/p>\n<p>\u2728 ReLU = max(0, x) \u306e\u30e1\u30ea\u30c3\u30c8<br \/>\n\u3000\ud83d\udd39\u6b63\u306e\u5165\u529b\u306f\u305d\u306e\u307e\u307e\u901a\u3059 \u2192 \u52fe\u914d\u306f1\u3067\u6d88\u5931\u3057\u306b\u304f\u3044<br \/>\n\u3000\ud83d\udd39\u8ca0\u306e\u5165\u529b\u306f\u5207\u308a\u6368\u3066\u308b\uff080\uff09\u2192 \u975e\u7dda\u5f62\u3092\u751f\u3080\u3001\u30b9\u30d1\u30fc\u30b9\u6d3b\u6027\u5316<br \/>\n\u3000\u3000 \u2192 \u30ce\u30a4\u30ba\u306b\u5f37\u304f\u306a\u308b\u3002\u904e\u5b66\u7fd2\u306e\u30ea\u30b9\u30af\u3092\u6e1b\u3089\u3059\u3002<br \/>\n\u3000\ud83d\udd39\u8a08\u7b97\u304c\u8efd\u3044\uff08if\u6587\u4e00\u3064\u3067\u6e08\u3080\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/05\/i002.jpg\" alt=\"\" \/><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# ReLU \u95a2\u6570\u306e\u5b9a\u7fa9\r\nrelu = np.maximum(0, x)\r\n\r\n# \u30b0\u30e9\u30d5\u63cf\u753b\r\nplt.figure(figsize=(8, 5))\r\nplt.plot(x, relu, label=&#039;ReLU&#039;, linestyle=&#039;-&#039;, linewidth=2)\r\nplt.title(&#039;ReLU Activation Function&#039;)\r\nplt.xlabel(&#039;x&#039;)\r\nplt.ylabel(&#039;y&#039;)\r\nplt.grid(True)\r\nplt.legend()\r\nplt.axhline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.axvline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.tight_layout()\r\nplt.show()\r\n<\/pre>\n<h3 class=\"my_h\">(3) Leaky ReLU<\/h3>\n<p>\u6b7b\u3093\u3060ReLU\u554f\u984c\u3078\u306e\u5bfe\u7b56\u3068\u3057\u3066\u767b\u5834\u3057\u305f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/nnet\/wp-content\/uploads\/2025\/05\/i003.jpg\" alt=\"\" \/><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# Leaky ReLU \u95a2\u6570\u306e\u5b9a\u7fa9\uff08\u8ca0\u306e\u9818\u57df\u306b\u4fc2\u65700.1\uff09\r\nleaky_relu = np.where(x &gt; 0, x, 0.1 * x)\r\n\r\n# \u30b0\u30e9\u30d5\u63cf\u753b\r\nplt.figure(figsize=(8, 5))\r\nplt.plot(x, leaky_relu, label=&#039;Leaky ReLU (slope=0.1)&#039;, linestyle=&#039;-&#039;, linewidth=2)\r\nplt.title(&#039;Leaky ReLU Activation Function&#039;)\r\nplt.xlabel(&#039;x&#039;)\r\nplt.ylabel(&#039;y&#039;)\r\nplt.grid(True)\r\nplt.legend()\r\nplt.axhline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.axvline(0, color=&#039;gray&#039;, linewidth=0.5)\r\nplt.tight_layout()\r\nplt.show()\r\n<\/pre>\n<h1 class=\"my_h\">ReLU vs Leaky ReLU<\/h1>\n<p>\u901f\u5ea6\u9762\u3001\u5b66\u7fd2\u6027\u80fd\u9762\u3067\u5927\u5dee\u306f\u306a\u3044\u3088\u3046\u3060\u3002<\/p>\n<p>\u6df1\u5c64\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3084\u4e0d\u5b89\u5b9a\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306a\u3069\u3001<br \/>\n<span class=\"my_fc_deeppinkBBig\">ReLU\u3067\u3046\u307e\u304f\u884c\u304b\u306a\u304b\u3063\u305f\u3089 Leaky ReLU\u3092\u4f7f\u3063\u3066\u307f\u308b<\/span><br \/>\n\u306e\u4f7f\u3044\u65b9\u3067\u826f\u3044\u3088\u3046\u3060\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u3084\u308a\u305f\u3044\u3053\u3068 Python\u306e\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b Matplotlib\u3092\u4f7f\u3063\u3066\u3001\u6d3b\u6027\u5316\u95a2\u6570\u3092\u30b0\u30e9\u30d5\u306b\u3057\u3066\u307f\u305f\u3044\u3002 \u3084\u3063\u3066\u307f\u305f (1) sigmoid, tanh \u30b0\u30e9\u30d5\u3092\u898b\u308b\u3068\u4e00\u76ee\u77ad\u7136\u3060\u304c\u3001 \u5165\u529b\u5024\u306e\u7d76\u5bfe\u5024\u304c\u5927\u304d\u3044\u6642\u306b\u51fa\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/nnet\/blog41-python-matplotlib%e3%81%a7%e6%b4%bb%e6%80%a7%e5%8c%96%e9%96%a2%e6%95%b0%e3%81%ae%e3%82%b0%e3%83%a9%e3%83%95%e3%82%92%e6%8f%8f%e3%81%8f%e3%80%82\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,24,23],"tags":[],"class_list":["post-1326","post","type-post","status-publish","format-standard","hentry","category-matplotlib","category-python","category-23"],"views":597,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/comments?post=1326"}],"version-history":[{"count":15,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1326\/revisions"}],"predecessor-version":[{"id":1344,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/posts\/1326\/revisions\/1344"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/media?parent=1326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/categories?post=1326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/nnet\/wp-json\/wp\/v2\/tags?post=1326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}