{"id":3270,"date":"2022-02-27T14:17:03","date_gmt":"2022-02-27T06:17:03","guid":{"rendered":"https:\/\/egonlin.com\/?p=3270"},"modified":"2022-02-27T14:17:03","modified_gmt":"2022-02-27T06:17:03","slug":"%e7%ac%ac%e5%9b%9b%e8%8a%82%ef%bc%9a%e7%bb%86%e5%88%86%e6%9e%84%e5%bb%ba%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%b5%81%e7%a8%8b-%e6%b5%81%e7%a8%8b%e7%ae%80","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=3270","title":{"rendered":"\u7b2c\u56db\u8282\uff1a\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb"},"content":{"rendered":"<h1>\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb<\/h1>\n<h1>1.1 sklearn\u5b89\u88c5<\/h1>\n<p>&emsp;&emsp;\u4e3a\u4e86\u5b9e\u73b0\u63a5\u4e0b\u91cc\u7684\u4ee3\u7801\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u4e0b\u52175\u4e2aPython\u7b2c\u4e09\u65b9\u5e93\uff0c\u672c\u6587\u53ea\u62ffsklearn\u7684\u5b89\u88c5\u4e3e\u4f8b\uff0c\u5982\u679c\u6709\u540c\u5b66\u5df2\u7ecf\u5b89\u88c5sklearn\uff0c\u53ef\u4ee5\u628a\u4f60\u7684sklearn\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\uff0c\u5176\u4ed6\u5e93\u540c\u7406\u3002<\/p>\n<ul>\n<li>numpy 1.15.4<\/li>\n<li>scipy 1.1.0<\/li>\n<li>matplotlib 3.0.2<\/li>\n<li>pandas 0.23.4<\/li>\n<li>scikit-learn 0.20.1<\/li>\n<\/ul>\n<p>\u5b89\u88c5\u65b9\u5f0f\u4e3a\uff1a<\/p>\n<p><code>pip install sklearn<\/code><\/p>\n<p>\u66f4\u65b0\u65b9\u5f0f\u4e3a\uff1a<\/p>\n<p><code>pip install --upgrade sklearn<\/code><\/p>\n<p>sklearn\u82f1\u6587\u6587\u6863\uff1a<a href=\"https:\/\/scikit-learn.org\/stable\/index.html\">https:\/\/scikit-learn.org\/stable\/index.html<\/a><\/p>\n<p>sklear\u4e2d\u6587\u6587\u6863\uff1a<a href=\"http:\/\/sklearn.apachecn.org\/\">http:\/\/sklearn.apachecn.org\/<\/a>#\/<\/p>\n<pre><code class=\"language-python\"># \u7ec8\u7aef\u8f93\u5165\uff0c\u5b89\u88c5sklear\uff0c\u5176\u4ed6\u5e93\u540c\u7406\n!pip install sklearn<\/code><\/pre>\n<pre><code>Requirement already satisfied: sklearn in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (0.0)\nRequirement already satisfied: scikit-learn in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from sklearn) (0.20.1)\nRequirement already satisfied: numpy>=1.8.2 in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from scikit-learn->sklearn) (1.15.4)\nRequirement already satisfied: scipy>=0.13.3 in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from scikit-learn->sklearn) (1.1.0)<\/code><\/pre>\n<pre><code class=\"language-python\">import sklearn\n\n# \u6253\u5370sklearn\u7684\u7248\u672c\nsklearn.__version__<\/code><\/pre>\n<pre><code>'0.20.1'<\/code><\/pre>\n<pre><code class=\"language-python\"># \u7ec8\u7aef\u8f93\u5165\uff0c\u66f4\u65b0sklear\n!pip install --upgrade sklearn<\/code><\/pre>\n<pre><code>Requirement already up-to-date: sklearn in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (0.0)\nRequirement already satisfied, skipping upgrade: scikit-learn in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from sklearn) (0.20.1)\nRequirement already satisfied, skipping upgrade: numpy>=1.8.2 in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from scikit-learn->sklearn) (1.15.4)\nRequirement already satisfied, skipping upgrade: scipy>=0.13.3 in \/Applications\/anaconda3\/lib\/python3.7\/site-packages (from scikit-learn->sklearn) (1.1.0)<\/code><\/pre>\n<h1>1.2 sklearn\u529f\u80fd\u6a21\u5757<\/h1>\n<h2>1.2.1 \u82f1\u6587\u7248\u672c<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u9996\u9875\u5bfc\u822a\u82f1\u6587.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u9996\u9875\u5bfc\u822a\u82f1\u6587.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>1.2.2 \u4e2d\u6587\u7248\u672c<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u9996\u9875\u5bfc\u822a\u4e2d\u6587.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u9996\u9875\u5bfc\u822a\u4e2d\u6587.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>1.2.3 API\u7edf\u4e00\u7684\u65b9\u6cd5<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u6a21\u578b<\/th>\n<th style=\"text-align: center;\">\u529f\u80fd\u6a21\u5757<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">estimator.fit(X_train, y_train)<\/td>\n<td style=\"text-align: center;\">estimator.fit(X_train, y_train)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">estimator.predict(X_test)<\/td>\n<td style=\"text-align: center;\">estimator.transform(X_test)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">get_params([deep])<\/td>\n<td style=\"text-align: center;\">get_params([deep])<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">set_params(**params)<\/td>\n<td style=\"text-align: center;\">set_params(**params)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u9002\u7528\u4e8e\u4ee5\u4e0b\u6a21\u578b<\/td>\n<td style=\"text-align: center;\">\u9002\u7528\u4e8e\u4ee5\u4e0b\u529f\u80fd\u6a21\u5757<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Classification\uff08\u5206\u7c7b\uff09<\/td>\n<td style=\"text-align: center;\">Preprocessing\uff08\u6570\u636e\u9884\u5904\u7406\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Regression\uff08\u56de\u5f52\uff09<\/td>\n<td style=\"text-align: center;\">Dimensionality Reduction\uff08\u964d\u7ef4\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Clustering\uff08\u805a\u7c7b\uff09<\/td>\n<td style=\"text-align: center;\">Feature Selection\uff08\u7279\u5f81\u9009\u62e9\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">&#8211;<\/td>\n<td style=\"text-align: center;\">Feature Extraction\uff08\u7279\u5f81\u63d0\u53d6\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>1.3 sklearn\u4f7f\u7528\u5730\u56fe<\/h1>\n<h2>1.3.1 \u82f1\u6587\u7248\u672c<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u5b66\u4e60\u5730\u56fe\u82f1\u6587.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u5b66\u4e60\u5730\u56fe\u82f1\u6587.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>1.3.2 \u4e2d\u6587\u7248\u672c<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u5b66\u4e60\u5730\u56fe\u4e2d\u6587.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/02\/\u7b2c\u56db\u90e8\u5206-sklearn\u5b66\u4e60\u5730\u56fe\u4e2d\u6587.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h1>1.4 \u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u6d41\u7a0b<\/h1>\n<p>&emsp;&emsp;\u6b64\u5904\u53ea\u662f\u7b80\u5355\u7684\u5e26\u540c\u5b66\u4eec\u4e86\u89e3\u4e0b\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b\uff0c\u5373\u4ee5\u4e0b6\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<pre><code>1. \u6536\u96c6\u6570\u636e\n2. \u6570\u636e\u9884\u5904\u7406\n3. \u8bad\u7ec3\u6a21\u578b\n4. \u6d4b\u8bd5\u6a21\u578b\n5. \u4f18\u5316\u6a21\u578b\n6. \u6301\u4e45\u5316\u6a21\u578b<\/code><\/pre>\n<p>\u4e4b\u540e\u4f1a\u8be6\u7ec6\u8bb2\u89e3\u8be5\u6d41\u7a0b\u7684\u6bcf\u4e00\u4e2a\u6b65\u9aa4\u3002<\/p>\n<h2>1.4.1 \u6536\u96c6\u6570\u636e<\/h2>\n<p>&emsp;&emsp;\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u8bba\u662f\u76d1\u7763\u5b66\u4e60\u8fd8\u662f\u65e0\u76d1\u7763\u5b66\u4e60\uff0c\u7b2c\u4e00\u6b65\u90fd\u662f\u83b7\u53d6\u6570\u636e\uff0c\u6b64\u5904\u4e3a\u4e86\u5e26\u5927\u5bb6\u5bf9\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u6709\u4e00\u4e2a\u7b80\u5355\u7684\u4e86\u89e3\uff0c\u6240\u4ee5\u5229\u7528sklearn\u81ea\u5e26\u9e22\u5c3e\u82b1\u6570\u636e\u96c6\u4f5c\u5c55\u793a\uff0c\u4e4b\u540e\u518d\u6536\u96c6\u6570\u636e\u5c0f\u8282\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u6536\u96c6\u6570\u636e\u7684\u51e0\u79cd\u65b9\u5f0f\u3002<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib.font_manager import FontProperties\nfrom sklearn import datasets\n%matplotlib inline\nfont = FontProperties(fname=&#039;\/Library\/Fonts\/Heiti.ttc&#039;)\n\niris = datasets.load_iris()\niris<\/code><\/pre>\n<pre><code>{'data': array([[5.1, 3.5, 1.4, 0.2],\n        [4.9, 3. , 1.4, 0.2],\n        [4.7, 3.2, 1.3, 0.2],\n        [4.6, 3.1, 1.5, 0.2],\n        [5. , 3.6, 1.4, 0.2],\n        [5.4, 3.9, 1.7, 0.4],\n        [4.6, 3.4, 1.4, 0.3],\n        [5. , 3.4, 1.5, 0.2],\n        [4.4, 2.9, 1.4, 0.2],\n        [4.9, 3.1, 1.5, 0.1],\n        [5.4, 3.7, 1.5, 0.2],\n        [4.8, 3.4, 1.6, 0.2],\n        [4.8, 3. , 1.4, 0.1],\n        [4.3, 3. , 1.1, 0.1],\n        [5.8, 4. , 1.2, 0.2],\n        [5.7, 4.4, 1.5, 0.4],\n        [5.4, 3.9, 1.3, 0.4],\n        [5.1, 3.5, 1.4, 0.3],\n        [5.7, 3.8, 1.7, 0.3],\n        [5.1, 3.8, 1.5, 0.3],\n        [5.4, 3.4, 1.7, 0.2],\n        [5.1, 3.7, 1.5, 0.4],\n        [4.6, 3.6, 1. , 0.2],\n        [5.1, 3.3, 1.7, 0.5],\n        [4.8, 3.4, 1.9, 0.2],\n        [5. , 3. , 1.6, 0.2],\n        [5. , 3.4, 1.6, 0.4],\n        [5.2, 3.5, 1.5, 0.2],\n        [5.2, 3.4, 1.4, 0.2],\n        [4.7, 3.2, 1.6, 0.2],\n        [4.8, 3.1, 1.6, 0.2],\n        [5.4, 3.4, 1.5, 0.4],\n        [5.2, 4.1, 1.5, 0.1],\n        [5.5, 4.2, 1.4, 0.2],\n        [4.9, 3.1, 1.5, 0.2],\n        [5. , 3.2, 1.2, 0.2],\n        [5.5, 3.5, 1.3, 0.2],\n        [4.9, 3.6, 1.4, 0.1],\n        [4.4, 3. , 1.3, 0.2],\n        [5.1, 3.4, 1.5, 0.2],\n        [5. , 3.5, 1.3, 0.3],\n        [4.5, 2.3, 1.3, 0.3],\n        [4.4, 3.2, 1.3, 0.2],\n        [5. , 3.5, 1.6, 0.6],\n        [5.1, 3.8, 1.9, 0.4],\n        [4.8, 3. , 1.4, 0.3],\n        [5.1, 3.8, 1.6, 0.2],\n        [4.6, 3.2, 1.4, 0.2],\n        [5.3, 3.7, 1.5, 0.2],\n        [5. , 3.3, 1.4, 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, 1.5],\n        [5.5, 2.3, 4. , 1.3],\n        [6.5, 2.8, 4.6, 1.5],\n        [5.7, 2.8, 4.5, 1.3],\n        [6.3, 3.3, 4.7, 1.6],\n        [4.9, 2.4, 3.3, 1. ],\n        [6.6, 2.9, 4.6, 1.3],\n        [5.2, 2.7, 3.9, 1.4],\n        [5. , 2. , 3.5, 1. ],\n        [5.9, 3. , 4.2, 1.5],\n        [6. , 2.2, 4. , 1. ],\n        [6.1, 2.9, 4.7, 1.4],\n        [5.6, 2.9, 3.6, 1.3],\n        [6.7, 3.1, 4.4, 1.4],\n        [5.6, 3. , 4.5, 1.5],\n        [5.8, 2.7, 4.1, 1. ],\n        [6.2, 2.2, 4.5, 1.5],\n        [5.6, 2.5, 3.9, 1.1],\n        [5.9, 3.2, 4.8, 1.8],\n        [6.1, 2.8, 4. , 1.3],\n        [6.3, 2.5, 4.9, 1.5],\n        [6.1, 2.8, 4.7, 1.2],\n        [6.4, 2.9, 4.3, 1.3],\n        [6.6, 3. , 4.4, 1.4],\n        [6.8, 2.8, 4.8, 1.4],\n        [6.7, 3. , 5. , 1.7],\n        [6. , 2.9, 4.5, 1.5],\n        [5.7, 2.6, 3.5, 1. ],\n        [5.5, 2.4, 3.8, 1.1],\n        [5.5, 2.4, 3.7, 1. ],\n        [5.8, 2.7, 3.9, 1.2],\n        [6. , 2.7, 5.1, 1.6],\n        [5.4, 3. , 4.5, 1.5],\n        [6. , 3.4, 4.5, 1.6],\n        [6.7, 3.1, 4.7, 1.5],\n        [6.3, 2.3, 4.4, 1.3],\n        [5.6, 3. , 4.1, 1.3],\n        [5.5, 2.5, 4. , 1.3],\n        [5.5, 2.6, 4.4, 1.2],\n        [6.1, 3. , 4.6, 1.4],\n        [5.8, 2.6, 4. , 1.2],\n        [5. , 2.3, 3.3, 1. ],\n        [5.6, 2.7, 4.2, 1.3],\n        [5.7, 3. , 4.2, 1.2],\n        [5.7, 2.9, 4.2, 1.3],\n        [6.2, 2.9, 4.3, 1.3],\n        [5.1, 2.5, 3. , 1.1],\n        [5.7, 2.8, 4.1, 1.3],\n        [6.3, 3.3, 6. , 2.5],\n        [5.8, 2.7, 5.1, 1.9],\n        [7.1, 3. , 5.9, 2.1],\n        [6.3, 2.9, 5.6, 1.8],\n        [6.5, 3. , 5.8, 2.2],\n        [7.6, 3. , 6.6, 2.1],\n        [4.9, 2.5, 4.5, 1.7],\n        [7.3, 2.9, 6.3, 1.8],\n        [6.7, 2.5, 5.8, 1.8],\n        [7.2, 3.6, 6.1, 2.5],\n        [6.5, 3.2, 5.1, 2. ],\n        [6.4, 2.7, 5.3, 1.9],\n        [6.8, 3. , 5.5, 2.1],\n        [5.7, 2.5, 5. , 2. ],\n        [5.8, 2.8, 5.1, 2.4],\n        [6.4, 3.2, 5.3, 2.3],\n        [6.5, 3. , 5.5, 1.8],\n        [7.7, 3.8, 6.7, 2.2],\n        [7.7, 2.6, 6.9, 2.3],\n        [6. , 2.2, 5. , 1.5],\n        [6.9, 3.2, 5.7, 2.3],\n        [5.6, 2.8, 4.9, 2. ],\n        [7.7, 2.8, 6.7, 2. ],\n        [6.3, 2.7, 4.9, 1.8],\n        [6.7, 3.3, 5.7, 2.1],\n        [7.2, 3.2, 6. , 1.8],\n        [6.2, 2.8, 4.8, 1.8],\n        [6.1, 3. , 4.9, 1.8],\n        [6.4, 2.8, 5.6, 2.1],\n        [7.2, 3. , 5.8, 1.6],\n        [7.4, 2.8, 6.1, 1.9],\n        [7.9, 3.8, 6.4, 2. ],\n        [6.4, 2.8, 5.6, 2.2],\n        [6.3, 2.8, 5.1, 1.5],\n        [6.1, 2.6, 5.6, 1.4],\n        [7.7, 3. , 6.1, 2.3],\n        [6.3, 3.4, 5.6, 2.4],\n        [6.4, 3.1, 5.5, 1.8],\n        [6. , 3. , 4.8, 1.8],\n        [6.9, 3.1, 5.4, 2.1],\n        [6.7, 3.1, 5.6, 2.4],\n        [6.9, 3.1, 5.1, 2.3],\n        [5.8, 2.7, 5.1, 1.9],\n        [6.8, 3.2, 5.9, 2.3],\n        [6.7, 3.3, 5.7, 2.5],\n        [6.7, 3. , 5.2, 2.3],\n        [6.3, 2.5, 5. , 1.9],\n        [6.5, 3. , 5.2, 2. ],\n        [6.2, 3.4, 5.4, 2.3],\n        [5.9, 3. , 5.1, 1.8]]),\n 'target': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n        0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]),\n 'target_names': array(['setosa', 'versicolor', 'virginica'], dtype='<U10'),\n 'DESCR': '.. _iris_dataset:\\n\\nIris plants dataset\\n--------------------\\n\\n**Data Set Characteristics:**\\n\\n    :Number of Instances: 150 (50 in each of three classes)\\n    :Number of Attributes: 4 numeric, predictive attributes and the class\\n    :Attribute Information:\\n        - sepal length in cm\\n        - sepal width in cm\\n        - petal length in cm\\n        - petal width in cm\\n        - class:\\n                - Iris-Setosa\\n                - Iris-Versicolour\\n                - Iris-Virginica\\n                \\n    :Summary Statistics:\\n\\n    ============== ==== ==== ======= ===== ====================\\n                    Min  Max   Mean    SD   Class Correlation\\n    ============== ==== ==== ======= ===== ====================\\n    sepal length:   4.3  7.9   5.84   0.83    0.7826\\n    sepal width:    2.0  4.4   3.05   0.43   -0.4194\\n    petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)\\n    petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)\\n    ============== ==== ==== ======= ===== ====================\\n\\n    :Missing Attribute Values: None\\n    :Class Distribution: 33.3% for each of 3 classes.\\n    :Creator: R.A. Fisher\\n    :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\\n    :Date: July, 1988\\n\\nThe famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\\nfrom Fisher\\'s paper. Note that it\\'s the same as in R, but not as in the UCI\\nMachine Learning Repository, which has two wrong data points.\\n\\nThis is perhaps the best known database to be found in the\\npattern recognition literature.  Fisher\\'s paper is a classic in the field and\\nis referenced frequently to this day.  (See Duda &#038; Hart, for example.)  The\\ndata set contains 3 classes of 50 instances each, where each class refers to a\\ntype of iris plant.  One class is linearly separable from the other 2; the\\nlatter are NOT linearly separable from each other.\\n\\n.. topic:: References\\n\\n   - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\\n     Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\\n     Mathematical Statistics\" (John Wiley, NY, 1950).\\n   - Duda, R.O., &#038; Hart, P.E. (1973) Pattern Classification and Scene Analysis.\\n     (Q327.D83) John Wiley &#038; Sons.  ISBN 0-471-22361-1.  See page 218.\\n   - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\\n     Structure and Classification Rule for Recognition in Partially Exposed\\n     Environments\".  IEEE Transactions on Pattern Analysis and Machine\\n     Intelligence, Vol. PAMI-2, No. 1, 67-71.\\n   - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\".  IEEE Transactions\\n     on Information Theory, May 1972, 431-433.\\n   - See also: 1988 MLC Proceedings, 54-64.  Cheeseman et al\"s AUTOCLASS II\\n     conceptual clustering system finds 3 classes in the data.\\n   - Many, many more ...',\n 'feature_names': ['sepal length (cm)',\n  'sepal width (cm)',\n  'petal length (cm)',\n  'petal width (cm)'],\n 'filename': '\/Applications\/anaconda3\/lib\/python3.6\/site-packages\/sklearn\/datasets\/data\/iris.csv'}<\/code><\/pre>\n<pre><code class=\"language-python\">X = iris.data\n# \u603b\u5171\u6709150\u4e2a\u6837\u672c\u6570\u636e\uff0c\u6b64\u5904\u53ea\u6253\u53705\u4e2a\n&#039;X\u7684\u4e2a\u6570:{}&#039;.format(len(X)), &#039;X:{}&#039;.format(X[0:5])<\/code><\/pre>\n<pre><code>('X\u7684\u4e2a\u6570:150',\n 'X:[[5.1 3.5 1.4 0.2]\\n [4.9 3.  1.4 0.2]\\n [4.7 3.2 1.3 0.2]\\n [4.6 3.1 1.5 0.2]\\n [5.  3.6 1.4 0.2]]')<\/code><\/pre>\n<pre><code class=\"language-python\">y = iris.target\n&#039;y\u7684\u4e2a\u6570:{}&#039;.format(len(y)), &#039;y:{}&#039;.format(y)<\/code><\/pre>\n<pre><code>('y\u7684\u4e2a\u6570:150',\n 'y:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\\n 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n 2 2]')<\/code><\/pre>\n<pre><code class=\"language-python\"># pandas\u53ef\u89c6\u5316\u6570\u636e\ndf = pd.DataFrame(X, columns=iris.feature_names)\ndf[&#039;target&#039;] = y\ndf.plot(figsize=(10, 8))\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\/08-03-\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb_26_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\/08-03-\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb_26_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<pre><code class=\"language-python\"># matplotlib\u53ef\u89c6\u5316\n# matplotlib\u9002\u5408\u4e8c\u7ef4\u53ef\u89c6\u5316\uff0c\u56e0\u6b64\u53ea\u9009\u7279\u5f811\u30012\uff0c\u5373\u843c\u7247\u957f\u5ea6\u3001\u843c\u7247\u5bbd\u5ea6\n# \u53d6\u6240\u6709\u884c\u7684\u7b2c1\uff0c2\u5217\u7279\u5f81\nX_ = X[:, [0, 1]]\n\n# \u53d6\u51fa\u5c71\u9e22\u5c3e\u6570\u636e\nplt.scatter(X_[0:50, 0], X_[0:50, 1], color=&#039;r&#039;, label=&#039;\u5c71\u9e22\u5c3e&#039;, s=10)\n# \u53d6\u51fa\u6742\u8272\u9e22\u5c3e\u6570\u636e\nplt.scatter(X_[50:100, 0], X_[50:100, 1], color=&#039;g&#039;, label=&#039;\u6742\u8272\u9e22\u5c3e&#039;, s=50)\n# \u53d6\u51fa\u7ef4\u5409\u5c3c\u4e9a\u9e22\u5c3e\nplt.scatter(X_[100:150, 0], X_[100:150, 1], color=&#039;b&#039;, label=&#039;\u7ef4\u5409\u5c3c\u4e9a\u9e22\u5c3e&#039;, s=100)\n\nplt.legend(prop=font)\nplt.xlabel(&#039;\u843c\u7247\u957f\u5ea6&#039;, fontproperties=font, fontsize=15)\nplt.ylabel(&#039;\u843c\u7247\u5bbd\u5ea6&#039;, fontproperties=font, fontsize=15)\nplt.title(&#039;\u843c\u7247\u957f\u5ea6-\u843c\u7247\u5bbd\u5ea6&#039;, fontproperties=font, 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\/08-03-\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb_27_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\/08-03-\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb_27_0.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>1.4.2 \u6570\u636e\u9884\u5904\u7406<\/h2>\n<p>&emsp;&emsp;\u53ef\u4ee5\u53d1\u73b0\u9e22\u5c3e\u82b1\u6570\u636e\u7684\u67d0\u4e00\u4e2a\u7279\u5f81\u7684\u7279\u5f81\u503c\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u5dee\u8ddd\u975e\u5e38\u5927\uff0c\u4e3a\u4e86\u89e3\u51b3\u4e0a\u8ff0\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>&emsp;&emsp;\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\">from sklearn.preprocessing import MinMaxScaler\n\nscaler = MinMaxScaler()\n# scaler.fit_transform(X) # \u7b49\u540c\u4e8e\u5148fit()\u540etransform()\nscaler = scaler.fit(X)\nprint(X)\nX1 = scaler.transform(X)\nX1<\/code><\/pre>\n<pre><code>[[5.1 3.5 1.4 0.2]\n [4.9 3.  1.4 0.2]\n [4.7 3.2 1.3 0.2]\n [4.6 3.1 1.5 0.2]\n [5.  3.6 1.4 0.2]\n [5.4 3.9 1.7 0.4]\n [4.6 3.4 1.4 0.3]\n [5.  3.4 1.5 0.2]\n [4.4 2.9 1.4 0.2]\n [4.9 3.1 1.5 0.1]\n [5.4 3.7 1.5 0.2]\n [4.8 3.4 1.6 0.2]\n [4.8 3.  1.4 0.1]\n [4.3 3.  1.1 0.1]\n [5.8 4.  1.2 0.2]\n [5.7 4.4 1.5 0.4]\n [5.4 3.9 1.3 0.4]\n [5.1 3.5 1.4 0.3]\n [5.7 3.8 1.7 0.3]\n [5.1 3.8 1.5 0.3]\n [5.4 3.4 1.7 0.2]\n [5.1 3.7 1.5 0.4]\n [4.6 3.6 1.  0.2]\n [5.1 3.3 1.7 0.5]\n [4.8 3.4 1.9 0.2]\n [5.  3.  1.6 0.2]\n [5.  3.4 1.6 0.4]\n [5.2 3.5 1.5 0.2]\n [5.2 3.4 1.4 0.2]\n [4.7 3.2 1.6 0.2]\n [4.8 3.1 1.6 0.2]\n [5.4 3.4 1.5 0.4]\n [5.2 4.1 1.5 0.1]\n [5.5 4.2 1.4 0.2]\n [4.9 3.1 1.5 0.2]\n [5.  3.2 1.2 0.2]\n [5.5 3.5 1.3 0.2]\n [4.9 3.6 1.4 0.1]\n [4.4 3.  1.3 0.2]\n [5.1 3.4 1.5 0.2]\n [5.  3.5 1.3 0.3]\n [4.5 2.3 1.3 0.3]\n [4.4 3.2 1.3 0.2]\n [5.  3.5 1.6 0.6]\n [5.1 3.8 1.9 0.4]\n [4.8 3.  1.4 0.3]\n [5.1 3.8 1.6 0.2]\n [4.6 3.2 1.4 0.2]\n [5.3 3.7 1.5 0.2]\n [5.  3.3 1.4 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 1.5]\n [5.5 2.3 4.  1.3]\n [6.5 2.8 4.6 1.5]\n [5.7 2.8 4.5 1.3]\n [6.3 3.3 4.7 1.6]\n [4.9 2.4 3.3 1. ]\n [6.6 2.9 4.6 1.3]\n [5.2 2.7 3.9 1.4]\n [5.  2.  3.5 1. ]\n [5.9 3.  4.2 1.5]\n [6.  2.2 4.  1. ]\n [6.1 2.9 4.7 1.4]\n [5.6 2.9 3.6 1.3]\n [6.7 3.1 4.4 1.4]\n [5.6 3.  4.5 1.5]\n [5.8 2.7 4.1 1. ]\n [6.2 2.2 4.5 1.5]\n [5.6 2.5 3.9 1.1]\n [5.9 3.2 4.8 1.8]\n [6.1 2.8 4.  1.3]\n [6.3 2.5 4.9 1.5]\n [6.1 2.8 4.7 1.2]\n [6.4 2.9 4.3 1.3]\n [6.6 3.  4.4 1.4]\n [6.8 2.8 4.8 1.4]\n [6.7 3.  5.  1.7]\n [6.  2.9 4.5 1.5]\n [5.7 2.6 3.5 1. ]\n [5.5 2.4 3.8 1.1]\n [5.5 2.4 3.7 1. ]\n [5.8 2.7 3.9 1.2]\n [6.  2.7 5.1 1.6]\n [5.4 3.  4.5 1.5]\n [6.  3.4 4.5 1.6]\n [6.7 3.1 4.7 1.5]\n [6.3 2.3 4.4 1.3]\n [5.6 3.  4.1 1.3]\n [5.5 2.5 4.  1.3]\n [5.5 2.6 4.4 1.2]\n [6.1 3.  4.6 1.4]\n [5.8 2.6 4.  1.2]\n [5.  2.3 3.3 1. ]\n [5.6 2.7 4.2 1.3]\n [5.7 3.  4.2 1.2]\n [5.7 2.9 4.2 1.3]\n [6.2 2.9 4.3 1.3]\n [5.1 2.5 3.  1.1]\n [5.7 2.8 4.1 1.3]\n [6.3 3.3 6.  2.5]\n [5.8 2.7 5.1 1.9]\n [7.1 3.  5.9 2.1]\n [6.3 2.9 5.6 1.8]\n [6.5 3.  5.8 2.2]\n [7.6 3.  6.6 2.1]\n [4.9 2.5 4.5 1.7]\n [7.3 2.9 6.3 1.8]\n [6.7 2.5 5.8 1.8]\n [7.2 3.6 6.1 2.5]\n [6.5 3.2 5.1 2. ]\n [6.4 2.7 5.3 1.9]\n [6.8 3.  5.5 2.1]\n [5.7 2.5 5.  2. ]\n [5.8 2.8 5.1 2.4]\n [6.4 3.2 5.3 2.3]\n [6.5 3.  5.5 1.8]\n [7.7 3.8 6.7 2.2]\n [7.7 2.6 6.9 2.3]\n [6.  2.2 5.  1.5]\n [6.9 3.2 5.7 2.3]\n [5.6 2.8 4.9 2. ]\n [7.7 2.8 6.7 2. ]\n [6.3 2.7 4.9 1.8]\n [6.7 3.3 5.7 2.1]\n [7.2 3.2 6.  1.8]\n [6.2 2.8 4.8 1.8]\n [6.1 3.  4.9 1.8]\n [6.4 2.8 5.6 2.1]\n [7.2 3.  5.8 1.6]\n [7.4 2.8 6.1 1.9]\n [7.9 3.8 6.4 2. ]\n [6.4 2.8 5.6 2.2]\n [6.3 2.8 5.1 1.5]\n [6.1 2.6 5.6 1.4]\n [7.7 3.  6.1 2.3]\n [6.3 3.4 5.6 2.4]\n [6.4 3.1 5.5 1.8]\n [6.  3.  4.8 1.8]\n [6.9 3.1 5.4 2.1]\n [6.7 3.1 5.6 2.4]\n [6.9 3.1 5.1 2.3]\n [5.8 2.7 5.1 1.9]\n [6.8 3.2 5.9 2.3]\n [6.7 3.3 5.7 2.5]\n [6.7 3.  5.2 2.3]\n [6.3 2.5 5.  1.9]\n [6.5 3.  5.2 2. ]\n [6.2 3.4 5.4 2.3]\n [5.9 3.  5.1 1.8]]\n\narray([[0.22222222, 0.625     , 0.06779661, 0.04166667],\n       [0.16666667, 0.41666667, 0.06779661, 0.04166667],\n       [0.11111111, 0.5       , 0.05084746, 0.04166667],\n       [0.08333333, 0.45833333, 0.08474576, 0.04166667],\n       [0.19444444, 0.66666667, 0.06779661, 0.04166667],\n       [0.30555556, 0.79166667, 0.11864407, 0.125     ],\n       [0.08333333, 0.58333333, 0.06779661, 0.08333333],\n       [0.19444444, 0.58333333, 0.08474576, 0.04166667],\n       [0.02777778, 0.375     , 0.06779661, 0.04166667],\n       [0.16666667, 0.45833333, 0.08474576, 0.        ],\n       [0.30555556, 0.70833333, 0.08474576, 0.04166667],\n       [0.13888889, 0.58333333, 0.10169492, 0.04166667],\n       [0.13888889, 0.41666667, 0.06779661, 0.        ],\n       [0.        , 0.41666667, 0.01694915, 0.        ],\n       [0.41666667, 0.83333333, 0.03389831, 0.04166667],\n       [0.38888889, 1.        , 0.08474576, 0.125     ],\n       [0.30555556, 0.79166667, 0.05084746, 0.125     ],\n       [0.22222222, 0.625     , 0.06779661, 0.08333333],\n       [0.38888889, 0.75      , 0.11864407, 0.08333333],\n       [0.22222222, 0.75      , 0.08474576, 0.08333333],\n       [0.30555556, 0.58333333, 0.11864407, 0.04166667],\n       [0.22222222, 0.70833333, 0.08474576, 0.125     ],\n       [0.08333333, 0.66666667, 0.        , 0.04166667],\n       [0.22222222, 0.54166667, 0.11864407, 0.16666667],\n       [0.13888889, 0.58333333, 0.15254237, 0.04166667],\n       [0.19444444, 0.41666667, 0.10169492, 0.04166667],\n       [0.19444444, 0.58333333, 0.10169492, 0.125     ],\n       [0.25      , 0.625     , 0.08474576, 0.04166667],\n       [0.25      , 0.58333333, 0.06779661, 0.04166667],\n       [0.11111111, 0.5       , 0.10169492, 0.04166667],\n       [0.13888889, 0.45833333, 0.10169492, 0.04166667],\n       [0.30555556, 0.58333333, 0.08474576, 0.125     ],\n       [0.25      , 0.875     , 0.08474576, 0.        ],\n       [0.33333333, 0.91666667, 0.06779661, 0.04166667],\n       [0.16666667, 0.45833333, 0.08474576, 0.04166667],\n       [0.19444444, 0.5       , 0.03389831, 0.04166667],\n       [0.33333333, 0.625     , 0.05084746, 0.04166667],\n       [0.16666667, 0.66666667, 0.06779661, 0.        ],\n       [0.02777778, 0.41666667, 0.05084746, 0.04166667],\n       [0.22222222, 0.58333333, 0.08474576, 0.04166667],\n       [0.19444444, 0.625     , 0.05084746, 0.08333333],\n       [0.05555556, 0.125     , 0.05084746, 0.08333333],\n       [0.02777778, 0.5       , 0.05084746, 0.04166667],\n       [0.19444444, 0.625     , 0.10169492, 0.20833333],\n       [0.22222222, 0.75      , 0.15254237, 0.125     ],\n       [0.13888889, 0.41666667, 0.06779661, 0.08333333],\n       [0.22222222, 0.75      , 0.10169492, 0.04166667],\n       [0.08333333, 0.5       , 0.06779661, 0.04166667],\n       [0.27777778, 0.70833333, 0.08474576, 0.04166667],\n       [0.19444444, 0.54166667, 0.06779661, 0.04166667],\n       [0.75      , 0.5       , 0.62711864, 0.54166667],\n       [0.58333333, 0.5       , 0.59322034, 0.58333333],\n       [0.72222222, 0.45833333, 0.66101695, 0.58333333],\n       [0.33333333, 0.125     , 0.50847458, 0.5       ],\n       [0.61111111, 0.33333333, 0.61016949, 0.58333333],\n       [0.38888889, 0.33333333, 0.59322034, 0.5       ],\n       [0.55555556, 0.54166667, 0.62711864, 0.625     ],\n       [0.16666667, 0.16666667, 0.38983051, 0.375     ],\n       [0.63888889, 0.375     , 0.61016949, 0.5       ],\n       [0.25      , 0.29166667, 0.49152542, 0.54166667],\n       [0.19444444, 0.        , 0.42372881, 0.375     ],\n       [0.44444444, 0.41666667, 0.54237288, 0.58333333],\n       [0.47222222, 0.08333333, 0.50847458, 0.375     ],\n       [0.5       , 0.375     , 0.62711864, 0.54166667],\n       [0.36111111, 0.375     , 0.44067797, 0.5       ],\n       [0.66666667, 0.45833333, 0.57627119, 0.54166667],\n       [0.36111111, 0.41666667, 0.59322034, 0.58333333],\n       [0.41666667, 0.29166667, 0.52542373, 0.375     ],\n       [0.52777778, 0.08333333, 0.59322034, 0.58333333],\n       [0.36111111, 0.20833333, 0.49152542, 0.41666667],\n       [0.44444444, 0.5       , 0.6440678 , 0.70833333],\n       [0.5       , 0.33333333, 0.50847458, 0.5       ],\n       [0.55555556, 0.20833333, 0.66101695, 0.58333333],\n       [0.5       , 0.33333333, 0.62711864, 0.45833333],\n       [0.58333333, 0.375     , 0.55932203, 0.5       ],\n       [0.63888889, 0.41666667, 0.57627119, 0.54166667],\n       [0.69444444, 0.33333333, 0.6440678 , 0.54166667],\n       [0.66666667, 0.41666667, 0.6779661 , 0.66666667],\n       [0.47222222, 0.375     , 0.59322034, 0.58333333],\n       [0.38888889, 0.25      , 0.42372881, 0.375     ],\n       [0.33333333, 0.16666667, 0.47457627, 0.41666667],\n       [0.33333333, 0.16666667, 0.45762712, 0.375     ],\n       [0.41666667, 0.29166667, 0.49152542, 0.45833333],\n       [0.47222222, 0.29166667, 0.69491525, 0.625     ],\n       [0.30555556, 0.41666667, 0.59322034, 0.58333333],\n       [0.47222222, 0.58333333, 0.59322034, 0.625     ],\n       [0.66666667, 0.45833333, 0.62711864, 0.58333333],\n       [0.55555556, 0.125     , 0.57627119, 0.5       ],\n       [0.36111111, 0.41666667, 0.52542373, 0.5       ],\n       [0.33333333, 0.20833333, 0.50847458, 0.5       ],\n       [0.33333333, 0.25      , 0.57627119, 0.45833333],\n       [0.5       , 0.41666667, 0.61016949, 0.54166667],\n       [0.41666667, 0.25      , 0.50847458, 0.45833333],\n       [0.19444444, 0.125     , 0.38983051, 0.375     ],\n       [0.36111111, 0.29166667, 0.54237288, 0.5       ],\n       [0.38888889, 0.41666667, 0.54237288, 0.45833333],\n       [0.38888889, 0.375     , 0.54237288, 0.5       ],\n       [0.52777778, 0.375     , 0.55932203, 0.5       ],\n       [0.22222222, 0.20833333, 0.33898305, 0.41666667],\n       [0.38888889, 0.33333333, 0.52542373, 0.5       ],\n       [0.55555556, 0.54166667, 0.84745763, 1.        ],\n       [0.41666667, 0.29166667, 0.69491525, 0.75      ],\n       [0.77777778, 0.41666667, 0.83050847, 0.83333333],\n       [0.55555556, 0.375     , 0.77966102, 0.70833333],\n       [0.61111111, 0.41666667, 0.81355932, 0.875     ],\n       [0.91666667, 0.41666667, 0.94915254, 0.83333333],\n       [0.16666667, 0.20833333, 0.59322034, 0.66666667],\n       [0.83333333, 0.375     , 0.89830508, 0.70833333],\n       [0.66666667, 0.20833333, 0.81355932, 0.70833333],\n       [0.80555556, 0.66666667, 0.86440678, 1.        ],\n       [0.61111111, 0.5       , 0.69491525, 0.79166667],\n       [0.58333333, 0.29166667, 0.72881356, 0.75      ],\n       [0.69444444, 0.41666667, 0.76271186, 0.83333333],\n       [0.38888889, 0.20833333, 0.6779661 , 0.79166667],\n       [0.41666667, 0.33333333, 0.69491525, 0.95833333],\n       [0.58333333, 0.5       , 0.72881356, 0.91666667],\n       [0.61111111, 0.41666667, 0.76271186, 0.70833333],\n       [0.94444444, 0.75      , 0.96610169, 0.875     ],\n       [0.94444444, 0.25      , 1.        , 0.91666667],\n       [0.47222222, 0.08333333, 0.6779661 , 0.58333333],\n       [0.72222222, 0.5       , 0.79661017, 0.91666667],\n       [0.36111111, 0.33333333, 0.66101695, 0.79166667],\n       [0.94444444, 0.33333333, 0.96610169, 0.79166667],\n       [0.55555556, 0.29166667, 0.66101695, 0.70833333],\n       [0.66666667, 0.54166667, 0.79661017, 0.83333333],\n       [0.80555556, 0.5       , 0.84745763, 0.70833333],\n       [0.52777778, 0.33333333, 0.6440678 , 0.70833333],\n       [0.5       , 0.41666667, 0.66101695, 0.70833333],\n       [0.58333333, 0.33333333, 0.77966102, 0.83333333],\n       [0.80555556, 0.41666667, 0.81355932, 0.625     ],\n       [0.86111111, 0.33333333, 0.86440678, 0.75      ],\n       [1.        , 0.75      , 0.91525424, 0.79166667],\n       [0.58333333, 0.33333333, 0.77966102, 0.875     ],\n       [0.55555556, 0.33333333, 0.69491525, 0.58333333],\n       [0.5       , 0.25      , 0.77966102, 0.54166667],\n       [0.94444444, 0.41666667, 0.86440678, 0.91666667],\n       [0.55555556, 0.58333333, 0.77966102, 0.95833333],\n       [0.58333333, 0.45833333, 0.76271186, 0.70833333],\n       [0.47222222, 0.41666667, 0.6440678 , 0.70833333],\n       [0.72222222, 0.45833333, 0.74576271, 0.83333333],\n       [0.66666667, 0.45833333, 0.77966102, 0.95833333],\n       [0.72222222, 0.45833333, 0.69491525, 0.91666667],\n       [0.41666667, 0.29166667, 0.69491525, 0.75      ],\n       [0.69444444, 0.5       , 0.83050847, 0.91666667],\n       [0.66666667, 0.54166667, 0.79661017, 1.        ],\n       [0.66666667, 0.41666667, 0.71186441, 0.91666667],\n       [0.55555556, 0.20833333, 0.6779661 , 0.75      ],\n       [0.61111111, 0.41666667, 0.71186441, 0.79166667],\n       [0.52777778, 0.58333333, 0.74576271, 0.91666667],\n       [0.44444444, 0.41666667, 0.69491525, 0.70833333]])<\/code><\/pre>\n<h2>1.4.3 \u8bad\u7ec3\u6a21\u578b<\/h2>\n<p>&emsp;&emsp;\u5bf9\u4e8e\u4e0d\u540c\u7684\u95ee\u9898\u9700\u8981\u8003\u8651\u4e0d\u540c\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\uff0c\u5982\u5206\u7c7b\u95ee\u9898\u4f7f\u7528\u5206\u7c7b\u7b97\u6cd5\uff1b\u56de\u5f52\u95ee\u9898\u4f7f\u7528\u56de\u5f52\u7b97\u6cd5\u2026\u2026<\/p>\n<p>&emsp;&emsp;\u5bf9\u4e8e\u9e22\u5c3e\u82b1\u5206\u7c7b\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5206\u7c7b\u95ee\u9898\uff0c\u4f46\u662f\u4f7f\u7528\u54ea\u4e2a\u5206\u7c7b\u7b97\u6cd5\u5462\uff1f\u6211\u4eec\u53ef\u4ee5\u4ecesklearn\u4f7f\u7528\u5730\u56fe\u4e2d\u83b7\u53d6\u3002<\/p>\n<p>&emsp;&emsp;\u9e22\u5c3e\u82b1\u7684\u6837\u672c\u6570\u5927\u4e8e50\u4e2a-&gt;\u5c5e\u4e8e\u5206\u7c7b\u95ee\u9898-&gt;\u6709\u5df2\u6807\u8bb0\u6570\u636e-&gt;\u6837\u672c\u6570\u5c0f\u4e8e100K-&gt;\u7ebf\u6027\u6838SVD(LinearSVC)<\/p>\n<pre><code class=\"language-python\">from sklearn.model_selection import train_test_split\n\n# \u628a\u8bad\u7ec3\u96c6\u6309\u71677:3\u7684\u6bd4\u4f8b\u5206\u6210\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1\/3)\n&#039;\u8bad\u7ec3\u96c6\u957f\u5ea6:{}&#039;.format(len(y_train)), &#039;\u6d4b\u8bd5\u96c6\u957f\u5ea6:{}&#039;.format(len(y_test))<\/code><\/pre>\n<pre><code>('\u8bad\u7ec3\u96c6\u957f\u5ea6:100', '\u6d4b\u8bd5\u96c6\u957f\u5ea6:50')<\/code><\/pre>\n<pre><code class=\"language-python\">y_train<\/code><\/pre>\n<pre><code>array([1, 0, 0, 0, 2, 1, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 0, 0, 1, 2, 0, 1,\n       1, 2, 0, 2, 0, 0, 2, 2, 2, 1, 0, 2, 0, 1, 2, 0, 1, 2, 1, 1, 0, 1,\n       1, 0, 1, 2, 2, 2, 0, 2, 2, 1, 2, 2, 1, 2, 0, 1, 0, 2, 0, 1, 1, 1,\n       0, 0, 1, 0, 2, 2, 0, 2, 0, 1, 1, 1, 1, 0, 1, 1, 2, 0, 0, 1, 1, 1,\n       2, 1, 2, 0, 2, 0, 1, 0, 1, 0, 0, 2])<\/code><\/pre>\n<pre><code class=\"language-python\">y_test<\/code><\/pre>\n<pre><code>array([1, 2, 1, 0, 0, 2, 1, 2, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 2, 1, 0, 2,\n       0, 1, 2, 1, 2, 2, 0, 2, 2, 2, 0, 1, 2, 2, 2, 1, 2, 0, 0, 0, 1, 0,\n       1, 2, 1, 0, 0, 0])<\/code><\/pre>\n<pre><code class=\"language-python\">from sklearn.svm import SVC\n# \u540c\u7406\nfrom sklearn.svm import LinearSVC\n\n# probability=Ture\u65f6\u624d\u80fd\u6253\u5370\u5206\u7c7b\u6982\u7387\uff0c\u5373\u624d\u80fd\u4f7f\u7528\u4e0b\u9762\u7684predict_proba()\u65b9\u6cd5\nclf = SVC(kernel=&#039;linear&#039;, probability=True)\n# \u8bad\u7ec3\u6570\u636e\nclf.fit(X_train, y_train)\n# \u9884\u6d4b\u6570\u636e\u5206\u7c7b\u7ed3\u679c\ny_prd = clf.predict(X_test)\ny_prd<\/code><\/pre>\n<pre><code>array([1, 2, 1, 0, 0, 2, 1, 2, 2, 1, 2, 0, 2, 0, 0, 1, 1, 1, 2, 1, 0, 2,\n       0, 1, 2, 1, 2, 2, 0, 2, 2, 2, 0, 1, 2, 2, 2, 2, 2, 0, 0, 0, 2, 0,\n       1, 2, 1, 0, 0, 0])<\/code><\/pre>\n<pre><code class=\"language-python\">y_prd-y_test<\/code><\/pre>\n<pre><code>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,\n       0, 0, 0, 0, 0, 0])<\/code><\/pre>\n<pre><code class=\"language-python\">clf.get_params()<\/code><\/pre>\n<pre><code>{'C': 1.0,\n 'cache_size': 200,\n 'class_weight': None,\n 'coef0': 0.0,\n 'decision_function_shape': 'ovr',\n 'degree': 3,\n 'gamma': 'auto_deprecated',\n 'kernel': 'linear',\n 'max_iter': -1,\n 'probability': True,\n 'random_state': None,\n 'shrinking': True,\n 'tol': 0.001,\n 'verbose': False}<\/code><\/pre>\n<pre><code class=\"language-python\">clf.C<\/code><\/pre>\n<pre><code>1.0<\/code><\/pre>\n<pre><code class=\"language-python\">clf.set_params(C=2)<\/code><\/pre>\n<pre><code>SVC(C=2, cache_size=200, class_weight=None, coef0=0.0,\n  decision_function_shape='ovr', degree=3, gamma='auto_deprecated',\n  kernel='linear', max_iter=-1, probability=True, random_state=None,\n  shrinking=True, tol=0.001, verbose=False)<\/code><\/pre>\n<pre><code class=\"language-python\">clf.get_params()<\/code><\/pre>\n<pre><code>{'C': 2,\n 'cache_size': 200,\n 'class_weight': None,\n 'coef0': 0.0,\n 'decision_function_shape': 'ovr',\n 'degree': 3,\n 'gamma': 'auto_deprecated',\n 'kernel': 'linear',\n 'max_iter': -1,\n 'probability': True,\n 'random_state': None,\n 'shrinking': True,\n 'tol': 0.001,\n 'verbose': False}<\/code><\/pre>\n<pre><code class=\"language-python\"># \u6253\u53701-5\u884c\u7684\u6240\u6709\u5217\nclf.predict_proba(X_test)[0:5, :]<\/code><\/pre>\n<pre><code>array([[0.02073772, 0.94985386, 0.02940841],\n       [0.93450081, 0.04756914, 0.01793006],\n       [0.00769491, 0.90027802, 0.09202706],\n       [0.96549643, 0.02213395, 0.01236963],\n       [0.01035414, 0.91467105, 0.07497481]])<\/code><\/pre>\n<pre><code class=\"language-python\"># \u67e5\u770b\u6a21\u578b\u5f97\u5206\uff0c\u6b64\u5904\u4e3a\u51c6\u786e\u7387\nclf.score(X_test, y_test)<\/code><\/pre>\n<pre><code>0.96<\/code><\/pre>\n<h2>1.4.4 \u6d4b\u8bd5\u6a21\u578b<\/h2>\n<p>&emsp;&emsp;\u6d4b\u8bd5\u6a21\u578b\u5219\u662f\u5728\u7b2c\u4e8c\u90e8\u5206\u8bf4\u7684\uff0c\u4f7f\u7528\u6a21\u578b\u6027\u80fd\u5ea6\u91cf\u5de5\u5177\u6d4b\u8bd5\u6a21\u578b\u7684\u6027\u80fd\u3002\u4e0a\u4e00\u8282\u7684score\u5176\u5b9e\u5c31\u662f\u4e00\u79cd\u5ea6\u91cf\u6a21\u578b\u6027\u80fd\u7684\u5de5\u5177\uff0c\u4f46\u662fscore\u53ea\u662f\u5bf9\u6a21\u578b\u505a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8bc4\u4f30\uff0c\u6211\u4eec\u901a\u5e38\u4f7f\u7528sklearn.metircs\u4e0b\u7684\u6a21\u5757\u5ea6\u91cf\u6a21\u578b\u6027\u80fd\uff1b\u4f7f\u7528sklearn.model_selection\u4e0b\u7684\u6a21\u5757\u8bc4\u4f30\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<h3>1.4.4.1 metircs\u6d4b\u8bd5\u6a21\u578b<\/h3>\n<pre><code class=\"language-python\">from sklearn.metrics import classification_report\n\nprint(classification_report(y, clf.predict(X), target_names=iris.target_names))<\/code><\/pre>\n<pre><code>              precision    recall  f1-score   support\n\n      setosa       1.00      1.00      1.00        50\n  versicolor       1.00      0.96      0.98        50\n   virginica       0.96      1.00      0.98        50\n\n   micro avg       0.99      0.99      0.99       150\n   macro avg       0.99      0.99      0.99       150\nweighted avg       0.99      0.99      0.99       150<\/code><\/pre>\n<h3>1.4.4.2 k\u6298\u4ea4\u53c9\u9a8c\u8bc1<\/h3>\n<p>\u6b64\u5904\u4f7f\u7528k\u6298\u4ea4\u53c9\u9a8c\u8bc1\u5ea6\u91cf\u6a21\u578b\u6027\u80fd\u3002<\/p>\n<p>&emsp;&emsp;k\u6298\u4ea4\u53c9\u9a8c\u8bc1\uff1a<\/p>\n<ul>\n<li>\u5c06\u6570\u636e\u968f\u673a\u7684\u5206\u4e3a?\u4e2a\u5b50\u96c6\uff08?\u7684\u53d6\u503c\u8303\u56f4\u4e00\u822c\u5728[1\u221220]\u4e4b\u95f4\uff09\uff0c\u7136\u540e\u53d6\u51fa?\u22121\u4e2a\u5b50\u96c6\u8fdb\u884c\u8bad\u7ec3\uff0c\u53e6\u4e00\u4e2a\u5b50\u96c6\u7528\u4f5c\u6d4b\u8bd5\u6a21\u578b\uff0c\u91cd\u590d?\u6b21\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u5f97\u5230\u6700\u4f18\u6a21\u578b\u3002<\/li>\n<\/ul>\n<ol>\n<li>\u5c06\u6570\u636e\u5206\u4e3a$k$\u4e2a\u5b50\u96c6<\/li>\n<li>\u9009\u62e9$k-1$\u4e2a\u5b50\u96c6\u8bad\u7ec3\u6a21\u578b<\/li>\n<li>\u9009\u62e9\u53e6\u4e00\u4e2a\u5b50\u96c6\u6d4b\u8bd5\u6a21\u578b<\/li>\n<li>\u91cd\u590d2-3\u6b65\uff0c\u76f4\u81f3\u6709$k$\u4e2a\u6a21\u578b<\/li>\n<li>\u5bf9$k$\u4e2a\u6a21\u578b\u7684\u9884\u6d4b\u7ed3\u679c\u53d6\u5e73\u5747\u503c<\/li>\n<\/ol>\n<p>&emsp;&emsp;\u4e0b\u56fe\u4e3a10\u6298\u4ea4\u53c9\u9a8c\u8bc1\u793a\u610f\u56fe\u3002<\/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-pTFy8dnD-1583320447319)(\u7b2c\u56db\u90e8\u5206-10\u6298\u4ea4\u53c9\u9a8c\u8bc1.jpg)]<\/p>\n<pre><code class=\"language-python\">from sklearn.model_selection import cross_val_score\n\n# 10\u4e2a\u6a21\u578b\u7684\u5404\u81ea\u5f97\u5206\nscores = cross_val_score(clf, X, y, cv=10)\nscores<\/code><\/pre>\n<pre><code>array([1.        , 1.        , 1.        , 1.        , 0.86666667,\n       1.        , 0.93333333, 1.        , 1.        , 1.        ])<\/code><\/pre>\n<pre><code class=\"language-python\"># \u5e73\u5747\u5f97\u5206\u548c\u7f6e\u4fe1\u533a\u95f4\nprint(&#039;\u51c6\u786e\u7387:{:.4f}(+\/-{:.4f})&#039;.format(scores.mean(), scores.std()*2))<\/code><\/pre>\n<pre><code>\u51c6\u786e\u7387:0.9800(+\/-0.0854)<\/code><\/pre>\n<h2>1.4.5 \u4f18\u5316\u6a21\u578b<\/h2>\n<p>&emsp;&emsp;\u8bad\u7ec3\u5e76\u6d4b\u8bd5\u6a21\u578b\u5df2\u7ecf\u8ba9\u6211\u4eec\u5f97\u5230\u4e86\u6700\u4f18\u7684\u53c2\u6570\uff0c\u4f18\u5316\u6a21\u578b\u5176\u5b9e\u76f8\u5f53\u4e8e\u627e\u51fa\u80fd\u591f\u4f7f\u5f97\u6a21\u578b\u6027\u80fd\u6700\u597d\u7684\u8d85\u53c2\u6570\uff0c\u4e5f\u53ef\u4ee5\u7406\u89e3\u6210\u6211\u4eec\u7684\u9a8c\u8bc1\u96c6\u7684\u4f5c\u7528\uff0c\u6b64\u5904\u6211\u4eec\u5c06\u901a\u8fc7\u7f51\u683c\u641c\u7d22\u6cd5\u4f18\u5316\u6a21\u578b\uff0c\u5f97\u5230\u76f8\u5bf9\u6700\u597d\u7684\u4e00\u7ec4\u8d85\u53c2\u6570\u3002<\/p>\n<pre><code class=\"language-python\">from sklearn.svm import SVC\nfrom sklearn.model_selection import GridSearchCV\n\n# \u6a21\u578b\nsvc = SVC()\n\n# \u8d85\u53c2\u6570\u5217\u8868\uff0c\u603b\u5171\u4f1a\u9a8c\u8bc14*4+4=20\u6b21\uff0c&#039;linear&#039;\u662f\u7ebf\u6027\u6838\uff0c\u7ebf\u6027\u6838\u8d85\u53c2\u6570\u6709\u4e00\u4e2a&#039;C&#039;\uff1brbf&#039;\u662f\u9ad8\u65af\u6838\uff0c\u9ad8\u65af\u6838\u6709\u4e24\u4e2a\u8d85\u53c2\u6570&#039;C&#039;\u548c&#039;gamma&#039;\nparam_grid = [{&#039;C&#039;: [0.1, 1, 10, 20], &#039;kernel&#039;:[&#039;linear&#039;]},\n              {&#039;C&#039;: [0.1, 1, 10, 20], &#039;kernel&#039;:[&#039;rbf&#039;], &#039;gamma&#039;:[0.1, 1, 10, 20]}]\n\n# \u6253\u5206\u51fd\u6570\nscoring = &#039;accuracy&#039;\n\nclf = GridSearchCV(estimator=svc, param_grid=param_grid,\n                   scoring=scoring, cv=10)\n\nclf = clf.fit(X, y)\nclf.predict(X)<\/code><\/pre>\n<pre><code>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n       1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,\n       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])<\/code><\/pre>\n<pre><code class=\"language-python\">clf.get_params()<\/code><\/pre>\n<pre><code>{'cv': 10,\n 'error_score': 'raise-deprecating',\n 'estimator__C': 1.0,\n 'estimator__cache_size': 200,\n 'estimator__class_weight': None,\n 'estimator__coef0': 0.0,\n 'estimator__decision_function_shape': 'ovr',\n 'estimator__degree': 3,\n 'estimator__gamma': 'auto_deprecated',\n 'estimator__kernel': 'rbf',\n 'estimator__max_iter': -1,\n 'estimator__probability': False,\n 'estimator__random_state': None,\n 'estimator__shrinking': True,\n 'estimator__tol': 0.001,\n 'estimator__verbose': False,\n 'estimator': SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,\n   decision_function_shape='ovr', degree=3, gamma='auto_deprecated',\n   kernel='rbf', max_iter=-1, probability=False, random_state=None,\n   shrinking=True, tol=0.001, verbose=False),\n 'fit_params': None,\n 'iid': 'warn',\n 'n_jobs': None,\n 'param_grid': [{'C': [0.1, 1, 10, 20], 'kernel': ['linear']},\n  {'C': [0.1, 1, 10, 20], 'kernel': ['rbf'], 'gamma': [0.1, 1, 10, 20]}],\n 'pre_dispatch': '2*n_jobs',\n 'refit': True,\n 'return_train_score': 'warn',\n 'scoring': 'accuracy',\n 'verbose': 0}<\/code><\/pre>\n<pre><code class=\"language-python\"># \u67e5\u770b\u6700\u4f18\u7684\u4e00\u7ec4\u8d85\u53c2\u6570\nclf.best_params_<\/code><\/pre>\n<pre><code>{'C': 10, 'kernel': 'linear'}<\/code><\/pre>\n<pre><code class=\"language-python\"># \u67e5\u770b\u6700\u4f18\u8d85\u53c2\u6570\u4e0b\u6a21\u578b\u7684\u51c6\u786e\u7387\nclf.best_score_<\/code><\/pre>\n<pre><code>0.98<\/code><\/pre>\n<h2>1.4.6 \u6301\u4e45\u5316\u6a21\u578b<\/h2>\n<p>&emsp;&emsp;\u4f7f\u7528\u7f51\u683c\u641c\u7d22\u5f97\u5230\u7684\u6a21\u578b\u7684\u51c6\u786e\u7387\u67090.98\uff0c\u5df2\u7ecf\u662f\u6bd4\u8f83\u597d\u7684\u4e00\u4e2a\u6a21\u578b\u4e86\uff0c\u5f97\u5230\u8fd9\u4e2a\u6a21\u578b\u4e4b\u540e\uff0c\u6211\u4eec\u600e\u4e48\u6837\u624d\u80fd\u505a\u5230\u4e0b\u6b21\u518d\u4f7f\u7528\u5462\uff1f\u4e00\u822c\u4f1a\u901a\u8fc7\u6301\u4e45\u5316\u6a21\u578b\u7684\u65b9\u5f0f\u628a\u4e0a\u8ff0\u6a21\u578b\u4fdd\u5b58\u5230.plk\u6587\u4ef6\u4e2d\uff0c\u4e0b\u6b21\u4ece.plk\u6587\u4ef6\u4e2d\u53d6\u51fa\u76f4\u63a5\u4f7f\u7528\u5373\u53ef\uff0c\u901a\u5e38\u6301\u4e45\u5316\u7684\u65b9\u5f0f\u53ea\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u901a\u8fc7Python\u81ea\u5e26pickle\u5e93\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7sklearn\u5e93\u4e0b\u7684joblib\u6a21\u5757\u3002<\/p>\n<h3>1.4.6.1 pickle\u6a21\u5757<\/h3>\n<pre><code class=\"language-python\">import pickle\n\n# \u4f7f\u7528pickle\u6a21\u5757\u628a\u6a21\u578b\u5e8f\u5217\u5316\u6210\u5b57\u7b26\u4e32\npkl_str = pickle.dumps(clf)\npkl_str[0:100]<\/code><\/pre>\n<pre><code>b'\\x80\\x03csklearn.model_selection._search\\nGridSearchCV\\nq\\x00)\\x81q\\x01}q\\x02(X\\x07\\x00\\x00\\x00scoringq\\x03X\\x08\\x00\\x00\\x00accuracyq\\x04X\\t\\x00\\x00\\x00estimato'<\/code><\/pre>\n<pre><code class=\"language-python\"># \u4f7f\u7528pickel\u6a21\u5757\u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\u6210\u4e3a\u6a21\u578b\nclf2 = pickle.loads(pkl_str)\nclf2.predict(X)<\/code><\/pre>\n<pre><code>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n       1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,\n       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])<\/code><\/pre>\n<h3>1.4.6.2 joblib\u6a21\u5757<\/h3>\n<pre><code class=\"language-python\">from sklearn.externals import joblib\n\n# \u4fdd\u5b58\u6a21\u578b\u5230clf.pkl\u6587\u4ef6\u5185\njoblib.dump(clf, &#039;clf.pkl&#039;)\n# \u4ececlf.pkl\u6587\u4ef6\u5185\u52a0\u8f7d\u6a21\u578b\nclf3 = joblib.load(&#039;clf.pkl&#039;)\nclf3.predict(X)<\/code><\/pre>\n<pre><code>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n       1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,\n       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ec6\u5206\u6784\u5efa\u673a\u5668\u5b66\u4e60\u5e94\u7528\u7a0b\u5e8f\u7684\u6d41\u7a0b-\u6d41\u7a0b\u7b80\u4ecb 1.1 sklearn\u5b89\u88c5 &emsp;&emsp;\u4e3a\u4e86\u5b9e\u73b0\u63a5\u4e0b\u91cc\u7684 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3275,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[276,301],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3270"}],"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=3270"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/3270\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/3275"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}