{"id":1167999,"date":"2025-01-15T15:52:39","date_gmt":"2025-01-15T07:52:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1167999.html"},"modified":"2025-01-15T15:52:41","modified_gmt":"2025-01-15T07:52:41","slug":"%e5%af%b9%e5%ba%94%e5%88%86%e6%9e%90python%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1167999.html","title":{"rendered":"\u5bf9\u5e94\u5206\u6790python\u5982\u4f55\u5b9e\u73b0"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26065402\/7d33ad9f-0000-4c4f-9ced-13a812fc8cbb.webp\" alt=\"\u5bf9\u5e94\u5206\u6790python\u5982\u4f55\u5b9e\u73b0\" \/><\/p>\n<p><p> <strong>\u5bf9\u5e94\u5206\u6790\u5728Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\uff0c\u5982Pandas\u3001Scikit-learn\u3001Matplotlib\u7b49\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\u6570\u636e\u51c6\u5907\u3001\u9884\u5904\u7406\u3001\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790\u3001\u53ef\u89c6\u5316\u7ed3\u679c\u3002<\/strong>\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u4e00\u70b9\uff1a<strong>\u6570\u636e\u51c6\u5907<\/strong>\u3002\u5728\u6570\u636e\u51c6\u5907\u9636\u6bb5\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u6570\u636e\u662f\u9002\u5408\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u7684\u683c\u5f0f\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u9891\u6570\u8868\u6216\u4ea4\u53c9\u8868\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u6765\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e\uff0c\u786e\u4fdd\u6570\u636e\u7684\u6bcf\u4e00\u884c\u548c\u5217\u4ee3\u8868\u4e0d\u540c\u7684\u7c7b\u522b\u6216\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u6570\u636e\u51c6\u5907<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u51c6\u5907\u597d\u6570\u636e\u3002\u6570\u636e\u51c6\u5907\u5305\u62ec\u6570\u636e\u7684\u6536\u96c6\u3001\u6e05\u7406\u3001\u5904\u7406\u7b49\u6b65\u9aa4\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u5bf9\u5e94\u5206\u6790\u7684\u6570\u636e\u683c\u5f0f\u662f\u4e00\u4e2a\u9891\u6570\u8868\u6216\u4ea4\u53c9\u8868\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u6765\u8bfb\u53d6\u548c\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;your_data.csv&#39;)<\/p>\n<h2><strong>\u663e\u793a\u6570\u636e\u524d\u51e0\u884c<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8bfb\u53d6\u6570\u636e\u4e4b\u540e\uff0c\u68c0\u67e5\u6570\u636e\u662f\u5426\u6709\u7f3a\u5931\u503c\uff0c\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002\u5982\u679c\u6709\u7f3a\u5931\u503c\uff0c\u53ef\u4ee5\u9009\u62e9\u5220\u9664\u6216\u586b\u5145\u7f3a\u5931\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u68c0\u67e5\u7f3a\u5931\u503c<\/p>\n<p>missing_values = data.isnull().sum()<\/p>\n<p>print(missing_values)<\/p>\n<h2><strong>\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>data.fillna(method=&#39;ffill&#39;, inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u6570\u636e\u9884\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u51c6\u5907\u597d\u4e4b\u540e\uff0c\u9700\u8981\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u3002\u6570\u636e\u9884\u5904\u7406\u5305\u62ec\u6570\u636e\u7684\u6807\u51c6\u5316\u3001\u5f52\u4e00\u5316\u7b49\u6b65\u9aa4\u3002\u5bf9\u4e8e\u5bf9\u5e94\u5206\u6790\u6765\u8bf4\uff0c\u6570\u636e\u4e0d\u9700\u8981\u8fdb\u884c\u6807\u51c6\u5316\u6216\u5f52\u4e00\u5316\u5904\u7406\uff0c\u4f46\u9700\u8981\u786e\u4fdd\u6570\u636e\u662f\u4e00\u4e2a\u9891\u6570\u8868\u6216\u4ea4\u53c9\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4ea4\u53c9\u8868<\/p>\n<p>cross_tab = pd.crosstab(data[&#39;RowCategory&#39;], data[&#39;ColumnCategory&#39;])<\/p>\n<h2><strong>\u663e\u793a\u4ea4\u53c9\u8868<\/strong><\/h2>\n<p>print(cross_tab)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u9884\u5904\u7406\u597d\u4e4b\u540e\uff0c\u53ef\u4ee5\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u3002\u5bf9\u5e94\u5206\u6790\u7684\u8ba1\u7b97\u53ef\u4ee5\u4f7f\u7528Scikit-learn\u5e93\u4e2d\u7684TruncatedSVD\u7c7b\u6765\u5b9e\u73b0\u3002TruncatedSVD\u7c7b\u53ef\u4ee5\u7528\u4e8e\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790\u7684\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.decomposition import TruncatedSVD<\/p>\n<h2><strong>\u521b\u5efaTruncatedSVD\u5bf9\u8c61<\/strong><\/h2>\n<p>svd = TruncatedSVD(n_components=2)<\/p>\n<h2><strong>\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790<\/strong><\/h2>\n<p>svd_fit = svd.fit_transform(cross_tab)<\/p>\n<h2><strong>\u663e\u793a\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/strong><\/h2>\n<p>print(svd.components_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u53ef\u89c6\u5316\u7ed3\u679c<\/p>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u597d\u5bf9\u5e94\u5206\u6790\u7684\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u4e4b\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Matplotlib\u5e93\u6765\u53ef\u89c6\u5316\u7ed3\u679c\u3002\u53ef\u89c6\u5316\u7ed3\u679c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efa\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>plt.scatter(svd_fit[:, 0], svd_fit[:, 1])<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e<\/strong><\/h2>\n<p>for i, label in enumerate(cross_tab.index):<\/p>\n<p>    plt.annotate(label, (svd_fit[i, 0], svd_fit[i, 1]))<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.xlabel(&#39;Component 1&#39;)<\/p>\n<p>plt.ylabel(&#39;Component 2&#39;)<\/p>\n<p>plt.title(&#39;Correspondence Analysis&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u89e3\u91ca\u7ed3\u679c<\/p>\n<\/p>\n<p><p>\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u901a\u5e38\u8868\u793a\u4e3a\u4e00\u4e2a\u4e8c\u7ef4\u56fe\u5f62\uff0c\u5176\u4e2d\u6bcf\u4e2a\u70b9\u4ee3\u8868\u4e00\u4e2a\u7c7b\u522b\u6216\u53d8\u91cf\u3002\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u8868\u793a\u7c7b\u522b\u6216\u53d8\u91cf\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u3002\u8ddd\u79bb\u8d8a\u8fd1\uff0c\u8868\u793a\u7c7b\u522b\u6216\u53d8\u91cf\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u8d8a\u9ad8\uff1b\u8ddd\u79bb\u8d8a\u8fdc\uff0c\u8868\u793a\u7c7b\u522b\u6216\u53d8\u91cf\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u8d8a\u4f4e\u3002<\/p>\n<\/p>\n<p><p>\u5728\u89e3\u91ca\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u65f6\uff0c\u53ef\u4ee5\u5173\u6ce8\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7c7b\u522b\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong>\uff1a\u901a\u8fc7\u89c2\u5bdf\u56fe\u5f62\u4e2d\u70b9\u7684\u5206\u5e03\uff0c\u53ef\u4ee5\u4e86\u89e3\u4e0d\u540c\u7c7b\u522b\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e9b\u7c7b\u522b\u7684\u70b9\u805a\u96c6\u5728\u4e00\u8d77\uff0c\u8868\u793a\u8fd9\u4e9b\u7c7b\u522b\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u8f83\u9ad8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong>\uff1a\u901a\u8fc7\u89c2\u5bdf\u56fe\u5f62\u4e2d\u70b9\u7684\u5206\u5e03\uff0c\u53ef\u4ee5\u4e86\u89e3\u4e0d\u540c\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e9b\u53d8\u91cf\u7684\u70b9\u805a\u96c6\u5728\u4e00\u8d77\uff0c\u8868\u793a\u8fd9\u4e9b\u53d8\u91cf\u4e4b\u95f4\u7684\u76f8\u4f3c\u5ea6\u8f83\u9ad8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7c7b\u522b\u548c\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong>\uff1a\u901a\u8fc7\u89c2\u5bdf\u56fe\u5f62\u4e2d\u7c7b\u522b\u548c\u53d8\u91cf\u7684\u5206\u5e03\uff0c\u53ef\u4ee5\u4e86\u89e3\u7c7b\u522b\u548c\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e2a\u7c7b\u522b\u7684\u70b9\u9760\u8fd1\u67d0\u4e2a\u53d8\u91cf\u7684\u70b9\uff0c\u8868\u793a\u8fd9\u4e2a\u7c7b\u522b\u548c\u8fd9\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u8f83\u5f3a\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u4f18\u5316\u6a21\u578b<\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u6a21\u578b\u7684\u53c2\u6570\u6765\u4f18\u5316\u6a21\u578b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u8c03\u6574TruncatedSVD\u7c7b\u4e2d\u7684n_components\u53c2\u6570\uff0c\u9009\u62e9\u9002\u5f53\u7684\u7279\u5f81\u503c\u6570\u91cf\uff0c\u4ee5\u786e\u4fdd\u6a21\u578b\u7684\u89e3\u91ca\u529b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8c03\u6574n_components\u53c2\u6570<\/p>\n<p>svd = TruncatedSVD(n_components=3)<\/p>\n<h2><strong>\u91cd\u65b0\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790<\/strong><\/h2>\n<p>svd_fit = svd.fit_transform(cross_tab)<\/p>\n<h2><strong>\u663e\u793a\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf<\/strong><\/h2>\n<p>print(svd.components_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u5e94\u7528\u573a\u666f<\/p>\n<\/p>\n<p><p>\u5bf9\u5e94\u5206\u6790\u5728\u5f88\u591a\u9886\u57df\u90fd\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u5728\u5e02\u573a\u7814\u7a76\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u4e86\u89e3\u6d88\u8d39\u8005\u7684\u504f\u597d\u548c\u8d2d\u4e70\u884c\u4e3a\uff1b\u5728\u751f\u7269\u5b66\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u7814\u7a76\u4e0d\u540c\u7269\u79cd\u4e4b\u95f4\u7684\u5173\u7cfb\uff1b\u5728\u793e\u4f1a\u79d1\u5b66\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u5206\u6790\u8c03\u67e5\u95ee\u5377\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5e02\u573a\u7814\u7a76<\/strong>\uff1a\u5728\u5e02\u573a\u7814\u7a76\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u4e86\u89e3\u6d88\u8d39\u8005\u7684\u504f\u597d\u548c\u8d2d\u4e70\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u4e0d\u540c\u6d88\u8d39\u8005\u7fa4\u4f53\u5bf9\u4e0d\u540c\u4ea7\u54c1\u7684\u504f\u597d\uff0c\u6765\u5236\u5b9a\u76f8\u5e94\u7684\u5e02\u573a\u8425\u9500\u7b56\u7565\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u751f\u7269\u5b66\u7814\u7a76<\/strong>\uff1a\u5728\u751f\u7269\u5b66\u7814\u7a76\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u7814\u7a76\u4e0d\u540c\u7269\u79cd\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u4e0d\u540c\u7269\u79cd\u7684\u57fa\u56e0\u8868\u8fbe\u6570\u636e\uff0c\u6765\u4e86\u89e3\u7269\u79cd\u4e4b\u95f4\u7684\u8fdb\u5316\u5173\u7cfb\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u793e\u4f1a\u79d1\u5b66\u7814\u7a76<\/strong>\uff1a\u5728\u793e\u4f1a\u79d1\u5b66\u7814\u7a76\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u5206\u6790\u8c03\u67e5\u95ee\u5377\u7684\u7ed3\u679c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5206\u6790\u4e0d\u540c\u7fa4\u4f53\u5bf9\u4e0d\u540c\u95ee\u9898\u7684\u56de\u7b54\uff0c\u6765\u4e86\u89e3\u4e0d\u540c\u7fa4\u4f53\u7684\u6001\u5ea6\u548c\u89c2\u70b9\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516b\u3001\u4f18\u7f3a\u70b9\u5206\u6790<\/p>\n<\/p>\n<p><p>\u5728\u4e86\u89e3\u4e86\u5bf9\u5e94\u5206\u6790\u7684\u57fa\u672c\u6982\u5ff5\u548c\u5b9e\u73b0\u65b9\u6cd5\u4e4b\u540e\uff0c\u8fd8\u9700\u8981\u4e86\u89e3\u5bf9\u5e94\u5206\u6790\u7684\u4f18\u7f3a\u70b9\uff0c\u4ee5\u4fbf\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u66f4\u597d\u5730\u4f7f\u7528\u5bf9\u5e94\u5206\u6790\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7b80\u5355\u6613\u61c2<\/strong>\uff1a\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u901a\u5e38\u8868\u793a\u4e3a\u4e00\u4e2a\u4e8c\u7ef4\u56fe\u5f62\uff0c\u76f4\u89c2\u6613\u61c2\uff0c\u4fbf\u4e8e\u89e3\u91ca\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9002\u7528\u6027\u5e7f<\/strong>\uff1a\u5bf9\u5e94\u5206\u6790\u9002\u7528\u4e8e\u5404\u79cd\u7c7b\u578b\u7684\u6570\u636e\uff0c\u7279\u522b\u662f\u9891\u6570\u8868\u548c\u4ea4\u53c9\u8868\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8ba1\u7b97\u6548\u7387\u9ad8<\/strong>\uff1a\u5bf9\u5e94\u5206\u6790\u7684\u8ba1\u7b97\u6548\u7387\u8f83\u9ad8\uff0c\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5c40\u9650\u6027<\/strong>\uff1a\u5bf9\u5e94\u5206\u6790\u53ea\u9002\u7528\u4e8e\u9891\u6570\u8868\u548c\u4ea4\u53c9\u8868\uff0c\u5bf9\u4e8e\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u53ef\u80fd\u4e0d\u9002\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7cbe\u5ea6\u6709\u9650<\/strong>\uff1a\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u4f9d\u8d56\u4e8e\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7684\u6570\u91cf\uff0c\u9009\u62e9\u4e0d\u5f53\u53ef\u80fd\u5f71\u54cd\u7ed3\u679c\u7684\u7cbe\u5ea6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u91ca\u56f0\u96be<\/strong>\uff1a\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5bf9\u5e94\u5206\u6790\u7684\u7ed3\u679c\u53ef\u80fd\u96be\u4ee5\u89e3\u91ca\uff0c\u7279\u522b\u662f\u5f53\u6570\u636e\u590d\u6742\u65f6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e5d\u3001\u5b9e\u9645\u6848\u4f8b\u5206\u6790<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u5bf9\u5e94\u5206\u6790\u7684\u5e94\u7528\uff0c\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5b9e\u9645\u6848\u4f8b\u6765\u6f14\u793a\u5bf9\u5e94\u5206\u6790\u7684\u8fc7\u7a0b\u548c\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4efd\u8c03\u67e5\u95ee\u5377\u6570\u636e\uff0c\u5305\u542b\u4e0d\u540c\u7fa4\u4f53\u5bf9\u4e0d\u540c\u95ee\u9898\u7684\u56de\u7b54\u3002\u6211\u4eec\u5e0c\u671b\u901a\u8fc7\u5bf9\u5e94\u5206\u6790\u6765\u4e86\u89e3\u4e0d\u540c\u7fa4\u4f53\u7684\u6001\u5ea6\u548c\u89c2\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6\u6570\u636e<\/strong><\/h2>\n<p>data = {<\/p>\n<p>    &#39;Group&#39;: [&#39;A&#39;, &#39;A&#39;, &#39;B&#39;, &#39;B&#39;, &#39;C&#39;, &#39;C&#39;],<\/p>\n<p>    &#39;Question1&#39;: [1, 2, 3, 4, 5, 6],<\/p>\n<p>    &#39;Question2&#39;: [6, 5, 4, 3, 2, 1]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u521b\u5efa\u4ea4\u53c9\u8868<\/strong><\/h2>\n<p>cross_tab = pd.crosstab(df[&#39;Group&#39;], [df[&#39;Question1&#39;], df[&#39;Question2&#39;]])<\/p>\n<h2><strong>\u663e\u793a\u4ea4\u53c9\u8868<\/strong><\/h2>\n<p>print(cross_tab)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u521b\u5efa\u597d\u4ea4\u53c9\u8868\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\uff0c\u5e76\u53ef\u89c6\u5316\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.decomposition import TruncatedSVD<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u521b\u5efaTruncatedSVD\u5bf9\u8c61<\/strong><\/h2>\n<p>svd = TruncatedSVD(n_components=2)<\/p>\n<h2><strong>\u8ba1\u7b97\u5bf9\u5e94\u5206\u6790<\/strong><\/h2>\n<p>svd_fit = svd.fit_transform(cross_tab)<\/p>\n<h2><strong>\u521b\u5efa\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>plt.scatter(svd_fit[:, 0], svd_fit[:, 1])<\/p>\n<h2><strong>\u6dfb\u52a0\u6807\u7b7e<\/strong><\/h2>\n<p>for i, label in enumerate(cross_tab.index):<\/p>\n<p>    plt.annotate(label, (svd_fit[i, 0], svd_fit[i, 1]))<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>plt.xlabel(&#39;Component 1&#39;)<\/p>\n<p>plt.ylabel(&#39;Component 2&#39;)<\/p>\n<p>plt.title(&#39;Correspondence Analysis&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u89c2\u5bdf\u56fe\u5f62\uff0c\u6211\u4eec\u53ef\u4ee5\u4e86\u89e3\u4e0d\u540c\u7fa4\u4f53\u5bf9\u4e0d\u540c\u95ee\u9898\u7684\u6001\u5ea6\u548c\u89c2\u70b9\u3002\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e2a\u7fa4\u4f53\u7684\u70b9\u9760\u8fd1\u67d0\u4e2a\u95ee\u9898\u7684\u70b9\uff0c\u8868\u793a\u8fd9\u4e2a\u7fa4\u4f53\u5bf9\u8fd9\u4e2a\u95ee\u9898\u7684\u56de\u7b54\u8f83\u4e3a\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><p>\u5341\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5bf9\u5e94\u5206\u6790\u7684\u57fa\u672c\u6982\u5ff5\u3001\u5b9e\u73b0\u65b9\u6cd5\u3001\u5e94\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\u3002\u5bf9\u5e94\u5206\u6790\u662f\u4e00\u79cd\u7b80\u5355\u6613\u61c2\u3001\u9002\u7528\u6027\u5e7f\u3001\u8ba1\u7b97\u6548\u7387\u9ad8\u7684\u6570\u636e\u5206\u6790\u65b9\u6cd5\uff0c\u7279\u522b\u9002\u7528\u4e8e\u9891\u6570\u8868\u548c\u4ea4\u53c9\u8868\u7684\u6570\u636e\u5206\u6790\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u6a21\u578b\u7684\u53c2\u6570\u6765\u4f18\u5316\u6a21\u578b\uff0c\u4ee5\u786e\u4fdd\u5206\u6790\u7ed3\u679c\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u80fd\u591f\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528\u5bf9\u5e94\u5206\u6790\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5bf9\u5e94\u5206\u6790\u7684\u57fa\u672c\u6982\u5ff5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5bf9\u5e94\u5206\u6790\u662f\u4e00\u79cd\u591a\u7ef4\u6570\u636e\u5206\u6790\u65b9\u6cd5\uff0c\u901a\u5e38\u7528\u4e8e\u63a2\u7d22\u548c\u53ef\u89c6\u5316\u5206\u7c7b\u6570\u636e\u7684\u5173\u7cfb\u3002\u5b83\u901a\u8fc7\u6784\u5efa\u4e00\u4e2a\u4e8c\u7ef4\u56fe\u5f62\uff0c\u5c06\u884c\u548c\u5217\u7684\u53d8\u91cf\u6295\u5f71\u5230\u4e00\u4e2a\u5171\u540c\u7684\u7a7a\u95f4\u4e2d\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u8054\u6027\u548c\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u51c6\u5907\u6570\u636e\u4ee5\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684\u6570\u636e\u4ee5\u9002\u5f53\u7684\u683c\u5f0f\u5448\u73b0\u3002\u901a\u5e38\u9700\u8981\u5c06\u6570\u636e\u6574\u7406\u6210\u4e00\u4e2a\u4ea4\u53c9\u8868\uff0c\u884c\u4ee3\u8868\u4e00\u4e2a\u5206\u7c7b\u53d8\u91cf\uff0c\u5217\u4ee3\u8868\u53e6\u4e00\u4e2a\u5206\u7c7b\u53d8\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u4e2d\u7684<code>pd.crosstab()<\/code>\u51fd\u6570\u6765\u521b\u5efa\u8fd9\u79cd\u4ea4\u53c9\u8868\uff0c\u786e\u4fdd\u6570\u636e\u662f\u6574\u6570\u7c7b\u578b\uff0c\u4e14\u6ca1\u6709\u7f3a\u5931\u503c\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\u7684\u4e3b\u8981\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5b9e\u73b0\u5bf9\u5e94\u5206\u6790\u7684\u6b65\u9aa4\u5305\u62ec\uff1a1) \u5bfc\u5165\u6240\u9700\u7684\u5e93\uff0c\u5982<code>pandas<\/code>\u548c<code>prince<\/code>\uff1b2) \u51c6\u5907\u548c\u6e05\u6d17\u6570\u636e\uff1b3) \u521b\u5efa\u4ea4\u53c9\u8868\uff1b4) \u5229\u7528<code>prince<\/code>\u5e93\u4e2d\u7684<code>CA<\/code>\u7c7b\u8fdb\u884c\u5bf9\u5e94\u5206\u6790\uff1b5) \u4f7f\u7528\u5206\u6790\u7ed3\u679c\u751f\u6210\u53ef\u89c6\u5316\u56fe\u8868\uff0c\u4f8b\u5982\u6563\u70b9\u56fe\uff0c\u4ee5\u4fbf\u66f4\u76f4\u89c2\u5730\u7406\u89e3\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u7528\u6237\u53ef\u4ee5\u6709\u6548\u5730\u5b9e\u73b0\u5bf9\u5e94\u5206\u6790\u5e76\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5bf9\u5e94\u5206\u6790\u5728Python\u4e2d\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\uff0c\u5982Pandas\u3001Scikit-learn\u3001Matplotl [&hellip;]","protected":false},"author":3,"featured_media":1168005,"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\/1167999"}],"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=1167999"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1167999\/revisions"}],"predecessor-version":[{"id":1168006,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1167999\/revisions\/1168006"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1168005"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1167999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1167999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1167999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}