{"id":49,"date":"2024-05-16T09:09:52","date_gmt":"2024-05-16T09:09:52","guid":{"rendered":"http:\/\/www.ohsumin.com\/sm24_wp\/?p=49"},"modified":"2025-06-11T01:23:00","modified_gmt":"2025-06-11T01:23:00","slug":"%ed%9a%8c%ea%b7%80%eb%b6%84%ec%84%9d","status":"publish","type":"post","link":"http:\/\/www.inmining.co.kr\/?p=49","title":{"rendered":"\ud68c\uadc0\ubd84\uc11d(Regression)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud68c\uadc0\ubd84\uc11d\uc740 \ud558\ub098 \uc774\uc0c1\uc758 \ub3c5\ub9bd \ubcc0\uc218\uc640 \uc885\uc18d \ubcc0\uc218 \uac04\uc758 \uad00\uacc4\ub97c \ubd84\uc11d\ud558\uace0 \ubaa8\ub378\ub9c1\ud558\ub294 \ud1b5\uacc4 \uae30\ubc95\uc785\ub2c8\ub2e4. \uc8fc\ub85c \uc608\uce21\uacfc \ubcc0\uc218\ub4e4 \uac04\uc758 \uad00\uacc4\ub97c \ud30c\uc545\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \ud68c\uadc0\ubd84\uc11d\uc5d0\ub294 \ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d\uacfc \ub2e4\uc911\ud68c\uadc0\ubd84\uc11d \ub4f1 \uc5ec\ub7ec \uc885\ub958\uac00 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\\(\\)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_%EB%8B%A8%EC%88%9C%ED%9A%8C%EA%B7%80%EB%B6%84%EC%84%9D_Simple_Linear_Regression\"><\/span>1. \ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d (Simple Linear Regression)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d\uc740 \ud558\ub098\uc758 \ub3c5\ub9bd \ubcc0\uc218\uc640 \ud558\ub098\uc758 \uc885\uc18d \ubcc0\uc218 \uac04\uc758 \uc120\ud615 \uad00\uacc4\ub97c \ubd84\uc11d\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, \uad11\uace0\ube44(\ub3c5\ub9bd \ubcc0\uc218)\uac00 \ub9e4\ucd9c\uc561(\uc885\uc18d \ubcc0\uc218)\uc5d0 \ubbf8\uce58\ub294 \uc601\ud5a5\uc744 \ubd84\uc11d\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud68c\uadc0\uc2dd:<br>\\[ Y = \\beta_0 + \\beta_1 X + \\epsilon \\]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uc5ec\uae30\uc11c:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\\( Y \\): \uc885\uc18d \ubcc0\uc218<\/li>\n\n\n\n<li>\\( X \\): \ub3c5\ub9bd \ubcc0\uc218<\/li>\n\n\n\n<li>\\( \\beta _0  \\) : Y \uc808\ud3b8 (\ud68c\uadc0\uc2dd\uc774 Y\ucd95\uacfc \ub9cc\ub098\ub294 \uc810)<\/li>\n\n\n\n<li>\\( \\beta _1 \\): \uae30\uc6b8\uae30 (\ub3c5\ub9bd \ubcc0\uc218 X\uc758 \ubcc0\ud654\uac00 \uc885\uc18d \ubcc0\uc218 Y\uc5d0 \ubbf8\uce58\ub294 \uc601\ud5a5)<\/li>\n\n\n\n<li>\\( \\epsilon \\): \uc624\ucc28 \ud56d (\uc608\uce21 \uac12\uacfc \uc2e4\uc81c \uac12\uc758 \ucc28\uc774)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_%EB%8B%A4%EC%A4%91%ED%9A%8C%EA%B7%80%EB%B6%84%EC%84%9D_Multiple_Linear_Regression\"><\/span>2. \ub2e4\uc911\ud68c\uadc0\ubd84\uc11d (Multiple Linear Regression)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\ub2e4\uc911\ud68c\uadc0\ubd84\uc11d\uc740 \ub450 \uac1c \uc774\uc0c1\uc758 \ub3c5\ub9bd \ubcc0\uc218\uc640 \uc885\uc18d \ubcc0\uc218 \uac04\uc758 \uad00\uacc4\ub97c \ubd84\uc11d\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, \uad11\uace0\ube44, \uac00\uaca9, \uacc4\uc808 \ub4f1\uc774 \ub9e4\ucd9c\uc561\uc5d0 \ubbf8\uce58\ub294 \uc601\ud5a5\uc744 \ubd84\uc11d\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud68c\uadc0\uc2dd:<br>\\[ Y = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\cdots + \\beta_n X_n + \\epsilon \\]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uc5ec\uae30\uc11c:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\\( X_1, X_2, \\cdots, X_n \\): \ub3c5\ub9bd \ubcc0\uc218\ub4e4<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%ED%9A%8C%EA%B7%80%EB%B6%84%EC%84%9D%EC%9D%98_%EA%B3%BC%EC%A0%95\"><\/span>\ud68c\uadc0\ubd84\uc11d\uc758 \uacfc\uc815<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\ub370\uc774\ud130 \uc218\uc9d1<\/strong>: \ubd84\uc11d\ud558\ub824\ub294 \ubcc0\uc218\uc5d0 \ub300\ud55c \ub370\uc774\ud130\ub97c \uc218\uc9d1\ud569\ub2c8\ub2e4.<\/li>\n\n\n\n<li><strong>\ubaa8\ub378 \uc124\uc815<\/strong>: \ud68c\uadc0\ubaa8\ub378\uc744 \uc124\uc815\ud558\uace0 \ud68c\uadc0\uc2dd\uc744 \ub9cc\ub4ed\ub2c8\ub2e4.<\/li>\n\n\n\n<li><strong>\ud68c\uadc0\ubd84\uc11d \uc218\ud589<\/strong>: \ub370\uc774\ud130\ub97c \uc0ac\uc6a9\ud574 \ud68c\uadc0\ubaa8\ub378\uc744 \ud559\uc2b5\uc2dc\ud0b5\ub2c8\ub2e4.<\/li>\n\n\n\n<li><strong>\ubaa8\ub378 \ud3c9\uac00<\/strong>: R\u00b2, Adjusted R\u00b2, MSE(\ud3c9\uade0 \uc81c\uacf1 \uc624\ucc28) \ub4f1 \uc9c0\ud45c\ub97c \ud1b5\ud574 \ubaa8\ub378\uc758 \uc131\ub2a5\uc744 \ud3c9\uac00\ud569\ub2c8\ub2e4.<\/li>\n\n\n\n<li><strong>\uacb0\uacfc \ud574\uc11d<\/strong>: \ud68c\uadc0\uacc4\uc218(\u03b2 \uac12)\ub97c \ud574\uc11d\ud558\uc5ec \ub3c5\ub9bd \ubcc0\uc218\ub4e4\uc774 \uc885\uc18d \ubcc0\uc218\uc5d0 \ubbf8\uce58\ub294 \uc601\ud5a5\uc744 \ud30c\uc545\ud569\ub2c8\ub2e4.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EC%98%88%EC%A0%9C\"><\/span>\uc608\uc81c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\ub2e4\uc74c\uc740 Python\uc744 \uc0ac\uc6a9\ud55c \ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d \uc608\uc81c\uc785\ub2c8\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import mean_squared_error, r2_score\n\n# \uc608\uc81c \ub370\uc774\ud130 \uc0dd\uc131\nnp.random.seed(0)\nX = 2 * np.random.rand(100, 1)\ny = 4 + 3 * X + np.random.randn(100, 1)\n\n# \ubaa8\ub378 \ud559\uc2b5\nreg = LinearRegression()\nreg.fit(X, y)\ny_pred = reg.predict(X)\n\n# \ud68c\uadc0\uacc4\uc218\nprint('\uc808\ud3b8 (Intercept):', reg.intercept_)\nprint('\uae30\uc6b8\uae30 (Slope):', reg.coef_)\n\n# \ubaa8\ub378 \ud3c9\uac00\nprint('Mean squared error:', mean_squared_error(y, y_pred))\nprint('Coefficient of determination (R\u00b2):', r2_score(y, y_pred))\n\n# \uacb0\uacfc \uc2dc\uac01\ud654\nplt.scatter(X, y, color='blue')\nplt.plot(X, y_pred, color='red', linewidth=2)\nplt.title('Linear Regression Example')\nplt.xlabel('Independent variable (X)')\nplt.ylabel('Dependent variable (y)')\nplt.show()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774 \uc608\uc81c\uc5d0\uc11c\ub294 \uc784\uc758\ub85c \uc0dd\uc131\ud55c \ub370\uc774\ud130\uc5d0 \ub300\ud574 \ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d\uc744 \uc218\ud589\ud558\uace0, \uc808\ud3b8\uacfc \uae30\uc6b8\uae30\ub97c \ucd9c\ub825\ud55c \ud6c4, \uc2e4\uc81c \ub370\uc774\ud130\uc640 \ud68c\uadc0\uc9c1\uc120\uc744 \uc2dc\uac01\ud654\ud569\ub2c8\ub2e4. \uc774\ub97c \ud1b5\ud574 \ub3c5\ub9bd \ubcc0\uc218 X\uac00 \uc885\uc18d \ubcc0\uc218 y\uc5d0 \ubbf8\uce58\ub294 \uc601\ud5a5\uc744 \ud30c\uc545\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud68c\uadc0\ubd84\uc11d\uc744 R\uc5d0\uc11c \uc218\ud589\ud558\ub294 \ucf54\ub4dc\ub97c \uc81c\uacf5\ud574\ub4dc\ub9ac\uaca0\uc2b5\ub2c8\ub2e4. \uc608\uc81c \ub370\uc774\ud130\ub85c \uac04\ub2e8\ud55c \ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d\uacfc \ub2e4\uc911\ud68c\uadc0\ubd84\uc11d\uc744 \uc218\ud589\ud574\ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EB%8B%A8%EC%88%9C%ED%9A%8C%EA%B7%80%EB%B6%84%EC%84%9D_%EC%98%88%EC%A0%9C\"><\/span>\ub2e8\uc21c\ud68c\uadc0\ubd84\uc11d \uc608\uc81c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \ub370\uc774\ud130 \uc0dd\uc131\nset.seed(0)\nX &lt;- 2 * runif(100)\ny &lt;- 4 + 3 * X + rnorm(100)\n\n# \ub370\uc774\ud130 \ud504\ub808\uc784\uc73c\ub85c \ubcc0\ud658\ndata &lt;- data.frame(X, y)\n\n# \ub2e8\uc21c\ud68c\uadc0\ubaa8\ub378 \uc801\ud569\nmodel &lt;- lm(y ~ X, data=data)\n\n# \ubaa8\ub378 \uc694\uc57d\nsummary(model)\n\n# \ud68c\uadc0\uc120 \uc2dc\uac01\ud654\nplot(data$X, data$y, main=\"Linear Regression Example\",\n     xlab=\"Independent Variable (X)\", ylab=\"Dependent Variable (y)\")\nabline(model, col=\"red\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EB%8B%A4%EC%A4%91%ED%9A%8C%EA%B7%80%EB%B6%84%EC%84%9D_%EC%98%88%EC%A0%9C\"><\/span>\ub2e4\uc911\ud68c\uadc0\ubd84\uc11d \uc608\uc81c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \ub370\uc774\ud130 \uc0dd\uc131\nset.seed(0)\nX1 &lt;- 2 * runif(100)\nX2 &lt;- 3 * runif(100)\ny &lt;- 4 + 3 * X1 + 2 * X2 + rnorm(100)\n\n# \ub370\uc774\ud130 \ud504\ub808\uc784\uc73c\ub85c \ubcc0\ud658\ndata &lt;- data.frame(X1, X2, y)\n\n# \ub2e4\uc911\ud68c\uadc0\ubaa8\ub378 \uc801\ud569\nmodel &lt;- lm(y ~ X1 + X2, data=data)\n\n# \ubaa8\ub378 \uc694\uc57d\nsummary(model)\n\n# \ub2e4\uc911\ud68c\uadc0 \uc2dc\uac01\ud654 (3D)\nlibrary(scatterplot3d)\ns3d &lt;- scatterplot3d(data$X1, data$X2, data$y, pch=16, highlight.3d=TRUE, type=\"h\")\ns3d$plane3d(model)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%EC%BD%94%EB%93%9C_%EC%84%A4%EB%AA%85\"><\/span>\ucf54\ub4dc \uc124\uba85<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\ub370\uc774\ud130 \uc0dd\uc131 \ubc0f \ubcc0\ud658<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>set.seed(0)<\/code>: \ub09c\uc218 \uc0dd\uc131\uc744 \uc704\ud55c \uc2dc\ub4dc \uc124\uc815.<\/li>\n\n\n\n<li><code>runif()<\/code>: \uade0\ub4f1 \ubd84\ud3ec\ub97c \ub530\ub974\ub294 \ub09c\uc218 \uc0dd\uc131.<\/li>\n\n\n\n<li><code>data.frame()<\/code>: \ub370\uc774\ud130\ub97c \ub370\uc774\ud130 \ud504\ub808\uc784\uc73c\ub85c \ubcc0\ud658.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\ub2e8\uc21c\ud68c\uadc0\ubaa8\ub378 \uc801\ud569<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>lm()<\/code>: \uc120\ud615 \ud68c\uadc0 \ubaa8\ub378\uc744 \uc801\ud569.<\/li>\n\n\n\n<li><code>summary()<\/code>: \ubaa8\ub378\uc758 \uc694\uc57d \ud1b5\uacc4\ub7c9\uc744 \ucd9c\ub825.<\/li>\n\n\n\n<li><code>plot()<\/code>, <code>abline()<\/code>: \ub370\uc774\ud130\ub97c \uc2dc\uac01\ud654\ud558\uace0 \ud68c\uadc0\uc120\uc744 \ucd94\uac00.<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\ub2e4\uc911\ud68c\uadc0\ubaa8\ub378 \uc801\ud569<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ub2e8\uc21c\ud68c\uadc0\ubaa8\ub378\uacfc \ub3d9\uc77c\ud558\uc9c0\ub9cc, <code>lm(y ~ X1 + X2, data=data)<\/code>\ub97c \uc0ac\uc6a9\ud558\uc5ec \ub450 \uac1c \uc774\uc0c1\uc758 \ub3c5\ub9bd \ubcc0\uc218\ub97c \ud3ec\ud568.<\/li>\n\n\n\n<li><code>scatterplot3d<\/code> \ud328\ud0a4\uc9c0\ub97c \uc0ac\uc6a9\ud558\uc5ec 3D \uc2dc\uac01\ud654.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\uc774 \ucf54\ub4dc\ub294 R\uc5d0\uc11c \ud68c\uadc0\ubd84\uc11d\uc744 \uc218\ud589\ud558\ub294 \uae30\ubcf8\uc801\uc778 \ubc29\ubc95\uc744 \ubcf4\uc5ec\uc90d\ub2c8\ub2e4. \uc2e4\uc81c \ub370\uc774\ud130\uc5d0 \ub9de\ucdb0 \ubcc0\uc218\ub97c \ubcc0\uacbd\ud558\uc5ec \uc0ac\uc6a9\ud558\uba74 \ub429\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud68c\uadc0\ubd84\uc11d\uc740 \ud558\ub098 \uc774\uc0c1\uc758 \ub3c5\ub9bd \ubcc0\uc218\uc640 \uc885\uc18d \ubcc0\uc218 \uac04\uc758 \uad00\uacc4\ub97c \ubd84\uc11d\ud558\uace0 \ubaa8\ub378\ub9c1\ud558\ub294 \ud1b5\uacc4 \uae30\ubc95\uc785\ub2c8\ub2e4. \uc8fc\ub85c \uc608\uce21\uacfc \ubcc0\uc218\ub4e4 \uac04\uc758 \uad00\uacc4\ub97c&#8230;<\/p>\n","protected":false},"author":1,"featured_media":277,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stat","wpcat-6-id"],"_links":{"self":[{"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=49"}],"version-history":[{"count":38,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":574,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions\/574"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=\/wp\/v2\/media\/277"}],"wp:attachment":[{"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.inmining.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}