{"id":4801,"date":"2024-09-08T08:17:49","date_gmt":"2024-09-08T00:17:49","guid":{"rendered":"http:\/\/cnliutz.ipyingshe.net\/?p=4801"},"modified":"2024-09-08T08:25:15","modified_gmt":"2024-09-08T00:25:15","slug":"%e5%88%a9%e7%94%a8scipy%e8%bf%9b%e8%a1%8c%e7%bb%9f%e8%ae%a1%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/xc.ipyingshe.net:5347\/?p=4801","title":{"rendered":"\u5229\u7528scipy\u8fdb\u884c\u7edf\u8ba1\u5206\u6790"},"content":{"rendered":"\n<p>\u901a\u5e38\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u7684 Python \u5e93\u5305\u62ec <code>SciPy<\/code>\u3001<code>Pandas<\/code> \u548c <code>StatsModels<\/code> \u7b49\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 <code>SciPy<\/code> \u5e93\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u88c5 <code>SciPy<\/code> \u5e93<\/h3>\n\n\n\n<p>\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5 <code>SciPy<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install scipy<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528 <code>SciPy<\/code> \u8fdb\u884c\u7edf\u8ba1\u5206\u6790<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u7edf\u8ba1\u5206\u6790\u793a\u4f8b\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. \u63cf\u8ff0\u6027\u7edf\u8ba1<\/h4>\n\n\n\n<p>\u8ba1\u7b97\u6570\u636e\u96c6\u7684\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u3001\u6807\u51c6\u5dee\u3001\u504f\u5ea6\u548c\u5cf0\u5ea6\uff1a<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br>from scipy import stats<br>\u200b<br># \u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u636e\u96c6<br>data = np.random.randint(0, 100, size=100)<br>\u200b<br># \u8ba1\u7b97\u5747\u503c<br>mean = np.mean(data)<br># \u8ba1\u7b97\u4e2d\u4f4d\u6570<br>median = np.median(data)<br># \u8ba1\u7b97\u6807\u51c6\u5dee<br>std_dev = np.std(data)<br># \u8ba1\u7b97\u504f\u5ea6<br>skewness = stats.skew(data)<br># \u8ba1\u7b97\u5cf0\u5ea6<br>kurtosis = stats.kurtosis(data)<br>\u200b<br>print(\"\u5747\u503c:\", mean)<br>print(\"\u4e2d\u4f4d\u6570:\", median)<br>print(\"\u6807\u51c6\u5dee:\", std_dev)<br>print(\"\u504f\u5ea6:\", skewness)<br>print(\"\u5cf0\u5ea6:\", kurtosis)<\/pre>\n\n\n\n<p>AI \u751f\u6210\u7684\u4ee3\u7801\u3002\u4ed4\u7ec6\u67e5\u770b\u548c\u4f7f\u7528\u3002 <a href=\"https:\/\/www.bing.com\/new#faq\">\u6709\u5173\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\u7684\u8be6\u7ec6\u4fe1\u606f<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. \u5047\u8bbe\u68c0\u9a8c<\/h4>\n\n\n\n<p>\u6267\u884c\u72ec\u7acb\u6837\u672c t \u68c0\u9a8c\u6765\u6bd4\u8f83\u4e24\u4e2a\u6837\u672c\u4e4b\u95f4\u7684\u5747\u503c\u5dee\u5f02\uff1a<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from scipy import stats<br>\u200b<br># \u521b\u5efa\u4e24\u4e2a\u6837\u672c<br>sample1 = [1, 2, 3, 4, 5]<br>sample2 = [2, 4, 6, 8, 10]<br>\u200b<br># \u6267\u884c\u72ec\u7acb\u6837\u672c t \u68c0\u9a8c<br>t_statistic, p_value = stats.ttest_ind(sample1, sample2)<br>\u200b<br>print(\"t \u7edf\u8ba1\u91cf:\", t_statistic)<br>print(\"p \u503c:\", p_value)<\/pre>\n\n\n\n<p>AI \u751f\u6210\u7684\u4ee3\u7801\u3002\u4ed4\u7ec6\u67e5\u770b\u548c\u4f7f\u7528\u3002 <a href=\"https:\/\/www.bing.com\/new#faq\">\u6709\u5173\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\u7684\u8be6\u7ec6\u4fe1\u606f<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u56de\u5f52\u5206\u6790<\/h4>\n\n\n\n<p>\u8fdb\u884c\u7b80\u5355\u7ebf\u6027\u56de\u5f52\u5206\u6790\uff1a<\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br>from scipy import stats<br>\u200b<br># \u521b\u5efa\u4e24\u4e2a\u53d8\u91cf<br>x = np.array([1, 2, 3, 4, 5])<br>y = np.array([2, 4, 6, 8, 10])<br>\u200b<br># \u6267\u884c\u7ebf\u6027\u56de\u5f52<br>slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)<br>\u200b<br>print(\"\u659c\u7387:\", slope)<br>print(\"\u622a\u8ddd:\", intercept)<br>print(\"\u76f8\u5173\u7cfb\u6570:\", r_value)<br>print(\"p \u503c:\", p_value)<br>print(\"\u6807\u51c6\u8bef\u5dee:\", std_err)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5168\u90e8\u4ee3\u7801<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u901a\u5e38\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u7684 Python \u5e93\u5305\u62ec `SciPy`\u3001`Pandas` \u548c `StatsModels` \u7b49\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 `SciPy` \u5e93\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u7684\u793a\u4f8b\uff1a\n### \u5b89\u88c5 `SciPy` \u5e93\n# \u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5 `SciPy`\uff1a\n# ```bash\n# pip install scipy\n# ```\n# ### \u4f7f\u7528 `SciPy` \u8fdb\u884c\u7edf\u8ba1\u5206\u6790\n# \u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u7edf\u8ba1\u5206\u6790\u793a\u4f8b\uff1a\n# #### 1. \u63cf\u8ff0\u6027\u7edf\u8ba1\n# \u8ba1\u7b97\u6570\u636e\u96c6\u7684\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u3001\u6807\u51c6\u5dee\u3001\u504f\u5ea6\u548c\u5cf0\u5ea6\uff1a\n\nimport numpy as np\nfrom scipy import stats\n\n# \u521b\u5efa\u4e00\u4e2a\u968f\u673a\u6570\u636e\u96c6\ndata = np.random.randint(0, 100, size=100)\n\n# \u8ba1\u7b97\u5747\u503c\nmean = np.mean(data)\n# \u8ba1\u7b97\u4e2d\u4f4d\u6570\nmedian = np.median(data)\n# \u8ba1\u7b97\u6807\u51c6\u5dee\nstd_dev = np.std(data)\n# \u8ba1\u7b97\u504f\u5ea6\nskewness = stats.skew(data)\n# \u8ba1\u7b97\u5cf0\u5ea6\nkurtosis = stats.kurtosis(data)\n\nprint(\"\u5747\u503c:\", mean)\nprint(\"\u4e2d\u4f4d\u6570:\", median)\nprint(\"\u6807\u51c6\u5dee:\", std_dev)\nprint(\"\u504f\u5ea6:\", skewness)\nprint(\"\u5cf0\u5ea6:\", kurtosis)\n\n\n#### 2. \u5047\u8bbe\u68c0\u9a8c\n\n# \u6267\u884c\u72ec\u7acb\u6837\u672c t \u68c0\u9a8c\u6765\u6bd4\u8f83\u4e24\u4e2a\u6837\u672c\u4e4b\u95f4\u7684\u5747\u503c\u5dee\u5f02\uff1a\n\n# \u521b\u5efa\u4e24\u4e2a\u6837\u672c\nsample1 = &#91;1, 2, 3, 4, 5]\nsample2 = &#91;2, 4, 6, 8, 10]\n\n# \u6267\u884c\u72ec\u7acb\u6837\u672c t \u68c0\u9a8c\nt_statistic, p_value = stats.ttest_ind(sample1, sample2)\n\nprint(\"t \u7edf\u8ba1\u91cf:\", t_statistic)\nprint(\"p \u503c:\", p_value)\n\n# #### 3. \u56de\u5f52\u5206\u6790\n\n# \u8fdb\u884c\u7b80\u5355\u7ebf\u6027\u56de\u5f52\u5206\u6790\uff1a\n\n# \u521b\u5efa\u4e24\u4e2a\u53d8\u91cf\nx = np.array(&#91;1, 2, 3, 4, 5])\ny = np.array(&#91;2, 4, 6, 8, 10])\n\n# \u6267\u884c\u7ebf\u6027\u56de\u5f52\nslope, intercept, r_value, p_value, std_err = stats.linregress(x, y)\n\nprint(\"\u659c\u7387:\", slope)\nprint(\"\u622a\u8ddd:\", intercept)\nprint(\"\u76f8\u5173\u7cfb\u6570:\", r_value)\nprint(\"p \u503c:\", p_value)\nprint(\"\u6807\u51c6\u8bef\u5dee:\", std_err)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u5e38\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u7684 Python \u5e93\u5305\u62ec SciPy\u3001Pandas \u548c Stat <span class=\"readmore\"><a href=\"http:\/\/xc.ipyingshe.net:5347\/?p=4801\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5],"tags":[],"class_list":["post-4801","post","type-post","status-publish","format-standard","hentry","category-python","category-statistics"],"_links":{"self":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4801"}],"version-history":[{"count":2,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4801\/revisions"}],"predecessor-version":[{"id":4805,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4801\/revisions\/4805"}],"wp:attachment":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4801"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}