{"id":126,"date":"2020-01-01T22:00:47","date_gmt":"2020-01-01T13:00:47","guid":{"rendered":"https:\/\/obgyn.jp\/?p=126"},"modified":"2022-03-13T19:52:54","modified_gmt":"2022-03-13T10:52:54","slug":"correlation","status":"publish","type":"post","link":"https:\/\/obgyn.jp\/?p=126","title":{"rendered":"Python \u306b\u3088\u308b\u76f8\u95a2\u4fc2\u6570\u306e\u8a08\u7b97"},"content":{"rendered":"\n<p><a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.DataFrame.corr.html\" rel=\"noopener noreferrer\" target=\"_blank\">pandas.DataFrame.corr()<\/a> \u30b3\u30de\u30f3\u30c9\u3092\u3064\u304b\u3044\u3001\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\u3002P \u5024\u3082\u8a08\u7b97\u3057\u305f\u3044\u5834\u5408\u306b\u306f <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.stats.pearsonr.html\" rel=\"noopener noreferrer\" target=\"_blank\">scipy.stats.pearsonr()<\/a> \u3092\u4f7f\u3046\u3002<\/p>\n\n\n\n<p>Python \u3092\u8d77\u52d5\u3057\u3001pandas \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<\/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({\"\u7e2b\u5408\u7d50\u7d2e\u306e\u7df4\u7fd2\u6642\u9593 (\u6642\u9593)\":[100,150,200,250,300,1000], \"\u624b\u8853\u6642\u9593 (\u5206)\":[210,220,150,100,90,45], \"\u51fa\u8840\u91cf (ml)\":[50,70,60,30,20,10]})<\/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>corr()\u30b3\u30de\u30f3\u30c9\u3067\u30d4\u30a2\u30bd\u30f3\u7a4d\u7387\u76f8\u95a2\u4fc2\u6570\uff08\u3044\u308f\u3086\u308b\u76f8\u95a2\u4fc2\u6570\uff09\u3092\u8868\u793a\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.corr() #\u30d4\u30a2\u30bd\u30f3\u7a4d\u7387\u76f8\u95a2\u4fc2\u6570\u3002<\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u9806\u4f4d\u76f8\u95a2\u4fc2\u6570\u3082\u8a08\u7b97\u3067\u304d\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.corr(method = \"spearman\") #\u30b9\u30d4\u30a2\u30de\u30f3\u9806\u4f4d\u76f8\u95a2\u4fc2\u6570\u3002\ndata.corr(method = \"kendall\") #\u30b1\u30f3\u30c9\u30fc\u30eb\u9806\u4f4d\u76f8\u95a2\u4fc2\u6570\u3002<\/pre>\n\n\n\n<p>Pandas \u3060\u3051\u3067\u306f P \u5024\u306f\u81ea\u52d5\u8a08\u7b97\u3055\u308c\u306a\u3044\u3002\u3053\u308c\u3082\u8a08\u7b97\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b scipy.stats \u3092 import \u3057\u3066\u4f7f\u3046\u3002\u3053\u3053\u3067\u306f\u3001x = \u7e2b\u5408\u7d50\u7d2e\u306e\u7df4\u7fd2\u6642\u9593 (\u6642\u9593)\u3001y = \u624b\u8853\u6642\u9593 (\u5206)\u3092 data \u304b\u3089\u62bd\u51fa\u3057\u3001x \u3068 y \u306e\u76f8\u95a2\u4fc2\u6570\u3068\u4e21\u5074\u691c\u5b9a\u306b\u3088\u308b P \u5024\u3092\u8a08\u7b97\u3057\u3066\u3044\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=\"\">from scipy import stats\nx, y = data[\"\u7e2b\u5408\u7d50\u7d2e\u306e\u7df4\u7fd2\u6642\u9593 (\u6642\u9593)\"], data[\"\u624b\u8853\u6642\u9593 (\u5206)\"]\nstats.pearsonr(x, y) #\u30d4\u30a2\u30bd\u30f3\u7a4d\u7387\u76f8\u95a2\u4fc2\u6570\u3002\nstats.spearmanr(x, y) #\u30b9\u30d4\u30a2\u30de\u30f3\u9806\u4f4d\u76f8\u95a2\u4fc2\u6570\u3002\nstats.kendalltau(x, y) #\u30b1\u30f3\u30c9\u30fc\u30eb\u9806\u4f4d\u76f8\u95a2\u4fc2\u6570\u3002<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>pandas.DataFrame.corr() \u30b3\u30de\u30f3\u30c9\u3092\u3064\u304b\u3044\u3001\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\u3002P \u5024\u3082\u8a08\u7b97\u3057\u305f\u3044\u5834\u5408\u306b\u306f scipy.stats.pearsonr() \u3092\u4f7f\u3046\u3002 Python \u3092\u8d77\u52d5\u3057\u3001pandas \u3092 impo &hellip; <a href=\"https:\/\/obgyn.jp\/?p=126\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Python \u306b\u3088\u308b\u76f8\u95a2\u4fc2\u6570\u306e\u8a08\u7b97<\/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":[36],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-data-science","tag-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/126","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=126"}],"version-history":[{"count":28,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":1086,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/126\/revisions\/1086"}],"wp:attachment":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}