{"id":3187,"date":"2022-02-27T13:05:43","date_gmt":"2022-02-27T05:05:43","guid":{"rendered":"https:\/\/egonlin.com\/?p=3187"},"modified":"2022-02-27T13:05:43","modified_gmt":"2022-02-27T05:05:43","slug":"%e7%ac%ac%e4%b8%80%e8%8a%82%ef%bc%9a%e7%89%b9%e5%be%81%e9%a2%84%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=3187","title":{"rendered":"\u7b2c\u4e00\u8282\uff1a\u7279\u5f81\u9884\u5904\u7406"},"content":{"rendered":"<h1>\u7279\u5f81\u9884\u5904\u7406<\/h1>\n<p>&emsp;&emsp;\u4e4b\u524d\u8bf4\u5230\u6784\u5efa\u673a\u5668\u5b66\u4e60\u7cfb\u7edf\u7684\u6b65\u9aa4\u4e2d\u7684\u7b2c\u4e8c\u6b65\u8bf4\u5230\u9700\u8981\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u8bf4\u5982\u4f55\u5bf9\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\uff0c\u8fd9\u4e00\u7ae0\u5c06\u4f1a\u5c55\u5f00\u6765\u8bf4\u8bf4\u5c06\u6765\u5efa\u6a21\u65f6\u4f1a\u78b0\u5230\u7684\u5404\u79cd\u810f\u6570\u636e\u7684\u5f62\u5f0f\uff0c\u4ee5\u53ca\u5bf9\u8fd9\u79cd\u5f62\u5f0f\u6570\u636e\u7684\u5904\u7406\u65b9\u5f0f\uff0c\u800c\u5bf9\u6570\u636e\u5904\u7406\u5373\u5bf9\u6570\u636e\u7684\u7279\u5f81\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<h1>\u7279\u5f81\u9884\u5904\u7406\u5b66\u4e60\u76ee\u6807<\/h1>\n<ol>\n<li>\u7f3a\u5931\u503c\u5904\u7406<\/li>\n<li>\u79bb\u7fa4\u503c\u5904\u7406<\/li>\n<li>\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/li>\n<li>\u5f52\u4e00\u5316\u6570\u636e<\/li>\n<li>\u4e8c\u503c\u5316\u6570\u636e<\/li>\n<\/ol>\n<h1>\u7279\u5f81\u9884\u5904\u7406\u8be6\u89e3<\/h1>\n<h2>\u7f3a\u5931\u503c\u5904\u7406<\/h2>\n<p>&emsp;&emsp;\u73b0\u5b9e\u751f\u6d3b\u4e2d\u7684\u6570\u636e\u5f80\u5f80\u662f\u4e0d\u5168\u9762\u7684\uff0c\u5f88\u591a\u6837\u672c\u7684\u5c5e\u6027\u503c\u4f1a\u6709\u7f3a\u5931\uff0c\u4f8b\u5982\u67d0\u4e2a\u4eba\u586b\u5199\u7684\u4e2a\u4eba\u4fe1\u606f\u4e0d\u5b8c\u6574\u6216\u8005\u5bf9\u4e2a\u4eba\u9690\u79c1\u7684\u4fdd\u62a4\u653f\u7b56\u5bfc\u81f4\u5efa\u6a21\u65f6\u53ef\u80fd\u65e0\u6cd5\u5f97\u5230\u6240\u9700\u8981\u7684\u7279\u5f81\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u91cf\u8f83\u5927\u65f6\uff0c\u8fd9\u79cd\u7f3a\u5931\u503c\u7684\u4ea7\u751f\u4f1a\u5bf9\u6a21\u578b\u7684\u6027\u80fd\u9020\u6210\u5f88\u5927\u7684\u5f71\u54cd\u3002\u63a5\u4e0b\u6765\u5c06\u901a\u8fc7\u9e22\u5c3e\u82b1\u6570\u636e\u8ba8\u8bba\u7f3a\u5931\u503c\u5904\u7406\u7684\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"language-python\"># \u7f3a\u5931\u503c\u5904\u7406\u793a\u4f8b\nimport pandas as pd\nfrom io import StringIO\n\niris_data = &#039;&#039;&#039;\n5.1,,1.4,0.2,Iris-setosa\n4.9,3.0,1.4,0.2,Iris-setosa\n4.7,3.2,,0.2,Iris-setosa\n7.0,3.2,4.7,1.4,Iris-versicolor\n6.4,3.2,4.5,1.5,Iris-versicolor\n6.9,3.1,4.9,,Iris-versicolor\n,,,,Iris-setosa\n&#039;&#039;&#039;\n\ndf = pd.read_csv(StringIO(iris_data), header=None)\n# \u5f3a\u8c03\uff1a\u4e4b\u540e\u7684\u4ee3\u7801\u53ea\u4e3a\u65b9\u4fbf\u4e2d\u6587\u9605\u8bfb\u4e60\u60ef\u7684\u8bfb\u8005\u770b\u8d77\u6765\u65b9\u4fbf\uff0c\u81ea\u5df1\u5199\u4ee3\u7801\u7279\u8bc1\u5c5e\u6027\u540d\u5c3d\u91cf\u4e0d\u8981\u7528\u4e2d\u6587\uff0c\u4e0d\u65b9\u4fbf\u53d8\u91cf\u540d\u7684\u521b\u5efa\ndf.columns = [&#039;\u82b1\u843c\u957f\u5ea6&#039;, &#039;\u82b1\u843c\u5bbd\u5ea6&#039;, &#039;\u82b1\u74e3\u957f\u5ea6&#039;, &#039;\u82b1\u74e3\u5bbd\u5ea6&#039;, &#039;class_label&#039;]\ndf = df.iloc[:, :4]\ndf<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>5.1<\/td>\n<td>NaN<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>4.9<\/td>\n<td>3.0<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4.7<\/td>\n<td>3.2<\/td>\n<td>NaN<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>7.0<\/td>\n<td>3.2<\/td>\n<td>4.7<\/td>\n<td>1.4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6.4<\/td>\n<td>3.2<\/td>\n<td>4.5<\/td>\n<td>1.5<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6.9<\/td>\n<td>3.1<\/td>\n<td>4.9<\/td>\n<td>NaN<\/td>\n<\/tr>\n<tr>\n<th>6<\/th>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&emsp;&emsp;\u901a\u8fc7\u7ed9\u5b9a\u7684\u9e22\u5c3e\u82b1\u6570\u636e\uff0c\u4f7f\u7528StringIO\u628a\u5b57\u7b26\u4e32\u7f13\u5b58\u6210\u4e3a\u6587\u672c\uff0c\u4e4b\u540e\u628a\u8be5\u6570\u636e\u8bfb\u5165pandas\u3002\u4ecepandas\u6253\u5370\u7684\u7ed3\u679c\u53ef\u4ee5\u660e\u663e\u7684\u770b\u5230\u7ed9\u51fa\u7684\u6570\u636e\u4e2d\u67093\u4e2aNAN\u5373\u7f3a\u5931\u503c\u3002\u7531\u4e8e\u6570\u636e\u5c11\uff0c\u5f88\u5bb9\u6613\u770b\u51fa\u6709\u51e0\u4e2a\u7f3a\u5931\u503c\u5e76\u4e14\u53ef\u4ee5\u624b\u52a8\u6539\u53d8\uff0c\u4f46\u662f\u5de5\u4e1a\u4e0a\u6570\u636e\u91cf\u662f\u975e\u5e38\u5e9e\u5927\u7684\uff0c\u8fd9\u4e2a\u65f6\u5019\u53ef\u4ee5\u8c03\u7528pandas\u7684isnull()\u3002isnull()\u65b9\u6cd5\u628a\u6570\u636e\u96c6\u4e2d\u5b58\u5728\u7684\u503c\u770b\u4f5cTrue\uff0c\u7f3a\u5931\u503c\u770b\u4f5cFalse\u3002<\/p>\n<pre><code class=\"language-python\">df.isnull()<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>False<\/td>\n<td>True<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>False<\/td>\n<td>False<\/td>\n<td>True<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>False<\/td>\n<td>False<\/td>\n<td>False<\/td>\n<td>True<\/td>\n<\/tr>\n<tr>\n<th>6<\/th>\n<td>True<\/td>\n<td>True<\/td>\n<td>True<\/td>\n<td>True<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u901a\u8fc7\u5728isnull()\u65b9\u6cd5\u540e\u4f7f\u7528sum()\u65b9\u6cd5\u5373\u53ef\u83b7\u5f97\u8be5\u6570\u636e\u96c6\u67d0\u4e2a\u7279\u5f81\u542b\u6709\u591a\u5c11\u4e2a\u7f3a\u5931\u503c\u3002<\/p>\n<pre><code class=\"language-python\">df.isnull().sum()<\/code><\/pre>\n<pre><code>\u82b1\u843c\u957f\u5ea6    1\n\u82b1\u843c\u5bbd\u5ea6    2\n\u82b1\u74e3\u957f\u5ea6    2\n\u82b1\u74e3\u5bbd\u5ea6    2\ndtype: int64<\/code><\/pre>\n<h3>\u5220\u9664\u7f3a\u5931\u503c<\/h3>\n<p>&emsp;&emsp;\u5904\u7406\u7f3a\u5931\u503c\u6700\u7b80\u5355\u4e5f\u662f\u6700\u66b4\u529b\u7684\u65b9\u6cd5\u4fbf\u662f\u5220\u9664\u542b\u6709\u7f3a\u5931\u503c\u7684\u6837\u672c\u6216\u8005\u7279\u5f81(\u6ce8\uff1a\u5de5\u4e1a\u4e0a\u6570\u636e\u975e\u5e38\u91cd\u8981\uff0c\u4e00\u822c\u4e0d\u63a8\u8350\u8fd9\u6837\u505a)\uff0c\u53ef\u4ee5\u4f7f\u7528dropna()\u65b9\u6cd5\u5e76\u901a\u8fc7\u5b83\u7684\u53c2\u6570axis\u9009\u62e9\u5220\u9664\u6837\u672c\u8fd8\u662f\u7279\u5f81\uff0c\u5982\u679c<code>axis=1<\/code>\u5373\u5220\u9664\u7279\u5f81\uff1b\u5982\u679c<code>axis=0<\/code>\u5373\u5220\u9664\u884c\uff0c<code>how=&#039;all&#039;<\/code>\u5220\u9664\u6240\u6709\u7279\u5f81\u5168\u4e3a\u7f3a\u5931\u503c\u7684\u6837\u672c\uff0c<code>thresh=4<\/code>\u5220\u9664\u7279\u5f81\u503c\u6570\u5c0f\u4e8e4\u7684\u6837\u672c\uff0c<code>subset=[&#039;\u82b1\u74e3\u5bbd\u5ea6&#039;]<\/code>\u5220\u9664\u82b1\u74e3\u5bbd\u5ea6\u7279\u5f81\u4e2d\u6709\u7f3a\u5931\u503c\u7684\u6837\u672c\u3002<\/p>\n<pre><code class=\"language-python\"># axis=0\u5220\u9664\u6709NaN\u503c\u7684\u884c\ndf.dropna(axis=0)<\/code><\/pre>\n<p>\u63d2\u56fe\uff1a\u6076\u641e\u56fe21<\/p>\n<p>[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u5931\u8d25,\u6e90\u7ad9\u53ef\u80fd\u6709\u9632\u76d7\u94fe\u673a\u5236,\u5efa\u8bae\u5c06\u56fe\u7247\u4fdd\u5b58\u4e0b\u6765\u76f4\u63a5\u4e0a\u4f20(img-ZNuX5C5C-1583198904234)(\u914d\u56fe\/\u6076\u641e\u56fe\/\u6076\u641e\u56fe21.png)]<\/p>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>1<\/th>\n<td>4.9<\/td>\n<td>3.0<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>7.0<\/td>\n<td>3.2<\/td>\n<td>4.7<\/td>\n<td>1.4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6.4<\/td>\n<td>3.2<\/td>\n<td>4.5<\/td>\n<td>1.5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code class=\"language-python\"># axis=1\u5220\u9664\u6709NaN\u503c\u7684\u5217\ndf.dropna(axis=1)<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<\/tr>\n<tr>\n<th>1<\/th>\n<\/tr>\n<tr>\n<th>2<\/th>\n<\/tr>\n<tr>\n<th>3<\/th>\n<\/tr>\n<tr>\n<th>4<\/th>\n<\/tr>\n<tr>\n<th>5<\/th>\n<\/tr>\n<tr>\n<th>6<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code class=\"language-python\"># \u5220\u9664\u5168\u4e3aNaN\u503c\u5f97\u884c\u6216\u5217\ndf.dropna(how=&#039;all&#039;)<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>5.1<\/td>\n<td>NaN<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>4.9<\/td>\n<td>3.0<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4.7<\/td>\n<td>3.2<\/td>\n<td>NaN<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>7.0<\/td>\n<td>3.2<\/td>\n<td>4.7<\/td>\n<td>1.4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6.4<\/td>\n<td>3.2<\/td>\n<td>4.5<\/td>\n<td>1.5<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6.9<\/td>\n<td>3.1<\/td>\n<td>4.9<\/td>\n<td>NaN<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code class=\"language-python\"># \u5220\u9664\u884c\u4e0d\u4e3a4\u4e2a\u503c\u7684\ndf.dropna(thresh=4)<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>1<\/th>\n<td>4.9<\/td>\n<td>3.0<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>7.0<\/td>\n<td>3.2<\/td>\n<td>4.7<\/td>\n<td>1.4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6.4<\/td>\n<td>3.2<\/td>\n<td>4.5<\/td>\n<td>1.5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code class=\"language-python\"># \u5220\u9664\u82b1\u843c\u5bbd\u5ea6\u4e2d\u6709NaN\u503c\u7684\u6570\u636e\ndf.dropna(subset=[&#039;\u82b1\u843c\u5bbd\u5ea6&#039;])<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u82b1\u843c\u957f\u5ea6<\/th>\n<th>\u82b1\u843c\u5bbd\u5ea6<\/th>\n<th>\u82b1\u74e3\u957f\u5ea6<\/th>\n<th>\u82b1\u74e3\u5bbd\u5ea6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>1<\/th>\n<td>4.9<\/td>\n<td>3.0<\/td>\n<td>1.4<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4.7<\/td>\n<td>3.2<\/td>\n<td>NaN<\/td>\n<td>0.2<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>7.0<\/td>\n<td>3.2<\/td>\n<td>4.7<\/td>\n<td>1.4<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6.4<\/td>\n<td>3.2<\/td>\n<td>4.5<\/td>\n<td>1.5<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6.9<\/td>\n<td>3.1<\/td>\n<td>4.9<\/td>\n<td>NaN<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3>\u586b\u5145\u7f3a\u5931\u503c<\/h3>\n<p>&emsp;&emsp;\u7531\u4e8e\u5de5\u4e1a\u4e0a\u7684\u6570\u636e\u6765\u4e4b\u4e0d\u6613\u662f\u5f88\u91cd\u8981\u7684\uff0c\u6240\u4ee5\u5bf9\u7f3a\u5931\u503c\u7684\u5904\u7406\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u586b\u5145\u7f3a\u5931\u503c\u3002\u586b\u5145\u7f3a\u5931\u503c\u53ef\u4ee5\u4f7f\u7528\u4e2d\u4f4d\u6570\u3001\u4f17\u6570\u3001\u5e73\u5747\u6570\u4e0e\u81ea\u5b9a\u4e49\u56fa\u5b9a\u503c\uff0c\u5177\u4f53\u7528\u54ea\u4e00\u79cd\u6ca1\u6709\u786c\u6027\u7684\u8981\u6c42\uff0c\u5177\u4f53\u95ee\u9898\u5177\u4f53\u5206\u6790\u3002\u672c\u8282\u5c06\u901a\u8fc7scikit-learn\u7684Imputer\u7ed9\u51fa\u586b\u5145\u5e73\u5747\u503c\u7684\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"language-python\"># \u586b\u5145\u7f3a\u5931\u503c\u793a\u4f8b\nfrom sklearn.impute import SimpleImputer\nimport numpy as np\n\n# \u5bf9\u6240\u6709\u7f3a\u5931\u503c\u586b\u5145\u56fa\u5b9a\u503c0\n# imputer = SimpleImputer(missing_values=np.nan, strategy=&#039;constant&#039;, fill_value=0)\n\n# \u4e2d\u4f4d\u6570strategy=median\uff0c\u4f17\u6570strategy=most_frequent\nimputer = SimpleImputer(missing_values=np.nan, strategy=&#039;mean&#039;)\nimputer = imputer.fit(df.values)\nimputed_data = imputer.transform(df.values)\nimputed_data<\/code><\/pre>\n<pre><code>array([[5.1       , 3.14      , 1.4       , 0.2       ],\n       [4.9       , 3.        , 1.4       , 0.2       ],\n       [4.7       , 3.2       , 3.38      , 0.2       ],\n       [7.        , 3.2       , 4.7       , 1.4       ],\n       [6.4       , 3.2       , 4.5       , 1.5       ],\n       [6.9       , 3.1       , 4.9       , 0.7       ],\n       [5.83333333, 3.14      , 3.38      , 0.7       ]])<\/code><\/pre>\n<h2>\u79bb\u7fa4\u503c\u5904\u7406<\/h2>\n<p>&emsp;&emsp;\u79bb\u7fa4\u503c\u53c8\u79f0\u4e3a\u5f02\u5e38\u503c\uff0c\u5373\u4e0d\u5408\u7406\u7684\u503c\u3002\u5047\u8bbe\u67d0\u4e2a\u6570\u636e\u96c6\u6709x1\u4e0ex2\u4e24\u4e2a\u7279\u5f81\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<pre><code class=\"language-python\"># \u79bb\u7fa4\u503c\u5904\u7406\u793a\u4f8b\nimport random\nimport matplotlib.pyplot as plt\nfrom matplotlib.font_manager import FontProperties\n\n%matplotlib inline\nfont = FontProperties(fname=&#039;\/Library\/Fonts\/Heiti.ttc&#039;)\n\nx1 = [i for i in range(6)]\nx2 = x1\n\nplt.scatter(x1, x2, color=&#039;b&#039;, label=&#039;\u6b63\u5e38\u503c&#039;)\nplt.scatter(x1, [i+random.random() for i in x1.copy()] , color=&#039;b&#039;)\nplt.scatter(1.5, 8, color=&#039;r&#039;, label=&#039;\u79bb\u7fa4\u503c&#039;)\nplt.xlabel(&#039;x1&#039;)\nplt.ylabel(&#039;x2&#039;)\nplt.legend(prop=font)\n# plt.savefig(&#039;img\/\u79bb\u7fa4\u503c.png&#039;, dpi=300)\nplt.show()<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/05-01-\u7279\u5f81\u9884\u5904\u7406_24_0.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/05-01-\u7279\u5f81\u9884\u5904\u7406_24_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h3>\u83b7\u53d6\u79bb\u7fa4\u503c<\/h3>\n<ol>\n<li>\n<p>\u7edf\u8ba1\u5206\u6790<br \/>\n&emsp;&emsp;\u5bf9\u7279\u5f81\u503c\u7edf\u8ba1\u540e\u5206\u6790\u5224\u65ad\u54ea\u4e9b\u503c\u662f\u4e0d\u7b26\u5408\u903b\u8f91\u7684\uff0c\u62ff\u5e74\u9f84\u4e3e\u4f8b\uff0c\u5982\u679c\u53d1\u73b0\u67d0\u4e2a\u4eba\u7684\u5e74\u9f84\u662f200\uff0c\u81f3\u5c11\u76ee\u524d\u662f\u4e0d\u5408\u7406\u7684\uff0c\u56e0\u6b64\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u6761\u4ef6\uff0c\u628a\u5e74\u9f84\u5927\u4e8e200\u7684\u6570\u636e\u90fd\u6392\u9664\u6389\u3002<\/p>\n<\/li>\n<li>\n<p>\u6982\u7387\u5206\u5e03\u539f\u5219<br \/>\n&emsp;&emsp;\u6839\u636e\u9ad8\u65af\u5206\u5e03\u53ef\u77e5\u8ddd\u79bb\u5e73\u5747\u503c$3\\delta$\u4e4b\u5916\u7684\u6982\u7387\u4e3a0.003\uff0c\u8fd9\u5728\u7edf\u8ba1\u5b66\u4e2d\u5c5e\u4e8e\u6781\u5c0f\u6982\u7387\u4e8b\u4ef6\uff0c\u56e0\u6b64\u53ef\u4ee5\u628a\u8d85\u8fc7\u8be5\u8ddd\u79bb\u7684\u503c\u5f53\u4f5c\u5f02\u5e38\u503c\u5904\u7406\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u624b\u52a8\u8bbe\u5b9a\u8fd9\u4e2a\u8ddd\u79bb\u6216\u6982\u7387\uff0c\u5177\u4f53\u95ee\u9898\u5177\u4f53\u5206\u6790\u3002<\/p>\n<\/li>\n<\/ol>\n<h3>\u79bb\u7fa4\u503c\u5904\u7406<\/h3>\n<p>&emsp;&emsp;\u5f80\u5f80\u53ef\u4ee5\u7528\u4e0a\u8ff0\u4e24\u79cd\u65b9\u6cd5\u83b7\u53d6\u79bb\u7fa4\u503c\uff0c\u83b7\u53d6\u79bb\u7fa4\u503c\u4e4b\u540e\u7684\u5904\u7406\u65b9\u5f0f\u5982\u540c\u7f3a\u5931\u503c\u4e00\u6837\uff0c\u53ef\u4ee5\u628a\u79bb\u7fa4\u503c\u8bbe\u7f6e\u4e3a\u7a7a\u503cNaN\uff0c\u7136\u540e\u4f7f\u7528\u4e0e\u5904\u7406\u7f3a\u5931\u503c\u540c\u6837\u7684\u65b9\u6cd5\u5904\u7406\u79bb\u7fa4\u503c\uff0c\u6b64\u5904\u4e0d\u591a\u5728\u8d58\u8ff0\u3002<\/p>\n<h2>\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h2>\n<p>&emsp;&emsp;\u73b0\u6709\u4e00\u4e2a\u6c7d\u8f66\u6837\u672c\u96c6\uff0c\u901a\u8fc7\u8fd9\u4e2a\u6c7d\u8f66\u6837\u672c\u96c6\u53ef\u4ee5\u5224\u65ad\u4eba\u4eec\u662f\u5426\u4f1a\u8d2d\u4e70\u8be5\u6c7d\u8f66\u3002\u4f46\u662f\u8fd9\u4e2a\u6837\u672c\u96c6\u7684\u7279\u5f81\u503c\u662f\u79bb\u6563\u578b\u7684\uff0c\u4e3a\u4e86\u786e\u4fdd\u8ba1\u7b97\u673a\u80fd\u6b63\u786e\u8bfb\u53d6\u8be5\u79bb\u6563\u503c\u7684\u7279\u5f81\uff0c\u9700\u8981\u7ed9\u8fd9\u4e9b\u7279\u5f81\u505a\u7f16\u7801\u5904\u7406\uff0c\u5373\u521b\u5efa\u4e00\u4e2a\u6620\u5c04\u8868\u3002\u5982\u679c\u7279\u5f81\u503c\u5206\u7c7b\u8f83\u5c11\uff0c\u53ef\u4ee5\u9009\u62e9\u81ea\u5b9a\u4e49\u4e00\u4e2a\u5b57\u5178\u5b58\u653e\u7279\u5f81\u503c\u4e0e\u81ea\u5b9a\u4e49\u503c\u7684\u5173\u7cfb\u3002<\/p>\n<pre><code class=\"language-python\">car_data=&#039;&#039;&#039;\n\u4e58\u5750\u4eba\u6570,\u540e\u5907\u7bb1\u5927\u5c0f,\u5b89\u5168\u6027,\u662f\u5426\u53ef\u4ee5\u63a5\u53d7\n4,med,high,acc\n2,big,low,unacc\n4,big,med,acc\n4,big,high,acc\n6,small,low,unacc\n6,small,med,unacc\n&#039;&#039;&#039;\n\ndf = pd.read_csv(StringIO(car_data), header=0)\ndf<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u4e58\u5750\u4eba\u6570<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f<\/th>\n<th>\u5b89\u5168\u6027<\/th>\n<th>\u662f\u5426\u53ef\u4ee5\u63a5\u53d7<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>4<\/td>\n<td>med<\/td>\n<td>high<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>big<\/td>\n<td>low<\/td>\n<td>unacc<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4<\/td>\n<td>big<\/td>\n<td>med<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>big<\/td>\n<td>high<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6<\/td>\n<td>small<\/td>\n<td>low<\/td>\n<td>unacc<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6<\/td>\n<td>small<\/td>\n<td>med<\/td>\n<td>unacc<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3>\u81ea\u5b9a\u4e49\u6570\u636e\u7c7b\u578b\u7f16\u7801<\/h3>\n<p>&emsp;&emsp;\u6b64\u5904\u53ea\u62ff\u6c7d\u8f66\u5b89\u5168\u6027(safety)\u4e3e\u4f8b\u3002<\/p>\n<pre><code class=\"language-python\">safety_mapping = {\n    &#039;low&#039;:0,\n    &#039;med&#039;:1,\n    &#039;high&#039;:2,\n}\n\ndf[&#039;\u5b89\u5168\u6027&#039;] = df[&#039;\u5b89\u5168\u6027&#039;].map(safety_mapping)\ndf<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u4e58\u5750\u4eba\u6570<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f<\/th>\n<th>\u5b89\u5168\u6027<\/th>\n<th>\u662f\u5426\u53ef\u4ee5\u63a5\u53d7<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>4<\/td>\n<td>med<\/td>\n<td>2<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>big<\/td>\n<td>0<\/td>\n<td>unacc<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4<\/td>\n<td>big<\/td>\n<td>1<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>big<\/td>\n<td>2<\/td>\n<td>acc<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6<\/td>\n<td>small<\/td>\n<td>0<\/td>\n<td>unacc<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6<\/td>\n<td>small<\/td>\n<td>1<\/td>\n<td>unacc<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u5bf9\u4e0a\u8ff0\u5b57\u5178\u505a\u53cd\u5411\u6620\u5c04\u5904\u7406\uff0c\u5373\u53ef\u53cd\u5411\u6620\u5c04\u56de\u539f\u6765\u7684\u79bb\u6563\u7c7b\u578b\u7684\u7279\u5f81\u503c\u3002<\/p>\n<pre><code class=\"language-python\">inverse_safety_mapping = {v: k for k, v in safety_mapping.items()}\ndf[&#039;\u5b89\u5168\u6027&#039;].map(inverse_safety_mapping)<\/code><\/pre>\n<pre><code>0    high\n1     low\n2     med\n3    high\n4     low\n5     med\nName: \u5b89\u5168\u6027, dtype: object<\/code><\/pre>\n<h3>scikit-learn\u6570\u636e\u7c7b\u578b\u7f16\u7801<\/h3>\n<p>&emsp;&emsp;\u76ee\u524dLabelEncoder\u652f\u6301\u5bf9\u4e00\u7ef4\u6570\u7ec4\u8fdb\u884c\u7f16\u7801\uff0c\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u6620\u5c04\u7684\u5199\u6cd5\u81ea\u5b9a\u4e49\u5c01\u88c5fit\u548ctransform\u65b9\u6cd5\u5199\u4e00\u4e2a\u5bf9\u591a\u4e2a\u7279\u5f81\u7f16\u7801\u7684LabelEncoder\u3002\u6b64\u5904\u53ea\u5bf9\u540e\u5907\u7bb1\u5927\u5c0f\u5c5e\u6027\u548c\u662f\u5426\u53ef\u4ee5\u63a5\u53d7\u6807\u7b7e\u4fe1\u606f\u505a\u7f16\u7801\u5904\u7406\u3002<\/p>\n<pre><code class=\"language-python\"># scikit-learn\u6570\u636e\u7c7b\u578b\u7f16\u7801\u793a\u4f8b\nfrom sklearn.preprocessing import LabelEncoder\n\nX_label_encoder = LabelEncoder()\nX = df[[&#039;\u4e58\u5750\u4eba\u6570&#039;, &#039;\u540e\u5907\u7bb1\u5927\u5c0f&#039;, &#039;\u5b89\u5168\u6027&#039;]].values\nX[:, 1] = X_label_encoder.fit_transform(X[:, 1])\n\nX<\/code><\/pre>\n<pre><code>array([[4, 1, 2],\n       [2, 0, 0],\n       [4, 0, 1],\n       [4, 0, 2],\n       [6, 2, 0],\n       [6, 2, 1]], dtype=object)<\/code><\/pre>\n<pre><code class=\"language-python\">y_label_encoder = LabelEncoder()\ny = y_label_encoder.fit_transform(df[&#039;\u662f\u5426\u53ef\u4ee5\u63a5\u53d7&#039;].values)\ny<\/code><\/pre>\n<pre><code>array([0, 1, 0, 0, 1, 1])<\/code><\/pre>\n<p>\u4e0e\u5b57\u5178\u6620\u5c04\u540c\u7406\uff0c\u53ef\u4ee5\u4f7f\u7528inverse_transform()\u65b9\u6cd5\u5bf9\u6570\u636e\u505a\u53cd\u5411\u6620\u5c04\u5904\u7406\u3002<\/p>\n<pre><code class=\"language-python\">y_label_encoder.inverse_transform(y)<\/code><\/pre>\n<pre><code>array(['acc', 'unacc', 'acc', 'acc', 'unacc', 'unacc'], dtype=object)<\/code><\/pre>\n<h3>\u72ec\u70ed\u7f16\u7801<\/h3>\n<p>&emsp;&emsp;\u5047\u8bbe\u6c7d\u8f66\u5b89\u5168\u6027\u53ea\u662f\u4e00\u4e2a\u8861\u91cf\u6807\u51c6\uff0c\u6ca1\u6709\u7279\u5b9a\u7684\u987a\u5e8f\u3002\u4f46\u662f\u8ba1\u7b97\u673a\u5f88\u6709\u53ef\u80fd\u628a\u8fd9\u4e9b$0,1,2$\u4f5c\u4e00\u4e2a\u7279\u5b9a\u6392\u5e8f\u6216\u8005\u56e0\u6b64\u533a\u5206\u5b83\u4eec\u7684\u91cd\u8981\u6027\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u5f97\u8003\u8651\u521b\u5efa\u4e00\u4e2a\u4e8c\u8fdb\u5236\u503c\u5206\u522b\u8868\u793alow\u3001med\u3001high\u8fd9\u4e09\u4e2a\u5c5e\u6027\u503c\uff0c\u6709\u4e3a1\uff0c\u6ca1\u6709\u4e3a0\uff0c\u4f8b\u5982$010$\u8868\u793a\u4e3amed\u3002<\/p>\n<p>scikit-learn\u4e2d\u7684OneHotEncoder\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u79cd\u7f16\u7801\u5904\u7406\u3002<\/p>\n<pre><code class=\"language-python\"># \u72ec\u70ed\u7f16\u7801\u793a\u4f8b\nfrom sklearn.preprocessing import OneHotEncoder\n\none_hot_encoder = OneHotEncoder(categories=&#039;auto&#039;)\none_hot_encoder.fit_transform(X).toarray()<\/code><\/pre>\n<pre><code>array([[0., 1., 0., 0., 1., 0., 0., 0., 1.],\n       [1., 0., 0., 1., 0., 0., 1., 0., 0.],\n       [0., 1., 0., 1., 0., 0., 0., 1., 0.],\n       [0., 1., 0., 1., 0., 0., 0., 0., 1.],\n       [0., 0., 1., 0., 0., 1., 1., 0., 0.],\n       [0., 0., 1., 0., 0., 1., 0., 1., 0.]])<\/code><\/pre>\n<p>\u4f7f\u7528categories\u5bf9\u5355\u4e2a\u5c5e\u6027\u8fdb\u884c\u72ec\u70ed\u7f16\u7801\u3002<\/p>\n<pre><code class=\"language-python\">one_hot_encoder = OneHotEncoder(categories=[[&#039;med&#039;,&#039;big&#039;,&#039;small&#039;]])\n# \u53ef\u5728OneHotEncoder\u7c7b\u4e2d\u52a0\u5165sparseFale\u53c2\u6570\u7b49\u540c\u4e8etoarray()\u65b9\u6cd5\none_hot_encoder.fit_transform(df[[&#039;\u540e\u5907\u7bb1\u5927\u5c0f&#039;]]).toarray()<\/code><\/pre>\n<pre><code>array([[1., 0., 0.],\n       [0., 1., 0.],\n       [0., 1., 0.],\n       [0., 1., 0.],\n       [0., 0., 1.],\n       [0., 0., 1.]])<\/code><\/pre>\n<p>\u4f7f\u7528pandas\u5bf9\u5b57\u7b26\u4e32\u5c5e\u6027\u72ec\u70ed\u7f16\u7801\uff0c\u5982\u679c\u5c5e\u6027\u503c\u4e3a\u6570\u503c\u578b\u5219\u4e0d\u8fdb\u884c\u72ec\u70ed\u7f16\u7801\u3002<\/p>\n<pre><code class=\"language-python\">pd.get_dummies(df[[&#039;\u4e58\u5750\u4eba\u6570&#039;, &#039;\u540e\u5907\u7bb1\u5927\u5c0f&#039;, &#039;\u5b89\u5168\u6027&#039;]])<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u4e58\u5750\u4eba\u6570<\/th>\n<th>\u5b89\u5168\u6027<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f_big<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f_med<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f_small<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>4<\/td>\n<td>2<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&emsp;&emsp;\u4f7f\u7528\u72ec\u70ed\u7f16\u7801\u5728\u89e3\u51b3\u7279\u5f81\u503c\u65e0\u5e8f\u6027\u7684\u540c\u65f6\u4e5f\u589e\u52a0\u4e86\u7279\u5f81\u6570\uff0c\u8fd9\u65e0\u7591\u4f1a\u7ed9\u672a\u6765\u7684\u8ba1\u7b97\u589e\u52a0\u96be\u5ea6\uff0c\u56e0\u6b64\u53ef\u4ee5\u9002\u5f53\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u7ef4\u5ea6\u3002\u4f8b\u5982\u5f53\u4e3a\u540e\u5907\u7bb1\u8fdb\u884c\u72ec\u70ed\u7f16\u7801\u7684\u65f6\u5019\u4f1a\u6709\u540e\u5907\u7bb1\u5927\u5c0f_big\u3001\u540e\u5907\u7bb1\u5927\u5c0f_med\u3001\u540e\u5907\u7bb1\u5927\u5c0f_small\u4e09\u4e2a\u7279\u5f81\uff0c\u53ef\u4ee5\u51cf\u53bb\u4e00\u4e2a\u7279\u5f81\uff0c\u5373\u540e\u5907\u7bb1\u5927\u5c0f_big\u4e0e\u540e\u5907\u7bb1\u5927\u5c0f_med\u90fd\u4e3a0\u5219\u4ee3\u8868\u662f\u540e\u5907\u7bb1\u5927\u5c0f_small\u3002\u5728\u8c03\u7528pandas\u7684get_dummies\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0drop_first=True\u53c2\u6570\uff1b\u800c\u4f7f\u7528OneHotEncoder\u65f6\u5f97\u81ea\u5df1\u5206\u9694\u3002<\/p>\n<pre><code class=\"language-python\">pd.get_dummies(df[[&#039;\u4e58\u5750\u4eba\u6570&#039;, &#039;\u540e\u5907\u7bb1\u5927\u5c0f&#039;, &#039;\u5b89\u5168\u6027&#039;]],drop_first=True)<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>\u4e58\u5750\u4eba\u6570<\/th>\n<th>\u5b89\u5168\u6027<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f_med<\/th>\n<th>\u540e\u5907\u7bb1\u5927\u5c0f_small<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>4<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>4<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>2<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>6<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<th>5<\/th>\n<td>6<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<pre><code class=\"language-python\">one_hot_encoder = OneHotEncoder(categories=[[&#039;med&#039;,&#039;big&#039;,&#039;small&#039;]])\none_hot_encoder.fit_transform(df[[&#039;\u540e\u5907\u7bb1\u5927\u5c0f&#039;]]).toarray()[:, 1:]<\/code><\/pre>\n<pre><code>array([[0., 0.],\n       [1., 0.],\n       [1., 0.],\n       [1., 0.],\n       [0., 1.],\n       [0., 1.]])<\/code><\/pre>\n<h2>\u5f52\u4e00\u5316\u6570\u636e<\/h2>\n<p>&emsp;&emsp;\u4e0d\u540c\u5c3a\u5ea6\u7279\u5f81\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3\uff0c\u623f\u4ef7\u53ef\u80fd\u548c\u623f\u5b50\u9762\u79ef\u4e0e\u623f\u95f4\u6570\u6709\u5173\u5e76\u4e14\u5047\u8bbe\u4e24\u4e2a\u7279\u5f81\u5177\u6709\u76f8\u540c\u7684\u6743\u91cd\uff0c\u4f46\u662f\u73b0\u5982\u4eca\u7531\u4e8e\u623f\u5b50\u9762\u79ef\u548c\u623f\u95f4\u6570\u7684\u5ea6\u91cf\u5355\u4f4d\u662f\u4e0d\u540c\u7684\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u623f\u5b50\u9762\u79ef\u7684\u6570\u503c\u5f80\u5f80\u662f\u8fdc\u5927\u4e8e\u623f\u95f4\u6570\u6570\u503c\u7684\uff0c\u90a3\u4e48\u79f0\u623f\u5b50\u9762\u79ef\u548c\u623f\u95f4\u6570\u662f\u4e0d\u540c\u5c3a\u5ea6\u7684\u3002\u5982\u679c\u5bf9\u8fd9\u4e24\u4e2a\u7279\u5f81\u505a\u5904\u7406\uff0c\u5f88\u6709\u53ef\u80fd\u623f\u5b50\u9762\u79ef\u7684\u5f71\u54cd\u4f1a\u63a9\u76d6\u4f4f\u623f\u95f4\u6570\u5bf9\u623f\u4ef7\u9020\u6210\u7684\u5f71\u54cd\u3002<\/p>\n<h3>\u6700\u5c0f-\u6700\u5927\u6807\u51c6\u5316<\/h3>\n<p>&emsp;&emsp;\u4e3a\u4e86\u89e3\u51b3\u76f8\u540c\u6743\u91cd\u7279\u5f81\u4e0d\u540c\u5c3a\u5ea6\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u6700\u5c0f-\u6700\u5927\u6807\u51c6\u5316\u505a\u5904\u7406\uff0c\u628a\u4ed6\u4eec\u4e24\u4e2a\u503c\u538b\u7f29\u5728$[0-1]$\u533a\u95f4\u5185\u3002<\/p>\n<p>\u6700\u5c0f-\u6700\u5927\u6807\u51c6\u5316\u516c\u5f0f\uff1a<br \/>\n$$<br \/>\nx<em>{norm}^{(i)}={\\frac{x^{(i)}-x<\/em>{min}}{x<em>{max}-x<\/em>{min}}}<br \/>\n$$<br \/>\n\u5176\u4e2d$i=1,2,\\cdots,m$\uff1b$m$\u4e3a\u6837\u672c\u4e2a\u6570\uff1b$x<em>{min},x<\/em>{max}$\u5206\u522b\u662f\u67d0\u4e2a\u7684\u7279\u5f81\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002<\/p>\n<pre><code class=\"language-python\"># \u6700\u5c0f\u6700\u5927\u6807\u51c6\u5316\u793a\u4f8b\nfrom sklearn.preprocessing import MinMaxScaler\nimport numpy as np\n\ntest_data = np.array([1,2,3,4,5]).reshape(-1, 1).astype(float)\nmin_max_scaler = MinMaxScaler()\nmin_max_scaler.fit_transform(test_data)\n<\/code><\/pre>\n<pre><code>array([[0.  ],\n       [0.25],\n       [0.5 ],\n       [0.75],\n       [1.  ]])<\/code><\/pre>\n<h3>Z-score\u6807\u51c6\u5316<\/h3>\n<p>&emsp;&emsp;\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u538b\u7f29\uff0c\u4f46\u662f\u5b83\u7684\u538b\u7f29\u5e76\u4e0d\u80fd\u628a\u6570\u636e\u9650\u5236\u5728\u67d0\u4e2a\u533a\u95f4\uff0c\u5b83\u628a\u6570\u636e\u538b\u7f29\u6210\u7c7b\u4f3c\u9ad8\u65af\u5206\u5e03\u7684\u5206\u5e03\u65b9\u5f0f\uff0c\u5e76\u4e14\u4e5f\u80fd\u5904\u7406\u79bb\u7fa4\u503c\u5bf9\u6570\u636e\u7684\u5f71\u54cd\u3002<\/p>\n<p>&emsp;&emsp;\u5728\u5206\u7c7b\u3001\u805a\u7c7b\u7b97\u6cd5\u4e2d\uff0c\u9700\u8981\u4f7f\u7528\u8ddd\u79bb\u6765\u5ea6\u91cf\u76f8\u4f3c\u6027\u7684\u65f6\u5019\u5e94\u7528\u975e\u5e38\u597d\uff0c\u5c24\u5176\u662f\u6570\u636e\u672c\u8eab\u5448\u6b63\u6001\u5206\u5e03\u7684\u65f6\u5019\u3002<\/p>\n<p>\u6570\u636e\u6807\u51c6\u5316\u516c\u5f0f\uff1a<br \/>\n$$<br \/>\nx_{std}^{(i)}={\\frac{x^{(i)}-\\mu{_x}}{\\sigma{_x}}}<br \/>\n$$<br \/>\n&emsp;&emsp;\u4f7f\u7528\u6807\u51c6\u5316\u540e\uff0c\u53ef\u4ee5\u628a\u7279\u5f81\u5217\u7684\u4e2d\u5fc3\u8bbe\u5728\u5747\u503c\u4e3a$0$\u4e14\u6807\u51c6\u5dee\u4e3a$1$\u7684\u4f4d\u7f6e\uff0c\u5373\u6570\u636e\u5904\u7406\u540e\u7279\u5f81\u5217\u7b26\u5408\u6807\u51c6\u6b63\u6001\u5206\u5e03\u3002<\/p>\n<pre><code class=\"language-python\"># Z-score\u6807\u51c6\u5316\nfrom sklearn.preprocessing import StandardScaler\n\ntest_data = np.array([1,2,3,4,5]).reshape(-1, 1).astype(float)\nstandard_scaler = StandardScaler()\n# fit_transform()=fit()+transform(), fit()\u65b9\u6cd5\u4f30\u7b97\u5e73\u5747\u503c\u548c\u65b9\u5dee\uff0ctransform()\u65b9\u6cd5\u5bf9\u6570\u636e\u6807\u51c6\u5316\nstandard_scaler.fit_transform(test_data)<\/code><\/pre>\n<pre><code>array([[-1.41421356],\n       [-0.70710678],\n       [ 0.        ],\n       [ 0.70710678],\n       [ 1.41421356]])<\/code><\/pre>\n<h2>\u4e8c\u503c\u5316\u6570\u636e<\/h2>\n<p>&emsp;&emsp;\u6570\u636e\u4e8c\u503c\u5316\u7c7b\u4f3c\u4e8e\u72ec\u70ed\u7f16\u7801\uff0c\u4f46\u662f\u4e0d\u540c\u4e8e\u72ec\u70ed\u7f16\u7801\u7684\u662f\u5b83\u4e0d\u662f0\u5c31\u662f1\uff0c\u5373\u53c8\u6709\u70b9\u7c7b\u4f3c\u4e8e\u4e8c\u5206\u7c7b\uff0c\u4e0d\u5356\u5173\u5b50\u3002\u76f4\u63a5\u7ed9\u51fa\u6570\u636e\u4e8c\u503c\u5316\u7684\u516c\u5f0f\uff1a<br \/>\n$$<br \/>\ny = \\begin{cases}<br \/>\n0,\\quad if x \\leq {\\theta} \\<br \/>\n1,\\quad if x \\geq {\\theta}<br \/>\n\\end{cases}<br \/>\n$$<br \/>\n\u4e0a\u8ff0$\\theta$\u662f\u624b\u52a8\u8bbe\u7f6e\u7684\u9608\u503c\uff0c\u5982\u679c\u7279\u5f81\u503c\u5c0f\u4e8e\u9608\u503c\u4e3a0\uff1b\u7279\u5f81\u503c\u5927\u4e8e\u9608\u503c\u4e3a1\u3002<\/p>\n<pre><code class=\"language-python\"># \u6570\u636e\u4e8c\u503c\u5316\u793a\u4f8b\nfrom sklearn.preprocessing import Binarizer\n\ntest_data = np.array([1,2,3,4,5]).reshape(-1, 1).astype(float)\nbinarizer = Binarizer(threshold=2.5)\nbinarizer.fit_transform(test_data)<\/code><\/pre>\n<pre><code>array([[0.],\n       [0.],\n       [1.],\n       [1.],\n       [1.]])<\/code><\/pre>\n<h2>\u6b63\u5219\u5316\u6570\u636e<\/h2>\n<p>&emsp;&emsp;\u6b63\u5219\u5316\u662f\u5c06\u6bcf\u4e2a\u6837\u672c\u7f29\u653e\u5230\u5355\u4f4d\u8303\u6570\uff0c\u5373\u4f7f\u5f97\u6bcf\u4e2a\u6837\u672c\u7684p\u8303\u6570\u4e3a1\uff0c\u5bf9\u9700\u8981\u8ba1\u7b97\u6837\u672c\u95f4\u76f8\u4f3c\u5ea6\u6709\u5f88\u5927\u7684\u4f5c\u7528\uff0c\u901a\u5e38\u6709L1\u6b63\u5219\u5316\u548cL2\u6b63\u5219\u5316\u4e24\u79cd\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"language-python\"># L1\u6b63\u5219\u5316\u793a\u4f8b\nfrom sklearn.preprocessing import normalize\n\ntest_data = [[1, 2, 0, 4, 5], [2, 3, 4, 5, 9]]\nnormalize = normalize(test_data, norm=&#039;l1&#039;)\nnormalize<\/code><\/pre>\n<pre><code>array([[0.08333333, 0.16666667, 0.        , 0.33333333, 0.41666667],\n       [0.08695652, 0.13043478, 0.17391304, 0.2173913 , 0.39130435]])<\/code><\/pre>\n<pre><code class=\"language-python\"># L2\u6b63\u5219\u5316\u793a\u4f8b\nfrom sklearn.preprocessing import Normalizer\n\ntest_data = [[1, 2, 0, 4, 5], [2, 3, 4, 5, 9]]\nnormalize = Normalizer(norm=&#039;l2&#039;)\nnormalize = normalize.fit_transform(test_data)\nnormalize<\/code><\/pre>\n<pre><code>array([[0.14744196, 0.29488391, 0.        , 0.58976782, 0.73720978],\n       [0.17213259, 0.25819889, 0.34426519, 0.43033148, 0.77459667]])<\/code><\/pre>\n<h2>\u751f\u6210\u591a\u9879\u5f0f\u7279\u5f81<\/h2>\n<pre><code class=\"language-python\"># make_circles()\u793a\u4f8b\nfrom sklearn import datasets\n\nX1, y1 = datasets.make_circles(\n    n_samples=1000, random_state=1, factor=0.5, noise=0.1)\n\nplt.scatter(0,0,s=23000,color=&#039;white&#039;,edgecolors=&#039;r&#039;)\nplt.scatter(X1[:, 0], X1[:, 1], marker=&#039;*&#039;, c=y1)\n\nplt.xlabel(&#039;$x_1$&#039;, fontsize=15)\nplt.ylabel(&#039;$x_2$&#039;, fontsize=15)\nplt.title(&#039;make_circles()&#039;, fontsize=20)\nplt.show()<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/05-01-\u7279\u5f81\u9884\u5904\u7406_69_0-1.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/05-01-\u7279\u5f81\u9884\u5904\u7406_69_0-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>&emsp;&emsp;\u6709\u65f6\u5019\u53ef\u80fd\u4f1a\u9047\u5230\u4e0a\u56fe\u6240\u793a\u7684\u6570\u636e\u5206\u5e03\u60c5\u51b5\uff0c\u5982\u679c\u8fd9\u4e2a\u65f6\u5019\u4f7f\u7528\u7b80\u5355\u7684$x_1,x_2$\u7279\u5f81\u53bb\u62df\u5408\u66f2\u7ebf\uff0c\u660e\u663e\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528$x_1^2+x_2^2=1$\u53bb\u62df\u5408\u6570\u636e\uff0c\u53ef\u80fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u8f83\u597d\u7684\u6a21\u578b\uff0c\u6240\u4ee5\u6211\u4eec\u6709\u65f6\u5019\u4f1a\u5bf9\u7279\u5f81\u505a\u4e00\u4e2a\u591a\u9879\u5f0f\u5904\u7406\uff0c\u5373\u628a\u7279\u5f81$x_1,x_2$\u53d8\u6210$x_1^2,x_2^2$\u3002<\/p>\n<pre><code class=\"language-python\">test_data = [[1, 2], [3, 4], [5,6]]\ntest_data<\/code><\/pre>\n<pre><code>[[1, 2], [3, 4], [5, 6]]<\/code><\/pre>\n<p>&emsp;&emsp;\u901a\u8fc7\u591a\u9879\u5f0f\u7279\u5f81\uff0c\u7279\u5f81\u5c06\u4f1a\u505a\u5982\u4e0b\u53d8\u6362<br \/>\n$$<br \/>\nx_1,x_2\\quad\\rightarrow\\quad1,x_1,x_2,x_1^2,x_1x_2,x_2^2<br \/>\n$$<\/p>\n<pre><code class=\"language-python\"># \u751f\u6210\u591a\u9879\u5f0f\u7279\u5f81\u793a\u4f8b\nfrom sklearn.preprocessing import PolynomialFeatures\n\npoly = PolynomialFeatures()\npoly = poly.fit_transform(test_data)\npoly<\/code><\/pre>\n<pre><code>array([[ 1.,  1.,  2.,  1.,  2.,  4.],\n       [ 1.,  3.,  4.,  9., 12., 16.],\n       [ 1.,  5.,  6., 25., 30., 36.]])<\/code><\/pre>\n<h1>\u5c0f\u7ed3<\/h1>\n<p>&emsp;&emsp;\u672c\u95ee\u4e3b\u8981\u4ecb\u7ecd\u4e86\u6570\u636e\u9884\u5904\u7406\u7684\u65b9\u6cd5\u3002\u4f46\u662f\u73b0\u5b9e\u751f\u6d3b\u4e2d\u6570\u636e\u7684\u6570\u91cf\u4ee5\u53ca\u590d\u6742\u5ea6\u8fdc\u4e0d\u662f\u672c\u6587\u6240\u4ecb\u7ecd\u7684\u5982\u6b64\u7b80\u5355\uff0c\u9650\u4e8e\u7bc7\u5e45\u53ea\u80fd\u7ed9\u4f60\u4eec\u505a\u4e2a\u5f15\u8def\u4eba\uff0c\u4f46\u662f\u5bf9\u6570\u636e\u9884\u5904\u7406\u7684\u76ee\u6807\u662f\u4e0d\u4f1a\u53d8\u7684\uff0c\u4e3a\u4e86\u8ba9\u7b97\u6cd5\u66f4\u597d\u7684\u5b9e\u73b0\uff0c\u5b9e\u73b0\u7684\u66f4\u597d\u3002\u5982\u82e5\u53ea\u662f\u6570\u636e\u4e2d\u6709\u810f\u6570\u636e\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u4e5f\u591f\u7528\u4e86\u3002<\/p>\n<p>&emsp;&emsp;\u7279\u5f81\u5de5\u7a0b\u4e5f\u7b97\u662f\u544a\u4e00\u6bb5\u843d\u4e86\uff0c\u4f46\u662f\u7279\u5f81\u5de5\u7a0b\u8fdc\u6ca1\u6709\u8fd9\u4e24\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u7684\u8fd9\u4e48\u7b80\u5355\u3002\u7279\u5f81\u5de5\u7a0b\u4e5f\u5982\u5176\u540d\uff0c\u5de5\u7a0b\u4e8c\u5b57\u5c31\u8bf4\u660e\u4e86\u592a\u591a\u592a\u591a\uff0c\u7279\u5f81\u5de5\u7a0b\u66f4\u591a\u7684\u662f\u5728\u5de5\u4f5c\u4e2d\u6216\u5404\u7c7b\u7ade\u8d5b\u4e2d\u7684\u7ecf\u9a8c\u79ef\u7d2f\uff0c\u4ed6\u4e0d\u5982\u7b97\u6cd5\u4e00\u6837\u6709\u56fa\u5b9a\u7684\u5957\u8def\uff0c\u4e5f\u6ca1\u6709\u54ea\u4e2a\u4eba\u80fd\u8bf4\u54ea\u4e2a\u6570\u636e\u5904\u7406\u7684\u65b9\u6cd5\u4f1a\u6bd4\u4efb\u4f55\u4e00\u4e2a\u5176\u4ed6\u7684\u6570\u636e\u5904\u7406\u7684\u65b9\u6cd5\u66f4\u4f18\u3002<\/p>\n<p>&emsp;&emsp;\u6700\u540e\uff0c\u8fd8\u662f\u9001\u7ed9\u5927\u5bb6\u90a3\u4e00\u53e5\u8bdd\uff1a\u6570\u636e\u548c\u7279\u5f81\u51b3\u5b9a\u4e86\u673a\u5668\u5b66\u4e60\u7684\u4e0a\u9650\uff0c\u800c\u6a21\u578b\u548c\u7b97\u6cd5\u53ea\u662f\u903c\u8fd1\u8fd9\u4e2a\u4e0a\u9650\u800c\u5df2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7279\u5f81\u9884\u5904\u7406 &emsp;&emsp;\u4e4b\u524d\u8bf4\u5230\u6784\u5efa\u673a\u5668\u5b66\u4e60\u7cfb\u7edf\u7684\u6b65\u9aa4\u4e2d\u7684\u7b2c\u4e8c\u6b65\u8bf4\u5230\u9700\u8981\u8fdb\u884c\u6570\u636e\u9884\u5904\u7406\uff0c\u4f46\u662f\u5e76\u6ca1\u6709 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3189,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[276,299],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3187"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3187"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3187\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/3189"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}