{"id":1126367,"date":"2025-01-08T20:00:37","date_gmt":"2025-01-08T12:00:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1126367.html"},"modified":"2025-01-08T20:00:39","modified_gmt":"2025-01-08T12:00:39","slug":"python%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e6%98%be%e8%91%97%e6%80%a7%e6%a3%80%e9%aa%8ct%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1126367.html","title":{"rendered":"python\u5982\u4f55\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090717\/83a70bb7-021f-4cd6-b80b-521a5a0a353d.webp\" alt=\"python\u5982\u4f55\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\" \/><\/p>\n<p><p> <strong>Python\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u7684\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<p><p><strong>Python\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u5305\u62ec\u4f7f\u7528SciPy\u5e93\u3001\u8fdb\u884c\u5355\u6837\u672ct\u68c0\u9a8c\u3001\u8fdb\u884c\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c\u3001\u8fdb\u884c\u914d\u5bf9\u6837\u672ct\u68c0\u9a8c\u3002<\/strong> \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f7f\u7528\u6b65\u9aa4\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528SciPy\u5e93\u8fdb\u884ct\u68c0\u9a8c<\/h3>\n<\/p>\n<p><p>Python\u7684SciPy\u5e93\u63d0\u4f9b\u4e86\u8bb8\u591a\u7edf\u8ba1\u5de5\u5177\uff0c\u5176\u4e2d\u5305\u62ec\u7528\u4e8e\u8fdb\u884ct\u68c0\u9a8c\u7684\u51fd\u6570<code>ttest_1samp<\/code>\u3001<code>ttest_ind<\/code>\u3001<code>ttest_rel<\/code>\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5355\u6837\u672ct\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u5355\u6837\u672ct\u68c0\u9a8c\u7528\u4e8e\u6bd4\u8f83\u6837\u672c\u5747\u503c\u4e0e\u5df2\u77e5\u7684\u603b\u4f53\u5747\u503c\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u6837\u672c\u6570\u636e\uff0c\u6211\u4eec\u60f3\u8981\u68c0\u9a8c\u8be5\u6837\u672c\u7684\u5747\u503c\u662f\u5426\u663e\u8457\u4e0d\u540c\u4e8e\u5df2\u77e5\u7684\u603b\u4f53\u5747\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from scipy.stats import ttest_1samp<\/p>\n<h2><strong>\u751f\u6210\u968f\u673a\u6837\u672c\u6570\u636e<\/strong><\/h2>\n<p>np.random.seed(0)<\/p>\n<p>sample_data = np.random.normal(loc=50, scale=10, size=100)<\/p>\n<h2><strong>\u5df2\u77e5\u7684\u603b\u4f53\u5747\u503c<\/strong><\/h2>\n<p>population_mean = 52<\/p>\n<h2><strong>\u8fdb\u884c\u5355\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_1samp(sample_data, population_mean)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e00\u4e2a\u5747\u503c\u4e3a50\u3001\u6807\u51c6\u5dee\u4e3a10\u7684\u968f\u673a\u6837\u672c\u6570\u636e\uff0c\u5e76\u68c0\u9a8c\u8be5\u6837\u672c\u7684\u5747\u503c\u662f\u5426\u663e\u8457\u4e0d\u540c\u4e8e\u5df2\u77e5\u7684\u603b\u4f53\u5747\u503c52\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u7684\u5747\u503c\u662f\u5426\u663e\u8457\u4e0d\u540c\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u60f3\u8981\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.stats import ttest_ind<\/p>\n<h2><strong>\u751f\u6210\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e<\/strong><\/h2>\n<p>sample_data1 = np.random.normal(loc=50, scale=10, size=100)<\/p>\n<p>sample_data2 = np.random.normal(loc=55, scale=10, size=100)<\/p>\n<h2><strong>\u8fdb\u884c\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_ind(sample_data1, sample_data2)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e24\u4e2a\u5747\u503c\u5206\u522b\u4e3a50\u548c55\u7684\u968f\u673a\u6837\u672c\u6570\u636e\uff0c\u5e76\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u914d\u5bf9\u6837\u672ct\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u914d\u5bf9\u6837\u672ct\u68c0\u9a8c\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u76f8\u5173\u6837\u672c\u7684\u5747\u503c\u662f\u5426\u663e\u8457\u4e0d\u540c\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u76f8\u5173\u6837\u672c\u6570\u636e\uff0c\u60f3\u8981\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.stats import ttest_rel<\/p>\n<h2><strong>\u751f\u6210\u4e24\u4e2a\u76f8\u5173\u6837\u672c\u6570\u636e<\/strong><\/h2>\n<p>sample_data1 = np.random.normal(loc=50, scale=10, size=100)<\/p>\n<p>sample_data2 = sample_data1 + np.random.normal(loc=1, scale=5, size=100)<\/p>\n<h2><strong>\u8fdb\u884c\u914d\u5bf9\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_rel(sample_data1, sample_data2)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e24\u4e2a\u76f8\u5173\u6837\u672c\u6570\u636e\uff0c\u5e76\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u89e3\u91cat\u503c\u548cp\u503c\u7684\u542b\u4e49<\/h3>\n<\/p>\n<p><h4>1\u3001t\u503c\u7684\u542b\u4e49<\/h4>\n<\/p>\n<p><p>t\u503c\u662ft\u68c0\u9a8c\u7684\u7edf\u8ba1\u91cf\uff0c\u7528\u4e8e\u8861\u91cf\u6837\u672c\u5747\u503c\u4e0e\u603b\u4f53\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u7a0b\u5ea6\u3002t\u503c\u8d8a\u5927\uff0c\u8868\u793a\u6837\u672c\u5747\u503c\u4e0e\u603b\u4f53\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u8d8a\u5927\u3002\u5728\u8fdb\u884ct\u68c0\u9a8c\u65f6\uff0c\u6211\u4eec\u9700\u8981\u8ba1\u7b97t\u503c\u5e76\u4e0e\u4e34\u754c\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u4ee5\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h4>2\u3001p\u503c\u7684\u542b\u4e49<\/h4>\n<\/p>\n<p><p>p\u503c\u662ft\u68c0\u9a8c\u7684\u663e\u8457\u6027\u6c34\u5e73\uff0c\u7528\u4e8e\u8861\u91cf\u89c2\u5bdf\u5230\u7684\u5dee\u5f02\u5728\u96f6\u5047\u8bbe\u6210\u7acb\u7684\u6761\u4ef6\u4e0b\u51fa\u73b0\u7684\u6982\u7387\u3002p\u503c\u8d8a\u5c0f\uff0c\u8868\u793a\u89c2\u5bdf\u5230\u7684\u5dee\u5f02\u8d8a\u4e0d\u53ef\u80fd\u662f\u7531\u4e8e\u968f\u673a\u8bef\u5dee\u5f15\u8d77\u7684\u3002\u5728\u8fdb\u884ct\u68c0\u9a8c\u65f6\uff0c\u6211\u4eec\u901a\u5e38\u5c06\u663e\u8457\u6027\u6c34\u5e73\u8bbe\u5b9a\u4e3a0.05\uff0c\u5982\u679cp\u503c\u5c0f\u4e8e0.05\uff0c\u5219\u8868\u793a\u89c2\u5bdf\u5230\u7684\u5dee\u5f02\u663e\u8457\uff0c\u6211\u4eec\u53ef\u4ee5\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Python\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8c\u7684\u5b9e\u9645\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u573a\u666f\uff0c\u5982\u533b\u5b66\u5b9e\u9a8c\u3001\u5e02\u573a\u7814\u7a76\u3001\u6559\u80b2\u8bc4\u4f30\u7b49\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5b9e\u9645\u5e94\u7528\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u533b\u5b66\u5b9e\u9a8c\u4e2d\u7684\u663e\u8457\u6027\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u5728\u533b\u5b66\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u6765\u6bd4\u8f83\u4e24\u7ec4\u75c5\u4eba\u7684\u6cbb\u7597\u6548\u679c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u6bd4\u8f83\u4f7f\u7528\u65b0\u836f\u548c\u65e7\u836f\u6cbb\u7597\u7684\u4e24\u7ec4\u75c5\u4eba\u7684\u5e73\u5747\u5eb7\u590d\u65f6\u95f4\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4f7f\u7528\u65b0\u836f\u548c\u65e7\u836f\u6cbb\u7597\u7684\u75c5\u4eba\u7684\u5eb7\u590d\u65f6\u95f4<\/p>\n<p>new_drug_recovery_time = np.random.normal(loc=20, scale=5, size=50)<\/p>\n<p>old_drug_recovery_time = np.random.normal(loc=22, scale=5, size=50)<\/p>\n<h2><strong>\u8fdb\u884c\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_ind(new_drug_recovery_time, old_drug_recovery_time)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4f7f\u7528\u65b0\u836f\u548c\u65e7\u836f\u6cbb\u7597\u7684\u75c5\u4eba\u7684\u5eb7\u590d\u65f6\u95f4\uff0c\u5e76\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5e02\u573a\u7814\u7a76\u4e2d\u7684\u663e\u8457\u6027\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u5728\u5e02\u573a\u7814\u7a76\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u6765\u6bd4\u8f83\u4e24\u79cd\u8425\u9500\u7b56\u7565\u7684\u6548\u679c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u6bd4\u8f83\u4e24\u79cd\u5e7f\u544a\u5ba3\u4f20\u7b56\u7565\u5e26\u6765\u7684\u5e73\u5747\u9500\u552e\u989d\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4e24\u79cd\u5e7f\u544a\u5ba3\u4f20\u7b56\u7565\u5e26\u6765\u7684\u9500\u552e\u989d<\/p>\n<p>strategy_a_sales = np.random.normal(loc=1000, scale=200, size=30)<\/p>\n<p>strategy_b_sales = np.random.normal(loc=1100, scale=200, size=30)<\/p>\n<h2><strong>\u8fdb\u884c\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_ind(strategy_a_sales, strategy_b_sales)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4e24\u79cd\u5e7f\u544a\u5ba3\u4f20\u7b56\u7565\u5e26\u6765\u7684\u9500\u552e\u989d\uff0c\u5e76\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u6559\u80b2\u8bc4\u4f30\u4e2d\u7684\u663e\u8457\u6027\u68c0\u9a8c<\/h4>\n<\/p>\n<p><p>\u5728\u6559\u80b2\u8bc4\u4f30\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u6765\u6bd4\u8f83\u4e24\u79cd\u6559\u5b66\u65b9\u6cd5\u7684\u6548\u679c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u6bd4\u8f83\u4e24\u7ec4\u5b66\u751f\u5728\u4e0d\u540c\u6559\u5b66\u65b9\u6cd5\u4e0b\u7684\u5e73\u5747\u8003\u8bd5\u6210\u7ee9\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4e24\u7ec4\u5b66\u751f\u5728\u4e0d\u540c\u6559\u5b66\u65b9\u6cd5\u4e0b\u7684\u8003\u8bd5\u6210\u7ee9<\/p>\n<p>method_a_scores = np.random.normal(loc=75, scale=10, size=40)<\/p>\n<p>method_b_scores = np.random.normal(loc=80, scale=10, size=40)<\/p>\n<h2><strong>\u8fdb\u884c\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c<\/strong><\/h2>\n<p>t_statistic, p_value = ttest_ind(method_a_scores, method_b_scores)<\/p>\n<p>print(f&quot;T\u503c: {t_statistic}&quot;)<\/p>\n<p>print(f&quot;p\u503c: {p_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u751f\u6210\u4e86\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u6570\u636e\uff0c\u5206\u522b\u8868\u793a\u4e24\u7ec4\u5b66\u751f\u5728\u4e0d\u540c\u6559\u5b66\u65b9\u6cd5\u4e0b\u7684\u8003\u8bd5\u6210\u7ee9\uff0c\u5e76\u68c0\u9a8c\u5b83\u4eec\u7684\u5747\u503c\u662f\u5426\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002t\u503c\u548cp\u503c\u5c06\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u662f\u5426\u62d2\u7edd\u96f6\u5047\u8bbe\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7edf\u8ba1\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u3002\u901a\u8fc7\u4f7f\u7528SciPy\u5e93\u4e2d\u7684<code>ttest_1samp<\/code>\u3001<code>ttest_ind<\/code>\u3001<code>ttest_rel<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u5355\u6837\u672ct\u68c0\u9a8c\u3001\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c\u548c\u914d\u5bf9\u6837\u672ct\u68c0\u9a8c\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u573a\u666f\uff0c\u5982\u533b\u5b66\u5b9e\u9a8c\u3001\u5e02\u573a\u7814\u7a76\u3001\u6559\u80b2\u8bc4\u4f30\u7b49\u3002\u4e86\u89e3t\u503c\u548cp\u503c\u7684\u542b\u4e49\uff0c\u5e76\u6b63\u786e\u5730\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8c\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u6570\u636e\u5206\u6790\u4e2d\u505a\u51fa\u66f4\u51c6\u786e\u7684\u51b3\u7b56\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u4ec0\u4e48\u662ft\u503c\uff0c\u4e3a\u4ec0\u4e48\u5728\u663e\u8457\u6027\u68c0\u9a8c\u4e2d\u4f7f\u7528\u5b83\uff1f<\/strong><br \/>t\u503c\u662f\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u7684\u4e00\u79cd\u6d4b\u91cf\uff0c\u4e3b\u8981\u7528\u4e8e\u68c0\u9a8c\u4e24\u4e2a\u6837\u672c\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u662f\u5426\u663e\u8457\u3002\u901a\u8fc7\u6bd4\u8f83\u6837\u672c\u5747\u503c\u4e0e\u5047\u8bbe\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\uff0ct\u503c\u53ef\u4ee5\u5e2e\u52a9\u5224\u65ad\u8fd9\u79cd\u5dee\u5f02\u662f\u7531\u4e8e\u968f\u673a\u8bef\u5dee\u9020\u6210\u7684\uff0c\u8fd8\u662f\u53cd\u6620\u4e86\u5b9e\u9645\u7684\u7fa4\u4f53\u5dee\u5f02\u3002\u5728\u663e\u8457\u6027\u68c0\u9a8c\u4e2d\uff0ct\u503c\u8d8a\u5927\uff0c\u901a\u5e38\u610f\u5473\u7740\u6837\u672c\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u8d8a\u663e\u8457\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8ba1\u7b97t\u503c\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u591a\u4e2a\u5e93\u6765\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\uff0c\u5176\u4e2dSciPy\u5e93\u4e2d\u7684<code>ttest_ind<\/code>\u51fd\u6570\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u72ec\u7acb\u6837\u672c\u7684t\u503c\u3002\u53ea\u9700\u5c06\u4e24\u4e2a\u6837\u672c\u6570\u636e\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\uff0c\u5373\u53ef\u83b7\u5f97t\u503c\u53ca\u5176\u5bf9\u5e94\u7684p\u503c\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">from scipy import stats\n\nsample1 = [5, 6, 7, 8, 9]\nsample2 = [1, 2, 3, 4, 5]\nt_statistic, p_value = stats.ttest_ind(sample1, sample2)\nprint(f&quot;t\u503c: {t_statistic}, p\u503c: {p_value}&quot;)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u89e3\u91cat\u68c0\u9a8c\u7684\u7ed3\u679c\u548cp\u503c\uff1f<\/strong><br \/>t\u68c0\u9a8c\u7684\u7ed3\u679c\u901a\u5e38\u5305\u62ect\u503c\u548cp\u503c\u3002p\u503c\u53cd\u6620\u4e86\u89c2\u5bdf\u5230\u7684\u6837\u672c\u5dee\u5f02\u5728\u96f6\u5047\u8bbe\u4e0b\u51fa\u73b0\u7684\u6982\u7387\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5982\u679cp\u503c\u5c0f\u4e8e0.05\uff0c\u901a\u5e38\u8ba4\u4e3a\u6837\u672c\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u662f\u663e\u8457\u7684\uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u62d2\u7edd\u96f6\u5047\u8bbe\u3002t\u503c\u5219\u63d0\u4f9b\u4e86\u5173\u4e8e\u6837\u672c\u5747\u503c\u5dee\u5f02\u7684\u5f3a\u5ea6\u7684\u4fe1\u606f\uff0ct\u503c\u8d8a\u5927\uff0c\u4ee3\u8868\u8d8a\u5f3a\u7684\u8bc1\u636e\u652f\u6301\u6837\u672c\u5747\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u3002<\/p>\n<p><strong>\u5728\u8fdb\u884ct\u68c0\u9a8c\u65f6\uff0c\u6709\u54ea\u4e9b\u5047\u8bbe\u9700\u8981\u6ee1\u8db3\uff1f<\/strong><br \/>\u5728\u8fdb\u884ct\u68c0\u9a8c\u524d\uff0c\u9700\u786e\u4fdd\u6570\u636e\u6ee1\u8db3\u4e00\u4e9b\u57fa\u672c\u5047\u8bbe\uff0c\u5305\u62ec\u6837\u672c\u6765\u81ea\u6b63\u6001\u5206\u5e03\uff0c\u6837\u672c\u4e4b\u95f4\u76f8\u4e92\u72ec\u7acb\uff0c\u4ee5\u53ca\u6837\u672c\u65b9\u5dee\u76f8\u7b49\uff08\u5bf9\u4e8e\u72ec\u7acb\u6837\u672ct\u68c0\u9a8c\uff09\u3002\u5982\u679c\u4e0d\u6ee1\u8db3\u8fd9\u4e9b\u5047\u8bbe\uff0c\u53ef\u80fd\u9700\u8981\u8003\u8651\u4f7f\u7528\u975e\u53c2\u6570\u68c0\u9a8c\u65b9\u6cd5\u6216\u8fdb\u884c\u6570\u636e\u8f6c\u6362\uff0c\u4ee5\u786e\u4fdd\u5206\u6790\u7ed3\u679c\u7684\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u7684\u6b65\u9aa4 Python\u8fdb\u884c\u663e\u8457\u6027\u68c0\u9a8ct\u503c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u5305\u62ec\u4f7f\u7528SciPy\u5e93\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1126375,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126367"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1126367"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126367\/revisions"}],"predecessor-version":[{"id":1126377,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126367\/revisions\/1126377"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1126375"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1126367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1126367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1126367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}