{"id":73623,"date":"2026-02-08T01:17:21","date_gmt":"2026-02-07T17:17:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/73623.html"},"modified":"2026-02-08T01:17:21","modified_gmt":"2026-02-07T17:17:21","slug":"%e5%9f%ba%e4%ba%8e%e6%9c%b4%e7%b4%a0%e8%b4%9d%e5%8f%b6%e6%96%af%e7%9a%84%e8%af%84%e8%ae%ba%e6%83%85%e6%84%9f%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/73623.html","title":{"rendered":"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790"},"content":{"rendered":"<h3>\u4e00\u3001\u524d\u671f\u51c6\u5907<\/h3>\n<ul>\n<li>\n<p>\u6570\u636e\u5904\u7406&#xff1a;Pandas&#xff0c;\u9ad8\u6548\u8bfb\u53d6\u6587\u672c \/ Excel \u6587\u4ef6&#xff0c;\u5b8c\u6210\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u4e0e\u62fc\u63a5&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4e2d\u6587\u5206\u8bcd&#xff1a;jieba&#xff0c;Python \u6700\u5e38\u7528\u7684\u4e2d\u6587\u5206\u8bcd\u5e93&#xff0c;\u8f7b\u91cf\u9ad8\u6548&#xff0c;\u652f\u6301\u7cbe\u51c6\u5206\u8bcd&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6587\u672c\u5411\u91cf\u5316&#xff1a;CountVectorizer&#xff0c;\u5c06\u5206\u8bcd\u540e\u7684\u6587\u672c\u8f6c\u5316\u4e3a\u8bcd\u9891\u77e9\u9635&#xff0c;\u5b9e\u73b0 \u201c\u6587\u672c\u2192\u6570\u503c\u201d \u7684\u6838\u5fc3\u8f6c\u6362&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5206\u7c7b\u7b97\u6cd5&#xff1a;\u6734\u7d20\u8d1d\u53f6\u65af&#xff08;MultinomialNB&#xff09;&#xff0c;\u57fa\u4e8e\u6982\u7387\u7edf\u8ba1\u7684\u7b97\u6cd5&#xff0c;\u5bf9\u6587\u672c\u5206\u7c7b\u4efb\u52a1\u9002\u914d\u6027\u5f3a\u3001\u8bad\u7ec3\u901f\u5ea6\u5feb\u3001\u6548\u679c\u7a33\u5b9a&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6a21\u578b\u8bc4\u4f30&#xff1a;sklearn.metrics&#xff0c;\u63d0\u4f9b\u7cbe\u51c6\u7387\u3001\u53ec\u56de\u7387\u3001F1 \u503c\u7b49\u591a\u7ef4\u5ea6\u8bc4\u4f30\u6307\u6807&#xff0c;\u9a8c\u8bc1\u6a21\u578b\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e8c\u3001\u5b9e\u73b0\u6d41\u7a0b<\/h3>\n<h4>2.1 \u6570\u636e\u8bfb\u53d6&#xff1a;\u52a0\u8f7d\u597d\u8bc4 \/ \u5dee\u8bc4\u539f\u59cb\u6570\u636e<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f7f\u7528\u00a0\u201c\u597d\u8bc4.txt\u201d \u548c \u201c\u5dee\u8bc4.txt\u201d \u6570\u636e\u96c6&#xff08;\u6bcf\u884c\u4e00\u6761\u8bc4\u8bba&#xff09;&#xff0c;\u540c\u65f6\u51c6\u5907\u4e2d\u6587\u505c\u7528\u8bcd\u8868\u201cStopwordsCN.txt\u201d&#xff08;\u5305\u542b\u7684\u3001\u4e86\u3001\u5417\u7b49\u65e0\u5b9e\u9645\u60c5\u611f\u610f\u4e49\u7684\u8bcd\u6c47&#xff09;\u3002\u4f7f\u7528 Pandas \u7684read_table\u8bfb\u53d6\u6587\u672c\u6587\u4ef6&#xff0c;\u81ea\u52a8\u6309\u884c\u5206\u5272\u6570\u636e<\/p>\n<p>import pandas as pd<\/p>\n<p># \u8bfb\u53d6\u5dee\u8bc4\u3001\u597d\u8bc4\u6570\u636e&#xff0c;\u7f16\u7801\u4e3autf-8<br \/>\ncp_content &#061; pd.read_table(r&#034;.\\\\\u5dee\u8bc4.txt&#034;, encoding&#061;&#039;utf-8&#039;)<br \/>\nyzpj_content &#061; pd.read_table(r&#034;.\\\\\u597d\u8bc4.txt&#034;, encoding&#061;&#039;utf-8&#039;)<br \/>\n# \u8bfb\u53d6\u505c\u7528\u8bcd\u8868&#xff0c;engine&#061;&#039;python&#039;\u89e3\u51b3\u6587\u4ef6\u8bfb\u53d6\u7f16\u7801\u95ee\u9898<br \/>\nstopwords &#061; pd.read_csv(r&#034;.\\\\StopwordsCN.txt&#034;, encoding&#061;&#039;utf8&#039;, engine&#061;&#039;python&#039;, index_col&#061;False)<\/p>\n<h4>2.2 \u4e2d\u6587\u5206\u8bcd&#xff1a;\u5c06\u6574\u53e5\u8bc4\u8bba\u62c6\u5206\u4e3a\u8bcd\u6c47<\/h4>\n<p>import jieba<\/p>\n<p># \u5b9a\u4e49\u5206\u8bcd\u51fd\u6570&#xff08;\u53ef\u9009&#xff0c;\u7b80\u5316\u91cd\u590d\u4ee3\u7801&#xff09;<br \/>\ndef jieba_cut(data):<br \/>\n    segments &#061; []<br \/>\n    # \u63d0\u53d6\u8bc4\u8bba\u5217\u5e76\u8f6c\u4e3a\u5217\u8868<br \/>\n    contents &#061; data.content.values.tolist()<br \/>\n    for content in contents:<br \/>\n        # \u7cbe\u51c6\u5206\u8bcd&#xff0c;\u8fd4\u56de\u5217\u8868<br \/>\n        results &#061; jieba.lcut(content)<br \/>\n        # \u8fc7\u6ee4\u5206\u8bcd\u540e\u4ec51\u4e2a\u8bcd\u6c47\u7684\u65e0\u6548\u8bc4\u8bba<br \/>\n        if len(results) &gt; 1:<br \/>\n            segments.append(results)<br \/>\n    # \u8f6c\u4e3aDataFrame\u65b9\u4fbf\u540e\u7eed\u5904\u7406<br \/>\n    return pd.DataFrame({&#039;content&#039;: segments})<\/p>\n<p># \u5dee\u8bc4\u5206\u8bcd\u5e76\u4fdd\u5b58<br \/>\ncp_fc_results &#061; jieba_cut(cp_content)<br \/>\ncp_fc_results.to_excel(&#039;cp_fc_results.xlsx&#039;, index&#061;False)<br \/>\n# \u597d\u8bc4\u5206\u8bcd\u5e76\u4fdd\u5b58<br \/>\nhp_fc_results &#061; jieba_cut(yzpj_content)<br \/>\nhp_fc_results.to_excel(&#039;hp_fc_results.xlsx&#039;, index&#061;False)<\/p>\n<h4>2.3 \u6587\u672c\u9884\u5904\u7406&#xff1a;\u53bb\u9664\u505c\u7528\u8bcd<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u505c\u7528\u8bcd\u662f\u6307\u5728\u6587\u672c\u4e2d\u9891\u7e41\u51fa\u73b0&#xff0c;\u4f46\u65e0\u5b9e\u9645\u60c5\u611f\u6216\u8bed\u4e49\u4ef7\u503c\u7684\u8bcd\u6c47&#xff08;\u5982 \u201c\u7684\u201d\u201c\u4e86\u201d\u201c\u6211\u201d\u201c\u5f88\u201d \u7b49&#xff09;&#xff0c;\u8fd9\u4e9b\u8bcd\u6c47\u4f1a\u5e72\u6270\u6a21\u578b\u8bad\u7ec3&#xff0c;\u5fc5\u987b\u53bb\u9664\u3002\u672c\u6b21\u901a\u8fc7\u81ea\u5b9a\u4e49\u51fd\u6570\u5b9e\u73b0\u505c\u7528\u8bcd\u53bb\u9664&#xff0c;\u6838\u5fc3\u903b\u8f91\u662f\u904d\u5386\u5206\u8bcd\u540e\u7684\u8bcd\u6c47\u5217\u8868&#xff0c;\u8fc7\u6ee4\u6389\u5728\u505c\u7528\u8bcd\u8868\u4e2d\u7684\u8bcd\u6c47.<\/p>\n<p># \u5b9a\u4e49\u53bb\u9664\u505c\u7528\u8bcd\u51fd\u6570<br \/>\ndef drop_stopwords(contents, stopwords):<br \/>\n    segments_clean &#061; []<br \/>\n    for content in contents:<br \/>\n        line_clean &#061; []<br \/>\n        for word in content:<br \/>\n            # \u8fc7\u6ee4\u505c\u7528\u8bcd<br \/>\n            if word not in stopwords:<br \/>\n                line_clean.append(word)<br \/>\n        segments_clean.append(line_clean)<br \/>\n    return segments_clean<\/p>\n<p># \u63d0\u53d6\u5206\u8bcd\u7ed3\u679c\u548c\u505c\u7528\u8bcd&#xff0c;\u8f6c\u4e3a\u5217\u8868<br \/>\ncp_contents &#061; cp_fc_results.content.values.tolist()<br \/>\nhp_contents &#061; hp_fc_results.content.values.tolist()<br \/>\nstopwords_list &#061; stopwords.stopword.values.tolist()<\/p>\n<p># \u53bb\u9664\u505c\u7528\u8bcd<br \/>\ncp_fc_contents_clean &#061; drop_stopwords(cp_contents, stopwords_list)<br \/>\nhp_fc_contents_clean &#061; drop_stopwords(hp_contents, stopwords_list)<\/p>\n<h4>2.4\u6570\u636e\u6807\u6ce8\u4e0e\u5408\u5e76&#xff1a;\u6784\u5efa\u8bad\u7ec3\u6570\u636e\u96c6<\/h4>\n<p>\u60c5\u611f\u5206\u6790\u5c5e\u4e8e\u76d1\u7763\u5b66\u4e60\u4efb\u52a1&#xff0c;\u9700\u8981\u4e3a\u6570\u636e\u6dfb\u52a0\u6807\u7b7e&#xff08;label&#xff09;&#xff0c;\u672c\u6b21\u5b9a\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5dee\u8bc4\u6807\u7b7e&#xff1a;1&#xff08;\u4ee3\u8868\u8d1f\u9762\u60c5\u611f&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u597d\u8bc4\u6807\u7b7e&#xff1a;0&#xff08;\u4ee3\u8868\u6b63\u9762\u60c5\u611f&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>\u5c06\u53bb\u9664\u505c\u7528\u8bcd\u540e\u7684\u5dee\u8bc4\u3001\u597d\u8bc4\u6570\u636e\u5206\u522b\u6807\u6ce8&#xff0c;\u518d\u901a\u8fc7pd.concat\u5408\u5e76\u4e3a\u7edf\u4e00\u7684\u8bad\u7ec3\u6570\u636e\u96c6&#xff0c;\u4e3a\u540e\u7eed\u6a21\u578b\u8bad\u7ec3\u505a\u51c6\u5907<\/p>\n<p># \u4e3a\u5dee\u8bc4\u3001\u597d\u8bc4\u6dfb\u52a0\u6807\u7b7e\u5e76\u6784\u5efaDataFrame<br \/>\ncp_train &#061; pd.DataFrame({&#039;segments_clean&#039;: cp_fc_contents_clean, &#039;label&#039;: 1})<br \/>\nhp_train &#061; pd.DataFrame({&#039;segments_clean&#039;: hp_fc_contents_clean, &#039;label&#039;: 0})<\/p>\n<p># \u5408\u5e76\u5dee\u8bc4\u3001\u597d\u8bc4\u6570\u636e&#xff0c;\u5f62\u6210\u5b8c\u6574\u8bad\u7ec3\u96c6<br \/>\npj_train &#061; pd.concat([cp_train, hp_train], ignore_index&#061;True)<\/p>\n<p>ignore_index&#061;True\u91cd\u7f6e\u7d22\u5f15&#xff0c;\u907f\u514d\u5408\u5e76\u540e\u7d22\u5f15\u91cd\u590d<\/p>\n<h4>2.5 \u6570\u636e\u96c6\u5212\u5206&#xff1a;\u8bad\u7ec3\u96c6\u4e0e\u6d4b\u8bd5\u96c6\u5206\u79bb<\/h4>\n<p>\u4e3a\u4e86\u9a8c\u8bc1\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b&#xff08;\u5373\u5bf9\u65b0\u6570\u636e\u7684\u9884\u6d4b\u80fd\u529b&#xff09;&#xff0c;\u9700\u8981\u5c06\u5408\u5e76\u540e\u7684\u6570\u636e\u96c6\u5212\u5206\u4e3a\u8bad\u7ec3\u96c6&#xff08;70%&#xff09;\u548c\u6d4b\u8bd5\u96c6&#xff08;30%&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bad\u7ec3\u96c6&#xff1a;\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b&#xff0c;\u8ba9\u6a21\u578b\u5b66\u4e60 \u201c\u8bcd\u6c47\u7279\u5f81\u2192\u60c5\u611f\u6807\u7b7e\u201d \u7684\u6620\u5c04\u5173\u7cfb&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u96c6&#xff1a;\u7528\u4e8e\u8bc4\u4f30\u6a21\u578b\u6027\u80fd&#xff0c;\u9a8c\u8bc1\u6a21\u578b\u5728\u672a\u89c1\u8fc7\u7684\u6570\u636e\u4e0a\u7684\u5206\u7c7b\u6548\u679c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f7f\u7528 sklearn \u7684train_test_split\u5b9e\u73b0\u968f\u673a\u5212\u5206&#xff0c;\u4fdd\u8bc1\u6570\u636e\u7684\u968f\u673a\u6027\u548c\u4ee3\u8868\u6027<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p># \u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6&#xff0c;test_size&#061;0.3\u8868\u793a30%\u4e3a\u6d4b\u8bd5\u96c6<br \/>\n# random_state&#061;0\u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u4fdd\u8bc1\u5b9e\u9a8c\u53ef\u590d\u73b0<br \/>\nx_train, x_test, y_train, y_test &#061; train_test_split(<br \/>\n    pj_train[&#039;segments_clean&#039;].values,<br \/>\n    pj_train[&#039;label&#039;].values,<br \/>\n    test_size&#061;0.3,<br \/>\n    random_state&#061;0<br \/>\n)<\/p>\n<h4>2.6 \u6587\u672c\u5411\u91cf\u5316&#xff1a;\u5c06\u8bcd\u6c47\u5217\u8868\u8f6c\u4e3a\u8bcd\u9891\u77e9\u9635<\/h4>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u673a\u5668\u5b66\u4e60\u6a21\u578b\u53ea\u80fd\u5904\u7406\u6570\u503c\u578b\u6570\u636e&#xff0c;\u800c\u5f53\u524d\u7684\u6587\u672c\u6570\u636e\u662f\u8bcd\u6c47\u5217\u8868\u683c\u5f0f&#xff0c;\u56e0\u6b64\u9700\u8981\u901a\u8fc7\u6587\u672c\u5411\u91cf\u5316\u5c06\u5176\u8f6c\u5316\u4e3a\u6570\u503c\u77e9\u9635\u3002\u672c\u6b21\u4f7f\u7528 CountVectorizer&#xff0c;\u6838\u5fc3\u539f\u7406\u662f\u6784\u5efa\u8bcd\u5e93&#xff0c;\u7edf\u8ba1\u6bcf\u4e2a\u8bc4\u8bba\u4e2d\u8bcd\u6c47\u7684\u51fa\u73b0\u9891\u7387\u3002<\/p>\n<p>2.6.1 \u5411\u91cf\u5316\u524d\u7684\u683c\u5f0f\u8f6c\u6362<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0CountVectorizer \u8981\u6c42\u8f93\u5165\u4e3a\u5b57\u7b26\u4e32\u5217\u8868&#xff08;\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u6761\u4ee5\u7a7a\u683c\u5206\u9694\u7684\u8bcd\u6c47\u5b57\u7b26\u4e32&#xff09;&#xff0c;\u56e0\u6b64\u9700\u8981\u5c06\u8bcd\u6c47\u5217\u8868\u8f6c\u4e3a\u6307\u5b9a\u683c\u5f0f<\/p>\n<p># \u8bad\u7ec3\u96c6\u683c\u5f0f\u8f6c\u6362&#xff1a;\u8bcd\u6c47\u5217\u8868\u2192\u7a7a\u683c\u5206\u9694\u7684\u5b57\u7b26\u4e32<br \/>\ntrain_words &#061; []<br \/>\nfor line in x_train:<br \/>\n    train_words.append(&#039; &#039;.join(line))<\/p>\n<p># \u6d4b\u8bd5\u96c6\u683c\u5f0f\u8f6c\u6362<br \/>\ntest_words &#061; []<br \/>\nfor line in x_test:<br \/>\n    test_words.append(&#039; &#039;.join(line))<\/p>\n<p>2.6.2 \u6784\u5efa\u8bcd\u5e93\u5e76\u5b8c\u6210\u5411\u91cf\u5316<\/p>\n<p>\u8bbe\u7f6e CountVectorizer \u5173\u952e\u53c2\u6570&#xff0c;\u6784\u5efa\u8bcd\u5e93\u5e76\u5c06\u8bad\u7ec3\u96c6\u3001\u6d4b\u8bd5\u96c6\u8f6c\u4e3a\u8bcd\u9891\u77e9\u9635<\/p>\n<p>from sklearn.feature_extraction.text import CountVectorizer<\/p>\n<p># \u521d\u59cb\u5316CountVectorizer<br \/>\nvec &#061; CountVectorizer(<br \/>\n    max_features&#061;4000,  # \u53ea\u4fdd\u7559\u8bcd\u9891\u524d4000\u7684\u8bcd\u6c47&#xff0c;\u51cf\u5c11\u8ba1\u7b97\u91cf<br \/>\n    lowercase&#061;False,    # \u4e0d\u8f6c\u6362\u4e3a\u5c0f\u5199&#xff08;\u4e2d\u6587\u65e0\u5927\u5c0f\u5199\u533a\u5206&#xff0c;\u5173\u95ed\u63d0\u5347\u6548\u7387&#xff09;<br \/>\n    ngram_range&#061;(1,3)   # \u63d0\u53d61-3\u5143\u8bcd&#xff0c;\u517c\u987e\u5355\u4e2a\u8bcd\u6c47\u548c\u8bcd\u6c47\u7ec4\u5408&#xff08;\u5982\u201c\u5f88\u5dee\u201d\u201c\u975e\u5e38\u5dee\u201d&#xff09;<br \/>\n)<\/p>\n<p># \u57fa\u4e8e\u8bad\u7ec3\u96c6\u6784\u5efa\u8bcd\u5e93&#xff08;\u5173\u952e&#xff1a;\u53ea\u4f7f\u7528\u8bad\u7ec3\u96c6&#xff0c;\u907f\u514d\u6570\u636e\u6cc4\u9732&#xff09;<br \/>\nvec.fit(train_words)<br \/>\n# \u8bad\u7ec3\u96c6\u5411\u91cf\u5316<br \/>\nx_train_vec &#061; vec.transform(train_words)<br \/>\n# \u6d4b\u8bd5\u96c6\u5411\u91cf\u5316&#xff08;\u4f7f\u7528\u8bad\u7ec3\u96c6\u8bcd\u5e93&#xff0c;\u4fdd\u8bc1\u4e00\u81f4\u6027&#xff09;<br \/>\nx_test_vec &#061; vec.transform(test_words)<\/p>\n<h4>2.7 \u6a21\u578b\u8bad\u7ec3&#xff1a;\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u8bad\u7ec3\u5206\u7c7b\u6a21\u578b<\/h4>\n<p>\u6734\u7d20\u8d1d\u53f6\u65af\u662f\u6587\u672c\u5206\u7c7b\u7684\u7ecf\u5178\u7b97\u6cd5&#xff0c;\u5176\u4e2d MultinomialNB&#xff08;\u591a\u9879\u5f0f\u6734\u7d20\u8d1d\u53f6\u65af&#xff09;\u3002\u8bbe\u7f6e\u5e73\u6ed1\u7cfb\u6570alpha&#061;0.1&#xff08;\u907f\u514d\u51fa\u73b0\u6982\u7387\u4e3a 0 \u7684\u60c5\u51b5&#xff09;&#xff0c;\u8bad\u7ec3\u6a21\u578b<\/p>\n<p>from sklearn.naive_bayes import MultinomialNB<\/p>\n<p># \u521d\u59cb\u5316\u6734\u7d20\u8d1d\u53f6\u65af\u5206\u7c7b\u5668<br \/>\nclassifier &#061; MultinomialNB(alpha&#061;0.1)<br \/>\n# \u8bad\u7ec3\u6a21\u578b&#xff1a;\u4f20\u5165\u8bad\u7ec3\u96c6\u8bcd\u9891\u77e9\u9635\u548c\u5bf9\u5e94\u6807\u7b7e<br \/>\nclassifier.fit(x_train_vec, y_train)<\/p>\n<h4>2.8 \u6a21\u578b\u8bc4\u4f30<\/h4>\n<p>\u6a21\u578b\u8bad\u7ec3\u5b8c\u6210\u540e&#xff0c;\u4f7f\u7528 sklearn \u7684classification_report\u751f\u6210\u7cbe\u51c6\u7387&#xff08;precision&#xff09;\u3001\u53ec\u56de\u7387&#xff08;recall&#xff09;\u3001F1 \u503c&#xff08;f1-score&#xff09;\u7b49\u6838\u5fc3\u6307\u6807&#xff0c;\u5168\u9762\u9a8c\u8bc1\u6a21\u578b\u6548\u679c<\/p>\n<p>from sklearn import metrics<\/p>\n<p># \u8bad\u7ec3\u96c6\u9884\u6d4b<br \/>\ntrain_pr &#061; classifier.predict(x_train_vec)<br \/>\n# \u8bad\u7ec3\u96c6\u8bc4\u4f30&#xff0c;digits&#061;6\u4fdd\u75596\u4f4d\u5c0f\u6570&#xff0c;\u63d0\u5347\u7cbe\u5ea6<br \/>\nprint(&#034;&#061;&#061;&#061;&#061;&#061; \u8bad\u7ec3\u96c6\u6a21\u578b\u8bc4\u4f30 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\nprint(metrics.classification_report(y_train, train_pr, digits&#061;6))<\/p>\n<p># \u6d4b\u8bd5\u96c6\u9884\u6d4b<br \/>\ntest_pr &#061; classifier.predict(x_test_vec)<br \/>\n# \u6d4b\u8bd5\u96c6\u8bc4\u4f30<br \/>\nprint(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; \u6d4b\u8bd5\u96c6\u6a21\u578b\u8bc4\u4f30 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\nprint(metrics.classification_report(y_test, test_pr))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u671f\u51c6\u5907\u6570\u636e\u5904\u7406&#xff1a;Pandas&#xff0c;\u9ad8\u6548\u8bfb\u53d6\u6587\u672c \/ Excel \u6587\u4ef6&#xff0c;\u5b8c\u6210\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u4e0e\u62fc\u63a5&#xff1b;\u4e2d\u6587\u5206\u8bcd&#xff1a;jieba&#xff0c;Python \u6700\u5e38\u7528\u7684\u4e2d\u6587\u5206\u8bcd\u5e93&#xff0c;\u8f7b\u91cf\u9ad8\u6548&#xff0c;\u652f\u6301\u7cbe\u51c6\u5206\u8bcd&#xff1b;\u6587\u672c\u5411\u91cf\u5316&#xff1a;CountVectorizer&#xff0c;\u5c06\u5206\u8bcd\u540e\u7684\u6587\u672c\u8f6c\u5316\u4e3a\u8bcd\u9891\u77e9\u9635&#xff0c;\u5b9e\u73b0 \u201c\u6587\u672c\u2192\u6570\u503c\u201d \u7684\u6838\u5fc3\u8f6c\u6362&#xff1b;\u5206\u7c7b\u7b97\u6cd5&amp;#x<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50,427],"topic":[],"class_list":["post-73623","post","type-post","status-publish","format-standard","hentry","category-server","tag-50","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/73623.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u524d\u671f\u51c6\u5907\u6570\u636e\u5904\u7406&#xff1a;Pandas&#xff0c;\u9ad8\u6548\u8bfb\u53d6\u6587\u672c \/ Excel \u6587\u4ef6&#xff0c;\u5b8c\u6210\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u4e0e\u62fc\u63a5&#xff1b;\u4e2d\u6587\u5206\u8bcd&#xff1a;jieba&#xff0c;Python \u6700\u5e38\u7528\u7684\u4e2d\u6587\u5206\u8bcd\u5e93&#xff0c;\u8f7b\u91cf\u9ad8\u6548&#xff0c;\u652f\u6301\u7cbe\u51c6\u5206\u8bcd&#xff1b;\u6587\u672c\u5411\u91cf\u5316&#xff1a;CountVectorizer&#xff0c;\u5c06\u5206\u8bcd\u540e\u7684\u6587\u672c\u8f6c\u5316\u4e3a\u8bcd\u9891\u77e9\u9635&#xff0c;\u5b9e\u73b0 \u201c\u6587\u672c\u2192\u6570\u503c\u201d \u7684\u6838\u5fc3\u8f6c\u6362&#xff1b;\u5206\u7c7b\u7b97\u6cd5&amp;#x\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/73623.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-07T17:17:21+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73623.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/73623.html\",\"name\":\"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-07T17:17:21+00:00\",\"dateModified\":\"2026-02-07T17:17:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/73623.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/73623.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73623.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/73623.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u524d\u671f\u51c6\u5907\u6570\u636e\u5904\u7406&#xff1a;Pandas&#xff0c;\u9ad8\u6548\u8bfb\u53d6\u6587\u672c \/ Excel \u6587\u4ef6&#xff0c;\u5b8c\u6210\u6570\u636e\u683c\u5f0f\u8f6c\u6362\u4e0e\u62fc\u63a5&#xff1b;\u4e2d\u6587\u5206\u8bcd&#xff1a;jieba&#xff0c;Python \u6700\u5e38\u7528\u7684\u4e2d\u6587\u5206\u8bcd\u5e93&#xff0c;\u8f7b\u91cf\u9ad8\u6548&#xff0c;\u652f\u6301\u7cbe\u51c6\u5206\u8bcd&#xff1b;\u6587\u672c\u5411\u91cf\u5316&#xff1a;CountVectorizer&#xff0c;\u5c06\u5206\u8bcd\u540e\u7684\u6587\u672c\u8f6c\u5316\u4e3a\u8bcd\u9891\u77e9\u9635&#xff0c;\u5b9e\u73b0 \u201c\u6587\u672c\u2192\u6570\u503c\u201d \u7684\u6838\u5fc3\u8f6c\u6362&#xff1b;\u5206\u7c7b\u7b97\u6cd5&amp;#x","og_url":"https:\/\/www.wsisp.com\/helps\/73623.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-07T17:17:21+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/73623.html","url":"https:\/\/www.wsisp.com\/helps\/73623.html","name":"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-07T17:17:21+00:00","dateModified":"2026-02-07T17:17:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/73623.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/73623.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/73623.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8e\u6734\u7d20\u8d1d\u53f6\u65af\u7684\u8bc4\u8bba\u60c5\u611f\u5206\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=73623"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73623\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=73623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=73623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=73623"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=73623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}