{"id":6128,"date":"2024-06-13T19:30:11","date_gmt":"2024-06-13T11:30:11","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6128"},"modified":"2024-06-13T19:30:12","modified_gmt":"2024-06-13T11:30:12","slug":"%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e6%95%b0%e6%8d%ae%e9%a2%84%e5%a4%84%e7%90%86%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e6%95%b0%e6%8d%ae%e7%89%b9%e5%be%81%e4%b8%8d%e5%b9%b3%e8%a1%a1%e7%9a%84%e9%97%ae","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6128","title":{"rendered":"[\u673a\u5668\u5b66\u4e60]\u6570\u636e\u9884\u5904\u7406\u5982\u4f55\u89e3\u51b3\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\u7684\u95ee\u9898"},"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\">\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\uff08class imbalance\uff09\u662f\u6307\u67d0\u4e9b\u7c7b\u522b\u7684\u6570\u636e\u6837\u672c\u6570\u91cf\u8fdc\u591a\u4e8e\u5176\u4ed6\u7c7b\u522b\u7684\u60c5\u51b5\uff0c\u8fd9\u79cd\u60c5\u51b5\u5728\u8bb8\u591a\u5b9e\u9645\u5e94\u7528\u4e2d\u90fd\u975e\u5e38\u5e38\u89c1\uff0c\u4f8b\u5982\u5728\u4fe1\u7528\u5361\u6b3a\u8bc8\u68c0\u6d4b\u3001\u75be\u75c5\u8bca\u65ad\u3001\u5f02\u5e38\u68c0\u6d4b\u7b49\u95ee\u9898\u4e2d\u3002\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\u4f1a\u5bfc\u81f4\u673a\u5668\u5b66\u4e60\u6a21\u578b\u5bf9\u5c11\u6570\u7c7b\u7684\u9884\u6d4b\u80fd\u529b\u8f83\u5dee\uff0c\u4ece\u800c\u5f71\u54cd\u6a21\u578b\u7684\u6574\u4f53\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u89e3\u51b3\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\u95ee\u9898\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6570\u636e\u91cd\u91c7\u6837\uff08Resampling\uff09<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1.1 \u6b20\u91c7\u6837\uff08Under-sampling\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u51cf\u5c11\u591a\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf\uff0c\u4f7f\u5176\u4e0e\u5c11\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf\u76f8\u5f53\u3002<\/li>\n\n\n\n<li><strong>\u65b9\u6cd5<\/strong>\uff1a\u968f\u673a\u5220\u9664\u591a\u6570\u7c7b\u6837\u672c\uff0c\u6216\u8005\u4f7f\u7528\u805a\u7c7b\u3001\u8fd1\u90bb\u7b49\u65b9\u6cd5\u9009\u62e9\u4ee3\u8868\u6027\u7684\u591a\u6570\u7c7b\u6837\u672c\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u5de5\u5177<\/strong>\uff1a<\/li>\n\n\n\n<li><code>imblearn.under_sampling<\/code>\uff1a<code>RandomUnderSampler<\/code>, <code>ClusterCentroids<\/code>, <code>TomekLinks<\/code>\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from imblearn.under_sampling import RandomUnderSampler\n  from sklearn.model_selection import train_test_split\n\n  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n  rus = RandomUnderSampler(random_state=42)\n  X_resampled, y_resampled = rus.fit_resample(X_train, y_train)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">1.2 \u8fc7\u91c7\u6837\uff08Over-sampling\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u589e\u52a0\u5c11\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf\uff0c\u4f7f\u5176\u4e0e\u591a\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf\u76f8\u5f53\u3002<\/li>\n\n\n\n<li><strong>\u65b9\u6cd5<\/strong>\uff1a\u590d\u5236\u5c11\u6570\u7c7b\u6837\u672c\uff0c\u6216\u4f7f\u7528\u5408\u6210\u6570\u636e\u751f\u6210\u65b9\u6cd5\uff08\u5982SMOTE\uff09\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u5de5\u5177<\/strong>\uff1a<\/li>\n\n\n\n<li><code>imblearn.over_sampling<\/code>\uff1a<code>RandomOverSampler<\/code>, <code>SMOTE<\/code>, <code>ADASYN<\/code>\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from imblearn.over_sampling import SMOTE\n  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n  smote = SMOTE(random_state=42)\n  X_resampled, y_resampled = smote.fit_resample(X_train, y_train)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5408\u6210\u5c11\u6570\u7c7b\u8fc7\u91c7\u6837\u6280\u672f\uff08Synthetic Minority Over-sampling Technique, SMOTE\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u539f\u7406<\/strong>\uff1a\u901a\u8fc7\u5728\u5c11\u6570\u7c7b\u6837\u672c\u4e4b\u95f4\u63d2\u503c\u751f\u6210\u65b0\u7684\u6837\u672c\uff0c\u589e\u52a0\u5c11\u6570\u7c7b\u6837\u672c\u7684\u6570\u91cf\uff0c\u907f\u514d\u7b80\u5355\u590d\u5236\u5bfc\u81f4\u7684\u8fc7\u62df\u5408\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from imblearn.over_sampling import SMOTE\n  smote = SMOTE(random_state=42)\n  X_resampled, y_resampled = smote.fit_resample(X_train, y_train)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u96c6\u6210\u65b9\u6cd5<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">3.1 \u96c6\u6210\u65b9\u6cd5\uff08Ensemble Methods\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65b9\u6cd5<\/strong>\uff1a\u4f7f\u7528\u96c6\u6210\u65b9\u6cd5\uff08\u5982\u968f\u673a\u68ee\u6797\u3001\u68af\u5ea6\u63d0\u5347\u6811\uff09\u6765\u63d0\u9ad8\u6a21\u578b\u5bf9\u5c11\u6570\u7c7b\u7684\u9884\u6d4b\u80fd\u529b\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u5de5\u5177<\/strong>\uff1a<\/li>\n\n\n\n<li><code>imbalanced-learn<\/code>\u4e2d\u7684<code>BalancedRandomForestClassifier<\/code>, <code>EasyEnsembleClassifier<\/code>, <code>RUSBoost<\/code>\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from imblearn.ensemble import BalancedRandomForestClassifier\n  model = BalancedRandomForestClassifier(random_state=42)\n  model.fit(X_train, y_train)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u6539\u8fdb\u7684\u8bc4\u4ef7\u6307\u6807<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u9002\u5f53\u7684\u8bc4\u4ef7\u6307\u6807<\/strong>\uff1a\u5728\u6570\u636e\u4e0d\u5e73\u8861\u7684\u60c5\u51b5\u4e0b\uff0c\u4f20\u7edf\u7684\u51c6\u786e\u7387\uff08Accuracy\uff09\u53ef\u80fd\u4e0d\u5408\u9002\uff0c\u5e94\u8be5\u4f7f\u7528\u5982\u4e0b\u8bc4\u4ef7\u6307\u6807\uff1a<\/li>\n\n\n\n<li>\u7cbe\u786e\u7387\uff08Precision\uff09<\/li>\n\n\n\n<li>\u53ec\u56de\u7387\uff08Recall\uff09<\/li>\n\n\n\n<li>F1\u5206\u6570\uff08F1 Score\uff09<\/li>\n\n\n\n<li>ROC\u66f2\u7ebf\u4e0b\u7684\u9762\u79ef\uff08AUC\uff09<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from sklearn.metrics import classification_report, roc_auc_score\n\n  y_pred = model.predict(X_test)\n  print(classification_report(y_test, y_pred))\n  print(f\"AUC Score: {roc_auc_score(y_test, y_pred)}\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u6570\u636e\u589e\u5f3a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u589e\u5f3a<\/strong>\uff1a\u5728\u6df1\u5ea6\u5b66\u4e60\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6570\u636e\u589e\u5f3a\u6280\u672f\uff08\u5982\u56fe\u50cf\u65cb\u8f6c\u3001\u7f29\u653e\u3001\u7ffb\u8f6c\uff09\u589e\u52a0\u5c11\u6570\u7c7b\u6837\u672c\u7684\u591a\u6837\u6027\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from tensorflow.keras.preprocessing.image import ImageDataGenerator\n\n  datagen = ImageDataGenerator(\n      rotation_range=20,\n      width_shift_range=0.2,\n      height_shift_range=0.2,\n      shear_range=0.2,\n      zoom_range=0.2,\n      horizontal_flip=True,\n      fill_mode='nearest'\n  )\n\n  datagen.fit(X_train)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u4f7f\u7528\u6210\u672c\u654f\u611f\u5b66\u4e60\uff08Cost-sensitive Learning\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65b9\u6cd5<\/strong>\uff1a\u8c03\u6574\u7b97\u6cd5\u7684\u635f\u5931\u51fd\u6570\uff0c\u4f7f\u5f97\u6a21\u578b\u5728\u5b66\u4e60\u65f6\u5bf9\u5c11\u6570\u7c7b\u6837\u672c\u7ed9\u4e88\u66f4\u591a\u7684\u5173\u6ce8\u3002<\/li>\n\n\n\n<li><strong>\u793a\u4f8b\u5de5\u5177<\/strong>\uff1a<\/li>\n\n\n\n<li><code>sklearn<\/code>\u4e2d\u7684<code>class_weight<\/code>\u53c2\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  from sklearn.ensemble import RandomForestClassifier\n\n  model = RandomForestClassifier(class_weight='balanced', random_state=42)\n  model.fit(X_train, y_train)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u9009\u62e9\u5408\u9002\u7684\u6a21\u578b<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u5bf9\u6570\u636e\u4e0d\u5e73\u8861\u6709\u8f83\u597d\u5904\u7406\u80fd\u529b\u7684\u6a21\u578b<\/strong>\uff0c\u4f8b\u5982\uff1a<\/li>\n\n\n\n<li>\u96c6\u6210\u65b9\u6cd5\u5982\u968f\u673a\u68ee\u6797\u3001\u68af\u5ea6\u63d0\u5347\u6811\u3002<\/li>\n\n\n\n<li>\u4e00\u4e9b\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\uff0c\u5982\u4f7f\u7528<code>class_weight<\/code>\u53c2\u6570\u8c03\u6574\u7684\u795e\u7ecf\u7f51\u7edc\u6a21\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u51b3\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\u95ee\u9898\u7684\u65b9\u6cd5\u591a\u79cd\u591a\u6837\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u9700\u8981\u6839\u636e\u5177\u4f53\u95ee\u9898\u7684\u7279\u70b9\u3001\u6570\u636e\u7684\u6027\u8d28\u4ee5\u53ca\u6a21\u578b\u7684\u9700\u6c42\u6765\u51b3\u5b9a\u3002\u901a\u5e38\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd\uff0c\u5982\u91cd\u91c7\u6837\u6280\u672f\u3001\u96c6\u6210\u65b9\u6cd5\u3001\u8bc4\u4ef7\u6307\u6807\u8c03\u6574\u548c\u6210\u672c\u654f\u611f\u5b66\u4e60\u7b49\uff0c\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u5206\u7c7b\u6548\u679c\u548c\u6a21\u578b\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\uff0cChatGPT \u95ee\u7b54\u751f\u6210 \u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u6570\u636e\u7279\u5f81\u4e0d\u5e73\u8861\uff08class imbalance\uff09\u662f\u6307\u67d0\u4e9b\u7c7b\u522b\u7684&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6128\">\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":[56,51],"class_list":["post-6128","post","type-post","status-publish","format-standard","hentry","category-5","tag-56","tag-51"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6128","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=6128"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6128\/revisions"}],"predecessor-version":[{"id":6129,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6128\/revisions\/6129"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}