{"id":6063,"date":"2024-05-29T14:05:27","date_gmt":"2024-05-29T06:05:27","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6063"},"modified":"2024-05-29T14:05:28","modified_gmt":"2024-05-29T06:05:28","slug":"sklearn-%e7%9a%84%e5%87%a0%e7%a7%8d%e7%9b%91%e7%9d%a3%e5%ad%a6%e4%b9%a0%e7%ae%97%e6%b3%95%e3%80%81%e5%85%b3%e9%94%ae%e7%82%b9%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6063","title":{"rendered":"sklearn \u7684\u51e0\u79cd\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\u3001\u5173\u952e\u70b9\u4ecb\u7ecd"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u975e\u539f\u521b\uff0cChatGPT \u95ee\u7b54\u751f\u6210<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scikit-learn \u63d0\u4f9b\u4e86\u591a\u79cd\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\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. \u7ebf\u6027\u56de\u5f52\uff08Linear Regression\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u7ebf\u6027\u56de\u5f52\u8bd5\u56fe\u627e\u5230\u8f93\u5165\u7279\u5f81\u548c\u76ee\u6807\u53d8\u91cf\u4e4b\u95f4\u7684\u7ebf\u6027\u5173\u7cfb\uff0c\u5373\u76ee\u6807\u53d8\u91cf\u53ef\u4ee5\u8868\u793a\u4e3a\u8f93\u5165\u7279\u5f81\u7684\u7ebf\u6027\u7ec4\u5408\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u5047\u8bbe\u7ebf\u6027\u5173\u7cfb\uff1a\u5047\u5b9a\u76ee\u6807\u53d8\u91cf\u4e0e\u8f93\u5165\u7279\u5f81\u4e4b\u95f4\u7684\u5173\u7cfb\u662f\u7ebf\u6027\u7684\u3002<\/li>\n\n\n\n<li>\u6700\u5c0f\u5316\u6b8b\u5dee\u5e73\u65b9\u548c\uff1a\u901a\u8fc7\u6700\u5c0f\u5316\u9884\u6d4b\u503c\u548c\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u6b8b\u5dee\u5e73\u65b9\u548c\u6765\u627e\u5230\u6700\u4f73\u62df\u5408\u7ebf\u3002<\/li>\n\n\n\n<li>\u9002\u7528\u6027\uff1a\u9002\u7528\u4e8e\u6570\u503c\u578b\u76ee\u6807\u53d8\u91cf\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.linear_model import LinearRegression\n\nmodel = LinearRegression()\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u903b\u8f91\u56de\u5f52\uff08Logistic Regression\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u903b\u8f91\u56de\u5f52\u7528\u4e8e\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u901a\u8fc7\u4f30\u8ba1\u6570\u636e\u70b9\u5c5e\u4e8e\u67d0\u4e00\u7c7b\u522b\u7684\u6982\u7387\uff0c\u8f93\u51fa\u503c\u88ab\u9650\u5236\u57280\u52301\u4e4b\u95f4\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>Sigmoid\u51fd\u6570\uff1a\u4f7f\u7528Sigmoid\u51fd\u6570\u5c06\u7ebf\u6027\u7ec4\u5408\u7684\u7ed3\u679c\u6620\u5c04\u52300\u52301\u4e4b\u95f4\u3002<\/li>\n\n\n\n<li>\u5bf9\u6570\u51e0\u7387\uff1a\u8f93\u51fa\u7684\u662f\u5c5e\u4e8e\u67d0\u4e00\u7c7b\u522b\u7684\u5bf9\u6570\u51e0\u7387\uff08log odds\uff09\u3002<\/li>\n\n\n\n<li>\u9002\u7528\u6027\uff1a\u9002\u7528\u4e8e\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u6269\u5c55\u5230\u591a\u5206\u7c7b\uff08softmax\u56de\u5f52\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.linear_model import LogisticRegression\n\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u652f\u6301\u5411\u91cf\u673a\uff08SVM, Support Vector Machine\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aSVM\u901a\u8fc7\u5728\u9ad8\u7ef4\u7a7a\u95f4\u4e2d\u627e\u5230\u4e00\u4e2a\u6700\u4f18\u7684\u8d85\u5e73\u9762\u6765\u6700\u5927\u5316\u7c7b\u522b\u4e4b\u95f4\u7684\u8fb9\u754c\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u6700\u5927\u5316\u8fb9\u754c\uff1a\u9009\u62e9\u4e00\u4e2a\u4f7f\u5f97\u5206\u7c7b\u95f4\u9694\uff08margin\uff09\u6700\u5927\u7684\u8d85\u5e73\u9762\u3002<\/li>\n\n\n\n<li>\u652f\u6301\u5411\u91cf\uff1a\u4ec5\u4f9d\u8d56\u4e8e\u6700\u63a5\u8fd1\u8d85\u5e73\u9762\u7684\u90a3\u4e9b\u70b9\uff08\u652f\u6301\u5411\u91cf\uff09\u6765\u51b3\u5b9a\u5206\u7c7b\u8fb9\u754c\u3002<\/li>\n\n\n\n<li>\u6838\u65b9\u6cd5\uff1a\u901a\u8fc7\u6838\u51fd\u6570\u5c06\u4f4e\u7ef4\u6570\u636e\u6620\u5c04\u5230\u9ad8\u7ef4\u7a7a\u95f4\uff0c\u4f7f\u5f97\u975e\u7ebf\u6027\u53ef\u5206\u7684\u6570\u636e\u7ebf\u6027\u53ef\u5206\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.svm import SVC\n\nmodel = SVC(kernel='linear')\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. K\u8fd1\u90bb\uff08K-Nearest Neighbors, KNN\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1aKNN\u901a\u8fc7\u8003\u8651\u6570\u636e\u96c6\u4e2d\u4e0e\u76ee\u6807\u6570\u636e\u70b9\u6700\u63a5\u8fd1\u7684K\u4e2a\u90bb\u5c45\u7684\u7c7b\u522b\u6765\u8fdb\u884c\u5206\u7c7b\u6216\u56de\u5f52\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u8ddd\u79bb\u5ea6\u91cf\uff1a\u5e38\u7528\u6b27\u6c0f\u8ddd\u79bb\u6765\u8ba1\u7b97\u6570\u636e\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002<\/li>\n\n\n\n<li>\u591a\u6570\u8868\u51b3\uff1a\u5206\u7c7b\u4efb\u52a1\u4e2d\uff0c\u76ee\u6807\u70b9\u7684\u7c7b\u522b\u7531K\u4e2a\u90bb\u5c45\u4e2d\u591a\u6570\u7c7b\u522b\u51b3\u5b9a\uff1b\u56de\u5f52\u4efb\u52a1\u4e2d\uff0c\u76ee\u6807\u70b9\u7684\u503c\u7531K\u4e2a\u90bb\u5c45\u7684\u5e73\u5747\u503c\u51b3\u5b9a\u3002<\/li>\n\n\n\n<li>\u8ba1\u7b97\u6210\u672c\uff1a\u9700\u8981\u8ba1\u7b97\u76ee\u6807\u70b9\u4e0e\u6240\u6709\u8bad\u7ec3\u70b9\u7684\u8ddd\u79bb\uff0c\u8ba1\u7b97\u6210\u672c\u8f83\u9ad8\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.neighbors import KNeighborsClassifier\n\nmodel = KNeighborsClassifier(n_neighbors=5)\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u51b3\u7b56\u6811\uff08Decision Tree\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u51b3\u7b56\u6811\u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u51b3\u7b56\u89c4\u5219\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u591a\u4e2a\u5b50\u96c6\uff0c\u5f62\u6210\u4e00\u4e2a\u6811\u72b6\u7ed3\u6784\uff0c\u7528\u4e8e\u5206\u7c7b\u6216\u56de\u5f52\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u9012\u5f52\u5212\u5206\uff1a\u9012\u5f52\u5730\u5c06\u6570\u636e\u96c6\u5212\u5206\u4e3a\u66f4\u5c0f\u7684\u5b50\u96c6\uff0c\u76f4\u5230\u6ee1\u8db3\u67d0\u4e2a\u505c\u6b62\u6761\u4ef6\u3002<\/li>\n\n\n\n<li>\u4fe1\u606f\u589e\u76ca\uff1a\u9009\u62e9\u80fd\u591f\u6700\u5927\u5316\u4fe1\u606f\u589e\u76ca\u6216\u6700\u5c0f\u5316\u4e0d\u7eaf\u5ea6\u7684\u7279\u5f81\u8fdb\u884c\u5212\u5206\u3002<\/li>\n\n\n\n<li>\u53ef\u89e3\u91ca\u6027\uff1a\u51b3\u7b56\u6811\u7ed3\u6784\u76f4\u89c2\u6613\u61c2\uff0c\u53ef\u4ee5\u89e3\u91ca\u51b3\u7b56\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.tree import DecisionTreeClassifier\n\nmodel = DecisionTreeClassifier()\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u968f\u673a\u68ee\u6797\uff08Random Forest\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u968f\u673a\u68ee\u6797\u901a\u8fc7\u6784\u5efa\u591a\u4e2a\u51b3\u7b56\u6811\u5e76\u7ed3\u5408\u5b83\u4eec\u7684\u9884\u6d4b\u7ed3\u679c\u6765\u63d0\u9ad8\u6a21\u578b\u7684\u51c6\u786e\u6027\u548c\u9c81\u68d2\u6027\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u96c6\u6210\u65b9\u6cd5\uff1a\u7ed3\u5408\u591a\u4e2a\u51b3\u7b56\u6811\u7684\u9884\u6d4b\u7ed3\u679c\u8fdb\u884c\u5206\u7c7b\u6216\u56de\u5f52\uff0c\u901a\u5e38\u91c7\u7528\u591a\u6570\u6295\u7968\uff08\u5206\u7c7b\uff09\u6216\u5e73\u5747\u503c\uff08\u56de\u5f52\uff09\u3002<\/li>\n\n\n\n<li>\u968f\u673a\u6027\uff1a\u901a\u8fc7\u968f\u673a\u9009\u62e9\u7279\u5f81\u548c\u6570\u636e\u5b50\u96c6\u6765\u6784\u5efa\u6bcf\u4e2a\u51b3\u7b56\u6811\uff0c\u589e\u52a0\u6a21\u578b\u7684\u591a\u6837\u6027\u3002<\/li>\n\n\n\n<li>\u51cf\u5c11\u8fc7\u62df\u5408\uff1a\u901a\u8fc7\u96c6\u6210\u591a\u4e2a\u51b3\u7b56\u6811\u51cf\u5c11\u5355\u4e2a\u6811\u7684\u8fc7\u62df\u5408\u98ce\u9669\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.ensemble import RandomForestClassifier\n\nmodel = RandomForestClassifier(n_estimators=100)\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u68af\u5ea6\u63d0\u5347\u6811\uff08Gradient Boosting Trees\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7406\u5ff5<\/strong>\uff1a\u68af\u5ea6\u63d0\u5347\u6811\u901a\u8fc7\u9010\u6b65\u6784\u5efa\u51b3\u7b56\u6811\uff0c\u6bcf\u4e2a\u65b0\u6811\u90fd\u5728\u524d\u4e00\u4e2a\u6811\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u6539\u8fdb\uff0c\u9010\u6b65\u51cf\u5c11\u9884\u6d4b\u8bef\u5dee\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u987a\u5e8f\u8bad\u7ec3\uff1a\u6bcf\u68f5\u6811\u4f9d\u6b21\u8bad\u7ec3\uff0c\u6bcf\u6b21\u8bad\u7ec3\u65f6\u5c1d\u8bd5\u7ea0\u6b63\u524d\u4e00\u68f5\u6811\u7684\u8bef\u5dee\u3002<\/li>\n\n\n\n<li>\u52a0\u6743\u6c42\u548c\uff1a\u6700\u7ec8\u6a21\u578b\u662f\u6240\u6709\u6811\u7684\u52a0\u6743\u6c42\u548c\u3002<\/li>\n\n\n\n<li>\u5b66\u4e60\u7387\uff1a\u63a7\u5236\u6bcf\u68f5\u6811\u5bf9\u6700\u7ec8\u9884\u6d4b\u7684\u5f71\u54cd\uff0c\u9632\u6b62\u8fc7\u62df\u5408\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.ensemble import GradientBoostingClassifier\n\nmodel = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1)\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u7b97\u6cd5\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u6709\u7740\u4e0d\u540c\u7684\u4f18\u52bf\u548c\u9002\u7528\u573a\u666f\uff0c\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u6570\u636e\u548c\u4efb\u52a1\u9700\u6c42\u8fdb\u884c\u6743\u8861\u3002\u901a\u8fc7\u7406\u89e3\u6bcf\u79cd\u7b97\u6cd5\u7684\u7406\u5ff5\u548c\u5173\u952e\u70b9\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u9009\u62e9\u548c\u8c03\u6574\u6a21\u578b\uff0c\u4ee5\u83b7\u5f97\u6700\u4f73\u7684\u9884\u6d4b\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\uff0cChatGPT \u95ee\u7b54\u751f\u6210 Scikit-learn \u63d0\u4f9b\u4e86\u591a\u79cd\u76d1\u7763\u5b66\u4e60\u7b97\u6cd5\uff0c\u6bcf\u79cd\u7b97\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u7406\u5ff5\u548c&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6063\">\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,52,56,51],"class_list":["post-6063","post","type-post","status-publish","format-standard","hentry","category-5","tag-llm","tag-52","tag-56","tag-51"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6063","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=6063"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6063\/revisions"}],"predecessor-version":[{"id":6064,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6063\/revisions\/6064"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}