{"id":412,"date":"2020-02-04T23:00:07","date_gmt":"2020-02-04T14:00:07","guid":{"rendered":"https:\/\/obgyn.jp\/?p=412"},"modified":"2022-03-13T19:51:50","modified_gmt":"2022-03-13T10:51:50","slug":"logistic-regression","status":"publish","type":"post","link":"https:\/\/obgyn.jp\/?p=412","title":{"rendered":"Python \u306b\u3088\u308b\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30\u5206\u6790"},"content":{"rendered":"\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\u3067\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002<a href=\"https:\/\/www.statsmodels.org\/stable\/glm.html\" rel=\"noopener noreferrer\" target=\"_blank\">\u4e00\u822c\u5316\u7dda\u5f62\u30e2\u30c7\u30eb<\/a>\u3068\u3057\u3066\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\nimport statsmodels.api as sm<\/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({\"\u518d\u767a\":[\"yes\",\"yes\",\"yes\",\"no\",\"no\",\"no\",\"yes\",\"no\",\"yes\",\"yes\"], \"\u5316\u5b66\u7642\u6cd5\u56de\u6570\":[6,5,4,3,3,3,1,0,0,0], \"\u624b\u8853\u6642\u816b\u760d\u6b8b\u5b58\":[\"yes\",\"yes\",\"yes\",\"no\",\"no\",\"no\",\"no\",\"no\",\"yes\",\"yes\"]})<\/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.glm.html\" rel=\"noopener noreferrer\" target=\"_blank\">statsmodels.formula.api.glm()<\/a> \u30b3\u30de\u30f3\u30c9\u3067\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002\u30ea\u30f3\u30af\u95a2\u6570\u306f\u30ed\u30b8\u30c3\u30c8\u95a2\u6570\u304c\u81ea\u52d5\u7684\u306b\u9078\u629e\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=\"\">result = smf.glm(formula = \"\u518d\u767a ~ \u5316\u5b66\u7642\u6cd5\u56de\u6570 + \u624b\u8853\u6642\u816b\u760d\u6b8b\u5b58\", data = data, family = sm.families.Binomial()).fit()\nresult.summary() #\u7d50\u679c\u306e\u8868\u793a\nresult.aic #\u8d64\u6c60\u60c5\u5831\u91cf\u57fa\u6e96<\/pre>\n\n\n\n<p>\u30aa\u30c3\u30ba\u6bd4\u306f NumPy \u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001 <a href=\"https:\/\/docs.scipy.org\/doc\/numpy\/reference\/generated\/numpy.exp.html\" rel=\"noopener noreferrer\" target=\"_blank\">numpy.exp()<\/a> \u30b3\u30de\u30f3\u30c9\u306e () \u5185\u306b\u5404\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u305d\u306e95%\u4fe1\u983c\u533a\u9593\u306e\u6570\u5024\u3092\u3072\u3068\u3064\u3072\u3068\u3064\u5165\u308c\u3066\u8a08\u7b97\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>statsmodels.formula.api.glm() \u30b3\u30de\u30f3\u30c9\u3067\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\u56de\u5e30\u5206\u6790\u3092\u884c\u3046\u3002\u4e00\u822c\u5316\u7dda\u5f62\u30e2\u30c7\u30eb\u3068\u3057\u3066\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 &hellip; <a href=\"https:\/\/obgyn.jp\/?p=412\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Python \u306b\u3088\u308b\u30ed\u30b8\u30b9\u30c6\u30a3\u30c3\u30af\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-412","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\/412","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=412"}],"version-history":[{"count":35,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/412\/revisions\/1055"}],"wp:attachment":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}