{"id":557,"date":"2018-12-23T21:20:38","date_gmt":"2018-12-23T13:20:38","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=557"},"modified":"2019-01-03T21:22:12","modified_gmt":"2019-01-03T13:22:12","slug":"1-16","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2018\/12\/23\/1-16\/","title":{"rendered":"\u3010\u6570\u636e\u5206\u6790\u3011\u4e24\u79cd\u76f8\u5173"},"content":{"rendered":"<h2>\u4e24\u79cd\u76f8\u5173<\/h2>\n<p>\u6700\u8fd1\u9047\u5230\u9700\u8981\u7528\u7edf\u8ba1\u5b66\u77e5\u8bc6\u8861\u91cf\u4e24\u4e2a\u53d8\u91cf\u7684\u76f8\u5173\u7a0b\u5ea6\uff0c\u4e8e\u662f\u7528\u4e86scipy\u4e2d\u7684\u5de5\u5177\u4e2dPearson\u76f8\u5173\u4e0eSpearman\u76f8\u5173\u7cfb\u6570\u3002<\/p>\n<ul>\n<li>Pearson\u76f8\u5173\u4e3b\u8981\u6765\u8861\u91cf\u7ebf\u6027\u5206\u5e03\u4e4b\u95f4\u7684\u76f8\u4f3c\u6027\u3002\u5f53\u4e24\u4e2a\u6210\u6b63\u6bd4\u4f8b\u4e14\u589e\u957f\u901f\u5ea6\u4e00\u76f4\u65f6\uff0cPearson\u63a5\u8fd1\u4e8e1\u3002<\/li>\n<li>Spearman\u76f8\u5173\u4e3b\u8981\u6765\u5ea6\u91cf\u5355\u8c03\u5173\u7cfb\u3002\u540c\u662f\u5355\u8c03\u589e\u957f\u65f6\uff0cSpearman\u63a5\u8fd11\uff0c\u54ea\u6015\u589e\u957f\u901f\u7387\u5dee\u522b\u5f88\u5927\u3002\n<p>\u5b83\u4fe9\u7684\u5173\u7cfb\uff0c\u4e0b\u9762\u8fd9\u7bc7\u6587\u7ae0\u8bf4\u7684\u975e\u5e38\u597d\uff1a<a href=\"https:\/\/support.minitab.com\/zh-cn\/minitab\/18\/help-and-how-to\/statistics\/basic-statistics\/supporting-topics\/correlation-and-covariance\/a-comparison-of-the-pearson-and-spearman-correlation-methods\/\" rel=\"noopener\" target=\"_blank\">Pearson \u76f8\u5173\u65b9\u6cd5\u548cSpearman\u76f8\u5173\u65b9\u6cd5\u7684\u6bd4\u8f83<\/a><\/p>\n<p>Pearson\u548cSpearman\u5728\u8861\u91cf\u4e24\u4e2a\u91cf\u6ca1\u6709\u5173\u7cfb\u4e0a\u90fd\u5f88\u7ed9\u529b\u3002\u5982\u679c\u7edd\u5bf9\u503c\u63a5\u8fd1\u4e8e0\uff0c\u90a3\u4e48\u5dee\u4e0d\u591a\u5c31\u662f\u6ca1\u5173\u7cfb\u4e86\u3002\u5176\u4e2d\uff0cPearson\u57280.8-1.0\uff0c\u4e3a\u6781\u5f3a\u76f8\u5173\uff0c0.6-0.8\u4e3a\u5f3a\u76f8\u5173\uff0c0.4-0.6\u4e3a\u4e2d\u7b49\u7a0b\u5ea6\u76f8\u5173\uff0c0.2-0.4\u4e3a\u5f31\u76f8\u5173\uff0c0-0.2\u4e3a\u6781\u5f31\u76f8\u5173\u6216\u65e0\u5173\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u9644\u4e0a\u4e00\u4e2a\u5c0fDemo\uff1a<\/p>\n<pre><code>import numpy as np\nfrom scipy.stats import pearsonr\nfrom scipy.stats import spearmanr\nfrom scipy.stats import ttest_ind\n\nx = np.random.normal(0,1,500) # \u4ece-1\u52301\u751f\u6210\u968f\u673a\u6570\ny1 = np.random.normal(0,1,500) # \u5747\u503c\u4e3a0\uff0c\u65b9\u5dee\u4e3a1\u7684\u4e00\u7ec4\u6570\ny2 = np.random.normal(0,100,500) # \u5747\u503c\u4e3a0\uff0c\u65b9\u5dee\u4e3a10\u7684\u4e00\u7ec4\u6570\n\nprint(\"----------------pearson----------------\")\nr1, p1 = pearsonr(x,y1)\nprint(\"r1 = \",r1)\nprint(\"p1 = \",p1)\n\n#y2\u76f8\u6bd4\u4e8ey1,\u65b9\u5dee\u66f4\u5927\uff0c\u6df7\u4e71\u7a0b\u5ea6\u66f4\u9ad8\uff0c\u4e0e\u76f8x1\u7684\u76f8\u5173\u6027\u8d8a\u5dee\nr2, p2 = pearsonr(x,y2)\nprint(\"r2 = \",r2) #[-1,1],\u7edd\u5bf9\u503c\u7ea6\u5927\u8d8a\u76f8\u5173\uff0c\u6b63\u4e3a\u6b63\u76f8\u5173\uff0c\u8d1f\u4e3a\u8d1f\u76f8\u5173\uff0c\u4e3a0\u65f6\u4e0d\u76f8\u5173\nprint(\"p2 = \",p2) #\u6052\u4e3a\u975e\u8d1f\uff0c\u8d8a\u5927\u8d8a\u76f8\u5173\uff0c500\u4e2a\u6837\u672c\u4ee5\u4e0a\u6709\u8f83\u9ad8\u53ef\u9760\u6027\nprint(\"----------------spearman---------------\")\n\nc1, pv1 = spearmanr(x,y1)\nprint(\"c1 = \",c1)\nprint(\"pv1 = \",pv1)\n\n#y2\u76f8\u6bd4\u4e8ey1,\u65b9\u5dee\u66f4\u5927\uff0c\u6df7\u4e71\u7a0b\u5ea6\u66f4\u9ad8\uff0c\u4e0e\u76f8x1\u7684\u76f8\u5173\u6027\u8d8a\u5dee\nc2, pv2 = spearmanr(x,y2)\nprint(\"c2 = \",c2) #[-1,1],\u7edd\u5bf9\u503c\u7ea6\u5927\u8d8a\u76f8\u5173\uff0c\u6b63\u4e3a\u6b63\u76f8\u5173\uff0c\u8d1f\u4e3a\u8d1f\u76f8\u5173\uff0c\u4e3a0\u65f6\u4e0d\u76f8\u5173\nprint(\"pv2 = \",pv2) #\u6052\u4e3a\u975e\u8d1f\uff0c\u8d8a\u5927\u8d8a\u76f8\u5173\uff0c500\u4e2a\u6837\u672c\u4ee5\u4e0a\u6709\u8f83\u9ad8\u53ef\u9760\u6027\n\n#\u663e\u8457\u6027\u68c0\u9a8c\nstat_val, p_val = ttest_ind(x, y1, equal_var=False)\nprint(\"----------------P-----------------------\")\nprint(\"stat_val = \",stat_val) #\u76f8\u5173\u6027\nprint(\"p_val = \",p_val) #\u662f\u5426\u663e\u8457 &lt;0.05\u4e3a\u663e\u8457\u6027\n<\/code><\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre><code>----------------pearson----------------\nr1 =  0.0001927775402233908\np1 =  0.9965692283410943\nr2 =  -0.04099559625239573\np2 =  0.3603073242705398\n----------------spearman---------------\nc1 =  0.011400429601718408\npv1 =  0.7992703026447947\nc2 =  -0.03298323593294373\npv2 =  0.4618025913714844\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e24\u79cd\u76f8\u5173 \u6700\u8fd1\u9047\u5230\u9700\u8981\u7528\u7edf\u8ba1\u5b66\u77e5\u8bc6\u8861\u91cf\u4e24\u4e2a\u53d8\u91cf\u7684\u76f8\u5173\u7a0b\u5ea6\uff0c\u4e8e\u662f\u7528\u4e86scipy\u4e2d\u7684\u5de5\u5177\u4e2dPearson\u76f8\u5173\u4e0eSp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[44],"tags":[93,92],"class_list":["post-557","post","type-post","status-publish","format-standard","hentry","category-44","tag-93","tag-92"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9Hs6X-8Z","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=557"}],"version-history":[{"count":7,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/557\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}