{"id":3656,"date":"2022-03-30T10:31:26","date_gmt":"2022-03-30T19:01:26","guid":{"rendered":"http:\/\/10ccc.cc\/?p=3656"},"modified":"2026-01-02T20:36:59","modified_gmt":"2026-01-02T12:36:59","slug":"%e3%80%90flag%e3%80%91%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0100%e5%a4%a9-%e7%ac%ac1%e5%a4%a9-%e6%95%b0%e6%8d%ae%e6%b8%85%e6%b4%97","status":"publish","type":"post","link":"https:\/\/10ccc.cc\/?p=3656","title":{"rendered":"\u3010Flag\u3011\u673a\u5668\u5b66\u4e60100\u5929-[\u7b2c1\u5929]-\u6570\u636e\u6e05\u6d17"},"content":{"rendered":"<p>\u7b2c\u4e00\u5929\uff1a\u4e00\u5207\u5c31\u7eea<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3655 size-full\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318.jpg\" alt=\"\" width=\"1920\" height=\"1057\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318.jpg 1920w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318-300x165.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318-1024x564.jpg 1024w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318-768x423.jpg 768w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-012318-1536x846.jpg 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<h2>\u6570\u636e\u9884\u5904\u7406\u7684\u57fa\u672c\u6b65\u9aa4<\/h2>\n<p>\u6839\u636e day_1 \u7684<a href=\"https:\/\/github.com\/Avik-Jain\/100-Days-Of-ML-Code\/blob\/master\/Code\/Day%201_Data%20PreProcessing.md\" target=\"_blank\"  rel=\"nofollow\" >\u539f\u6587<\/a>\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u6570\u636e\u9884\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u6570\u636e\u5904\u7406\u76f8\u5173\u5e93<\/strong>\uff1a\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u5e93\u662f numpy \u4ee5\u53ca pandas \u3002\u5176\u4ed6\u7684\u5e93\u53ef\u4ee5\u6839\u636e\u9700\u8981\u518d\u8fdb\u884c\u5bfc\u5165\uff1b<\/li>\n<li><strong>\u5bfc\u5165\u6570\u636e\u96c6<\/strong>\uff1a\u6570\u636e\u96c6\u4e00\u822c\u662f.csv\u6216.xlsx\u683c\u5f0f\u7684\u6587\u4ef6(\u5982\u679c\u4e0d\u662f\u8fd9\u7c7b\u578b\u7684\u6bd4\u5982sql\u7b49\uff0c\u5219\u53ef\u4e8b\u5148\u8f6c\u4e3a\u6b63\u786e\u7684\u683c\u5f0f)\u3002\u8fd9\u79cd\u6587\u4ef6\u6700\u5927\u7684\u6bcf\u4e00\u884c\u90fd\u662f\u4e00\u6761\u6570\u636e\u8bb0\u5f55\u3002\u5bfc\u5165\u6570\u636e\u96c6\u6211\u4eec\u4e00\u822c\u4f7f\u7528pandas\u7684read_csv()\u65b9\u6cd5\uff0c\u8bfb\u53d6\u540e\uff0c\u5c06\u5176\u8f6c\u4e3a\u4e00\u4e2a\u6570\u636e\u5e27\u3002\u4e4b\u540e\u6211\u4eec\u53ef\u4ee5\u518d\u6839\u636e\u5177\u4f53\u7684\u4e1a\u52a1\u9009\u53d6\u81ea\u53d8\u91cf\u77e9\u9635\u53ca\u56e0\u53d8\u91cf\u5411\u91cf\uff1b<\/li>\n<li><strong>\u5904\u7406\u4e22\u5931\u6570\u636e<\/strong>\uff1a\u5982\u9047\u5230\u6570\u636e\u96c6\u4e0d\u5b8c\u6574\u7684\u60c5\u51b5\uff0c\u4e3a\u4e0d\u5f71\u54cd\u6a21\u578b\u7684\u6027\u80fd\uff0c\u6216\u7eaf\u7cb9\u4e3a\u4e86\u6a21\u578b\u80fd\u591f\u8dd1\u8d77\u6765\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u6570\u636e\u4e2d\u7684\u7a7a\u503c(\u6216\u5176\u4ed6\u7c7b\u578b\u7684\u975e\u6570\u503c)\uff0c\u5e76\u7528\u6574\u5217\u7684\u5747\u503c\u3001\u4e2d\u503c\u3001\u4f17\u6570\u6216\u7279\u5b9a\u7684\u5e38\u6570\u8fdb\u884c\u5904\u7406\u3002\u5b8c\u6210\u8fd9\u4e00\u6b65\u9aa4\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 sklearn.impute \u4e2d\u5bfc\u5165SimpleImputer \u65b9\u6cd5\u6765\u8fdb\u884c\u5904\u7406\uff1b<\/li>\n<li><strong>\u89e3\u6790\u5206\u7c7b\u6570\u636e(Encoding categorical data)\uff1a\u5206\u7c7b\u6570\u636e\u6307\u7684\u662f\u8fd8\u6709\u6807\u7b7e\u503c\u800c\u4e0d\u662f\u6570\u5b57\u7684\u53d8\u91cf(\u5982\u5b9a\u5e8f\u3001\u5b9a\u7c7b\u4ee5\u53ca\u5b9a\u8ddd\u53d8\u91cf\u7b49\uff0c\u6216\u5176\u4ed6\u7684\u975e\u6570\u5b57\u6807\u7b7e)\u3002\u8fd9\u7c7b\u578b\u7684\u6570\u636e\u901a\u5e38\u662f\u56fa\u5b9a\u7684\uff0c\u5982\u539f\u59cb\u6570\u636e\u4e2d\u7684 purchased \u5411\u91cf\u4e2d\u7684 YES \u548c NO\u3002\u4f46\u8fd9\u4e9b\u6807\u7b7e\u662f\u65e0\u6cd5\u8fdb\u884c\u6570\u5b66\u8ba1\u7b97\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u8981\u6839\u636e\u4e00\u5b9a\u7684\u89c4\u5219\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u5b57\u3002\u901a\u5e38\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 sklearn.preprocessing \u5e93\u4e2d\u7684 LabelEncoder \u7c7b \u6765\u5b8c\u6210\u8fd9\u4e00\u6b65\u9aa4\u7684\u5904\u7406\uff1b<\/strong><\/li>\n<li><strong>\u5c06\u6570\u636e\u96c6\u62c6\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong>\uff1a\u5176\u4e2d\u8bad\u7ec3\u96c6\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\u3002\u8bad\u7ec3\u597d\u540e\uff0c\u518d\u7528\u6d4b\u8bd5\u96c6\u6765\u9a8c\u8bc1\u6a21\u578b\u9884\u6d4b\u7684\u7ed3\u679c\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u8fd9\u4e24\u8005\u7684\u6570\u636e\u91cf\u6bd4\u4e3a ----&gt; \u8bad\u7ec3\u96c6:\u6d4b\u8bd5\u96c6 = 80:20 \u3002\u800c\u62c6\u5206\u6570\u636e\u96c6\u53ef\u4ee5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 sklearn.crossvalidation \u4e2d\u7684tran_test_split()\u65b9\u6cd5\u5b9e\u73b0\u3002<\/li>\n<li><strong>\u7279\u5f81\u7f29\u653e(Feature Scaling)<\/strong>\uff1a\u5927\u90e8\u5206\u6a21\u578b\u7b97\u6cd5\u5728\u8ba1\u7b97\u4e24\u70b9\u95f4\u7684\u8ddd\u79bb\u65f6\u4e00\u822c\u7528\u6b27\u5f0f\u8ddd\u79bb\u3002\u4f46\u6b64\u7279\u7279\u5f81\u5728\u5e45\u5ea6\u3001\u5355\u4f4d\u4ee5\u53ca\u8303\u56f4\u4e0a\u53d8\u5316\u5f88\u5927\u3002\u5728\u8ddd\u79bb\u8ba1\u7b97\u65f6\uff0c\u9ad8\u5e45\u5ea6\u7684\u7279\u5f81\u6bd4\u4f4e\u5e45\u5ea6\u7684\u7279\u5f81\u6743\u91cd\u66f4\u5927\u3002\u4e3a\u6b64\uff0c\u53ef\u4f7f\u7528\u7279\u5f81\u6807\u51c6\u6216Z\u503c<a href=\"https:\/\/www.jianshu.com\/p\/95a8f035c86c\" target=\"_blank\"  rel=\"nofollow\" >\u5f52\u4e00\u5316<\/a>\u5c06\u6240\u6709\u6570\u636e\u6620\u5c04\u5230[0\uff0c1] \u6216 [-1, 1]\u533a\u95f4\u5185\uff0c\u907f\u514d\"\u8ddd\u79bb\"\u6570\u91cf\u7ea7\u5dee\u8ddd\u8fc7\u5927\u7684\u5f71\u54cd\u3002(\u53c2\u8003:<a href=\"https:\/\/blog.csdn.net\/quiet_girl\/article\/details\/72517053\" target=\"_blank\"  rel=\"nofollow\" >\u8fd9\u91cc<\/a>)<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>\u521b\u5efa\u9879\u76ee\u76ee\u5f55<\/h2>\n<p>\u8fdb\u5165 Jupiter Notebook \u540e\uff0c\u6211\u4eec\u9700\u8981\u505a\u7684\u7b2c\u4e00\u4ef6\u4e8b\u5c31\u662f\u5728\u81ea\u5df1\u559c\u6b22\u7684\u4f4d\u7f6e\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u4f5c\u4e3a\u6211\u4eec\u9879\u76ee\u7684\u5de5\u4f5c\u76ee\u5f55\u3002\u540e\u7eed\u4e2d\uff0c\u6211\u4eec\u7684\u4ee3\u7801\u3001\u6570\u636e\u96c6\u90fd\u5c06\u653e\u7f6e\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e2d\u3002\u4e00\u4e2a\u6574\u6d01\u3001\u6e05\u6670\u7684\u9879\u76ee\u9879\u76ee\u6587\u4ef6\u7ed3\u6784\uff0c\u53ef\u4ee5\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u63d0\u9ad8\u6211\u4eec\u7684\u6548\u7387\u5e76\u4e14\u51cf\u5c11\u72af\u9519\u7684\u51e0\u7387\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728\u8fd9\u6b21\u9879\u76ee\u4e2d\uff0c\u9879\u76ee\u7684\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3660\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-022409.jpg\" alt=\"\" width=\"862\" height=\"529\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-022409.jpg 862w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-022409-300x184.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-022409-768x471.jpg 768w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/p>\n<p>\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u6709\u5176\u4ed6\u7684\u6587\u4ef6\u5f52\u7eb3\u65b9\u5f0f\u3002\u4e4b\u6240\u4ee5\u8fd9\u4e48\u5f52\u7eb3\u7684\u539f\u56e0\u5728\u4e8e\uff0c\u5982\u7b2c0\u5929\u4e2d\u6240\u8bf4\uff0c100-Days-Of-ML-Code \u8fd9\u4e2a\u9879\u76ee\u6bcf\u5929\u7684\u5185\u5bb9\u5dee\u5f02\u5de8\u5927\uff0c\u4e14\u6240\u7528\u5230\u6570\u636e\u96c6\u4e5f\u5927\u76f8\u5f84\u5ead\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0c\u6211\u5e0c\u671b\u53ef\u4ee5\u8fbe\u5230\uff0c\u6253\u5f00\u67d0\u5929\u7684\u7b14\u8bb0\uff0c\u5373\u53ef\u5c06\u76f8\u5173\u5185\u5bb9\u5c3d\u6536\u773c\u5e95\uff0c\u6ca1\u6709\u9057\u6f0f\u3002\u5f53\u7136\uff0c\u4e5f\u4e0d\u9700\u8981\u5728\u81ea\u5df1\u60f3\u8981\u67e5\u770b\u6570\u636e\u7684\u539f\u59cb\u6587\u4ef6\u65f6\uff0c\u5728\u65e0\u6570\u7684\u6587\u4ef6\u5939\u4e2d\u5207\u6362\u67e5\u770b\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u6837\u7684\u601d\u7ef4\u65b9\u5f0f\u5728\u9879\u76ee\u4e2d\u7684\u5177\u4f53\u4f53\u73b0\u53ef\u4ee5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<figure id=\"attachment_3658\" aria-describedby=\"caption-attachment-3658\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3658 size-medium\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-021925-300x102.jpg\" alt=\"\u6574\u4f53\u7ed3\u6784\" width=\"300\" height=\"102\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-021925-300x102.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-021925-768x261.jpg 768w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-021925.jpg 909w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-3658\" class=\"wp-caption-text\">\u6574\u4f53\u7ed3\u6784<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_3661\" aria-describedby=\"caption-attachment-3661\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3661 size-medium\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-023524-300x98.jpg\" alt=\"day_1\u6587\u4ef6\u76ee\u5f55\" width=\"300\" height=\"98\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-023524-300x98.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-023524-768x252.jpg 768w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-023524.jpg 832w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-3661\" class=\"wp-caption-text\">day_1\u6587\u4ef6\u76ee\u5f55<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u8fdb\u5165\u5230 day_1 \u6587\u4ef6\u5939\uff0c\u8fdb\u5165 day_1.ipynb \u6587\u4ef6\uff0c\u5373\u53ef\u5f00\u59cb\u7f16\u5199day_1\u7684\u76f8\u5173\u4ee3\u7801\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u67e5\u770b\u539f\u59cb\u6570\u636e<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3662 size-full\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-165928.jpg\" alt=\"\u539f\u59cb\u6570\u636e\" width=\"512\" height=\"360\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-165928.jpg 512w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-165928-300x211.jpg 300w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u662f\u4e00\u7ec4\u6bd4\u8f83\u7b80\u5355\u7684\u6570\u636e\u3002\u8fd9\u7ec4\u6570\u7ec4\u4e2d\u5305\u542b country(\u56fd\u7c4d)\u3001age(\u5e74\u9f84)\u3001salary(\u6536\u5165)\u3001 purchased(\u662f\u5426\u8d2d\u4e70)\u51e0\u4e2a\u7ef4\u5ea6\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5176\u4e2d\u7684Age \u4ee5\u53ca Salary \u8fd9\u4e24\u5217\u4e2d\u5b58\u5728\u7a7a\u503c\u3002\u4f46\u4e0d\u7528\u62c5\u5fc3\uff0c\u8fd9\u70b9\u6211\u4eec\u5728\u6570\u636e\u9884\u5904\u7406\/\u6570\u636e\u6e05\u6d17\u9636\u6bb5\u4f1a\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u731c\u6d4b\uff1a<\/p>\n<blockquote><p>\u4f3c\u4e4e\u5c1d\u8bd5\u901a\u8fc7\u56fd\u7c4d\u3001\u5e74\u9f84\u3001\u4ee5\u53ca\u6536\u5165\u7b49\u51e0\u4e2a\u81ea\u53d8\u91cf\u53d8\u91cf\u53bb\u9884\u6d4b\u8d2d\u4e70\u7ed3\u679c\u7684\u56e0\u53d8\u91cf<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>\u5f00\u59cb\u7f16\u7801<\/h2>\n<h3><strong>\u5bfc\u5165\u5e93\u548c\u6570\u636e\u96c6<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<pre class=\"dm-pre-admin-side\">import numpy as np\r\nimport pandas as pd\r\n\r\ndataset = pd.read_csv('Data.csv')\r\nX = dataset.iloc[ : , :-1].values\r\nY = dataset.iloc[ : , 3].values<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>&nbsp;<\/p>\n<h3><strong>\u5904\u7406\u4e22\u5931\u6570\u636e<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<pre class=\"dm-pre-admin-side\">from sklearn.impute import SimpleImputer as Imputer\r\n\r\nimputer = Imputer(missing_values = np.NAN, strategy = \"mean\")\r\nimputer = imputer.fit(X[ : , 1:3])\r\nX[ : , 1:3] = imputer.transform(X[ : , 1:3])<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>\u6ce8\u610f\uff0c\u6b64\u5904\u4e0d\u80fd\u6309\u7167github\u4e0a\u7684\u6e90\u4ee3\u7801\u8fdb\u884c\u5904\u7406\uff0c\u56e0\u4e3a\u65b0\u7248\u7684sklearn\u5df2\u7ecf\u6ca1\u6709imputer\u51fd\u6570\u3002\u9700\u6309\u7167\u672c\u6587\u4e2d\u7684\u65b9\u6cd5\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<figure id=\"attachment_3664\" aria-describedby=\"caption-attachment-3664\" style=\"width: 554px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3664 size-full\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200521.jpg\" alt=\"\u6570\u636e\u7a7a\u503c\u5904\u7406\u524d\" width=\"554\" height=\"183\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200521.jpg 554w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200521-300x99.jpg 300w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><figcaption id=\"caption-attachment-3664\" class=\"wp-caption-text\">\u6570\u636e\u7a7a\u503c\u5904\u7406\u524d<\/figcaption><\/figure>\n<figure id=\"attachment_3665\" aria-describedby=\"caption-attachment-3665\" style=\"width: 328px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3665 size-full\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200548.jpg\" alt=\"\u6570\u636e\u7a7a\u503c\u5904\u7406\" width=\"328\" height=\"188\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200548.jpg 328w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200548-300x172.jpg 300w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><figcaption id=\"caption-attachment-3665\" class=\"wp-caption-text\">\u6570\u636e\u7a7a\u503c\u5904\u7406\u540e<\/figcaption><\/figure>\n<p>\u4f7f\u7528 SimpleImuter \u65b9\u6cd5\u5904\u7406\u7a7a\u503c\u65f6\uff0c\u6211\u4eec\u6ce8\u610fstategy\u53c2\u6570\uff0c\u6b64\u5904\u6211\u4eec\u9009\u62e9\u201cmean\u201d\u5373\u5747\u503c\uff0c\u610f\u601d\u4e3a<span style=\"color: #ffff00;\" data-darkreader-inline-color=\"\">\u5c06\u8be5\u5217\u6240\u6709\u7684\u7a7a\u503c\u66ff\u6362\u4e3a\u8be5\u5217\u6240\u6709\u975e\u7a7a\u503c\u7684\u5747\u503c\u3002<\/span><span style=\"--darkreader-inline-color: #fefe79;\">\u53c2\u6570<\/span><span style=\"--darkreader-inline-color: #fefe79;\">\u5176\u4ed6\u53ef\u9009\u7684\u503c\u4e3a\uff1a<\/span><\/p>\n<blockquote><p>The imputation strategy.<br \/>\nIf \u201cmean\u201d, then replace missing values using the mean along the axis. \u4f7f\u7528\u5e73\u5747\u503c\u4ee3\u66ff<\/p>\n<p>If \u201cmedian\u201d, then replace missing values using the median along the axis.\u4f7f\u7528\u4e2d\u503c\u4ee3\u66ff<\/p>\n<p>If \u201cmost_frequent\u201d, then replace missing using the most frequent value along the axis.\u4f7f\u7528\u4f17\u6570\u4ee3\u66ff\uff0c\u4e5f\u5c31\u662f\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u6570<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u9a8c\u8bc1\u4e00\u4e0bage\u5217\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3666\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200851.jpg\" alt=\"\" width=\"663\" height=\"402\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200851.jpg 663w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220331-200851-300x182.jpg 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/p>\n<p>\u624b\u52a8\u8ba1\u7b97\u503c\u4e0e SimpleImputer \u7ed9\u51fa\u7684\u7ed3\u679c\u4e00\u81f4\uff08\u6ce8\u610f\u8be5\u5217\u975e\u7a7a\u503c\u67099\u4e2a\u6240\u4ee5\u9664\u6570\u4e3a9\uff09\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u53e6\u5916\uff0cImputer\u548cSimpleImputer\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u7684\u533a\u522b\u4e3a\uff1a<\/p>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<p>SI = SimpleImputer(missing_values=np.NAN, strategy=\u2019mean\u2019)<\/p>\n<p>I = Imputer(missing_values=\u2019NaN\u2019, strategy=\u2019mean\u2019, axis=0, verbose=0, copy=True)<\/p>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>\u5176\u4e2d\u6700\u5927\u7684\u533a\u522b\u4e3a SimpleImputer\u6ca1\u6709axis\u53c2\u6570\uff0c\u9ed8\u8ba4\u4e3a\u6309\u5217\u5904\u7406\u3002\u8fd9\u4e5f\u8981\u6c42\u6211\u4eec\u5728\u641c\u96c6\u5904\u7406\u6570\u636e\u96c6\u65f6\uff0c\u9700\u8981\u4e25\u683c\u6309\u7167\u6807\u51c6\u3002<\/p>\n<p>&nbsp;<\/p>\n<div class=\"mceTemp\"><\/div>\n<h3><strong>\u89e3\u6790\u5206\u7c7b\u6570\u636e<\/strong><\/h3>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<p>from sklearn.preprocessing import LabelEncoder, OneHotEncoder<br \/>\nlabelencoder_X = LabelEncoder()<br \/>\nX[ : , 0] = labelencoder_X.fit_transform(X[ : , 0])<\/p>\n<p>print(X[ : , 0])<\/p>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<blockquote><p>\u8fd0\u884c\u7ed3\u679c\u4e3a\uff1a[0 2 1 2 1 0 2 0 1 0]<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u505a\u4e86\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u770b\u4e00\u4e0b\u4e0b\u56fe\u3002\u8fd9\u6bb5\u4ee3\u7801\u5c06\u6570\u636e\u96c6\u4e2d\u7684 country \u4e00\u5217\u6570\u636e\u7531\u6587\u5b57\u8f6c\u4e3a\u4e86\u6570\u5b57\u3002\u6709\u610f\u601d\u7684\u662f\uff0cX[ : , 0]\u5177\u6709\u4e0einnerHTML\u7c7b\u4f3c\u7684\u529f\u80fd\uff1a\u65e2\u80fd\u53d6\u503c\uff0c\u4e5f\u53ef\u8d4b\u503c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3667 size-large\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/page_1-1024x236.png\" alt=\"\" width=\"1024\" height=\"236\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/page_1-1024x236.png 1024w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/page_1-300x69.png 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/page_1-768x177.png 768w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/page_1.png 1223w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>\u521b\u5efa\u54d1\u53d8\u91cf<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3687\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001241.jpg\" alt=\"\" width=\"891\" height=\"735\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001241.jpg 891w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001241-300x247.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001241-768x634.jpg 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/p>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<p>onehotencoder = OneHotEncoder(categorical_features = [0])<br \/>\nX = onehotencoder.fit_transform(X).toarray()<br \/>\nlabelencoder_Y = LabelEncoder()<br \/>\nY = labelencoder_Y.fit_transform(Y)<br \/>\nprint(\"\u53d8\u91cfX\", X)<br \/>\nprint(\"\u53d8\u91cfY\",Y)<\/p>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>&nbsp;<\/p>\n<h3>\u62c6\u5206\u6570\u636e\u96c6\u4e3a\u8bad\u7ec3\u96c6\u5408\u548c\u6d4b\u8bd5\u96c6\u5408<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3688\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001323.jpg\" alt=\"\" width=\"921\" height=\"414\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001323.jpg 921w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001323-300x135.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001323-768x345.jpg 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/p>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>X_train, X_test, Y_train, Y_test = train_test_split( X , Y , test_size = 0.2, random_state = 0)<\/p>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>\u6ce8\u610f\uff0c\u539f\u6587\u4e2d\u7684<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">sklearn<\/span>.<span class=\"pl-s1\">cross_validation<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">train_test_split \u5df2\u5931\u6548\uff0c\u9700\u66ff\u6362\u4e3a\u4e0a\u6587\u4ee3\u7801\u4e2d\u7684\u8bed\u53e5\u3002 <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>\u7279\u5f81\u7f29\u653e<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3689\" src=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001331.jpg\" alt=\"\" width=\"902\" height=\"279\" srcset=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001331.jpg 902w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001331-300x93.jpg 300w, https:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Jietu20220403-001331-768x238.jpg 768w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/p>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<p>from sklearn.preprocessing import StandardScaler<\/p>\n<p>sc_X = StandardScaler()<br \/>\nX_train = sc_X.fit_transform(X_train)<br \/>\nX_test = sc_X.fit_transform(X_test)<br \/>\nprint(X_train, X_test)<\/p>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<h2>\u76f8\u5173\u77e5\u8bc6\u8865\u5145<\/h2>\n<p>\u81f3\u4e8efit_transform()\u76f8\u5173\u7684<\/p>\n<ol>\n<li>\u8fdb\u884c\u5f52\u4e00\u5316\u64cd\u4f5c\u7684\u539f\u56e0\uff0c\u4ee5\u53ca\u5e38\u7528\u7684\u5f52\u4e00\u5316\u65b9\u6cd5\u53ef\u53c2\u8003<a href=\"http:\/\/10ccc.cc\/?page_id=3682\" target=\"_blank\"  rel=\"nofollow\" >\u672c\u6587<\/a><\/li>\n<li>fit(), fit_transform(), transform()\u5728\u4e0d\u540c\u65b9\u6cd5\u4e0b\u7684\u5f02\u540c\u53ef\u53c2\u8003<a href=\"https:\/\/cloud.tencent.com\/developer\/article\/1770568\" target=\"_blank\"  rel=\"nofollow\" >\u672c\u6587<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2>\u7b14\u8bb0\u4e0b\u8f7d<\/h2>\n<p>&nbsp;<\/p>\n<a class=\"download\" href=\"<a href=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/Data.csv\" target=\"_blank\"  rel=\"nofollow\" >Data<\/a>, <a href=\"http:\/\/10ccc.cc\/wp-content\/uploads\/2022\/03\/day_1.ipynb.zip\" target=\"_blank\"  rel=\"nofollow\" >day_1.ipynb<\/a>\" rel=\"external\"\r\ntarget=\"_blank\" title=\"\u4e0b\u8f7d\u5730\u5740\">\r\n<span><i class=\"fa-solid fa-download\"><\/i>Download<\/span><\/a>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u5929\uff1a\u4e00\u5207\u5c31\u7eea \u6570\u636e\u9884\u5904\u7406\u7684\u57fa\u672c\u6b65\u9aa4 \u6839\u636e day_1 \u7684\u539f\u6587\uff0c\u6211\u4eec\u53ef\u4ee5\u603b\u7ed3\u51fa\u6570\u636e\u9884\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\uff1a \u5bfc\u5165\u6570\u636e\u5904\u7406\u76f8\u5173\u5e93\uff1a\u5176\u4e2d\u6700 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[82],"tags":[105,107,106],"class_list":["post-3656","post","type-post","status-publish","format-standard","hentry","category-82","tag-105","tag-107","tag-106"],"_links":{"self":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/3656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3656"}],"version-history":[{"count":3,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/3656\/revisions"}],"predecessor-version":[{"id":4519,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/3656\/revisions\/4519"}],"wp:attachment":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}