{"id":20081,"date":"2026-01-16T16:24:26","date_gmt":"2026-01-16T08:24:26","guid":{"rendered":"https:\/\/92it.top\/?p=20081"},"modified":"2026-01-16T16:24:26","modified_gmt":"2026-01-16T08:24:26","slug":"%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0_%e7%89%b9%e5%be%81%e5%b7%a5%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=20081","title":{"rendered":"\u673a\u5668\u5b66\u4e60_\u7279\u5f81\u5de5\u7a0b"},"content":{"rendered":"\n<p><strong>\u524d\u8a00\u200b\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u662f\u4e00\u4f4d\u53a8\u5e08\uff0c\u8981\u505a\u4e00\u9053\u7f8e\u5473\u7684\u83dc\u80b4\uff0c\u673a\u5668\u5b66\u4e60\u6a21\u578b\u5c31\u50cf\u4f60\u7684&#8221;\u70f9\u996a\u7b97\u6cd5&#8221;\uff0c\u800c\u539f\u59cb\u6570\u636e\u5c31\u662f\u4f60\u4ece\u5e02\u573a\u4e70\u56de\u6765\u7684\u5404\u79cd\u98df\u6750\uff1a\u6709\u852c\u83dc\u3001\u8089\u7c7b\u3001\u8c03\u6599\uff0c\u4f46\u53ef\u80fd\u6709\u4e9b\u662f\u5e26\u6ce5\u7684\uff0c\u6709\u4e9b\u662f\u6574\u5757\u7684\uff0c\u6709\u4e9b\u5473\u9053\u5f88\u51b2\u3002<strong>\u7279\u5f81\u5de5\u7a0b<\/strong>\uff0c\u5c31\u662f\u5c06\u8fd9\u4e9b\u539f\u59cb&#8221;\u98df\u6750&#8221;\u8fdb\u884c\u6e05\u6d17\u3001\u5207\u5272\u3001\u814c\u5236\u3001\u642d\u914d\uff0c\u6700\u7ec8\u5904\u7406\u6210\u53ef\u4ee5\u76f4\u63a5\u4e0b\u9505\u70f9\u996a\u7684&#8221;\u534a\u6210\u54c1&#8221;\u7684\u8fc7\u7a0b\uff0c\u5b83\u662f\u8fde\u63a5\u539f\u59cb\u6570\u636e\u4e0e\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u6865\u6881\uff0c\u662f\u51b3\u5b9a\u6a21\u578b\u6027\u80fd\u4e0a\u9650\u7684\u5173\u952e\u6b65\u9aa4\u3002<\/p>\n\n\n\n<p>\u7b80\u5355\u6765\u8bf4\uff0c<strong>\u7279\u5f81\u5de5\u7a0b<\/strong>\u662f\u5229\u7528\u9886\u57df\u77e5\u8bc6\uff0c\u901a\u8fc7\u4e00\u7cfb\u5217\u6280\u672f\u624b\u6bb5\uff0c\u4ece\u539f\u59cb\u6570\u636e\u4e2d\u63d0\u53d6\u3001\u6784\u9020\u3001\u9009\u62e9\u51fa\u5bf9\u673a\u5668\u5b66\u4e60\u6a21\u578b\u66f4\u6709\u4ef7\u503c\u3001\u66f4\u6613\u5b66\u4e60\u7684\u7279\u5f81\uff08\u53d8\u91cf\uff09\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u7279\u5f81\u5de5\u7a0b\u5982\u6b64\u91cd\u8981\uff1f\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5728\u673a\u5668\u5b66\u4e60\u9879\u76ee\u4e2d\uff0c\u6570\u636e\u548c\u7279\u5f81\u7684\u8d28\u91cf\u76f4\u63a5\u51b3\u5b9a\u4e86\u6a21\u578b\u6027\u80fd\u7684\u4e0a\u9650\uff0c\u800c\u6a21\u578b\u548c\u7b97\u6cd5\u53ea\u662f\u903c\u8fd1\u8fd9\u4e2a\u4e0a\u9650\u3002\u4e00\u4e2a\u4f18\u79c0\u7684\u7279\u5f81\u5de5\u7a0b\u53ef\u4ee5\uff1a<\/p>\n\n\n\n<ol>\n<li><strong>\u63d0\u5347\u6a21\u578b\u6027\u80fd<\/strong>\uff1a\u597d\u7684\u7279\u5f81\u80fd\u8ba9\u6a21\u578b\u66f4\u5bb9\u6613\u53d1\u73b0\u6570\u636e\u4e2d\u7684\u89c4\u5f8b\u3002<\/li>\n\n\n\n<li><strong>\u52a0\u901f\u6a21\u578b\u8bad\u7ec3<\/strong>\uff1a\u51cf\u5c11\u65e0\u5173\u6216\u5197\u4f59\u7279\u5f81\uff0c\u53ef\u4ee5\u964d\u4f4e\u8ba1\u7b97\u590d\u6742\u5ea6\u3002<\/li>\n\n\n\n<li><strong>\u589e\u5f3a\u6a21\u578b\u6cdb\u5316\u80fd\u529b<\/strong>\uff1a\u9632\u6b62\u6a21\u578b\u8fc7\u62df\u5408\u4e8e\u8bad\u7ec3\u6570\u636e\u4e2d\u7684\u566a\u58f0\u3002<\/li>\n\n\n\n<li><strong>\u9002\u5e94\u6a21\u578b\u9700\u6c42<\/strong>\uff1a\u4e0d\u540c\u7684\u6a21\u578b\u5bf9\u6570\u636e\u6709\u4e0d\u540c\u7684\u5047\u8bbe\uff08\u5982\u7ebf\u6027\u6a21\u578b\u5047\u8bbe\u7ebf\u6027\u5173\u7cfb\uff09\uff0c\u7279\u5f81\u5de5\u7a0b\u53ef\u4ee5\u4f7f\u6570\u636e\u6ee1\u8db3\u8fd9\u4e9b\u5047\u8bbe\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u4ee5\u4e0b\u6d41\u7a0b\u56fe\u6765\u76f4\u89c2\u7406\u89e3\u7279\u5f81\u5de5\u7a0b\u5728\u6574\u4e2a\u673a\u5668\u5b66\u4e60\u6d41\u7a0b\u4e2d\u7684\u4f4d\u7f6e\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"409\" height=\"1024\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-409x1024.png\" alt=\"\" class=\"wp-image-20082\" style=\"width:207px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-409x1024.png 409w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-120x300.png 120w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-230x575.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-350x876.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob-480x1201.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/ml-feature-engineering-runoob.png 510w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u7279\u5f81\u5de5\u7a0b\u7684\u6838\u5fc3\u64cd\u4f5c\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u7279\u5f81\u5de5\u7a0b\u4e3b\u8981\u5305\u542b\u4e09\u5927\u7c7b\u64cd\u4f5c\uff1a<strong>\u7279\u5f81\u5904\u7406<\/strong>\u3001<strong>\u7279\u5f81\u6784\u9020<\/strong>\u548c<strong>\u7279\u5f81\u9009\u62e9<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\ud83d\udd391. \u7279\u5f81\u5904\u7406<\/strong><\/p>\n\n\n\n<p>\u8fd9\u662f\u6700\u57fa\u7840\u7684\u4e00\u6b65\uff0c\u76ee\u7684\u662f\u5c06\u539f\u59cb\u6570\u636e&#8221;\u6e05\u6d17&#8221;\u6210\u5e72\u51c0\u3001\u89c4\u6574\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<ul>\n<li>a) \u5904\u7406\u7f3a\u5931\u503c<\/li>\n<\/ul>\n\n\n\n<p>\u6570\u636e\u4e2d\u7ecf\u5e38\u5b58\u5728\u7f3a\u5931\u503c\uff08\u5982&nbsp;<code>NaN<\/code>,&nbsp;<code>NULL<\/code>\uff09\uff0c\u9700\u8981\u5408\u7406\u5904\u7406\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u7406\u65b9\u6cd5<\/th><th>\u8bf4\u660e<\/th><th>\u9002\u7528\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td><strong>\u5220\u9664<\/strong><\/td><td>\u76f4\u63a5\u5220\u9664\u7f3a\u5931\u503c\u6240\u5728\u7684\u884c\u6216\u5217<\/td><td>\u7f3a\u5931\u6570\u636e\u6781\u5c11\uff0c\u6216\u8be5\u7279\u5f81\u4e0d\u91cd\u8981\u65f6<\/td><\/tr><tr><td><strong>\u586b\u5145<\/strong><\/td><td>\u7528\u67d0\u4e2a\u503c\u586b\u5145\uff0c\u5982\u5747\u503c\u3001\u4e2d\u4f4d\u6570\u3001\u4f17\u6570\u6216\u4e00\u4e2a\u7279\u6b8a\u503c\uff08\u5982 -1\uff09<\/td><td>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u60c5\u51b5<\/td><\/tr><tr><td><strong>\u63d2\u503c<\/strong><\/td><td>\u7528\u65f6\u95f4\u5e8f\u5217\u6216\u76f8\u90bb\u6570\u636e\u70b9\u8fdb\u884c\u63d2\u503c\u8ba1\u7b97<\/td><td>\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff08\u4f7f\u7528 Python \u7684 pandas \u5e93\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\nimport numpy as np\n\n# \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u7f3a\u5931\u503c\u7684\u793a\u4f8b DataFrame\ndata = {'\u5e74\u9f84': [25, np.nan, 30, 35, np.nan],\n        '\u5de5\u8d44': [50000, 54000, np.nan, 62000, 58000],\n        '\u57ce\u5e02': ['\u5317\u4eac', '\u4e0a\u6d77', '\u5e7f\u5dde', np.nan, '\u5317\u4eac']}\ndf = pd.DataFrame(data)\nprint(\"\u539f\u59cb\u6570\u636e\uff1a\")\nprint(df)\n\n# 1. \u5220\u9664\u7f3a\u5931\u503c\uff08\u5220\u9664\u4efb\u4f55\u5305\u542b NaN \u7684\u884c\uff09\ndf_dropped = df.dropna()\nprint(\"\\n\u5220\u9664\u7f3a\u5931\u503c\u540e\uff1a\")\nprint(df_dropped)\n\n# 2. \u586b\u5145\u7f3a\u5931\u503c\n# \u6570\u503c\u5217\u7528\u5747\u503c\u586b\u5145\ndf_filled = df.copy()\ndf_filled['\u5e74\u9f84'].fillna(df_filled['\u5e74\u9f84'].mean(), inplace=True)\ndf_filled['\u5de5\u8d44'].fillna(df_filled['\u5de5\u8d44'].mean(), inplace=True)\n# \u7c7b\u522b\u5217\u7528\u4f17\u6570\u586b\u5145\ndf_filled['\u57ce\u5e02'].fillna(df_filled['\u57ce\u5e02'].mode()[0], inplace=True)\nprint(\"\\n\u586b\u5145\u7f3a\u5931\u503c\u540e\uff1a\")\nprint(df_filled)<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"487\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56.png\" alt=\"\" class=\"wp-image-20083\" style=\"width:310px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56.png 488w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56-300x300.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56-150x150.png 150w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56-230x230.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56-350x349.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-56-480x479.png 480w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<ul>\n<li>b) \u5904\u7406\u5f02\u5e38\u503c<\/li>\n<\/ul>\n\n\n\n<p>\u5f02\u5e38\u503c\u662f\u4e0e\u5927\u90e8\u5206\u6570\u636e\u660e\u663e\u4e0d\u540c\u7684\u503c\uff0c\u53ef\u80fd\u4f1a\u5e72\u6270\u6a21\u578b\u3002\u5e38\u7528\u68c0\u6d4b\u65b9\u6cd5\u6709\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>\u6807\u51c6\u5dee\u6cd5<\/strong>\uff1a\u8ba4\u4e3a\u8d85\u51fa\u5747\u503c \u00b1 3\u500d\u6807\u51c6\u5dee\u8303\u56f4\u7684\u503c\u662f\u5f02\u5e38\u503c\u3002<\/li>\n\n\n\n<li><strong>\u7bb1\u7ebf\u56fe\u6cd5<\/strong>\uff1a\u8ba4\u4e3a\u5c0f\u4e8e\u00a0<code>Q1 - 1.5*IQR<\/code>\u00a0\u6216\u5927\u4e8e\u00a0<code>Q3 + 1.5*IQR<\/code>\u00a0\u7684\u503c\u662f\u5f02\u5e38\u503c\uff08<code>IQR = Q3 - Q1<\/code>\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5904\u7406\u65b9\u5f0f\u53ef\u4ee5\u662f\u5220\u9664\u3001\u66ff\u6362\u4e3a\u8fb9\u754c\u503c\u6216\u89c6\u4e3a\u7f3a\u5931\u503c\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<ul>\n<li>c) \u6570\u636e\u6807\u51c6\u5316\/\u5f52\u4e00\u5316<\/li>\n<\/ul>\n\n\n\n<p>\u8bb8\u591a\u6a21\u578b\uff08\u5982 SVM\u3001KNN\u3001\u795e\u7ecf\u7f51\u7edc\uff09\u5bf9\u7279\u5f81\u7684\u5c3a\u5ea6\u654f\u611f\u3002\u6211\u4eec\u9700\u8981\u5c06\u4e0d\u540c\u5c3a\u5ea6\u7684\u7279\u5f81\u8f6c\u6362\u5230\u540c\u4e00\u5c3a\u5ea6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><br>\u516c\u5f0f<\/th><th>\u8bf4\u660e<\/th><th>\u9002\u7528\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td><strong>\u6807\u51c6\u5316<\/strong><\/td><td><code>(x - \u5747\u503c) \/ \u6807\u51c6\u5dee<\/code><\/td><td>\u5904\u7406\u540e\u6570\u636e\u5747\u503c\u4e3a0\uff0c\u6807\u51c6\u5dee\u4e3a1<\/td><td>\u6570\u636e\u5206\u5e03\u8fd1\u4f3c\u6b63\u6001\u5206\u5e03\u65f6<\/td><\/tr><tr><td><strong>\u5f52\u4e00\u5316<\/strong><\/td><td><code>(x - min) \/ (max - min)<\/code><\/td><td>\u5c06\u6570\u636e\u7f29\u653e\u5230 [0, 1] \u533a\u95f4<\/td><td>\u6570\u636e\u8fb9\u754c\u660e\u786e\uff0c\u9700\u8981\u5feb\u901f\u8ba1\u7b97\u65f6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff08\u4f7f\u7528 scikit-learn \u5e93\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from sklearn.preprocessing import StandardScaler, MinMaxScaler\nimport numpy as np\n\n# \u793a\u4f8b\u6570\u636e\ndata = np.array([[1000, 25],\n                 [1500, 30],\n                 [800, 20],\n                 [1200, 28]])\n\n# \u6807\u51c6\u5316\nscaler_standard = StandardScaler()\ndata_standardized = scaler_standard.fit_transform(data)\nprint(\"\u6807\u51c6\u5316\u540e\u7684\u6570\u636e\uff08\u5747\u503c~0\uff0c \u6807\u51c6\u5dee~1\uff09\uff1a\")\nprint(data_standardized)\nprint(f\"\u5747\u503c\uff1a {data_standardized.mean(axis=0)}\")\nprint(f\"\u6807\u51c6\u5dee\uff1a {data_standardized.std(axis=0)}\")\n\n# \u5f52\u4e00\u5316\nscaler_minmax = MinMaxScaler()\ndata_normalized = scaler_minmax.fit_transform(data)\nprint(\"\\n\u5f52\u4e00\u5316\u540e\u7684\u6570\u636e\uff08\u8303\u56f4[0,1]\uff09\uff1a\")\nprint(data_normalized)<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"348\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-57.png\" alt=\"\" class=\"wp-image-20084\" style=\"width:288px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-57.png 422w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-57-300x247.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-57-230x190.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-57-350x289.png 350w\" sizes=\"(max-width: 422px) 100vw, 422px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\ud83d\udd392. \u7279\u5f81\u6784\u9020<\/strong><\/p>\n\n\n\n<p>\u901a\u8fc7\u7ec4\u5408\u6216\u8f6c\u6362\u73b0\u6709\u7279\u5f81\uff0c\u521b\u9020\u51fa\u65b0\u7684\u3001\u66f4\u5177\u9884\u6d4b\u529b\u7684\u7279\u5f81\u3002<\/p>\n\n\n\n<ul>\n<li>a) \u5bf9\u6570\u503c\u7279\u5f81\u8fdb\u884c\u53d8\u6362<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u591a\u9879\u5f0f\u7279\u5f81<\/strong>\uff1a\u521b\u5efa\u7279\u5f81\u7684\u5e73\u65b9\u3001\u7acb\u65b9\u7b49\uff0c\u5e2e\u52a9\u7ebf\u6027\u6a21\u578b\u5b66\u4e60\u975e\u7ebf\u6027\u5173\u7cfb\u3002<\/li>\n\n\n\n<li><strong>\u5206\u7bb1<\/strong>\uff1a\u5c06\u8fde\u7eed\u5e74\u9f84\u5206\u4e3a&#8221;\u9752\u5e74&#8221;\u3001&#8221;\u4e2d\u5e74&#8221;\u3001&#8221;\u8001\u5e74&#8221;\u7b49\u533a\u95f4\uff0c\u5c06\u8fde\u7eed\u6570\u636e\u79bb\u6563\u5316\u3002<\/li>\n\n\n\n<li><strong>\u6570\u5b66\u53d8\u6362<\/strong>\uff1a\u4f7f\u7528\u5bf9\u6570\u3001\u6307\u6570\u7b49\u53d8\u6362\u6539\u53d8\u6570\u636e\u5206\u5e03\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>b) \u5bf9\u7c7b\u522b\u7279\u5f81\u8fdb\u884c\u7f16\u7801<\/li>\n<\/ul>\n\n\n\n<p>\u673a\u5668\u5b66\u4e60\u6a21\u578b\u65e0\u6cd5\u76f4\u63a5\u5904\u7406&#8221;\u5317\u4eac&#8221;\u3001&#8221;\u4e0a\u6d77&#8221;\u8fd9\u6837\u7684\u6587\u672c\u3002\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u65b9\u6cd5<\/th><th>\u8bf4\u660e<\/th><th>\u7279\u70b9<\/th><\/tr><\/thead><tbody><tr><td><strong>\u6807\u7b7e\u7f16\u7801<\/strong><\/td><td>\u4e3a\u6bcf\u4e2a\u7c7b\u522b\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u6574\u6570\uff0c\u5982&nbsp;<code>\u5317\u4eac:0\uff0c \u4e0a\u6d77:1<\/code><\/td><td>\u7b80\u5355\uff0c\u4f46\u53ef\u80fd\u5f15\u5165\u9519\u8bef\u7684\u987a\u5e8f\u5173\u7cfb\uff08\u6a21\u578b\u53ef\u80fd\u8ba4\u4e3a 1&gt;0\uff09<\/td><\/tr><tr><td><strong>\u72ec\u70ed\u7f16\u7801<\/strong><\/td><td>\u4e3a\u6bcf\u4e2a\u7c7b\u522b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8c\u8fdb\u5236\u7279\u5f81\uff080\u62161\uff09<\/td><td>\u80fd\u6d88\u9664\u987a\u5e8f\u8bef\u89e3\uff0c\u4f46\u82e5\u7c7b\u522b\u5f88\u591a\uff0c\u4f1a\u5bfc\u81f4\u7279\u5f81\u7ef4\u5ea6\u7206\u70b8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\nfrom sklearn.preprocessing import LabelEncoder, OneHotEncoder\n\n# \u793a\u4f8b\u6570\u636e\ndf_cat = pd.DataFrame({'\u57ce\u5e02': ['\u5317\u4eac', '\u4e0a\u6d77', '\u5e7f\u5dde', '\u5317\u4eac', '\u6df1\u5733']})\n\n# \u6807\u7b7e\u7f16\u7801\nle = LabelEncoder()\ndf_cat['\u57ce\u5e02_\u6807\u7b7e\u7f16\u7801'] = le.fit_transform(df_cat['\u57ce\u5e02'])\nprint(\"\u6807\u7b7e\u7f16\u7801\u7ed3\u679c\uff1a\")\nprint(df_cat)\n\n# \u72ec\u70ed\u7f16\u7801\n# \u65b9\u6cd51: \u4f7f\u7528 pandas \u7684 get_dummies\ndf_onehot_pd = pd.get_dummies(df_cat['\u57ce\u5e02'], prefix='\u57ce\u5e02')\nprint(\"\\n\u4f7f\u7528 pandas \u8fdb\u884c\u72ec\u70ed\u7f16\u7801\uff1a\")\nprint(df_onehot_pd)\n\n# \u65b9\u6cd52: \u4f7f\u7528 sklearn \u7684 OneHotEncoder (\u66f4\u5e38\u7528\u4e8e\u7ba1\u9053)\nohe = OneHotEncoder(sparse_output=False) # sparse_output=False \u8fd4\u56de\u6570\u7ec4\u800c\u975e\u7a00\u758f\u77e9\u9635\nencoded_array = ohe.fit_transform(df_cat[['\u57ce\u5e02']]) # \u6ce8\u610f\u8f93\u5165\u662f\u4e8c\u7ef4\u7684\nprint(\"\\n\u4f7f\u7528 sklearn \u8fdb\u884c\u72ec\u70ed\u7f16\u7801\uff08\u6570\u7ec4\u5f62\u5f0f\uff09\uff1a\")\nprint(encoded_array)\nprint(\"\u65b0\u7279\u5f81\u540d\u79f0\uff1a\", ohe.get_feature_names_out())<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"665\" height=\"598\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58.png\" alt=\"\" class=\"wp-image-20085\" style=\"width:477px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58.png 665w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58-300x270.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58-230x207.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58-350x315.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-58-480x432.png 480w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\ud83d\udd393. \u7279\u5f81\u9009\u62e9<\/strong><\/p>\n\n\n\n<p>\u4ece\u6240\u6709\u7279\u5f81\u4e2d\u6311\u9009\u51fa\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u4ee5\u964d\u4f4e\u7ef4\u5ea6\u3001\u51cf\u5c11\u8fc7\u62df\u5408\u98ce\u9669\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u65b9\u6cd5<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><strong>\u8fc7\u6ee4\u6cd5<\/strong><\/td><td>\u6839\u636e\u7279\u5f81\u4e0e\u76ee\u6807\u53d8\u91cf\u7684\u7edf\u8ba1\u76f8\u5173\u6027\uff08\u5982\u65b9\u5dee\u3001\u5361\u65b9\u68c0\u9a8c\u3001\u4e92\u4fe1\u606f\uff09\u8fdb\u884c\u6392\u5e8f\u7b5b\u9009\u3002\u72ec\u7acb\u4e8e\u4efb\u4f55\u6a21\u578b\u3002<\/td><\/tr><tr><td><strong>\u5305\u88f9\u6cd5<\/strong><\/td><td>\u5c06\u7279\u5f81\u9009\u62e9\u770b\u4f5c\u4e00\u4e2a\u641c\u7d22\u95ee\u9898\uff0c\u4f7f\u7528\u6a21\u578b\u6027\u80fd\u4f5c\u4e3a\u8bc4\u4ef7\u6807\u51c6\uff08\u5982\u9012\u5f52\u7279\u5f81\u6d88\u9664 RFE\uff09\u3002\u6548\u679c\u8f83\u597d\uff0c\u4f46\u8ba1\u7b97\u6210\u672c\u9ad8\u3002<\/td><\/tr><tr><td><strong>\u5d4c\u5165\u6cd5<\/strong><\/td><td>\u5728\u6a21\u578b\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u81ea\u52a8\u8fdb\u884c\u7279\u5f81\u9009\u62e9\uff08\u5982 L1 \u6b63\u5219\u5316 LASSO \u56de\u5f52\u3001\u6811\u6a21\u578b\u7684\u7279\u5f81\u91cd\u8981\u6027\uff09\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff08\u57fa\u4e8e\u7279\u5f81\u91cd\u8981\u6027\u8fdb\u884c\u9009\u62e9\uff09\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from sklearn.datasets import load_breast_cancer\nfrom sklearn.ensemble import RandomForestClassifier\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\n# \u52a0\u8f7d\u6570\u636e\u96c6\ndata = load_breast_cancer()\nX = pd.DataFrame(data.data, columns=data.feature_names)\ny = data.target\n\n# \u8bad\u7ec3\u4e00\u4e2a\u968f\u673a\u68ee\u6797\u6a21\u578b\uff0c\u5b83\u4f1a\u8ba1\u7b97\u7279\u5f81\u91cd\u8981\u6027\nmodel = RandomForestClassifier(n_estimators=100, random_state=42)\nmodel.fit(X, y)\n\n# \u83b7\u53d6\u7279\u5f81\u91cd\u8981\u6027\nimportances = model.feature_importances_\nfeature_importance_df = pd.DataFrame({\n    '\u7279\u5f81': data.feature_names,\n    '\u91cd\u8981\u6027': importances\n}).sort_values('\u91cd\u8981\u6027', ascending=False)\n\nprint(\"\u7279\u5f81\u91cd\u8981\u6027\u6392\u5e8f\uff1a\")\nprint(feature_importance_df.head(10)) # \u67e5\u770b\u6700\u91cd\u8981\u768410\u4e2a\u7279\u5f81\n\n# \u53ef\u89c6\u5316\nplt.figure(figsize=(10, 6))\nplt.barh(feature_importance_df['\u7279\u5f81'][:10], feature_importance_df['\u91cd\u8981\u6027'][:10])\nplt.xlabel('\u7279\u5f81\u91cd\u8981\u6027')\nplt.title('Top 10 \u7279\u5f81\u91cd\u8981\u6027')\nplt.gca().invert_yaxis() # \u8ba9\u6700\u91cd\u8981\u7684\u5728\u9876\u90e8\nplt.show()\n\n# \u5047\u8bbe\u6211\u4eec\u9009\u62e9\u91cd\u8981\u6027\u5927\u4e8e0.03\u7684\u7279\u5f81\nselected_features = feature_importance_df[feature_importance_df['\u91cd\u8981\u6027'] > 0.03]['\u7279\u5f81'].tolist()\nprint(f\"\\n\u7b5b\u9009\u51fa\u7684\u7279\u5f81\uff1a {selected_features}\")<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"745\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-1024x745.png\" alt=\"\" class=\"wp-image-20087\" style=\"width:654px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-1024x745.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-300x218.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-768x559.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-1536x1118.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-830x604.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-550x400.png 550w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-230x167.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-350x255.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60-480x349.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2026\/01\/image-60.png 1676w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u603b\u7ed3\ud83d\udd16<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u7279\u5f81\u5de5\u7a0b\u662f\u673a\u5668\u5b66\u4e60\u4e2d\u4e00\u95e8\u7ed3\u5408\u4e86<strong>\u827a\u672f<\/strong>\uff08\u9886\u57df\u77e5\u8bc6\u3001\u7ecf\u9a8c\u3001\u76f4\u89c9\uff09\u4e0e<strong>\u79d1\u5b66<\/strong>\uff08\u7edf\u8ba1\u65b9\u6cd5\u3001\u7b97\u6cd5\uff09\u7684\u6280\u827a\u3002\u5b83\u6ca1\u6709\u4e00\u6210\u4e0d\u53d8\u7684\u89c4\u5219\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u6570\u636e\u3001\u95ee\u9898\u548c\u6a21\u578b\u53cd\u590d\u5c1d\u8bd5\u548c\u8fed\u4ee3\u3002\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u638c\u63e1\u672c\u6587\u4ecb\u7ecd\u7684\u57fa\u7840\u65b9\u6cd5\u5e76\u52e4\u52a0\u7ec3\u4e60\uff0c\u4f60\u5c31\u5df2\u7ecf\u4e3a\u6784\u5efa\u6709\u6548\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u6253\u4e0b\u4e86\u6700\u575a\u5b9e\u7684\u4e00\u5757\u57fa\u77f3\u3002\u8bb0\u4f4f\uff0c<strong>\u4f18\u79c0\u7684\u6a21\u578b\u5f80\u5f80\u6e90\u4e8e\u4f18\u79c0\u7684\u7279\u5f81<\/strong>\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/www.runoob.com\/ml\/ml-data-cleaning.html\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\u200b\ud83d\udd16 \u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u662f\u4e00\u4f4d\u53a8\u5e08\uff0c\u8981\u505a\u4e00\u9053\u7f8e\u5473\u7684\u83dc\u80b4\uff0c\u673a\u5668\u5b66\u4e60\u6a21\u578b\u5c31\u50cf\u4f60\u7684&#8221;\u70f9\u996a\u7b97\u6cd5&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20081"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20081"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20081\/revisions"}],"predecessor-version":[{"id":20088,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/20081\/revisions\/20088"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}