{"id":17974,"date":"2022-09-30T23:31:26","date_gmt":"2022-09-30T23:31:26","guid":{"rendered":"https:\/\/club.informatix.co.jp\/?p=17974"},"modified":"2024-10-31T07:40:25","modified_gmt":"2024-10-31T07:40:25","slug":"numpy%e3%81%a7%e8%a1%8c%e5%88%97%e3%80%80%e5%9b%9e%e5%b8%b0%e5%88%86%e6%9e%90-%e3%81%9d%e3%81%ae4%ef%bd%9cpython%e3%81%a7%e6%95%b0%e5%ad%a6%e3%82%92%e5%ad%a6%e3%81%bc%e3%81%86%ef%bc%81%e3%80%80","status":"publish","type":"post","link":"https:\/\/club.informatix.co.jp\/?p=17974","title":{"rendered":"NumPy\u3067\u884c\u5217\u3000\u56de\u5e30\u5206\u6790 \u305d\u306e4\uff5cPython\u3067\u6570\u5b66\u3092\u5b66\u307c\u3046\uff01 \u7b2c25\u56de"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u6b21<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fbd42089427\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fbd42089427\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#NumPy%E3%81%AEpolyfit%E9%96%A2%E6%95%B0%E3%81%A7%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90\" >NumPy\u306epolyfit\u95a2\u6570\u3067\u56de\u5e30\u5206\u6790<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ckaiki1py%E3%80%8D%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90%EF%BC%881%E6%AC%A1%E5%BC%8F%EF%BC%89%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u300ckaiki1.py\u300d\u56de\u5e30\u5206\u6790\uff081\u6b21\u5f0f\uff09\u30d7\u30ed\u30b0\u30e9\u30e0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#STEP1%E3%80%80_%E3%83%87%E3%83%BC%E3%82%BF%E3%82%921%E6%AC%A1%E5%85%83%E9%85%8D%E5%88%97%E3%81%A8%E3%81%97%E3%81%A6%E6%A0%BC%E7%B4%8D%E3%81%99%E3%82%8B\" >STEP1.\u3000 \u30c7\u30fc\u30bf\u30921\u6b21\u5143\u914d\u5217\u3068\u3057\u3066\u683c\u7d0d\u3059\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#STEP2%E3%80%80STEP1%E3%81%AE1%E6%AC%A1%E5%85%83%E9%85%8D%E5%88%97%E3%82%92profit%E9%96%A2%E6%95%B0%E3%81%AB%E6%B8%A1%E3%81%99%E3%81%93%E3%81%A8%E3%81%A7%E5%9B%9E%E5%B8%B0%E4%BF%82%E6%95%B0%E3%81%8C%E5%BE%97%E3%82%89%E3%82%8C%E3%82%8B\" >STEP2.\u3000STEP1\u306e1\u6b21\u5143\u914d\u5217\u3092profit\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u304c\u5f97\u3089\u308c\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#STEP3%E3%80%80%E5%9B%9E%E5%B8%B0%E7%9B%B4%E7%B7%9A%E3%81%AE%E3%82%B0%E3%83%A9%E3%83%95%E3%82%92%E6%8F%8F%E7%94%BB%E3%81%99%E3%82%8B\" >STEP3.\u3000\u56de\u5e30\u76f4\u7dda\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#polyfit%E9%96%A2%E6%95%B0%E3%81%A72%E6%AC%A1%E5%BC%8F%E3%81%AE%E5%9B%9E%E5%B8%B0%E5%BC%8F%E3%82%92%E6%B1%82%E3%82%81%E3%82%8B\" >polyfit\u95a2\u6570\u30672\u6b21\u5f0f\u306e\u56de\u5e30\u5f0f\u3092\u6c42\u3081\u308b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ckaiki2py%E3%80%8D%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90%EF%BC%882%E6%AC%A1%E9%96%A2%E6%95%B0%EF%BC%89%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u300ckaiki2.py\u300d\u56de\u5e30\u5206\u6790\uff082\u6b21\u95a2\u6570\uff09\u30d7\u30ed\u30b0\u30e9\u30e0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/club.informatix.co.jp\/?p=17974\/#%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C-2\" >\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h2><span class=\"ez-toc-section\" id=\"NumPy%E3%81%AEpolyfit%E9%96%A2%E6%95%B0%E3%81%A7%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90\"><\/span>NumPy\u306epolyfit\u95a2\u6570\u3067\u56de\u5e30\u5206\u6790<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6570\u5024\u8a08\u7b97\u30e9\u30a4\u30d6\u30e9\u30ea\u300cNumPy\u300d\u306f\u56de\u5e30\u5206\u6790\u306e\u305f\u3081\u306eprofit\u95a2\u6570\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3055\u3063\u305d\u304f\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u6b21\u306e\u88681\u306e10\u7d44\u306e\u30c7\u30fc\u30bf\u306b\u3064\u3044\u3066\u56de\u5e30\u5206\u6790\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-17977\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-3.jpg\" alt=\"\" width=\"581\" height=\"134\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-3.jpg 581w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-3-300x69.jpg 300w\" sizes=\"(max-width: 581px) 100vw, 581px\" \/>\u88681\uff1a\u8eab\u9577\u3068\u4f53\u91cd\u306e\u30c7\u30fc\u30bf<\/p>\n<ul>\n<li>STEP1.\u3000\u30c7\u30fc\u30bf\u30921\u6b21\u5143\u914d\u5217\u3068\u3057\u3066\u683c\u7d0d\u3059\u308b\u3002<\/li>\n<li>STEP2.\u3000STEP1\u306e1\u6b21\u5143\u914d\u5217\u3092profit\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u304c\u5f97\u3089\u308c\u308b\u3002<\/li>\n<li>STEP3.\u3000\u56de\u5e30\u76f4\u7dda\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ckaiki1py%E3%80%8D%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90%EF%BC%881%E6%AC%A1%E5%BC%8F%EF%BC%89%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ckaiki1.py\u300d\u56de\u5e30\u5206\u6790\uff081\u6b21\u5f0f\uff09\u30d7\u30ed\u30b0\u30e9\u30e0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt; import numpy as np<br \/>\n&gt;&gt;&gt; import matplotlib.pyplot as plt<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # STEP1. \u30c7\u30fc\u30bf\u30921\u6b21\u5143\u914d\u5217\u3068\u3057\u3066\u683c\u7d0d\u3059\u308b<br \/>\n&gt;&gt;&gt; x1_data = np.array([165, 170, 172, 175, 170, 172, 183, 187, 180, 185])<br \/>\n&gt;&gt;&gt; y_data = np.array([ 53, 59, 64, 75, 72, 74, 83, 87, 84, 90])<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # STEP2. STEP1\u306e1\u6b21\u5143\u914d\u5217\u3092profit\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u304c\u5f97\u3089\u308c\u308b<br \/>\n&gt;&gt;&gt; a, b = np.polyfit(x1_data, y_data, 1)<br \/>\n&gt;&gt;&gt; print(&#8220;\u56de\u5e30\u5f0f\uff1ay =&#8221;, a, &#8220;x1 +&#8221;, b)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # STEP3. \u56de\u5e30\u76f4\u7dda\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u753b<br \/>\n&gt;&gt;&gt; margin = 10<br \/>\n&gt;&gt;&gt; x_min, x_max = x1_data.min() &#8211; margin, x1_data.max() + margin<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # \u56de\u5e30\u5f0f\u306e\u76f4\u7dda\u3092\u63cf\u304f\u305f\u3081\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u308b<br \/>\n&gt;&gt;&gt; X1 = np.arange(x_min, x_max, 1)<br \/>\n&gt;&gt;&gt; Y = a * X1 + b<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; plt.figure(dpi=200)<br \/>\n&gt;&gt;&gt; plt.scatter(x1_data, y_data, c=&#8217;Blue&#8217;) # \u88681\u306e\u30c7\u30fc\u30bf\u3092\u30d7\u30ed\u30c3\u30c8<br \/>\n&gt;&gt;&gt; plt.plot(X1, Y, c=&#8217;Red&#8217;) # \u56de\u5e30\u76f4\u7dda\u3092\u63cf\u753b<br \/>\n&gt;&gt;&gt; plt.xlabel(&#8216;x : Height (cm)&#8217;)<br \/>\n&gt;&gt;&gt; plt.ylabel(&#8216;y : Weight (kg)&#8217;)<br \/>\n&gt;&gt;&gt; plt.show()<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u30d5\u30a1\u30a4\u30eb\u306f\u6b21\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/drive.google.com\/file\/d\/1saayabfRHRNLg4btyKU1KLl3i71avzKQ\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">https:\/\/drive.google.com\/file\/d\/1saayabfRHRNLg4btyKU1KLl3i71avzKQ\/view?usp=sharing<\/a><\/p>\n<p>\u56de\u5e30\u76f4\u7dday=ax+b\u306e\u56de\u5e30\u4fc2\u6570a\u3068b\u3092\u6c42\u3081\u308b\u30b3\u30fc\u30c9\u306fSTEP2\u306e1\u884c\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; a, b = np.polyfit(x1_data, y_data, 1)<\/p>\n<p>\u3053\u306e\u3042\u3068\u30c7\u30fc\u30bf\u30fb\u30d7\u30ed\u30c3\u30c8\u3068\u56de\u5e30\u76f4\u7dda\u3092\u63cf\u304f\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u7d9a\u304d\u307e\u3059\u3002\u4f53\u88c1\u826f\u304f\u30b0\u30e9\u30d5\u3092\u63cf\u304f\u305f\u3081\u306b\u5c11\u3057\u9577\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u56de\u5e30\u76f4\u7dda\u3060\u3051\u3092\u6c42\u3081\u308b\u306e\u3067\u3042\u308c\u3070STEP2\u307e\u3067\u306e\u6570\u884c\u3067\u6e08\u307f\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"STEP1%E3%80%80_%E3%83%87%E3%83%BC%E3%82%BF%E3%82%921%E6%AC%A1%E5%85%83%E9%85%8D%E5%88%97%E3%81%A8%E3%81%97%E3%81%A6%E6%A0%BC%E7%B4%8D%E3%81%99%E3%82%8B\"><\/span>STEP1.\u3000 \u30c7\u30fc\u30bf\u30921\u6b21\u5143\u914d\u5217\u3068\u3057\u3066\u683c\u7d0d\u3059\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>NumPy\u306earray\u95a2\u6570\u3092\u7528\u3044\u3066\u88681\u306e\u30c7\u30fc\u30bf\u30921\u6b21\u5143\u914d\u5217\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; import numpy as np<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; x1_data = np.array([165, 170, 172, 175, 170, 172, 183, 187, 180, 185])<br \/>\n&gt;&gt;&gt; y_data = np.array([ 53, 59, 64, 75, 72, 74, 83, 87, 84, 90])<\/p>\n<p>x1_data\u304c\u8eab\u9577\u3001y_data\u304c\u4f53\u91cd\u306e\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"STEP2%E3%80%80STEP1%E3%81%AE1%E6%AC%A1%E5%85%83%E9%85%8D%E5%88%97%E3%82%92profit%E9%96%A2%E6%95%B0%E3%81%AB%E6%B8%A1%E3%81%99%E3%81%93%E3%81%A8%E3%81%A7%E5%9B%9E%E5%B8%B0%E4%BF%82%E6%95%B0%E3%81%8C%E5%BE%97%E3%82%89%E3%82%8C%E3%82%8B\"><\/span>STEP2.\u3000STEP1\u306e1\u6b21\u5143\u914d\u5217\u3092profit\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u304c\u5f97\u3089\u308c\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6b21\u306e\u3088\u3046\u306bpolyfit\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u306ea\u3068b\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; a, b = np.polyfit(x1_data, y_data, 1)<\/p>\n<p>\u7b2c3\u5f15\u6570\u306e1\u306f\u56de\u5e30\u5f0f\u30921\u6b21\u5f0f\u306b\u3059\u308b\u6307\u5b9a\u3067\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"STEP3%E3%80%80%E5%9B%9E%E5%B8%B0%E7%9B%B4%E7%B7%9A%E3%81%AE%E3%82%B0%E3%83%A9%E3%83%95%E3%82%92%E6%8F%8F%E7%94%BB%E3%81%99%E3%82%8B\"><\/span>STEP3.\u3000\u56de\u5e30\u76f4\u7dda\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u30b0\u30e9\u30d5\u63cf\u753b\u306e\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u300cMatplotlib\u300d\u3092\u7528\u3044\u3066\u3001\u5f97\u3089\u308c\u305f\u56de\u5e30\u5f0f\u3092\u53ef\u8996\u5316\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u56de\u5e30\u76f4\u7dda\u306ex\u306e\u7bc4\u56f2\u3092\u3046\u307e\u304f\u6c7a\u3081\u3066\u3042\u3052\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u63cf\u753b\u3059\u308b\u76f4\u7dda\u309210\u7d44\u306e\u30c7\u30fc\u30bf\u306e\u4e21\u7aef\u306e\u30c7\u30fc\u30bf\u3092\u7d50\u3076\u7dda\u5206\u3068\u3059\u308b\u3088\u308a\u3082\u3001\u4e21\u7aef\u306b\u30de\u30fc\u30b8\u30f3\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u56de\u5e30\u76f4\u7dda\u3089\u3057\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>x1_data\u306e\u6700\u5c0f\u5024\u3068\u6700\u5927\u5024\u3092\u53d6\u5f97\u3057\u305d\u308c\u3089\u306b\u30de\u30fc\u30b8\u30f3\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u300110\u500b\u306e\u70b9\u306e\u9818\u57df\u3088\u308a\u3082\u5927\u304d\u306a\u7bc4\u56f2\u306e\u56de\u5e30\u76f4\u7dda\u3092\u63cf\u304d\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; margin = 10<br \/>\n&gt;&gt;&gt; x_min, x_max = x1_data.min() &#8211; margin, x1_data.max() + margin<\/p>\n<p>\u5909\u6570margin\u306e\u5024\u3092\u5909\u3048\u308b\u3053\u3068\u3067\u4f38\u3073\u5e45\u306e\u8abf\u6574\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>kaiki1.py\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u6b21\u306e\u3088\u3046\u306b\u56de\u5e30\u5f0f\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u56de\u5e30\u5f0f\uff1ay = 1.546155406776225 x1 + -197.868736051938<\/p>\n<p>\u3053\u306e\u56de\u5e30\u5f0f\u3092\u4f7f\u3063\u3066\u3001\u8eab\u9577\u304c160cm\u306e\u4f53\u91cd\u3092\u63a8\u6e2c\u3067\u304d\u307e\u3059\u3002x1\u306b160\u3092\u4ee3\u5165\u3057\u3066\u8a08\u7b97\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; 1.546155406776225 * 160 -197.868736051938<\/p>\n<p>\u7d50\u679c\u306f\u300c49.51612903225802\u300d\u3068\u306a\u308a\u3001\u7d0450kg\u3067\u3042\u308b\u3068\u63a8\u6e2c\u3067\u304d\u307e\u3059\u3002\u56de\u5e30\u5206\u6790\u3092\u4f7f\u3046\u3053\u3068\u3067\u63a8\u6e2c\u30fb\u4e88\u6e2c\u304c\u3067\u304d\u308b\u3053\u3068\u304c\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u306e\u73fe\u5834\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u7406\u7531\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u56f31\u306e\u30b0\u30e9\u30d5\u3082\u5408\u308f\u305b\u3066\u51fa\u529b\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u3092\u898b\u308b\u3068\u3001\u56de\u5e30\u76f4\u7dda\u304c10\u500b\u306e\u70b9\u306e\u4e2d\u592e\u3042\u305f\u308a\u3092\u901a\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002\u5b9f\u306b\u3046\u307e\u3044\u5177\u5408\u306b\u56de\u5e30\u5f0f\u304c\u5f97\u3089\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u76f4\u611f\u7684\u306b\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u5f8c\u3001\u6700\u5c0f2\u4e57\u6cd5\u306b\u3088\u308a\u3053\u306e\u3088\u3046\u306a\u76f4\u7dda\u304c\u6c42\u3081\u3089\u308c\u308b\u3053\u3068\u3092\u3058\u3063\u304f\u308a\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-17978\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-1.jpg\" alt=\"\" width=\"1000\" height=\"675\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-1.jpg 1000w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-1-300x203.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-1-768x518.jpg 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/>\u56f31\uff1a\u300ckaiki1.py\u300d\u306e\u5b9f\u884c\u7d50\u679c<\/p>\n<h2><span class=\"ez-toc-section\" id=\"polyfit%E9%96%A2%E6%95%B0%E3%81%A72%E6%AC%A1%E5%BC%8F%E3%81%AE%E5%9B%9E%E5%B8%B0%E5%BC%8F%E3%82%92%E6%B1%82%E3%82%81%E3%82%8B\"><\/span>polyfit\u95a2\u6570\u30672\u6b21\u5f0f\u306e\u56de\u5e30\u5f0f\u3092\u6c42\u3081\u308b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>polyfit\u95a2\u6570\u306e\u7b2c3\u5f15\u6570\u30922\u3068\u3057\u3066\u56de\u5e30\u5f0f\u30922\u6b21\u5f0f y = a*x1\u00b2 + b*x1 + c<br \/>\n\u3068\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>x1_data\u306e2\u4e57\u306b\u8aa4\u5dee\u3092\u52a0\u3048\u305f\u5024\u3092y_data\u3068\u3059\u308b\u5b9f\u9a13\u30c7\u30fc\u30bf\u309220\u7d44\u6e96\u5099\u3057\u307e\u3059\u3002NumPy\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u7528\u610f\u3055\u308c\u305fnp.random.randn\u95a2\u6570\u304c\u4fbf\u5229\u3067\u3059\u3002\u5e73\u57470\u3001\u5206\u65631\uff08\u6a19\u6e96\u504f\u5dee1\uff09\u306e\u6b63\u898f\u5206\u5e03\uff08\u6a19\u6e96\u6b63\u898f\u5206\u5e03\uff09\u306b\u5f93\u3046\u4e71\u6570\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; x1_data = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])<br \/>\n&gt;&gt;&gt; y_data = np.round(x1_data ** 2 + np.random.randn(20) * 10)<\/p>\n<p>polyfit\u95a2\u6570\u306e\u7b2c3\u5f15\u6570\u30922\u3068\u3059\u308b\u3068\u3001\u56de\u5e30\u4fc2\u6570\u306f3\u3064\u8fd4\u3055\u308c\u308b\u306e\u3067\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; a, b, c = np.polyfit(x1_data, y_data, 2)<\/p>\n<p>\u305d\u308c\u306b\u5408\u308f\u305b\u3066\u56de\u5e30\u5f0f\u306e\u51fa\u529b\u3082\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p>&gt;&gt;&gt; print(&#8220;\u56de\u5e30\u5f0f\uff1ay =&#8221;, a, &#8220;x1\u00b2 +&#8221;, b ,&#8221;x1 +&#8221;, c)<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%80%8Ckaiki2py%E3%80%8D%E5%9B%9E%E5%B8%B0%E5%88%86%E6%9E%90%EF%BC%882%E6%AC%A1%E9%96%A2%E6%95%B0%EF%BC%89%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u300ckaiki2.py\u300d\u56de\u5e30\u5206\u6790\uff082\u6b21\u95a2\u6570\uff09\u30d7\u30ed\u30b0\u30e9\u30e0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&gt;&gt;&gt; import numpy as np<br \/>\n&gt;&gt;&gt; import matplotlib.pyplot as plt<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; x1_data = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])<br \/>\n&gt;&gt;&gt; y_data = np.round(x1_data ** 2 + np.random.randn(20) * 10)<br \/>\n&gt;&gt;&gt; print(y_data)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # STEP2. STEP1\u306e1\u6b21\u5143\u914d\u5217\u3092profit\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3067\u56de\u5e30\u4fc2\u6570\u304c\u5f97\u3089\u308c\u308b<br \/>\n&gt;&gt;&gt; a, b, c = np.polyfit(x1_data, y_data, 2)<br \/>\n&gt;&gt;&gt; print(&#8220;\u56de\u5e30\u5f0f\uff1ay =&#8221;, a, &#8220;x1\u00b2 +&#8221;, b,&#8221;x1 +&#8221;, c)<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # STEP3. \u56de\u5e30\u5f0f\u306e\u30b0\u30e9\u30d5\u3092\u63cf\u753b<br \/>\n&gt;&gt;&gt; margin = 2<br \/>\n&gt;&gt;&gt; x_min, x_max = x1_data.min() &#8211; margin, x1_data.max() + margin<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; # \u56de\u5e30\u5f0f\u3092\u63cf\u304f\u305f\u3081\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u308b<br \/>\n&gt;&gt;&gt; X1 = np.arange(x_min, x_max, 1)<br \/>\n&gt;&gt;&gt; Y = a * X1**2 + b * X1 + c<br \/>\n&gt;&gt;&gt;<br \/>\n&gt;&gt;&gt; plt.figure(dpi=200)<br \/>\n&gt;&gt;&gt; plt.scatter(x1_data, y_data, c=&#8217;Blue&#8217;) # \u30c7\u30fc\u30bf\u3092\u30d7\u30ed\u30c3\u30c8<br \/>\n&gt;&gt;&gt; plt.plot(X1, Y, c=&#8217;Red&#8217;) # \u56de\u5e30\u5f0f\u3092\u63cf\u753b<br \/>\n&gt;&gt;&gt; plt.xlabel(&#8216;x1&#8217;)<br \/>\n&gt;&gt;&gt; plt.ylabel(&#8216;y&#8217;)<br \/>\n&gt;&gt;&gt; plt.show()<\/p>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u30d5\u30a1\u30a4\u30eb\u306f\u6b21\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/drive.google.com\/file\/d\/1EO8X9UpSay5EpYk-gn5vXRmL_qd2SdTY\/view?usp=sharing\" target=\"_blank\" rel=\"noopener\">https:\/\/drive.google.com\/file\/d\/1EO8X9UpSay5EpYk-gn5vXRmL_qd2SdTY\/view?usp=sharing<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C-2\"><\/span>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u884c\u7d50\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>kaiki2.py\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u6b21\u306e\u3088\u3046\u306by_data\u3068\u56de\u5e30\u5f0f\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\u3055\u308c\u307e\u3059\u3002y_data\u306fx1_data\u306e\u5024\u30922\u4e57\u3057\u305f\u5024\u3092\u3082\u3068\u306b\u3057\u305f\u3082\u306e\u306a\u306e\u3067x1\u00b2\u306e\u4fc2\u6570a\u306f1\u306b\u8fd1\u30440.91\u3067\u3059\u3002<\/p>\n<p>[ 3. -9. 1. 3. 27. 27. 44. 48. 54. 89. 108. 147. 146. 168. 198. 219. 256. 297. 319. 364.]<br \/>\n\u56de\u5e30\u5f0f\uff1ay = 0.9175780359990887 x1\u00b2 + 1.7171451355661895 x1 + -4.183766233766231<\/p>\n<p>\u305d\u3057\u3066\u56f32\u306e\u30b0\u30e9\u30d5\u3082\u5408\u308f\u305b\u3066\u51fa\u529b\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u3092\u898b\u308b\u3068\u3001\u56de\u5e30\u5f0f\u306e2\u6b21\u5f0f\uff08\u653e\u7269\u7dda\uff09\u306f20\u500b\u306e\u30c7\u30fc\u30bf\u306e\u70b9\u306b\u3046\u307e\u304f\u30d5\u30a3\u30c3\u30c8\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u898b\u3066\u53d6\u308c\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-17979\" src=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-2.jpg\" alt=\"\" width=\"1000\" height=\"675\" srcset=\"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-2.jpg 1000w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-2-300x203.jpg 300w, https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-2-768x518.jpg 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/p>\n<p style=\"text-align: center;\">\u56f32\uff1a2\u6b21\u5f0f\u306e\u56de\u5e30\u5f0f<\/p>\n<p>\u4ee5\u4e0a\u304c\u8aac\u660e\u5909\u65701\u500b\u306e\u5834\u5408\u306e\u56de\u5e30\u5206\u6790\u3067\u5358\u56de\u5e30\u5206\u6790\u3068\u3082\u547c\u3070\u308c\u307e\u3059\u3002<a href=\"https:\/\/club.informatix.co.jp\/?p=18075\" target=\"_blank\" rel=\"noopener\">\u6b21\u56de<\/a>\u306f\u8aac\u660e\u5909\u65702\u500b\u306e\u5834\u5408\u306e\u91cd\u56de\u5e30\u5206\u6790\u3078\u3068\u9032\u307f\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NumPy\u306epolyfit\u95a2\u6570\u3067\u56de\u5e30\u5206\u6790 \u6570\u5024\u8a08\u7b97\u30e9\u30a4\u30d6\u30e9\u30ea\u300cNumPy\u300d\u306f\u56de\u5e30\u5206\u6790\u306e\u305f\u3081\u306eprofit\u95a2\u6570\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002 \u3055\u3063\u305d\u304f\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u6b21\u306e\u88681\u306e10\u7d44\u306e\u30c7\u30fc\u30bf\u306b\u3064\u3044\u3066\u56de\u5e30\u5206\u6790\u3092\u884c\u3044 &#8230; <\/p>\n","protected":false},"author":4,"featured_media":17978,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,464,526],"tags":[65,750],"class_list":["post-17974","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4","category-hito-star-mathmatics","category-526","tag-python","tag-750"],"jetpack_featured_media_url":"https:\/\/club.informatix.co.jp\/wp-content\/uploads\/2022\/09\/20220930-1.jpg","_links":{"self":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17974"}],"version-history":[{"count":11,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17974\/revisions"}],"predecessor-version":[{"id":20756,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/17974\/revisions\/20756"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=\/wp\/v2\/media\/17978"}],"wp:attachment":[{"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/club.informatix.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}