{"id":174444,"date":"2024-05-08T18:31:36","date_gmt":"2024-05-08T10:31:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/174444.html"},"modified":"2024-05-08T18:31:52","modified_gmt":"2024-05-08T10:31:52","slug":"python3-6-5%e5%ae%89%e8%a3%85%e5%a6%82%e4%bd%95statsmodels%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/174444.html","title":{"rendered":"python3.6.5\u5b89\u88c5\u5982\u4f55statsmodels\u5305"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27052052\/3cd5ce5a-0c04-4c20-bf8d-e85d72223098.webp\" alt=\"python3.6.5\u5b89\u88c5\u5982\u4f55statsmodels\u5305\" \/><\/p>\n<p><p>Python 3.6.5\u4e2d\u5b89\u88c5statsmodels\u5305\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\uff1a<strong>\u9996\u5148\u786e\u4fdd\u5b89\u88c5\u4e86pip\u5de5\u5177\u3001\u5176\u6b21\u5b89\u88c5numpy\u548cscipy\u4f9d\u8d56\u5305\u3001\u63a5\u7740\u4f7f\u7528pip\u547d\u4ee4\u884c\u8fdb\u884c\u5b89\u88c5<\/strong>\u3002\u5f53\u5728\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u5b89\u88c5\u547d\u4ee4\u540e\uff0cpip\u4f1a\u81ea\u52a8\u89e3\u51b3\u6240\u6709\u76f8\u5173\u4f9d\u8d56\u5173\u7cfb\uff0c\u76f4\u81f3\u5b89\u88c5\u5b8c\u6210\u3002<strong>\u8fd9\u79cd\u5b89\u88c5\u65b9\u5f0f\u9002\u7528\u4e8e\u5927\u591a\u6570Python\u5e93<\/strong>\uff0c\u5b83\u4eec\u90fd\u4f9d\u8d56\u4e8epip\u548cPython\u8f6f\u4ef6\u5305\u7d22\u5f15(PyPI)\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecdstatsmodels\u5305\u7684\u5b89\u88c5\u8fc7\u7a0b\u53ca\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5PIP\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u5b89\u88c5statsmodels\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u60a8\u7684Python\u73af\u5883\u4e2d\u5b89\u88c5\u4e86pip\u5de5\u5177\u3002Pip\u662fPython\u7684\u5305\u5b89\u88c5\u5668\uff0c\u53ef\u4ee5\u4ecePython\u8f6f\u4ef6\u5305\u7d22\u5f15(PyPI)\u4e0b\u8f7d\u548c\u5b89\u88c5Python\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u68c0\u67e5pip\u662f\u5426\u5df2\u5b89\u88c5<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3.6 -m pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u5df2\u5b89\u88c5\uff0c\u5219\u4f1a\u770b\u5230\u7248\u672c\u4fe1\u606f\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u60a8\u9700\u8981\u5148\u4e0b\u8f7d\u548c\u5b89\u88c5pip\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b89\u88c5pip<\/strong>\uff1a<\/p>\n<p>\u5728\u672a\u5b89\u88c5pip\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4e0b\u8f7dget-pip.py\u811a\u672c\u6765\u5b89\u88c5pip\u3002<\/li>\n<\/p>\n<\/ol>\n<p><pre><code class=\"language-bash\">wget https:\/\/bootstrap.pypa.io\/get-pip.py<\/p>\n<p>python3.6 get-pip.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u5b89\u88c5Numpy\u548cScipy<\/p>\n<\/p>\n<p><p>\u5728\u5b89\u88c5statsmodels\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u5176\u4f9d\u8d56\u5e93numpy\u548cscipy\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5numpy<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3.6 -m pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b89\u88c5scipy<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3.6 -m pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u5b89\u88c5numpy\u548cscipy\u7684\u6700\u65b0\u7248\u672c\u3002\u5982\u679c\u9700\u8981\u6307\u5b9a\u7248\u672c\uff0c\u53ef\u4ee5\u5728\u5b89\u88c5\u547d\u4ee4\u540e\u9762\u6dfb\u52a0\u7248\u672c\u53f7\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528PIP\u5b89\u88c5Statsmodels<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u4e86numpy\u548cscipy\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5b89\u88c5statsmodels\u4e86\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5statsmodels<\/strong>\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3.6 -m pip install statsmodels<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u544a\u8bc9pip\u4e3aPython 3.6.5\u7248\u672c\u5b89\u88c5statsmodels\u5305\u3002\u5b89\u88c5\u8fc7\u7a0b\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\uff0c\u56e0\u4e3a\u5b83\u9700\u8981\u7f16\u8bd1\u4e00\u4e9b\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong>\uff1a<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u6267\u884c\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u6765\u786e\u8ba4statsmodels\u662f\u5426\u6b63\u786e\u5b89\u88c5\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528\u3002<\/li>\n<\/p>\n<\/ol>\n<p><pre><code class=\"language-python\">import statsmodels.api as sm<\/p>\n<p>print(sm.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ee5\u4e0a\u547d\u4ee4\u5c06\u8f93\u51fa\u5b89\u88c5\u7684statsmodels\u7248\u672c\uff0c\u786e\u8ba4\u65e0\u8bef\u540e\u5373\u53ef\u5f00\u59cb\u4f7f\u7528statsmodels\u5305\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u6392\u9519\u53ca\u95ee\u9898\u89e3\u51b3<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u8bd1\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a<\/p>\n<p>\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u9047\u5230\u7f16\u8bd1\u4f9d\u8d56\u6027\u7684\u9519\u8bef\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u7cfb\u7edf\u7ea7\u522b\u7684\u5e93\uff0c\u6bd4\u5982BLAS\u548cLAPACK\u3002\u8fd9\u4e9b\u5e93\u4e3anumpy\u548cscipy\u7b49Python\u5e93\u63d0\u4f9b\u5e95\u5c42\u6570\u5b66\u8fd0\u7b97\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a<\/p>\n<p>\u5982\u679c\u5728\u5b89\u88c5\u65f6\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u80fd\u9700\u8981\u5728pip\u547d\u4ee4\u524d\u6dfb\u52a0sudo\uff0c\u4ee5\u7ed9\u4e88\u5b89\u88c5\u8fc7\u7a0b\u5fc5\u8981\u7684\u6743\u9650\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo python3.6 -m pip install statsmodels<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u5b89\u88c5statsmodels\u5305\u4e3b\u8981\u6d89\u53ca\u5230\u4e86\u5bf9\u4e8e\u5f00\u53d1\u73af\u5883\u7684\u51c6\u5907\u3001\u5bf9\u4e8e\u4f9d\u8d56\u5305\u7684\u5b89\u88c5\u4ee5\u53ca\u5b9e\u9645\u7684\u5b89\u88c5\u547d\u4ee4\u3002\u6b63\u786e\u9075\u5faa\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u5927\u591a\u6570\u7528\u6237\u90fd\u80fd\u6210\u529f\u5730\u5728Python 3.6.5\u73af\u5883\u4e2d\u5b89\u88c5statsmodels\u5305\uff0c\u5c3d\u4eab\u6570\u636e\u5206\u6790\u548c\u7edf\u8ba1\u5efa\u6a21\u7684\u4fbf\u5229\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u5982\u4f55\u5728Python 3.6.5\u4e2d\u5b89\u88c5statsmodels\u5305\uff1f<\/strong><\/p>\n<p>\u5728Python 3.6.5\u4e2d\u5b89\u88c5statsmodels\u5305\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u6253\u5f00\u60a8\u7684\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u7a97\u53e3\u3002<\/li>\n<li>\u7136\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5statsmodels\u5305\uff1a<code>pip install statsmodels<\/code>\u3002<\/li>\n<li>\u7b49\u5f85\u547d\u4ee4\u6267\u884c\u5b8c\u6210\u540e\uff0c\u60a8\u7684\u7cfb\u7edf\u5c06\u81ea\u52a8\u4ecePython Package Index\uff08PyPI\uff09\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684statsmodels\u5305\u3002<\/li>\n<li>\u6700\u540e\uff0c\u5f53\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u5373\u53ef\u6210\u529f\u4f7f\u7528statsmodels\u5305\u8fdb\u884c\u7edf\u8ba1\u5efa\u6a21\u548c\u5206\u6790\u3002<\/li>\n<\/ol>\n<p>\u8bf7\u786e\u4fdd\u60a8\u7684Python\u7248\u672c\u4e3a3.6.5\uff0c\u5e76\u4e14\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u4e86pip\u5305\u7ba1\u7406\u5de5\u5177\u3002\u5982\u679c\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86\u65e7\u7248\u672c\u7684statsmodels\u5305\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5176\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff1a<code>pip install --upgrade statsmodels<\/code>\u3002<\/p>\n<p><strong>Q2: \u5728Python 3.6.5\u4e2d\u5982\u4f55\u4f7f\u7528statsmodels\u5305\u8fdb\u884c\u7edf\u8ba1\u5efa\u6a21\u548c\u5206\u6790\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528statsmodels\u5305\u53ef\u4ee5\u8fdb\u884c\u591a\u79cd\u7edf\u8ba1\u5efa\u6a21\u548c\u5206\u6790\u4efb\u52a1\uff0c\u4f8b\u5982\u7ebf\u6027\u56de\u5f52\u3001\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u3001\u65b9\u5dee\u5206\u6790\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528statsmodels\u5305\u8fdb\u884c\u7ebf\u6027\u56de\u5f52\u5206\u6790\uff1a<\/p>\n<pre><code class=\"language-python\">import statsmodels.api as sm\n\n# \u51c6\u5907\u6570\u636e\nX = [1, 2, 3, 4, 5]  # \u81ea\u53d8\u91cf\ny = [2, 4, 6, 8, 10]  # \u56e0\u53d8\u91cf\n\n# \u6dfb\u52a0\u622a\u8ddd\u9879\nX = sm.add_constant(X)\n\n# \u6784\u5efa\u7ebf\u6027\u56de\u5f52\u6a21\u578b\nmodel = sm.OLS(y, X)\n\n# \u62df\u5408\u6a21\u578b\nresults = model.fit()\n\n# \u6253\u5370\u56de\u5f52\u7ed3\u679c\nprint(results.summary())\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u9996\u5148\u5bfc\u5165\u4e86statsmodels\u5305\uff0c\u5e76\u4f7f\u7528<code>sm.add_constant()<\/code>\u51fd\u6570\u6dfb\u52a0\u4e86\u622a\u8ddd\u9879\u3002\u7136\u540e\uff0c\u5229\u7528<code>sm.OLS()<\/code>\u51fd\u6570\u6784\u5efa\u4e86\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff0c\u5e76\u4f7f\u7528<code>fit()<\/code>\u65b9\u6cd5\u5bf9\u6a21\u578b\u8fdb\u884c\u4e86\u62df\u5408\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>results.summary()<\/code>\u6253\u5370\u51fa\u4e86\u56de\u5f52\u7ed3\u679c\u7684\u8be6\u7ec6\u7edf\u8ba1\u6458\u8981\u3002<\/p>\n<p><strong>Q3: Python 3.6.5\u4e2dstatsmodels\u5305\u9002\u7528\u4e8e\u54ea\u4e9b\u7edf\u8ba1\u5206\u6790\u573a\u666f\uff1f<\/strong><\/p>\n<p>statsmodels\u5305\u63d0\u4f9b\u4e86\u8bb8\u591a\u7528\u4e8e\u7edf\u8ba1\u5efa\u6a21\u548c\u5206\u6790\u7684\u529f\u80fd\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u7edf\u8ba1\u5206\u6790\u573a\u666f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n<ol>\n<li>\u7ebf\u6027\u56de\u5f52\uff1astatsmodels\u5305\u53ef\u4ee5\u7528\u4e8e\u8fdb\u884c\u7b80\u5355\u7ebf\u6027\u56de\u5f52\u3001\u591a\u91cd\u7ebf\u6027\u56de\u5f52\u4ee5\u53ca\u5cad\u56de\u5f52\u7b49\u3002<\/li>\n<li>\u65f6\u95f4\u5e8f\u5217\u5206\u6790\uff1astatsmodels\u5305\u63d0\u4f9b\u4e86\u7528\u4e8e\u5206\u6790\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u5de5\u5177\uff0c\u4f8b\u5982\u81ea\u56de\u5f52\uff08AR\uff09\u3001\u79fb\u52a8\u5e73\u5747\uff08MA\uff09\u6a21\u578b\u548c\u5dee\u5206\u81ea\u56de\u5f52\u79fb\u52a8\u5e73\u5747\uff08ARIMA\uff09\u6a21\u578b\u7b49\u3002<\/li>\n<li>\u65b9\u5dee\u5206\u6790\uff1astatsmodels\u5305\u53ef\u4ee5\u8fdb\u884c\u65b9\u5dee\u5206\u6790\uff0c\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u6216\u591a\u4e2a\u7ec4\u4e4b\u95f4\u7684\u5dee\u5f02\u3002<\/li>\n<li>\u5e7f\u4e49\u7ebf\u6027\u6a21\u578b\uff1astatsmodels\u5305\u652f\u6301\u5e7f\u4e49\u7ebf\u6027\u6a21\u578b\uff08GLM\uff09\uff0c\u4f8b\u5982\u903b\u8f91\u56de\u5f52\u3001\u6cca\u677e\u56de\u5f52\u7b49\u3002<\/li>\n<li>\u975e\u53c2\u6570\u7edf\u8ba1\u5206\u6790\uff1astatsmodels\u5305\u8fd8\u63d0\u4f9b\u4e86\u8fdb\u884c\u975e\u53c2\u6570\u7edf\u8ba1\u5206\u6790\u7684\u5de5\u5177\uff0c\u4f8b\u5982\u6838\u5bc6\u5ea6\u4f30\u8ba1\u548cKendall&#039;s Tau\u76f8\u5173\u6027\u7b49\u3002<\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0cstatsmodels\u5305\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u7edf\u8ba1\u5206\u6790\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u4f17\u591a\u6d89\u53ca\u7edf\u8ba1\u5efa\u6a21\u548c\u5206\u6790\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python 3.6.5\u4e2d\u5b89\u88c5statsmodels\u5305\u9700\u8981\u51e0\u4e2a\u6b65\u9aa4\uff1a\u9996\u5148\u786e\u4fdd\u5b89\u88c5\u4e86pip\u5de5\u5177\u3001\u5176\u6b21\u5b89\u88c5nump [&hellip;]","protected":false},"author":3,"featured_media":174474,"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\/174444"}],"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=174444"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/174444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/174474"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=174444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=174444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=174444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}