{"id":381,"date":"2020-01-29T22:00:23","date_gmt":"2020-01-29T13:00:23","guid":{"rendered":"https:\/\/obgyn.jp\/?p=381"},"modified":"2022-03-13T19:51:51","modified_gmt":"2022-03-13T10:51:51","slug":"linear-regression","status":"publish","type":"post","link":"https:\/\/obgyn.jp\/?p=381","title":{"rendered":"Python \u306b\u3088\u308b\u91cd\u56de\u5e30\u5206\u6790"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.statsmodels.org\/dev\/generated\/statsmodels.formula.api.ols.html\" rel=\"noopener noreferrer\" target=\"_blank\">statsmodels.formula.api.ols()<\/a> \u30b3\u30de\u30f3\u30c9\u3067\u91cd\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002<\/p>\n\n\n\n<p>Python \u3092\u8d77\u52d5\u3057\u3001\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092 import \u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\nimport statsmodels.formula.api as smf<\/pre>\n\n\n\n<p>\u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 pandas \u306b\u8aad\u307f\u8fbc\u3093\u3067\u5206\u6790\u3059\u308b\u3002\u3057\u304b\u3057\u3001\u3053\u3053\u3067\u306f\u4fbf\u5b9c\u7684\u306b\u4ee5\u4e0b\u306e\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c\u6210\u3057\u3001data \u3068\u3044\u3046\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data = pd.DataFrame({\"\u51fa\u8840\u91cf\":[10,200,300,5,5,3,250,500], \"\u624b\u8853\u65b9\u6cd5\":[\"\u5185\u8996\u93e1\",\"\u958b\u8179\",\"\u958b\u8179\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\",\"\u958b\u8179\",\"\u958b\u8179\"], \"\u624b\u8853\u6642\u9593\":[60,50,60,60,30,40,60,50]})<\/pre>\n\n\n\n<p>data \u306e\u5185\u5bb9\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data<\/pre>\n\n\n\n<p><a href=\"https:\/\/www.statsmodels.org\/dev\/generated\/statsmodels.formula.api.ols.html\" rel=\"noopener noreferrer\" target=\"_blank\">statsmodels.formula.api.ols()<\/a> \u30b3\u30de\u30f3\u30c9\u3067\u91cd\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002\u5358\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3053\u3068\u3082\u3067\u304d\u308b\u3002\u624b\u8853\u65b9\u6cd5\u306e\u3088\u3046\u306a2\u5024\u30c7\u30fc\u30bf\u306f\u30c0\u30df\u30fc\u306b\u5909\u63db\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">lm = smf.ols(\"\u51fa\u8840\u91cf ~ \u624b\u8853\u6642\u9593 + \u624b\u8853\u65b9\u6cd5\", data).fit()\nlm.summary() #\u7d50\u679c\u306e\u8868\u793a\u3002<\/pre>\n\n\n\n<p><a href=\"https:\/\/www.statsmodels.org\/dev\/generated\/statsmodels.formula.api.glm.html\" rel=\"noopener noreferrer\" target=\"_blank\">statsmodels.formula.api.glm()<\/a> \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3044\u3001\u4e00\u822c\u5316\u7dda\u5f62\u30e2\u30c7\u30eb\u3068\u3057\u3066\u91cd\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3053\u3068\u3082\u3067\u304d\u308b\u3002\u3053\u306e\u5834\u5408\u3001\u691c\u5b9a\u306f t \u691c\u5b9a\u3067\u306f\u306a\u304f\u3001Wald \u691c\u5b9a\u304c\u884c\u308f\u308c\u308b\u3002\u30ea\u30f3\u30af\u95a2\u6570\u306f\u6052\u7b49\u95a2\u6570\u304c\u81ea\u52d5\u7684\u306b\u9078\u629e\u3055\u308c\u308b\u3002\u307e\u305f\u3001summary() \u30b3\u30de\u30f3\u30c9\u3067 AIC\uff08\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96\uff09\u306f\u8868\u793a\u3055\u308c\u306a\u3044\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import statsmodels.api as sm #\u78ba\u7387\u5206\u5e03\u6307\u5b9a\u306e\u305f\u3081\u306b\u5fc5\u8981\nglm = smf.glm(formula = \"\u51fa\u8840\u91cf ~ \u624b\u8853\u6642\u9593 + \u624b\u8853\u65b9\u6cd5\", data = data, family = sm.families.Gaussian()).fit()\nglm.summary() #\u7d50\u679c\u306e\u8868\u793a\nglm.aic #\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>statsmodels.formula.api.ols() \u30b3\u30de\u30f3\u30c9\u3067\u91cd\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002 Python \u3092\u8d77\u52d5\u3057\u3001\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092 import \u3059\u308b\u3002 \u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 panda &hellip; <a href=\"https:\/\/obgyn.jp\/?p=381\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Python \u306b\u3088\u308b\u91cd\u56de\u5e30\u5206\u6790<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[18,19,36],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-data-science","tag-multivariate","tag-model","tag-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=381"}],"version-history":[{"count":20,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":1069,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions\/1069"}],"wp:attachment":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}