{"id":6065,"date":"2024-05-29T14:11:31","date_gmt":"2024-05-29T06:11:31","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6065"},"modified":"2024-05-29T14:11:33","modified_gmt":"2024-05-29T06:11:33","slug":"sklearn-%e7%9a%84%e5%87%a0%e7%a7%8d%e6%97%a0%e7%9b%91%e7%9d%a3%e5%ad%a6%e4%b9%a0%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6065","title":{"rendered":"sklearn \u7684\u51e0\u79cd\u65e0\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">ChatGPT \u95ee\u7b54\u751f\u6210\uff0c\u975e\u539f\u521b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scikit-learn \u63d0\u4f9b\u4e86\u591a\u79cd\u65e0\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\uff0c\u6bcf\u79cd\u7b97\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u7406\u5ff5\u548c\u5173\u952e\u70b9\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u7528\u7684\u65e0\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\u53ca\u5176\u7406\u5ff5\u548c\u5173\u952e\u70b9\u7684\u7b80\u8981\u4ecb\u7ecd\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. K-means \u805a\u7c7b\uff08K-means Clustering\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aK-means \u901a\u8fc7\u5c06\u6570\u636e\u70b9\u5206\u914d\u5230 K \u4e2a\u7c07\u4e2d\uff0c\u4f7f\u6bcf\u4e2a\u7c07\u5185\u7684\u6570\u636e\u70b9\u5c3d\u53ef\u80fd\u76f8\u4f3c\uff0c\u800c\u7c07\u4e4b\u95f4\u5c3d\u53ef\u80fd\u4e0d\u540c\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u521d\u59cb\u4e2d\u5fc3\uff1a\u9009\u62e9 K \u4e2a\u521d\u59cb\u4e2d\u5fc3\u70b9\uff08\u53ef\u4ee5\u968f\u673a\u9009\u62e9\u6216\u4f7f\u7528 k-means++\uff09\u3002<\/li>\n\n\n\n<li>\u5206\u914d\u548c\u66f4\u65b0\uff1a\u53cd\u590d\u5206\u914d\u6bcf\u4e2a\u6570\u636e\u70b9\u5230\u6700\u8fd1\u7684\u4e2d\u5fc3\uff0c\u5e76\u66f4\u65b0\u4e2d\u5fc3\u4e3a\u7c07\u4e2d\u6240\u6709\u70b9\u7684\u5e73\u5747\u503c\uff0c\u76f4\u5230\u6536\u655b\u3002<\/li>\n\n\n\n<li>\u6536\u655b\uff1a\u5f53\u4e2d\u5fc3\u70b9\u4e0d\u518d\u53d1\u751f\u53d8\u5316\u6216\u53d8\u5316\u5f88\u5c0f\u65f6\u505c\u6b62\u8fed\u4ee3\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.cluster import KMeans\n\nmodel = KMeans(n_clusters=3)\nmodel.fit(X)\nlabels = model.labels_<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5c42\u6b21\u805a\u7c7b\uff08Hierarchical Clustering\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u5c42\u6b21\u805a\u7c7b\u901a\u8fc7\u6784\u5efa\u4e00\u4e2a\u5c42\u6b21\u7ed3\u6784\uff0c\u5c06\u6570\u636e\u70b9\u805a\u96c6\u5230\u6811\u72b6\u7ed3\u6784\uff08\u6811\u72b6\u56fe\u6216\u5c42\u6b21\u6811\uff09\u4e2d\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u81ea\u5e95\u5411\u4e0a\uff08\u51dd\u805a\u5c42\u6b21\u805a\u7c7b\uff09\uff1a\u6bcf\u4e2a\u6570\u636e\u70b9\u5f00\u59cb\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u7c07\uff0c\u4e0d\u65ad\u5408\u5e76\u6700\u76f8\u4f3c\u7684\u7c07\uff0c\u76f4\u5230\u6240\u6709\u6570\u636e\u70b9\u805a\u4e3a\u4e00\u4e2a\u7c07\u3002<\/li>\n\n\n\n<li>\u81ea\u9876\u5411\u4e0b\uff08\u5206\u88c2\u5c42\u6b21\u805a\u7c7b\uff09\uff1a\u4ece\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6570\u636e\u70b9\u7684\u7c07\u5f00\u59cb\uff0c\u4e0d\u65ad\u5206\u88c2\u6210\u66f4\u5c0f\u7684\u7c07\uff0c\u76f4\u5230\u6bcf\u4e2a\u7c07\u53ea\u5305\u542b\u4e00\u4e2a\u6570\u636e\u70b9\u3002<\/li>\n\n\n\n<li>\u8ddd\u79bb\u5ea6\u91cf\uff1a\u4f7f\u7528\u4e0d\u540c\u7684\u8ddd\u79bb\u5ea6\u91cf\uff08\u5982\u5355\u94fe\u3001\u5168\u94fe\u3001\u5e73\u5747\u94fe\uff09\u6765\u51b3\u5b9a\u7c07\u4e4b\u95f4\u7684\u76f8\u4f3c\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.cluster import AgglomerativeClustering\n\nmodel = AgglomerativeClustering(n_clusters=3)\nlabels = model.fit_predict(X)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. DBSCAN\uff08Density-Based Spatial Clustering of Applications with Noise\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aDBSCAN \u901a\u8fc7\u8bc6\u522b\u5bc6\u5ea6\u76f8\u8fde\u7684\u533a\u57df\u6765\u53d1\u73b0\u7c07\uff0c\u540c\u65f6\u53ef\u4ee5\u8bc6\u522b\u566a\u58f0\u70b9\uff08\u4e0d\u5c5e\u4e8e\u4efb\u4f55\u7c07\u7684\u70b9\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u6838\u5fc3\u70b9\uff1a\u5728\u6307\u5b9a\u534a\u5f84\u5185\u5305\u542b\u81f3\u5c11\u6700\u5c0f\u6570\u91cf\u70b9\u7684\u70b9\u3002<\/li>\n\n\n\n<li>\u8fb9\u754c\u70b9\uff1a\u5728\u6838\u5fc3\u70b9\u534a\u5f84\u5185\u4f46\u4e0d\u6ee1\u8db3\u6838\u5fc3\u70b9\u6761\u4ef6\u7684\u70b9\u3002<\/li>\n\n\n\n<li>\u566a\u58f0\u70b9\uff1a\u65e2\u4e0d\u5c5e\u4e8e\u6838\u5fc3\u70b9\u4e5f\u4e0d\u5c5e\u4e8e\u8fb9\u754c\u70b9\u7684\u70b9\u3002<\/li>\n\n\n\n<li>\u7c07\u5f62\u6210\uff1a\u901a\u8fc7\u8fde\u63a5\u5bc6\u5ea6\u76f8\u8fde\u7684\u6838\u5fc3\u70b9\u5f62\u6210\u7c07\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.cluster import DBSCAN\n\nmodel = DBSCAN(eps=0.5, min_samples=5)\nlabels = model.fit_predict(X)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u4e3b\u6210\u5206\u5206\u6790\uff08PCA, Principal Component Analysis\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aPCA \u901a\u8fc7\u7ebf\u6027\u53d8\u6362\u5c06\u9ad8\u7ef4\u6570\u636e\u964d\u5230\u4f4e\u7ef4\u7a7a\u95f4\uff0c\u540c\u65f6\u5c3d\u53ef\u80fd\u4fdd\u7559\u6570\u636e\u7684\u65b9\u5dee\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u65b9\u5dee\u6700\u5927\u5316\uff1a\u9009\u62e9\u90a3\u4e9b\u80fd\u591f\u89e3\u91ca\u6570\u636e\u6700\u5927\u65b9\u5dee\u7684\u65b9\u5411\u4f5c\u4e3a\u4e3b\u6210\u5206\u3002<\/li>\n\n\n\n<li>\u7ebf\u6027\u53d8\u6362\uff1a\u6570\u636e\u70b9\u5728\u65b0\u7a7a\u95f4\u4e2d\u7684\u6295\u5f71\u4ecd\u7136\u4fdd\u6301\u5c3d\u53ef\u80fd\u591a\u7684\u539f\u59cb\u6570\u636e\u7279\u5f81\u3002<\/li>\n\n\n\n<li>\u964d\u7ef4\uff1a\u901a\u8fc7\u9009\u62e9\u524d\u51e0\u4e2a\u4e3b\u6210\u5206\u6765\u51cf\u5c11\u6570\u636e\u7ef4\u5ea6\uff0c\u4ece\u800c\u7b80\u5316\u6570\u636e\u548c\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.decomposition import PCA\n\nmodel = PCA(n_components=2)\nX_reduced = model.fit_transform(X)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u72ec\u7acb\u6210\u5206\u5206\u6790\uff08ICA, Independent Component Analysis\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aICA \u901a\u8fc7\u5c06\u591a\u53d8\u91cf\u4fe1\u53f7\u5206\u89e3\u6210\u5f7c\u6b64\u72ec\u7acb\u7684\u975e\u9ad8\u65af\u4fe1\u53f7\u6e90\uff0c\u5e38\u7528\u4e8e\u76f2\u4fe1\u53f7\u5206\u79bb\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u975e\u9ad8\u65af\u6027\u6700\u5927\u5316\uff1a\u5047\u8bbe\u4fe1\u53f7\u6e90\u662f\u975e\u9ad8\u65af\u5206\u5e03\uff0c\u5c3d\u91cf\u4f7f\u5f97\u5206\u89e3\u540e\u7684\u5206\u91cf\u5f7c\u6b64\u72ec\u7acb\u3002<\/li>\n\n\n\n<li>\u76f2\u4fe1\u53f7\u5206\u79bb\uff1a\u65e0\u9700\u5148\u9a8c\u77e5\u8bc6\uff0c\u901a\u8fc7\u7b97\u6cd5\u4ece\u89c2\u6d4b\u4fe1\u53f7\u4e2d\u5206\u79bb\u51fa\u72ec\u7acb\u4fe1\u53f7\u6e90\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u9884\u5904\u7406\uff1a\u901a\u5e38\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u767d\u5316\u5904\u7406\uff0c\u4ee5\u53bb\u9664\u5197\u4f59\u4fe1\u606f\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.decomposition import FastICA\n\nmodel = FastICA(n_components=2)\nX_independent = model.fit_transform(X)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u56e0\u5b50\u5206\u6790\uff08FA, Factor Analysis\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u56e0\u5b50\u5206\u6790\u5047\u8bbe\u89c2\u6d4b\u6570\u636e\u662f\u7531\u5c11\u6570\u51e0\u4e2a\u672a\u89c2\u6d4b\u7684\u6f5c\u5728\u53d8\u91cf\uff08\u56e0\u5b50\uff09\u7ebf\u6027\u7ec4\u5408\u52a0\u4e0a\u566a\u58f0\u5f62\u6210\u7684\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u6f5c\u5728\u53d8\u91cf\uff1a\u901a\u8fc7\u63d0\u53d6\u6f5c\u5728\u56e0\u5b50\u6765\u89e3\u91ca\u89c2\u6d4b\u6570\u636e\u4e4b\u95f4\u7684\u76f8\u5173\u6027\u3002<\/li>\n\n\n\n<li>\u7ebf\u6027\u6a21\u578b\uff1a\u5047\u8bbe\u89c2\u6d4b\u53d8\u91cf\u662f\u56e0\u5b50\u548c\u8bef\u5dee\u9879\u7684\u7ebf\u6027\u7ec4\u5408\u3002<\/li>\n\n\n\n<li>\u65b9\u5dee\u89e3\u91ca\uff1a\u76ee\u6807\u662f\u627e\u5230\u80fd\u591f\u89e3\u91ca\u5927\u90e8\u5206\u89c2\u6d4b\u6570\u636e\u65b9\u5dee\u7684\u56e0\u5b50\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.decomposition import FactorAnalysis\n\nmodel = FactorAnalysis(n_components=2)\nX_factors = model.fit_transform(X)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u5947\u5f02\u503c\u5206\u89e3\uff08SVD, Singular Value Decomposition\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aSVD \u901a\u8fc7\u5c06\u77e9\u9635\u5206\u89e3\u4e3a\u4e09\u4e2a\u5b50\u77e9\u9635\uff08U\u3001\u03a3 \u548c V\uff09\uff0c\u7528\u4e8e\u6570\u636e\u964d\u7ef4\u548c\u77e9\u9635\u8fd1\u4f3c\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u5206\u89e3\uff1a\u5c06\u539f\u59cb\u77e9\u9635\u5206\u89e3\u4e3a\u5de6\u5947\u5f02\u77e9\u9635\u3001\u5947\u5f02\u503c\u5bf9\u89d2\u77e9\u9635\u548c\u53f3\u5947\u5f02\u77e9\u9635\u7684\u4e58\u79ef\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u964d\u7ef4\uff1a\u901a\u8fc7\u4fdd\u7559\u6700\u5927\u7684\u5947\u5f02\u503c\u5bf9\u5e94\u7684\u90e8\u5206\u6765\u8fd1\u4f3c\u539f\u59cb\u77e9\u9635\uff0c\u4ece\u800c\u51cf\u5c11\u6570\u636e\u7ef4\u5ea6\u3002<\/li>\n\n\n\n<li>\u4fe1\u606f\u538b\u7f29\uff1a\u7528\u4e8e\u4fe1\u606f\u68c0\u7d22\u3001\u56fe\u50cf\u538b\u7f29\u7b49\u573a\u666f\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.decomposition import TruncatedSVD\n\nmodel = TruncatedSVD(n_components=2)\nX_reduced = model.fit_transform(X)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u65e0\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\u5728\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u548c\u4efb\u52a1\u65f6\u5177\u6709\u5404\u81ea\u7684\u4f18\u52bf\u3002\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u9700\u8981\u6839\u636e\u6570\u636e\u7684\u7279\u6027\u548c\u4efb\u52a1\u7684\u5177\u4f53\u9700\u6c42\u8fdb\u884c\u6743\u8861\u3002\u7406\u89e3\u6bcf\u79cd\u7b97\u6cd5\u7684\u7406\u5ff5\u548c\u5173\u952e\u70b9\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5e94\u7528\u8fd9\u4e9b\u7b97\u6cd5\u6765\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ChatGPT \u95ee\u7b54\u751f\u6210\uff0c\u975e\u539f\u521b Scikit-learn \u63d0\u4f9b\u4e86\u591a\u79cd\u65e0\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\uff0c\u6bcf\u79cd\u7b97\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u7406\u5ff5&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6065\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[53,56,51],"class_list":["post-6065","post","type-post","status-publish","format-standard","hentry","category-5","tag-llm","tag-56","tag-51"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6065"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6065\/revisions"}],"predecessor-version":[{"id":6066,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6065\/revisions\/6066"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}