{"id":437,"date":"2020-04-04T16:53:35","date_gmt":"2020-04-04T07:53:35","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=437"},"modified":"2020-04-04T16:53:35","modified_gmt":"2020-04-04T07:53:35","slug":"%eb%8b%a8%ec%88%9c-%ec%84%a0%ed%98%95-%ed%9a%8c%ea%b7%80simple-linear-regression","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=437","title":{"rendered":"\ub2e8\uc21c \uc120\ud615 \ud68c\uadc0(simple linear regression)"},"content":{"rendered":"<h1>\ub2e8\uc21c \uc120\ud615 \ud68c\uadc0(simple linear regression)<\/h1>\n<p>\uc544\ud30c\ud2b8 \ud3c9\uc218\ub77c\ub294 \ub2e8\ud558\ub098\uc758 <code>\ud2b9\uc131(feature)<\/code> \uc73c\ub85c \uc544\ud30c\ud2b8\uc758 \uac00\uaca9\uc744 \uc608\uce21\ud55c\ub2e4\uace0 \ud560 \ub54c, \uc544\ub798\uc640 \uac19\uc740 <code>\uac00\uc124(Hyperthesis)<\/code> \uc744 \uc138\uc6b8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ucc38\uc870 : <a href=\"https:\/\/katex.org\/docs\/supported.html\">Katex<\/a><\/p>\n<pre><code class=\"language-katex\">H(x) = Wx + b<\/code><\/pre>\n<p>\uc704 \uc218\uc2dd\uc5d0\uc11c <code>W<\/code> \ub294 <code>\uac00\uc911\uce58(Weight)<\/code> \uac00 \ub418\uace0, <code>b<\/code> \ub294 <code>\uc808\ud3b8(bias)<\/code> \uc774 \ub429\ub2c8\ub2e4.<\/p>\n<h2>\uc544\ud30c\ud2b8 \uac00\uaca9 \uc608\uce21<\/h2>\n<p>\uc11c\uc6b8\uc2dc\uc5d0 \uc788\ub294 \uc784\uc758\uc758 10\ucc44\uc758 \uc544\ud30c\ud2b8\uc758 \ud3c9\uc218\uc640 \ub9e4\ub9e4\uac00\ub97c \uad6c\ud574 \uc2dc\uac01\ud654\ud574 \ubcf4\uc558\uc2b5\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nfrom matplotlib import pyplot as plt\n\ndata = np.array([[212, 10.75],\n                 [152, 12.9],\n                 [158, 12.0],\n                 [202, 13.5],\n                 [106, 9.5],\n                 [181, 11.8],\n                 [80, 6.7],\n                 [152, 12.8],\n                 [88, 8.8],\n                 [158, 11.8]])\n\nplt.scatter(data[:, 0], data[:, 1])\nplt.title(&quot;Area \/ Price&quot;)\nplt.xlabel(&quot;Price (million won)&quot;)\nplt.ylabel(&quot;Area (square meter)&quot;)\nplt.axis([0, 420, 0, 50])\nplt.show();<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2020\/04\/20200404-04.png\" alt=\"\" \/><\/p>\n<p>\ub300\uac15 \uc544\ub798\uc640 \uac19\uc740 1\ucc28 \ud568\uc218\uac00 \ud3c9\uade0\uce58\uac00 \ub420 \ub4ef \ud569\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2020\/04\/20200404-05.png\" alt=\"\" \/><\/p>\n<h2>\ube44\uc6a9(cost) \ud568\uc218<\/h2>\n<p>\uc2e4\uc81c\uac12\uacfc \uc608\uce21\uac12\uc758 <code>\uc624\ucc28(error)<\/code> \ub97c \uce21\uc815\ud558\ub294 \ud568\uc218\ub97c <code>\ube44\uc6a9(cost) \ud568\uc218<\/code> \ub77c\uace0 \ud569\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2020\/04\/20200404-06.png\" alt=\"\" \/><\/p>\n<p>\uac00\uc7a5 \ub9ce\uc774 \uc4f0\uc774\ub294 \ud568\uc218\uac00 MSE(Mean Squared Error) \uc785\ub2c8\ub2e4. \uc624\ucc28\uc81c\uacf1\uc758 \ud3c9\uade0\uc744 \uad6c\ud558\ub294 \ubc29\uc2dd\uc785\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-katex\">MSE = \\cfrac 1 n \\displaystyle\\sum_{i=1}^n(y_i - \\tilde{y_i})^2<\/code><\/pre>\n<p>\uac00\uc911\uce58 <code>W<\/code> \ub97c \ubcc0\uacbd\ud558\uba74\uc11c \uc624\ucc28\uac00 \ucd5c\uc18c\uac00 \ub418\ub294 W \ub97c \uad6c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-katex\">J = \\cfrac 1 n \\displaystyle\\sum_{i=1}^n(pred_i - y_i)^2<\/code><\/pre>\n<p>\uc608\uce21\uac12\uacfc \uc2e4\uc81c\uac12\uacfc\uc758 \ucc28\uc774\ub97c \uc81c\uacf1\ud558\uace0 \ud569\uc0b0\ud55c \ud6c4 \ud3c9\uade0\uc744 \ub0b4\uc5b4 \uadf8 \ube44\uc6a9\uc744 \ucd5c\uc18c\ud654\ud558\ub294 <code>W<\/code> \uac12\uc744 \uad6c\ud558\uba74 \ub429\ub2c8\ub2e4.<\/p>\n<h2>\uacbd\uc0ac\ud558\uac15\ubc95<\/h2>\n<p><code>MSE<\/code> \ub294 \uc624\ucc28\ub97c \uc81c\uacf1\ud558\ub294 \ubc29\uc2dd\uc774\uae30 \ub54c\ubb38\uc5d0 <code>W<\/code> \uac00 \ubcc0\ud654\ud560 \ub54c, \uc544\ub798\ucc98\ub7fc 2\ucc28\uc6d0 \uace1\uc120\uc774 \ub429\ub2c8\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.skyer9.pe.kr\/wordpress\/wp-content\/uploads\/2020\/04\/20200404-07.png\" alt=\"\" \/><\/p>\n<p>\uacbd\uc0ac\uac00 \ub0ae\uc544\uc9c0\ub294 \ubc29\ud5a5\uc73c\ub85c <code>W<\/code> \uac12\uc5d0 \ubcc0\ud654\ub97c \uc8fc\uba74\uc11c \uc624\ucc28\ub97c \uc904\uc774\ub294 \ubc29\uc2dd\uc744 <code>\uacbd\uc0ac\ud558\uac15\ubc95<\/code> \uc774\ub77c\uace0 \ud569\ub2c8\ub2e4.<\/p>\n<p><code>W<\/code> \uc5d0 \ubcc0\ud654\ub97c \uc8fc\ub294 \uc815\ub3c4\ub97c <code>\ud559\uc2b5\ub960(learning rate)<\/code> \uc774\ub77c\uace0 \ud569\ub2c8\ub2e4. \ud559\uc2b5\ub960\uc744 \ub108\ubb34 \uc791\uac8c \ud558\uba74 \ub108\ubb34 \uc624\ub79c \uacc4\uc0b0\uc2dc\uac04\uc774 \ub4e4\uace0, \ubc18\ub300\ub85c \ub108\ubb34 \ud070 \uac12\uc744 \ud560\ub2f9\ud558\uac8c \ub418\uba74 \ucd5c\uc801\uc758 <code>W<\/code> \uac12\uc744 \uc9c0\ub098\uccd0 \ubc84\ub9ac\uae30 \ub54c\ubb38\uc5d0 \uc801\uc808\ud55c \ud559\uc2b5\ub960\uc744 \ubd80\uc5ec\ud574\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<h2>\ud30c\uc774\uc36c\uc73c\ub85c \uad6c\ud604\ud558\uae30<\/h2>\n<p><code>sklearn<\/code> \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc774\uc6a9\ud574 \uad6c\ud604\ud574 \ubd05\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-python\">from sklearn.linear_model import LinearRegression\nimport pandas as pd\nimport numpy as np\n\ndata = np.array([[212, 10.75],\n                 [152, 12.9],\n                 [158, 12.0],\n                 [202, 13.5],\n                 [106, 9.5],\n                 [181, 11.8],\n                 [80, 6.7],\n                 [152, 12.8],\n                 [88, 8.8],\n                 [158, 11.8]])\n\ndf = pd.DataFrame({&#039;Area&#039;: data[:, 0], &#039;Price&#039;: data[:, 1]})\n\nX = df[&quot;Area&quot;]\ny = df[&quot;Price&quot;]\n\nline_fitter = LinearRegression()\nline_fitter.fit(X.values.reshape(-1,1), y)\n\nline_fitter.predict([[200]])\n# array([12.91089751])<\/code><\/pre>\n<p>\ud3c9\uc218\uc640 \uac00\uaca9\uc744 \uac01\uac01 <code>X<\/code>, <code>y<\/code> \uc5d0 \uc785\ub825\ud569\ub2c8\ub2e4.<\/p>\n<p>200 \uc81c\uacf1\ubbf8\ud130\uc758 \ub9e4\ub9e4\uac00\ub294 12.9 \uc5b5\uc73c\ub85c \uc608\uce21\ub418\ub294\uad70\uc694.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ub2e8\uc21c \uc120\ud615 \ud68c\uadc0(simple linear regression) \uc544\ud30c\ud2b8 \ud3c9\uc218\ub77c\ub294 \ub2e8\ud558\ub098\uc758 \ud2b9\uc131(feature) \uc73c\ub85c \uc544\ud30c\ud2b8\uc758 \uac00\uaca9\uc744 \uc608\uce21\ud55c\ub2e4\uace0 \ud560 \ub54c, \uc544\ub798\uc640 \uac19\uc740 \uac00\uc124(Hyperthesis) \uc744 \uc138\uc6b8 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ucc38\uc870 : Katex H(x) = Wx + b \uc704 \uc218\uc2dd\uc5d0\uc11c W \ub294 \uac00\uc911\uce58(Weight) \uac00 \ub418\uace0, b \ub294 \uc808\ud3b8(bias) \uc774 \ub429\ub2c8\ub2e4. \uc544\ud30c\ud2b8 \uac00\uaca9 \uc608\uce21 \uc11c\uc6b8\uc2dc\uc5d0 \uc788\ub294 \uc784\uc758\uc758 10\ucc44\uc758 \uc544\ud30c\ud2b8\uc758 \ud3c9\uc218\uc640 \ub9e4\ub9e4\uac00\ub97c \uad6c\ud574 \uc2dc\uac01\ud654\ud574 \ubcf4\uc558\uc2b5\ub2c8\ub2e4.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=437\">Read More &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":[14],"tags":[],"class_list":["post-437","post","type-post","status-publish","format-standard","hentry","category-ml"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":8,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}