{"id":1082279,"date":"2025-01-08T12:47:22","date_gmt":"2025-01-08T04:47:22","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1082279.html"},"modified":"2025-01-08T12:47:24","modified_gmt":"2025-01-08T04:47:24","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%bf%9b%e8%a1%8c%e6%95%b0%e6%8d%ae%e9%a2%84%e5%a4%84%e7%90%86-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1082279.html","title":{"rendered":"\u5982\u4f55\u7528python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183901\/9def9854-219d-4340-a7e7-47b243dbfa48.webp\" alt=\"\u5982\u4f55\u7528python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p><strong>\u6570\u636e\u6e05\u6d17\u3001\u7279\u5f81\u63d0\u53d6\u3001\u6570\u636e\u6807\u51c6\u5316\u3001\u5904\u7406\u7f3a\u5931\u503c\u3001\u7f16\u7801\u5206\u7c7b\u53d8\u91cf\u3001\u6570\u636e\u5206\u5272<\/strong>\u3002\u6570\u636e\u9884\u5904\u7406\u662f\u6570\u636e\u79d1\u5b66\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u5de5\u4f5c\u6d41\u7a0b\u4e2d\u6700\u5173\u952e\u7684\u6b65\u9aa4\u4e4b\u4e00\u3002\u4e00\u4e2a\u5e72\u51c0\u4e14\u683c\u5f0f\u5316\u826f\u597d\u7684\u6570\u636e\u96c6\u80fd\u663e\u8457\u63d0\u5347\u6a21\u578b\u7684\u6027\u80fd\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u7528Python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\uff0c\u91cd\u70b9\u5c55\u793a\u6570\u636e\u6e05\u6d17\u548c\u5904\u7406\u7f3a\u5931\u503c\u7684\u5177\u4f53\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6570\u636e\u6e05\u6d17<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u6e05\u6d17\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u7b2c\u4e00\u6b65\uff0c\u4e3b\u8981\u5305\u62ec\u53bb\u9664\u91cd\u590d\u9879\u3001\u5904\u7406\u5f02\u5e38\u503c\u3001\u4fee\u6b63\u6570\u636e\u683c\u5f0f\u7b49\u3002\u7528Python\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u901a\u5e38\u4f7f\u7528Pandas\u5e93\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u53bb\u9664\u91cd\u590d\u9879<\/h4>\n<\/p>\n<p><p>\u91cd\u590d\u7684\u6570\u636e\u4f1a\u5f71\u54cd\u5206\u6790\u7ed3\u679c\uff0c\u56e0\u6b64\u9700\u8981\u53bb\u9664\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>drop_duplicates()<\/code>\u65b9\u6cd5\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;data.csv&#39;)<\/p>\n<h2><strong>\u53bb\u9664\u91cd\u590d\u9879<\/strong><\/h2>\n<p>data_cleaned = data.drop_duplicates()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u5f02\u5e38\u503c<\/h4>\n<\/p>\n<p><p>\u5f02\u5e38\u503c\u662f\u6307\u660e\u663e\u4e0d\u540c\u4e8e\u5176\u4ed6\u6570\u636e\u7684\u503c\uff0c\u5b83\u4eec\u53ef\u80fd\u662f\u6570\u636e\u8f93\u5165\u9519\u8bef\u6216\u7279\u6b8a\u60c5\u51b5\u7684\u7ed3\u679c\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ecIQR\uff08\u56db\u5206\u4f4d\u8ddd\uff09\u6cd5\u548cZ-Score\uff08\u6807\u51c6\u5206\uff09\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528IQR\u65b9\u6cd5\u5904\u7406\u5f02\u5e38\u503c<\/p>\n<p>Q1 = data_cleaned.quantile(0.25)<\/p>\n<p>Q3 = data_cleaned.quantile(0.75)<\/p>\n<p>IQR = Q3 - Q1<\/p>\n<h2><strong>\u8fc7\u6ee4\u5f02\u5e38\u503c<\/strong><\/h2>\n<p>data_filtered = data_cleaned[~((data_cleaned &lt; (Q1 - 1.5 * IQR)) | (data_cleaned &gt; (Q3 + 1.5 * IQR))).any(axis=1)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u7279\u5f81\u63d0\u53d6<\/h3>\n<\/p>\n<p><p>\u7279\u5f81\u63d0\u53d6\u662f\u4ece\u539f\u59cb\u6570\u636e\u4e2d\u63d0\u53d6\u6709\u7528\u4fe1\u606f\u7684\u8fc7\u7a0b\u3002\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u6587\u672c\u5904\u7406\u3001\u65f6\u95f4\u7279\u5f81\u63d0\u53d6\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6587\u672c\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5904\u7406\u6587\u672c\u6570\u636e\u65f6\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u5206\u8bcd\u3001\u53bb\u505c\u7528\u8bcd\u3001\u8bcd\u5e72\u63d0\u53d6\u7b49\u3002\u4f7f\u7528NLTK\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import nltk<\/p>\n<p>from nltk.corpus import stopwords<\/p>\n<p>from nltk.tokenize import word_tokenize<\/p>\n<h2><strong>\u4e0b\u8f7d\u5fc5\u8981\u7684\u8d44\u6e90<\/strong><\/h2>\n<p>nltk.download(&#39;punkt&#39;)<\/p>\n<p>nltk.download(&#39;stopwords&#39;)<\/p>\n<h2><strong>\u793a\u4f8b\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;This is an example sentence for text processing.&quot;<\/p>\n<h2><strong>\u5206\u8bcd<\/strong><\/h2>\n<p>tokens = word_tokenize(text)<\/p>\n<h2><strong>\u53bb\u505c\u7528\u8bcd<\/strong><\/h2>\n<p>filtered_tokens = [word for word in tokens if word.lower() not in stopwords.words(&#39;english&#39;)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u65f6\u95f4\u7279\u5f81\u63d0\u53d6<\/h4>\n<\/p>\n<p><p>\u5904\u7406\u65f6\u95f4\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u63d0\u53d6\u5e74\u6708\u65e5\u3001\u5c0f\u65f6\u3001\u5206\u949f\u7b49\u7279\u5f81\uff0c\u4ee5\u4fbf\u8fdb\u884c\u8fdb\u4e00\u6b65\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u6570\u636e<\/p>\n<p>data[&#39;date&#39;] = pd.to_datetime(data[&#39;date&#39;])<\/p>\n<h2><strong>\u63d0\u53d6\u65f6\u95f4\u7279\u5f81<\/strong><\/h2>\n<p>data[&#39;year&#39;] = data[&#39;date&#39;].dt.year<\/p>\n<p>data[&#39;month&#39;] = data[&#39;date&#39;].dt.month<\/p>\n<p>data[&#39;day&#39;] = data[&#39;date&#39;].dt.day<\/p>\n<p>data[&#39;hour&#39;] = data[&#39;date&#39;].dt.hour<\/p>\n<p>data[&#39;minute&#39;] = data[&#39;date&#39;].dt.minute<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6570\u636e\u6807\u51c6\u5316<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u6807\u51c6\u5316\u662f\u5c06\u4e0d\u540c\u91cf\u7eb2\u7684\u6570\u636e\u8c03\u6574\u5230\u540c\u4e00\u91cf\u7eb2\uff0c\u4ee5\u6d88\u9664\u91cf\u7eb2\u5bf9\u6a21\u578b\u7684\u5f71\u54cd\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u5f52\u4e00\u5316\u548c\u6807\u51c6\u5316\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5f52\u4e00\u5316<\/h4>\n<\/p>\n<p><p>\u5f52\u4e00\u5316\u662f\u5c06\u6570\u636e\u538b\u7f29\u5230[0,1]\u8303\u56f4\u5185\uff0c\u5e38\u7528\u7684Min-Max\u5f52\u4e00\u5316\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import MinMaxScaler<\/p>\n<h2><strong>\u521d\u59cb\u5316Min-Max\u5f52\u4e00\u5316\u5668<\/strong><\/h2>\n<p>scaler = MinMaxScaler()<\/p>\n<h2><strong>\u5bf9\u6570\u636e\u8fdb\u884c\u5f52\u4e00\u5316<\/strong><\/h2>\n<p>data_normalized = scaler.fit_transform(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6807\u51c6\u5316<\/h4>\n<\/p>\n<p><p>\u6807\u51c6\u5316\u662f\u5c06\u6570\u636e\u8c03\u6574\u5230\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1\u7684\u5206\u5e03\u3002\u53ef\u4ee5\u4f7f\u7528Sklearn\u7684StandardScaler\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import StandardScaler<\/p>\n<h2><strong>\u521d\u59cb\u5316\u6807\u51c6\u5316\u5668<\/strong><\/h2>\n<p>scaler = StandardScaler()<\/p>\n<h2><strong>\u5bf9\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316<\/strong><\/h2>\n<p>data_standardized = scaler.fit_transform(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u7f3a\u5931\u503c<\/h3>\n<\/p>\n<p><p>\u5904\u7406\u7f3a\u5931\u503c\u662f\u6570\u636e\u9884\u5904\u7406\u7684\u4e00\u4e2a\u91cd\u8981\u73af\u8282\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u5220\u9664\u7f3a\u5931\u503c\u3001\u586b\u5145\u7f3a\u5931\u503c\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5220\u9664\u7f3a\u5931\u503c<\/h4>\n<\/p>\n<p><p>\u5220\u9664\u7f3a\u5931\u503c\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>dropna()<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c<\/p>\n<p>data_dropped = data.dropna()<\/p>\n<h2><strong>\u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u5217<\/strong><\/h2>\n<p>data_dropped = data.dropna(axis=1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u586b\u5145\u7f3a\u5931\u503c<\/h4>\n<\/p>\n<p><p>\u586b\u5145\u7f3a\u5931\u503c\u7684\u65b9\u6cd5\u5305\u62ec\u7528\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u3001\u4f17\u6570\u7b49\u8fdb\u884c\u586b\u5145\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>fillna()<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7528\u5747\u503c\u586b\u5145\u7f3a\u5931\u503c<\/p>\n<p>data_filled = data.fillna(data.mean())<\/p>\n<h2><strong>\u7528\u4e2d\u4f4d\u6570\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>data_filled = data.fillna(data.median())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u7f16\u7801\u5206\u7c7b\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5206\u7c7b\u53d8\u91cf\u662f\u6307\u5177\u6709\u591a\u4e2a\u7c7b\u522b\u7684\u53d8\u91cf\uff0c\u4f8b\u5982\u6027\u522b\u3001\u56fd\u5bb6\u7b49\u3002\u5904\u7406\u5206\u7c7b\u53d8\u91cf\u7684\u65b9\u6cd5\u5305\u62ecLabel Encoding\u548cOne-Hot Encoding\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Label Encoding<\/h4>\n<\/p>\n<p><p>Label Encoding\u662f\u5c06\u5206\u7c7b\u53d8\u91cf\u8f6c\u6362\u4e3a\u6574\u6570\u7f16\u7801\u3002\u53ef\u4ee5\u4f7f\u7528Sklearn\u7684LabelEncoder\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.preprocessing import LabelEncoder<\/p>\n<h2><strong>\u521d\u59cb\u5316\u7f16\u7801\u5668<\/strong><\/h2>\n<p>encoder = LabelEncoder()<\/p>\n<h2><strong>\u5bf9\u5206\u7c7b\u53d8\u91cf\u8fdb\u884c\u7f16\u7801<\/strong><\/h2>\n<p>data[&#39;category_encoded&#39;] = encoder.fit_transform(data[&#39;category&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001One-Hot Encoding<\/h4>\n<\/p>\n<p><p>One-Hot Encoding\u662f\u5c06\u5206\u7c7b\u53d8\u91cf\u8f6c\u6362\u4e3a\u72ec\u70ed\u7801\u3002\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>get_dummies()<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bf9\u5206\u7c7b\u53d8\u91cf\u8fdb\u884cOne-Hot\u7f16\u7801<\/p>\n<p>data_one_hot = pd.get_dummies(data, columns=[&#39;category&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6570\u636e\u5206\u5272<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u5206\u5272\u662f\u5c06\u6570\u636e\u96c6\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\uff0c\u4ee5\u4fbf\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528Sklearn\u7684<code>tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_test_split()<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import train_test_split<\/p>\n<h2><strong>\u5206\u5272\u6570\u636e<\/strong><\/h2>\n<p>train_data, test_data = train_test_split(data, test_size=0.2, random_state=42)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u6570\u636e\u9884\u5904\u7406\u662f\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\u4e2d\u81f3\u5173\u91cd\u8981\u7684\u4e00\u6b65\u3002\u901a\u8fc7\u6570\u636e\u6e05\u6d17\u3001\u7279\u5f81\u63d0\u53d6\u3001\u6570\u636e\u6807\u51c6\u5316\u3001\u5904\u7406\u7f3a\u5931\u503c\u3001\u7f16\u7801\u5206\u7c7b\u53d8\u91cf\u548c\u6570\u636e\u5206\u5272\uff0c\u53ef\u4ee5\u4e3a\u540e\u7eed\u7684\u6a21\u578b\u8bad\u7ec3\u548c\u8bc4\u4f30\u6253\u4e0b\u575a\u5b9e\u7684\u57fa\u7840\u3002Python\u4f5c\u4e3a\u6570\u636e\u79d1\u5b66\u7684\u4e3b\u8981\u5de5\u5177\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e93\u548c\u51fd\u6570\uff0c\u5e2e\u52a9\u6211\u4eec\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u60a8\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u9884\u5904\u7406\u5de5\u5177\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u81f3\u5173\u91cd\u8981\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ecPandas\u3001NumPy\u548cScikit-learn\u3002Pandas\u975e\u5e38\u9002\u5408\u5904\u7406\u8868\u683c\u6570\u636e\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff1bNumPy\u5219\u64c5\u957f\u4e8e\u5904\u7406\u6570\u503c\u8ba1\u7b97\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\uff1bScikit-learn\u5219\u5305\u542b\u4e86\u8bb8\u591a\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u548c\u9884\u5904\u7406\u529f\u80fd\uff0c\u5982\u6807\u51c6\u5316\u3001\u5f52\u4e00\u5316\u7b49\u3002\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u7c7b\u578b\u548c\u5904\u7406\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p><strong>\u6570\u636e\u9884\u5904\u7406\u7684\u5e38\u89c1\u6b65\u9aa4\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u6570\u636e\u9884\u5904\u7406\u901a\u5e38\u5305\u62ec\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u6570\u636e\u6e05\u6d17\u3001\u7f3a\u5931\u503c\u5904\u7406\u3001\u6570\u636e\u8f6c\u6362\u548c\u7279\u5f81\u5de5\u7a0b\u3002\u6570\u636e\u6e05\u6d17\u6d89\u53ca\u53bb\u9664\u91cd\u590d\u8bb0\u5f55\u548c\u9519\u8bef\u6570\u636e\uff1b\u7f3a\u5931\u503c\u5904\u7406\u53ef\u4ee5\u9009\u62e9\u586b\u8865\u3001\u5220\u9664\u6216\u63d2\u503c\u7684\u65b9\u6cd5\uff1b\u6570\u636e\u8f6c\u6362\u5305\u62ec\u6807\u51c6\u5316\u3001\u5f52\u4e00\u5316\u548c\u7f16\u7801\u7b49\uff1b\u7279\u5f81\u5de5\u7a0b\u5219\u662f\u901a\u8fc7\u9009\u62e9\u3001\u521b\u5efa\u548c\u53d8\u6362\u7279\u5f81\u6765\u63d0\u9ad8\u6a21\u578b\u7684\u8868\u73b0\u3002\u638c\u63e1\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u6709\u6548\u5730\u51c6\u5907\u6570\u636e\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u6216\u5efa\u6a21\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5206\u7c7b\u6570\u636e\u4ee5\u4fbf\u4e8e\u6a21\u578b\u8bad\u7ec3\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5904\u7406\u5206\u7c7b\u6570\u636e\u901a\u5e38\u9700\u8981\u8fdb\u884c\u7f16\u7801\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u6807\u7b7e\u7f16\u7801\u548c\u72ec\u70ed\u7f16\u7801\u3002\u6807\u7b7e\u7f16\u7801\u5c06\u6bcf\u4e2a\u7c7b\u522b\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6574\u6570\uff0c\u800c\u72ec\u70ed\u7f16\u7801\u5219\u5c06\u6bcf\u4e2a\u7c7b\u522b\u8f6c\u6362\u4e3a\u4e00\u4e2a\u4e8c\u8fdb\u5236\u53d8\u91cf\uff0c\u9002\u7528\u4e8e\u65e0\u5e8f\u5206\u7c7b\u6570\u636e\u3002\u6b64\u5916\uff0c\u4f7f\u7528Scikit-learn\u7684<code>OneHotEncoder<\/code>\u6216<code>LabelEncoder<\/code>\u5de5\u5177\u53ef\u4ee5\u7b80\u5316\u8fd9\u4e00\u8fc7\u7a0b\u3002\u9009\u62e9\u5408\u9002\u7684\u7f16\u7801\u65b9\u5f0f\u4e0d\u4ec5\u6709\u52a9\u4e8e\u6a21\u578b\u7684\u7406\u89e3\uff0c\u8fd8\u80fd\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406 \u6570\u636e\u6e05\u6d17\u3001\u7279\u5f81\u63d0\u53d6\u3001\u6570\u636e\u6807\u51c6\u5316\u3001\u5904\u7406\u7f3a\u5931\u503c\u3001\u7f16\u7801\u5206\u7c7b\u53d8\u91cf\u3001\u6570\u636e\u5206\u5272\u3002\u6570\u636e\u9884\u5904 [&hellip;]","protected":false},"author":3,"featured_media":1082284,"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\/1082279"}],"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=1082279"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1082279\/revisions"}],"predecessor-version":[{"id":1082285,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1082279\/revisions\/1082285"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1082284"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1082279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1082279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1082279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}