{"id":90469,"date":"2026-08-05T11:16:40","date_gmt":"2026-08-05T03:16:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/90469.html"},"modified":"2026-08-05T11:16:40","modified_gmt":"2026-08-05T03:16:40","slug":"%e9%9a%8f%e6%9c%ba%e6%a3%ae%e6%9e%97%e7%ae%97%e6%b3%95%e5%ae%9e%e6%88%98%ef%bc%9a%e5%9e%83%e5%9c%be%e9%82%ae%e4%bb%b6%e5%88%86%e7%b1%bb%e5%85%a8%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/90469.html","title":{"rendered":"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790"},"content":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u7cfb\u7edf\u4ecb\u7ecd\u4e86\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u7684\u6838\u5fc3\u6982\u5ff5\u3001\u7279\u70b9\u3001\u4f18\u7f3a\u70b9\u53caAPI\u4f7f\u7528\u65b9\u6cd5&#xff0c;\u5e76\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5e94\u7528\u968f\u673a\u68ee\u6797\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002\u6587\u7ae0\u9996\u5148\u9610\u8ff0\u4e86\u968f\u673a\u68ee\u6797\u4f5c\u4e3a\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406&#xff0c;\u7136\u540e\u8be6\u7ec6\u5206\u6790\u4e86\u5176\u6570\u636e\u91c7\u6837\u968f\u673a\u3001\u7279\u5f81\u9009\u53d6\u968f\u673a\u7b49\u6838\u5fc3\u7279\u70b9&#xff0c;\u63a5\u7740\u5217\u4e3e\u4e86\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u548c\u5173\u952eAPI\u53c2\u6570&#xff0c;\u6700\u540e\u901a\u8fc7Spambase\u6570\u636e\u96c6\u5b9e\u6218\u6f14\u793a\u4e86\u4ece\u6570\u636e\u9884\u5904\u7406\u3001\u53c2\u6570\u8c03\u4f18\u5230\u6a21\u578b\u8bc4\u4f30\u7684\u5168\u6d41\u7a0b&#xff0c;\u4e3a\u8bfb\u8005\u63d0\u4f9b\u4e86\u4ece\u7406\u8bba\u5230\u5b9e\u8df5\u7684\u5b8c\u6574\u5b66\u4e60\u8def\u5f84\u3002<\/p>\n<p>\u4e00\u3001\u4ec0\u4e48\u662f\u968f\u673a\u68ee\u6797<\/p>\n<p>\u4e00\u79cd\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5&#xff08;\u96c6\u6210\u5b66\u4e60&#xff1a;\u662f\u5c06\u591a\u4e2a\u57fa\u5b66\u4e60\u5668\u8fdb\u884c\u7ec4\u5408\u6765\u5b9e\u73b0\u6bd4\u5355\u4e00\u5b66\u4e60\u5668\u663e\u8457\u4f18\u8d8a\u7684\u5b66\u4e60\u6027\u80fd&#xff09;&#xff0c;\u7531\u591a\u4e2a\u51b3\u7b56\u6811\u7ec4\u6210&#xff0c;\u5e7f\u6cdb\u7528\u4e8e\u5206\u7c7b\u3001\u56de\u5f52\u7b49\u4efb\u52a1\u3002\u5176\u6838\u5fc3\u601d\u60f3\u662f\u901a\u8fc7\u6784\u5efa\u5927\u91cf\u76f8\u4e92\u72ec\u7acb\u7684\u51b3\u7b56\u6811&#xff0c;\u5e76\u5c06\u5b83\u4eec\u7684\u9884\u6d4b\u7ed3\u679c\u8fdb\u884c\u96c6\u6210&#xff0c;\u4ece\u800c\u63d0\u5347\u6a21\u578b\u7684\u51c6\u786e\u6027\u548c\u9c81\u68d2\u6027\u3002<\/p>\n<p>\u4e8c\u3001\u968f\u673a\u68ee\u6797\u7684\u7279\u70b9<\/p>\n<p>\u6570\u636e\u91c7\u6837\u968f\u673a&#xff0c;\u7279\u5f81\u9009\u53d6\u968f\u673a&#xff0c;\u68ee\u6797&#xff0c;\u57fa\u5206\u7c7b\u5668\u4e3a\u51b3\u7b56\u6811\u3002<\/p>\n<p>\u6570\u636e\u91c7\u6837\u968f\u673a\u7684\u610f\u601d\u662f&#xff0c;\u6bcf\u4e2a\u51b3\u7b56\u6811\u7684\u6240\u8bad\u7ec3\u7684\u6570\u636e\u96c6\u90fd\u662f\u968f\u673a\u5728\u6570\u636e\u96c6\u4e2d\u62bd\u53d6\u7684&#xff0c;\u56e0\u4e3a\u6bcf\u4e2a\u51b3\u7b56\u6811\u7684\u6570\u636e\u96c6\u4e0d\u4e00\u6837&#xff0c;\u6240\u4ee5\u751f\u6210\u7684\u6bcf\u4e2a\u51b3\u7b56\u6811\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u540c\u6837\u7684\u7279\u5f81\u968f\u673a\u9009\u53d6\u4e5f\u662f&#xff0c;\u5e76\u4e0d\u4f1a\u5168\u90e8\u8bad\u7ec3\u800c\u662f\u968f\u673a\u7684\u9009\u53d6\u8fdb\u884c\u8bad\u7ec3&#xff0c;\u7279\u5f81\u7684\u968f\u673a\u9009\u53d6&#xff0c;\u53ef\u4ee5\u8ba9\u6211\u4eec\u77e5\u9053\u54ea\u4e9b\u7279\u5f81\u91cd\u8981&#xff0c;\u54ea\u4e9b\u4e0d\u91cd\u8981\u3002<\/p>\n<p>\u68ee\u6797\u662f\u6307&#xff0c;\u6709\u591a\u4e2a\u51b3\u7b56\u6811\u6784\u5efa\u7684\u3002<\/p>\n<p>\u57fa\u5206\u7c7b\u5668\u4e3a\u51b3\u7b56\u6811&#xff1a;\u6bcf\u4e2a\u57fa\u5206\u7c7b\u5668\u5168\u90e8\u90fd\u662f\u51b3\u7b56\u6811&#xff0c;\u6ca1\u6709\u5176\u4ed6\u7684\u7b97\u6cd5\u3002<\/p>\n<p>\u968f\u673a\u68ee\u6797\u53ef\u4ee5\u5b9e\u73b0\u5206\u7c7b\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u56de\u5f52\u3002<\/p>\n<p>\u4e09\u3001\u968f\u673a\u68ee\u6797\u7684\u4f18\u7f3a\u70b9<\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<p>1\u3001\u5177\u6709\u6781\u9ad8\u7684\u51c6\u786e\u7387\u3002<\/p>\n<p>2\u3001\u968f\u673a\u6027\u7684\u5f15\u5165&#xff0c;\u4f7f\u5f97\u968f\u673a\u68ee\u6797\u7684\u6297\u566a\u58f0\u80fd\u529b\u5f88\u5f3a\u3002<\/p>\n<p>3\u3001\u968f\u673a\u6027\u7684\u5f15\u5165&#xff0c;\u4f7f\u5f97\u968f\u673a\u68ee\u6797\u7684\u4e0d\u5bb9\u6613\u8fc7\u62df\u5408\u3002<\/p>\n<p>4\u3001\u80fd\u591f\u5904\u7406\u5f88\u9ad8\u7ef4\u5ea6\u7684\u6570\u636e&#xff0c;\u4e0d\u7528\u505a\u7279\u5f81\u9009\u62e9\u3002<\/p>\n<p>5\u3001\u5bb9\u6613\u5b9e\u73b0\u5e76\u884c\u5316\u5904\u7406\u3002<\/p>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<p>1\u3001\u5f53\u968f\u673a\u68ee\u6797\u4e2d\u7684\u51b3\u7b56\u6811\u4e2a\u6570\u5f88\u591a\u65f6&#xff0c;\u8bad\u7ec3\u65f6\u9700\u8981t\u7684\u7a7a\u95f4\u548c\u65f6\u95f4\u4f1a\u6bd4\u8f83\u5927\u3002<\/p>\n<p>2\u3001\u968f\u673a\u68ee\u6797\u6a21\u578b\u8fd8\u6709\u8bb8\u591a\u4e0d\u597d\u89e3\u91ca\u7684\u5730\u65b9&#xff0c;\u6709\u70b9\u7b97\u4e2a\u9ed1\u76d2\u6a21\u578b\u3002<\/p>\n<p>\u56db\u3001\u968f\u673a\u68ee\u6797\u7684API<\/p>\n<table>\n<tr>\u53c2\u6570\u7c7b\u578b\u542b\u4e49\u5efa\u8bae\u503c<\/tr>\n<tbody>\n<tr>\n<td>n_estimators<\/td>\n<td>int<\/td>\n<td>\u6811\u7684\u6570\u91cf<\/td>\n<td>\u8d8a\u5927\u8d8a\u7a33\u5b9a&#xff0c;\u4f46\u8bad\u7ec3\u8d8a\u6162\u3002\u5e38\u7528 100-500<\/td>\n<\/tr>\n<tr>\n<td>max_depth<\/td>\n<td>int \/ None<\/td>\n<td>\u6811\u7684\u6700\u5927\u6df1\u5ea6<\/td>\n<td>\u9ed8\u8ba4None&#xff08;\u4e0d\u9650\u5236&#xff09;&#xff0c;\u4e00\u822c\u8bbe 3-15 \u9632\u8fc7\u62df\u5408<\/td>\n<\/tr>\n<tr>\n<td>min_samples_split<\/td>\n<td>int \/ float<\/td>\n<td>\u5185\u90e8\u8282\u70b9\u5206\u88c2\u6240\u9700\u7684\u6700\u5c0f\u6837\u672c\u6570<\/td>\n<td>\u9ed8\u8ba42&#xff0c;\u8bbe 5-20 \u9632\u8fc7\u62df\u5408<\/td>\n<\/tr>\n<tr>\n<td>min_samples_leaf<\/td>\n<td>int \/ float<\/td>\n<td>\u53f6\u5b50\u8282\u70b9\u6700\u5c0f\u6837\u672c\u6570<\/td>\n<td>\u9ed8\u8ba41&#xff0c;\u8bbe 2-10 \u9632\u8fc7\u62df\u5408<\/td>\n<\/tr>\n<tr>\n<td>max_features<\/td>\n<td>int \/ float \/ str<\/td>\n<td>\u5206\u88c2\u65f6\u8003\u8651\u7684\u6700\u5927\u7279\u5f81\u6570<\/td>\n<td>&#039;sqrt&#039;&#xff08;\u9ed8\u8ba4&#xff09;\u3001&#039;log2&#039; \u6216\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>bootstrap<\/td>\n<td>bool<\/td>\n<td>\u662f\u5426\u81ea\u52a9\u91c7\u6837&#xff08;\u6709\u653e\u56de&#xff09;<\/td>\n<td>\u9ed8\u8ba4True<\/td>\n<\/tr>\n<tr>\n<td>oob_score<\/td>\n<td>bool<\/td>\n<td>\u662f\u5426\u4f7f\u7528\u888b\u5916\u6837\u672c\u6765\u8bc4\u4f30<\/td>\n<td>\u9ed8\u8ba4False&#xff0c;\u8bbe\u4e3aTrue\u53ef\u67e5\u770b\u888b\u5916\u8bc4\u5206<\/td>\n<\/tr>\n<tr>\n<td>n_jobs<\/td>\n<td>int<\/td>\n<td>\u5e76\u884c\u8ba1\u7b97\u6838\u5fc3\u6570<\/td>\n<td>-1 \u8868\u793a\u4f7f\u7528\u6240\u6709\u6838\u5fc3<\/td>\n<\/tr>\n<tr>\n<td>random_state<\/td>\n<td>int<\/td>\n<td>\u968f\u673a\u79cd\u5b50<\/td>\n<td>\u56fa\u5b9a\u540e\u7ed3\u679c\u53ef\u590d\u73b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e94\u3001\u968f\u673a\u68ee\u6797\u7684\u5b9e\u6218\u6848\u4f8b&#8212;\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b<\/p>\n<p>\u672c\u6b21\u5b9e\u9a8c\u57fa\u4e8e\u7ecf\u5178\u7684Spambase\u5783\u573e\u90ae\u4ef6\u6570\u636e\u96c6&#xff0c;\u6784\u5efa\u968f\u673a\u68ee\u6797\u4e8c\u5206\u7c7b\u6a21\u578b\u4ee5\u5b9e\u73b0\u90ae\u4ef6\u7684\u81ea\u52a8\u8bc6\u522b\u3002\u6570\u636e\u96c6\u5171\u5305\u542b4601\u6761\u6837\u672c&#xff0c;\u6bcf\u6761\u6837\u672c\u753157\u7ef4\u6570\u503c\u7279\u5f81\u6784\u6210&#xff0c;\u6db5\u76d6\u8bcd\u9891\u7edf\u8ba1\u3001\u7279\u6b8a\u5b57\u7b26\u5360\u6bd4\u4ee5\u53ca\u5927\u5199\u5b57\u6bcd\u5e8f\u5217\u7b49\u90ae\u4ef6\u6587\u672c\u7684\u91cf\u5316\u5c5e\u6027&#xff0c;\u6807\u7b7e\u4e3a\u4e8c\u5206\u7c7b&#xff08;1\u8868\u793a\u5783\u573e\u90ae\u4ef6&#xff0c;0\u8868\u793a\u6b63\u5e38\u90ae\u4ef6&#xff09;\u3002\u5b9e\u9a8c\u91c7\u7528\u5206\u5c42K\u6298\u4ea4\u53c9\u9a8c\u8bc1\u7b56\u7565\u7cfb\u7edf\u6027\u5730\u641c\u7d22\u6700\u4f18\u9884\u526a\u679d\u53c2\u6570\u7ec4\u5408&#xff0c;\u5728\u4fdd\u8bc1\u6a21\u578b\u7cbe\u5ea6\u7684\u540c\u65f6\u6709\u6548\u6291\u5236\u8fc7\u62df\u5408\u98ce\u9669&#xff0c;\u6700\u7ec8\u6784\u5efa\u51fa\u5177\u5907\u9ad8\u6cdb\u5316\u80fd\u529b\u7684\u968f\u673a\u68ee\u6797\u6a21\u578b\u3002<\/p>\n<p>1.\u6a21\u578b\u5e93\u5bfc\u5165<\/p>\n<p># \u5bfc\u5165\u6240\u9700\u5de5\u5177\u5e93<br \/>\nimport pandas as pd<br \/>\nimport matplotlib.pyplot as plt<br \/>\nfrom sklearn.model_selection import train_test_split, cross_val_score, StratifiedKFold<br \/>\nfrom sklearn.metrics import classification_report, confusion_matrix<br \/>\nfrom sklearn.ensemble import RandomForestClassifier<\/p>\n<ul>\n<li>pandas \u4e3a\u4e86\u8bfb\u53d6\u6570\u636e\u96c6<\/li>\n<li>matplotlib\u662fPython \u7684\u753b\u56fe\u5e93&#xff0c;\u7528\u6765\u628a\u6570\u5b57\u53d8\u6210\u56fe\u8868&#xff08;\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u70ed\u529b\u56fe\u7b49&#xff09;\u3002 \u5728\u673a\u5668\u5b66\u4e60\u4e2d&#xff0c;\u5b83\u7528\u6765\u53ef\u89c6\u5316\u6570\u636e\u5206\u5e03\u3001\u6a21\u578b\u6548\u679c\u3001\u53c2\u6570\u8c03\u4f18\u8fc7\u7a0b\u7b49&#xff0c;\u8ba9\u4f60\u201c\u7528\u773c\u775b\u770b\u6570\u636e\u201d&#xff0c;\u6bd4\u770b\u4e00\u4e32\u6570\u5b57\u76f4\u89c2\u5f97\u591a\u3002<\/li>\n<li>train_test_split \u662f\u7528\u6765\u5212\u5206\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u7684<\/li>\n<li>cross_val_score \u662f\u4e00\u4e2a\u201c\u4ea4\u53c9\u9a8c\u8bc1\u5feb\u6377\u51fd\u6570<\/li>\n<li>StratifiedKFold \u662f\u4e00\u4e2a\u7528\u4e8e\u4ea4\u53c9\u9a8c\u8bc1\u7684\u6570\u636e\u5207\u5206\u5de5\u5177\u3002\u5b83\u548c\u666e\u901a KFold \u7684\u533a\u522b\u5728\u4e8e&#xff1a;\u5b83\u4f1a\u5728\u5207\u5206\u65f6\u201c\u5206\u5c42\u201d&#xff0c;\u786e\u4fdd\u6bcf\u4e00\u6298\u4e2d\u5783\u573e\u90ae\u4ef6\u548c\u6b63\u5e38\u90ae\u4ef6\u7684\u6bd4\u4f8b\u90fd\u548c\u539f\u59cb\u6570\u636e\u4fdd\u6301\u4e00\u81f4\u3002\u8fd9\u6837\u505a\u662f\u4e3a\u4e86\u8ba9\u6bcf\u4e00\u8f6e\u9a8c\u8bc1\u90fd\u66f4\u516c\u5e73\u3001\u66f4\u53ef\u9760<\/li>\n<li>classfication_report \u662f\u4e00\u4e2a\u201c\u8bc4\u4f30\u62a5\u544a\u751f\u6210\u5668\u201d&#xff0c;\u4f60\u7ed9\u5b83\u771f\u5b9e\u6807\u7b7e\u548c\u9884\u6d4b\u6807\u7b7e&#xff0c;\u5b83\u81ea\u52a8\u7b97\u597d\u7cbe\u786e\u7387\u3001\u53ec\u56de\u7387\u3001F1\u5206\u6570&#xff0c;\u7528\u6574\u9f50\u7684\u8868\u683c\u6253\u5370\u51fa\u6765<\/li>\n<li>confusion_matrix \u53ef\u7528\u6765\u7ed8\u5236\u6df7\u6dc6\u77e9\u9635<\/li>\n<li>RandomForestClassifier,\u968f\u673a\u68ee\u6797\u5206\u7c7b\u5668\u7684\u5b9e\u73b0&#xff0c;\u662f\u4e00\u4e2a\u201c\u591a\u68f5\u6811\u6295\u7968\u51b3\u5b9a\u7ed3\u679c\u201d\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002<\/li>\n<\/ul>\n<p>2.\u6df7\u6dc6\u77e9\u9635\u7684\u7ed8\u5236<\/p>\n<p>\u6a21\u578b\u9884\u6d4b\u7684\u7ed3\u679c\u53ef\u89c6\u5316&#xff0c;\u8ba9\u4f60\u4e00\u773c\u770b\u51fa\u6a21\u578b\u5728\u54ea\u4e9b\u7c7b\u522b\u4e0a\u8868\u73b0\u597d\u3001\u54ea\u4e9b\u7c7b\u522b\u5bb9\u6613\u5206\u9519\u3002\u6df7\u6dc6\u77e9\u9635 \u7684\u5b9a\u4e49\u662f\u56fa\u5b9a\u7684\u6a21\u677f&#xff0c;\u53ef\u81ea\u884c\u8bb0\u5fc6<\/p>\n<p># \u5b9a\u4e49\u6df7\u6dc6\u77e9\u9635\u7ed8\u5236\u51fd\u6570<br \/>\ndef cm_plot(y, yp):<br \/>\n    cm &#061; confusion_matrix(y, yp)<br \/>\n    plt.matshow(cm, cmap&#061;plt.cm.Blues)<br \/>\n    plt.colorbar()<br \/>\n    # \u904d\u5386\u586b\u5145\u6df7\u6dc6\u77e9\u9635\u6570\u503c<br \/>\n    for x in range(len(cm)):<br \/>\n        for y in range(len(cm)):<br \/>\n            plt.annotate(cm[x, y], xy&#061;(y, x), horizontalalignment&#061;&#034;center&#034;, verticalalignment&#061;&#034;center&#034;)<br \/>\n    plt.ylabel(&#039;True label&#039;)<br \/>\n    plt.xlabel(&#039;Predicted label&#039;)<br \/>\n    return plt<\/p>\n<p>3.\u6570\u636e\u8bfb\u53d6\u4e0e\u7279\u5f81\u3001\u6807\u7b7e\u62c6\u5206<\/p>\n<p>datas &#061; pd.read_csv(&#039;spambase.csv&#039;)<br \/>\n# \u6700\u540e\u4e00\u5217\u4e3a\u6807\u7b7e&#xff0c;\u5176\u4f59\u4e3a\u7279\u5f81<br \/>\ndata &#061; datas.iloc[:, :-1]<br \/>\nlabels &#061; datas.iloc[:, -1]<br \/>\n# 2.\u5212\u5206\u8bad\u7ec3\u96c6\u3001\u6d4b\u8bd5\u96c6&#xff0c;\u4fdd\u7559\u539f\u59cb\u6570\u636e\u5206\u5e03<br \/>\ndata_train, data_test, label_train, label_test &#061; train_test_split(<br \/>\n    data, labels, test_size&#061;0.2, random_state&#061;42<br \/>\n)<\/p>\n<p>4.\u4ea4\u53c9\u9a8c\u8bc1\u9009\u53d6\u6700\u4f18\u53c2\u6570<\/p>\n<p># 3.\u6784\u5efa5\u6298\u5206\u5c42\u4ea4\u53c9\u9a8c\u8bc1&#xff0c;\u9002\u914d\u4e8c\u5206\u7c7b\u6570\u636e\u5206\u5e03<br \/>\nskf &#061; StratifiedKFold(n_splits&#061;5, shuffle&#061;True, random_state&#061;0)<br \/>\n# 4.\u5b9a\u4e49\u9884\u526a\u679d\u8d85\u53c2\u6570\u904d\u5386\u8303\u56f4<br \/>\ntree_depth &#061; [8, 9, 10, None]    # \u51b3\u7b56\u6811\u6700\u5927\u6df1\u5ea6&#xff0c;None\u4e0d\u9650\u5236\u6df1\u5ea6\u6811\u53ef\u4ee5\u4e00\u76f4\u957f\u4e0b\u53bb&#xff0c;\u76f4\u5230\u6bcf\u4e2a\u53f6\u5b50\u90fd\u662f\u7eaf\u7684&#xff08;\u5168\u5783\u573e\u6216\u5168\u6b63\u5e38&#xff09;<br \/>\ntree_min_leaf &#061; [1, 2, 3]        # \u53f6\u5b50\u8282\u70b9\u6700\u5c0f\u6837\u672c\u6570<br \/>\ntree_min_samples &#061; [2, 3, 4, 6]  # \u5185\u90e8\u8282\u70b9\u6700\u5c0f\u5206\u88c2\u6837\u672c\u6570<br \/>\nbest_zuhe &#061; [0, 0, 0]  # \u5b58\u50a8\u6700\u4f18\u53c2\u6570\u7ec4\u5408<br \/>\nbest_recall &#061; 0         # \u5b58\u50a8\u6700\u4f18\u53ec\u56de\u7387<br \/>\n# 5.\u4e09\u91cd\u5faa\u73af\u7f51\u683c\u5bfb\u4f18&#xff0c;\u4ee5\u53ec\u56de\u7387\u4e3a\u8bc4\u4ef7\u6307\u6807<br \/>\nfor l in tree_min_samples:<br \/>\n    for i in tree_depth:<br \/>\n        for j in tree_min_leaf:<br \/>\n            rf &#061; RandomForestClassifier(<br \/>\n                n_estimators&#061;10,      # \u68ee\u6797\u51b3\u7b56\u6811\u6570\u91cf<br \/>\n                min_samples_split&#061;l,  # \u8282\u70b9\u5206\u88c2\u9884\u526a\u679d<br \/>\n                max_depth&#061;i,  # \u6700\u5927\u6df1\u5ea6\u9884\u526a\u679d<br \/>\n                min_samples_leaf&#061;j,  # \u53f6\u5b50\u6837\u672c\u9884\u526a\u679d<br \/>\n                max_features&#061;0.7,     # \u968f\u673a\u9009\u53d670%\u7279\u5f81\u8bad\u7ec3<br \/>\n                random_state&#061;0,      # \u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u7ed3\u679c\u53ef\u590d\u73b0<br \/>\n                n_jobs&#061;-1             # \u5f00\u542f\u591a\u7ebf\u7a0b\u5e76\u884c\u8bad\u7ec3<br \/>\n            )<br \/>\n            # 5\u6298\u4ea4\u53c9\u9a8c\u8bc1\u8ba1\u7b97\u5e73\u5747\u53ec\u56de\u7387<br \/>\n            score &#061; cross_val_score(rf, data_train, label_train, cv&#061;skf, scoring&#061;&#039;recall&#039;)<br \/>\n            score_mean &#061; score.mean()<br \/>\n            print(f&#034;\u5f53\u524d\u53c2\u6570-\u6df1\u5ea6:{i}, \u6700\u5c0f\u53f6\u5b50:{j}, \u6700\u5c0f\u5206\u88c2:{l}&#xff0c;\u5e73\u5747\u53ec\u56de\u7387:{score_mean:.4f}&#034;)<br \/>\n            # \u66f4\u65b0\u6700\u4f18\u53c2\u6570<br \/>\n            if score_mean &gt; best_recall:<br \/>\n                best_recall &#061; score_mean<br \/>\n                best_zuhe &#061; [i, j, l]<br \/>\nprint(&#034;&#061;&#034;*70)<br \/>\nprint(f&#034;\u6700\u4f18\u9884\u526a\u679d\u53c2\u6570\u7ec4\u5408&#xff1a;\u6700\u5927\u6df1\u5ea6{best_zuhe[0]}&#xff0c;\u53f6\u5b50\u6700\u5c0f\u6837\u672c{best_zuhe[1]}&#xff0c;\u8282\u70b9\u6700\u5c0f\u5206\u88c2\u6570{best_zuhe[2]}&#034;)<br \/>\nprint(f&#034;\u6700\u4f18\u4ea4\u53c9\u9a8c\u8bc1\u5e73\u5747\u53ec\u56de\u7387&#xff1a;{best_recall:.4f}&#034;)<\/p>\n<p>\u8fd9\u4e2ak\u6298&#xff0c;\u4e00\u822c\u90095\u6216\u800510&#xff0c;K\u503c\u7531\u4f60\u81ea\u7531\u5b9a\u4e49&#xff0c;\u4f46\u63a8\u8350\u4ece5\u621610\u5f00\u59cb\u3002 K\u592a\u5c0f\u8bc4\u4f30\u4e0d\u7a33\u5b9a&#xff0c;K\u592a\u5927\u8ba1\u7b97\u6210\u672c\u9ad8\u4f46\u6536\u76ca\u6709\u9650\u3002\u5bf9\u4e8e\u4f60\u76844601\u6761\u6570\u636e&#xff0c;5\u6298\u5df2\u7ecf\u8db3\u591f\u597d&#xff0c;\u6362\u621010\u6298\u4e5f\u53ef\u4ee5&#xff0c;\u7ed3\u679c\u4f1a\u66f4\u7a33\u5b9a\u4e00\u4e9b\u3002<\/p>\n<p>5.\u52a0\u8f7d\u6700\u4f18\u53c2\u6570&#xff0c;\u8bad\u7ec3\u6700\u7ec8\u968f\u673a\u68ee\u6797\u6a21\u578b<\/p>\n<p>tr &#061; RandomForestClassifier(<br \/>\n    criterion&#061;&#039;gini&#039;,<br \/>\n    max_depth&#061;best_zuhe[0],<br \/>\n    min_samples_leaf&#061;best_zuhe[1],<br \/>\n    min_samples_split&#061;best_zuhe[2],<br \/>\n    random_state&#061;42<br \/>\n)<br \/>\ntr.fit(data_train, label_train)<\/p>\n<p>6.\u6a21\u578b\u7684\u8bc4\u4f30\u4e0e\u53ef\u89c6\u5316<\/p>\n<p># 6.\u52a0\u8f7d\u6700\u4f18\u53c2\u6570&#xff0c;\u8bad\u7ec3\u6700\u7ec8\u968f\u673a\u68ee\u6797\u6a21\u578b<br \/>\ntr &#061; RandomForestClassifier(<br \/>\n    criterion&#061;&#039;gini&#039;,<br \/>\n    max_depth&#061;best_zuhe[0],<br \/>\n    min_samples_leaf&#061;best_zuhe[1],<br \/>\n    min_samples_split&#061;best_zuhe[2],<br \/>\n    random_state&#061;42<br \/>\n)<br \/>\ntr.fit(data_train, label_train)<br \/>\n7.\u8bad\u7ec3\u96c6\u6a21\u578b\u8bc4\u4f30<br \/>\ntrain_pred &#061; tr.predict(data_train)<br \/>\nprint(&#034;\\\\n\u3010\u8bad\u7ec3\u96c6\u5206\u7c7b\u8bc4\u4f30\u62a5\u544a\u3011&#034;)<br \/>\nprint(classification_report(label_train, train_pred, digits&#061;9))<br \/>\ncm_plot(label_train, train_pred).show()<br \/>\n#8.\u6d4b\u8bd5\u96c6\u6cdb\u5316\u80fd\u529b\u8bc4\u4f30<br \/>\nte_pred &#061; tr.predict(data_test)<br \/>\nprint(&#034;\\\\n\u3010\u6d4b\u8bd5\u96c6\u6700\u7ec8\u5206\u7c7b\u8bc4\u4f30\u62a5\u544a\u3011&#034;)<br \/>\nprint(classification_report(label_test, te_pred, digits&#061;9))<br \/>\ncm_plot(label_test, te_pred).show()<br \/>\n9.\u7279\u5f81\u91cd\u8981\u6027\u53ef\u89c6\u5316&#xff08;\u7b5b\u9009Top10\u5173\u952e\u7279\u5f81&#xff09;<br \/>\nimportants &#061; pd.DataFrame({<br \/>\n&#039;importance&#039;: tr.feature_importances_,<br \/>\n&#039;name&#039;: data.columns<br \/>\n})<br \/>\n\u6309\u91cd\u8981\u6027\u964d\u5e8f\u6392\u5e8f&#xff0c;\u53d6\u524d10\u7279\u5f81<br \/>\nim &#061; importants.sort_values(by&#061;&#039;importance&#039;, ascending&#061;False)[:10]<br \/>\nindex &#061; range(len(im))<br \/>\n\u6a2a\u5411\u67f1\u72b6\u56fe\u53ef\u89c6\u5316<br \/>\nplt.figure(figsize&#061;(12, 6))<br \/>\nplt.barh(index, im[&#039;importance&#039;], color&#061;&#039;steelblue&#039;)<br \/>\nplt.yticks(index, im[&#039;name&#039;])<br \/>\nplt.xlabel(&#039;\u7279\u5f81\u91cd\u8981\u6027\u6743\u91cd&#039;)<br \/>\nplt.title(&#039;\u968f\u673a\u68ee\u6797-Top10\u6838\u5fc3\u7279\u5f81\u91cd\u8981\u6027\u6392\u5e8f&#039;)<br \/>\nplt.gca().invert_yaxis()  # \u5012\u5e8f\u5c55\u793a&#xff0c;\u6743\u91cd\u6700\u9ad8\u5728\u9876\u90e8<br \/>\nplt.show()<\/p>\n<p>\u603b\u7684\u4ee3\u7801<\/p>\n<p># \u5bfc\u5165\u6240\u9700\u5de5\u5177\u5e93<br \/>\nimport pandas as pd<br \/>\nimport matplotlib.pyplot as plt<br \/>\nfrom sklearn.model_selection import train_test_split, cross_val_score, StratifiedKFold<br \/>\nfrom sklearn.metrics import classification_report, confusion_matrix<br \/>\nfrom sklearn.ensemble import RandomForestClassifier<br \/>\n# \u5b9a\u4e49\u6df7\u6dc6\u77e9\u9635\u7ed8\u5236\u51fd\u6570<br \/>\ndef cm_plot(y, yp):<br \/>\n    cm &#061; confusion_matrix(y, yp)<br \/>\n    plt.matshow(cm, cmap&#061;plt.cm.Blues)<br \/>\n    plt.colorbar()<br \/>\n    # \u904d\u5386\u586b\u5145\u6df7\u6dc6\u77e9\u9635\u6570\u503c<br \/>\n    for x in range(len(cm)):<br \/>\n        for y in range(len(cm)):<br \/>\n            plt.annotate(cm[x, y], xy&#061;(y, x), horizontalalignment&#061;&#034;center&#034;, verticalalignment&#061;&#034;center&#034;)<br \/>\n    plt.ylabel(&#039;True label&#039;)<br \/>\n    plt.xlabel(&#039;Predicted label&#039;)<br \/>\n    return plt<br \/>\n# 1.\u6570\u636e\u8bfb\u53d6\u4e0e\u7279\u5f81\u3001\u6807\u7b7e\u62c6\u5206<br \/>\ndatas &#061; pd.read_csv(&#039;spambase.csv&#039;)<br \/>\n# \u6700\u540e\u4e00\u5217\u4e3a\u6807\u7b7e&#xff0c;\u5176\u4f59\u4e3a\u7279\u5f81<br \/>\ndata &#061; datas.iloc[:, :-1]<br \/>\nlabels &#061; datas.iloc[:, -1]<br \/>\n# 2.\u5212\u5206\u8bad\u7ec3\u96c6\u3001\u6d4b\u8bd5\u96c6&#xff0c;\u4fdd\u7559\u539f\u59cb\u6570\u636e\u5206\u5e03<br \/>\ndata_train, data_test, label_train, label_test &#061; train_test_split(<br \/>\n    data, labels, test_size&#061;0.2, random_state&#061;42<br \/>\n)<br \/>\n# 3.\u6784\u5efa5\u6298\u5206\u5c42\u4ea4\u53c9\u9a8c\u8bc1&#xff0c;\u9002\u914d\u4e8c\u5206\u7c7b\u6570\u636e\u5206\u5e03<br \/>\nskf &#061; StratifiedKFold(n_splits&#061;5, shuffle&#061;True, random_state&#061;0)<br \/>\n# 4.\u5b9a\u4e49\u9884\u526a\u679d\u8d85\u53c2\u6570\u904d\u5386\u8303\u56f4<br \/>\ntree_depth &#061; [8, 9, 10, None]    # \u51b3\u7b56\u6811\u6700\u5927\u6df1\u5ea6&#xff0c;None\u4e0d\u9650\u5236\u6df1\u5ea6\u6811\u53ef\u4ee5\u4e00\u76f4\u957f\u4e0b\u53bb&#xff0c;\u76f4\u5230\u6bcf\u4e2a\u53f6\u5b50\u90fd\u662f\u7eaf\u7684&#xff08;\u5168\u5783\u573e\u6216\u5168\u6b63\u5e38&#xff09;<br \/>\ntree_min_leaf &#061; [1, 2, 3]        # \u53f6\u5b50\u8282\u70b9\u6700\u5c0f\u6837\u672c\u6570<br \/>\ntree_min_samples &#061; [2, 3, 4, 6]  # \u5185\u90e8\u8282\u70b9\u6700\u5c0f\u5206\u88c2\u6837\u672c\u6570<br \/>\nbest_zuhe &#061; [0, 0, 0]  # \u5b58\u50a8\u6700\u4f18\u53c2\u6570\u7ec4\u5408<br \/>\nbest_recall &#061; 0         # \u5b58\u50a8\u6700\u4f18\u53ec\u56de\u7387<br \/>\n# 5.\u4e09\u91cd\u5faa\u73af\u7f51\u683c\u5bfb\u4f18&#xff0c;\u4ee5\u53ec\u56de\u7387\u4e3a\u8bc4\u4ef7\u6307\u6807<br \/>\nfor l in tree_min_samples:<br \/>\n    for i in tree_depth:<br \/>\n        for j in tree_min_leaf:<br \/>\n            rf &#061; RandomForestClassifier(<br \/>\n                n_estimators&#061;10,      # \u68ee\u6797\u51b3\u7b56\u6811\u6570\u91cf<br \/>\n                min_samples_split&#061;l,  # \u8282\u70b9\u5206\u88c2\u9884\u526a\u679d<br \/>\n                max_depth&#061;i,  # \u6700\u5927\u6df1\u5ea6\u9884\u526a\u679d<br \/>\n                min_samples_leaf&#061;j,  # \u53f6\u5b50\u6837\u672c\u9884\u526a\u679d<br \/>\n                max_features&#061;0.7,     # \u968f\u673a\u9009\u53d670%\u7279\u5f81\u8bad\u7ec3<br \/>\n                random_state&#061;0,      # \u56fa\u5b9a\u968f\u673a\u79cd\u5b50&#xff0c;\u7ed3\u679c\u53ef\u590d\u73b0<br \/>\n                n_jobs&#061;-1             # \u5f00\u542f\u591a\u7ebf\u7a0b\u5e76\u884c\u8bad\u7ec3<br \/>\n            )<br \/>\n            # 5\u6298\u4ea4\u53c9\u9a8c\u8bc1\u8ba1\u7b97\u5e73\u5747\u53ec\u56de\u7387<br \/>\n            score &#061; cross_val_score(rf, data_train, label_train, cv&#061;skf, scoring&#061;&#039;recall&#039;)<br \/>\n            score_mean &#061; score.mean()<br \/>\n            print(f&#034;\u5f53\u524d\u53c2\u6570-\u6df1\u5ea6:{i}, \u6700\u5c0f\u53f6\u5b50:{j}, \u6700\u5c0f\u5206\u88c2:{l}&#xff0c;\u5e73\u5747\u53ec\u56de\u7387:{score_mean:.4f}&#034;)<br \/>\n            # \u66f4\u65b0\u6700\u4f18\u53c2\u6570<br \/>\n            if score_mean &gt; best_recall:<br \/>\n                best_recall &#061; score_mean<br \/>\n                best_zuhe &#061; [i, j, l]<br \/>\nprint(&#034;&#061;&#034;*70)<br \/>\nprint(f&#034;\u6700\u4f18\u9884\u526a\u679d\u53c2\u6570\u7ec4\u5408&#xff1a;\u6700\u5927\u6df1\u5ea6{best_zuhe[0]}&#xff0c;\u53f6\u5b50\u6700\u5c0f\u6837\u672c{best_zuhe[1]}&#xff0c;\u8282\u70b9\u6700\u5c0f\u5206\u88c2\u6570{best_zuhe[2]}&#034;)<br \/>\nprint(f&#034;\u6700\u4f18\u4ea4\u53c9\u9a8c\u8bc1\u5e73\u5747\u53ec\u56de\u7387&#xff1a;{best_recall:.4f}&#034;)<br \/>\n6.\u52a0\u8f7d\u6700\u4f18\u53c2\u6570&#xff0c;\u8bad\u7ec3\u6700\u7ec8\u968f\u673a\u68ee\u6797\u6a21\u578b<br \/>\ntr &#061; RandomForestClassifier(<br \/>\ncriterion&#061;&#039;gini&#039;,<br \/>\nmax_depth&#061;best_zuhe[0],<br \/>\nmin_samples_leaf&#061;best_zuhe[1],<br \/>\nmin_samples_split&#061;best_zuhe[2],<br \/>\nrandom_state&#061;0<br \/>\n)<br \/>\ntr.fit(data_train, label_train)<br \/>\n7.\u8bad\u7ec3\u96c6\u6a21\u578b\u8bc4\u4f30<br \/>\ntrain_pred &#061; tr.predict(data_train)<br \/>\nprint(&#034;\\\\n\u3010\u8bad\u7ec3\u96c6\u5206\u7c7b\u8bc4\u4f30\u62a5\u544a\u3011&#034;)<br \/>\nprint(classification_report(label_train, train_pred, digits&#061;9))<br \/>\ncm_plot(label_train, train_pred).show()<br \/>\n#8.\u6d4b\u8bd5\u96c6\u6cdb\u5316\u80fd\u529b\u8bc4\u4f30<br \/>\nte_pred &#061; tr.predict(data_test)<br \/>\nprint(&#034;\\\\n\u3010\u6d4b\u8bd5\u96c6\u6700\u7ec8\u5206\u7c7b\u8bc4\u4f30\u62a5\u544a\u3011&#034;)<br \/>\nprint(classification_report(label_test, te_pred, digits&#061;9))<br \/>\ncm_plot(label_test, te_pred).show()<br \/>\n9.\u7279\u5f81\u91cd\u8981\u6027\u53ef\u89c6\u5316&#xff08;\u7b5b\u9009Top10\u5173\u952e\u7279\u5f81&#xff09;<br \/>\nimportants &#061; pd.DataFrame({<br \/>\n&#039;importance&#039;: tr.feature_importances_,<br \/>\n&#039;name&#039;: data.columns<br \/>\n})<br \/>\n\u6309\u91cd\u8981\u6027\u964d\u5e8f\u6392\u5e8f&#xff0c;\u53d6\u524d10\u7279\u5f81<br \/>\nim &#061; importants.sort_values(by&#061;&#039;importance&#039;, ascending&#061;False)[:10]<br \/>\nindex &#061; range(len(im))<br \/>\n\u6a2a\u5411\u67f1\u72b6\u56fe\u53ef\u89c6\u5316<br \/>\nplt.figure(figsize&#061;(12, 6))<br \/>\nplt.barh(index, im[&#039;importance&#039;], color&#061;&#039;steelblue&#039;)<br \/>\nplt.yticks(index, im[&#039;name&#039;])<br \/>\nplt.xlabel(&#039;\u7279\u5f81\u91cd\u8981\u6027\u6743\u91cd&#039;)<br \/>\nplt.title(&#039;\u968f\u673a\u68ee\u6797-Top10\u6838\u5fc3\u7279\u5f81\u91cd\u8981\u6027\u6392\u5e8f&#039;)<br \/>\nplt.gca().invert_yaxis()  # \u5012\u5e8f\u5c55\u793a&#xff0c;\u6743\u91cd\u6700\u9ad8\u5728\u9876\u90e8<br \/>\nplt.show()<\/p>\n<h3>\u516d\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/h3>\n<p>\u672c\u6587\u7cfb\u7edf\u68b3\u7406\u4e86\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u7684\u6838\u5fc3\u8981\u70b9\u4e0e\u5b9e\u6218\u6d41\u7a0b\u3002\u9996\u5148&#xff0c;\u6211\u4eec\u660e\u786e\u4e86\u968f\u673a\u68ee\u6797\u662f\u4e00\u79cd\u57fa\u4e8e\u51b3\u7b56\u6811\u7684\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u5176\u6838\u5fc3\u7279\u70b9\u5728\u4e8e\u6570\u636e\u91c7\u6837\u968f\u673a\u548c\u7279\u5f81\u9009\u53d6\u968f\u673a&#xff0c;\u901a\u8fc7\u6784\u5efa\u5927\u91cf\u76f8\u4e92\u72ec\u7acb\u7684\u51b3\u7b56\u6811\u5e76\u96c6\u6210\u9884\u6d4b\u7ed3\u679c&#xff0c;\u663e\u8457\u63d0\u5347\u4e86\u6a21\u578b\u7684\u51c6\u786e\u6027\u548c\u9c81\u68d2\u6027\u3002\u5176\u6b21&#xff0c;\u6211\u4eec\u8be6\u7ec6\u5206\u6790\u4e86\u968f\u673a\u68ee\u6797\u7684\u4f18\u7f3a\u70b9&#xff1a;\u4f18\u70b9\u5305\u62ec\u9ad8\u51c6\u786e\u7387\u3001\u6297\u566a\u58f0\u80fd\u529b\u5f3a\u3001\u4e0d\u6613\u8fc7\u62df\u5408\u3001\u80fd\u5904\u7406\u9ad8\u7ef4\u6570\u636e\u4e14\u6613\u4e8e\u5e76\u884c\u5316&#xff1b;\u7f3a\u70b9\u5219\u4f53\u73b0\u5728\u8bad\u7ec3\u8d44\u6e90\u6d88\u8017\u8f83\u5927\u548c\u6a21\u578b\u53ef\u89e3\u91ca\u6027\u76f8\u5bf9\u8f83\u5f31\u3002\u6700\u540e&#xff0c;\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b\u5b9e\u6218\u6848\u4f8b&#xff0c;\u6211\u4eec\u6f14\u793a\u4e86\u4ece\u6570\u636e\u9884\u5904\u7406\u3001\u53c2\u6570\u8c03\u4f18\u5230\u6a21\u578b\u8bc4\u4f30\u7684\u5168\u6d41\u7a0b&#xff0c;\u6db5\u76d6\u4e86\u4ea4\u53c9\u9a8c\u8bc1\u3001\u7f51\u683c\u641c\u7d22\u3001\u6df7\u6dc6\u77e9\u9635\u53ef\u89c6\u5316\u4ee5\u53ca\u7279\u5f81\u91cd\u8981\u6027\u5206\u6790\u7b49\u5173\u952e\u73af\u8282\u3002<\/p>\n<p>\u5c55\u671b\u672a\u6765&#xff0c;\u968f\u673a\u68ee\u6797\u5728\u4ee5\u4e0b\u573a\u666f\u4e2d\u4ecd\u6709\u5e7f\u6cdb\u5e94\u7528\u524d\u666f&#xff1a;<\/p>\n<ul>\n<li>\u91d1\u878d\u98ce\u63a7\u4e0e\u4fe1\u7528\u8bc4\u5206&#xff1a;\u51ed\u501f\u5176\u9ad8\u51c6\u786e\u7387\u548c\u6297\u566a\u58f0\u80fd\u529b&#xff0c;\u968f\u673a\u68ee\u6797\u5728\u6b3a\u8bc8\u68c0\u6d4b\u3001\u4fe1\u7528\u8bc4\u4f30\u7b49\u9886\u57df\u8868\u73b0\u4f18\u5f02\u3002<\/li>\n<li>\u533b\u7597\u8bca\u65ad\u4e0e\u751f\u7269\u4fe1\u606f\u5b66&#xff1a;\u80fd\u591f\u5904\u7406\u9ad8\u7ef4\u57fa\u56e0\u8868\u8fbe\u6570\u636e&#xff0c;\u8f85\u52a9\u75be\u75c5\u5206\u7c7b\u3001\u836f\u7269\u53cd\u5e94\u9884\u6d4b\u7b49\u4efb\u52a1\u3002<\/li>\n<li>\u5de5\u4e1a\u7269\u8054\u7f51\u4e0e\u5f02\u5e38\u68c0\u6d4b&#xff1a;\u5bf9\u4f20\u611f\u5668\u65f6\u5e8f\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u548c\u56de\u5f52&#xff0c;\u5b9e\u73b0\u8bbe\u5907\u6545\u969c\u9884\u8b66\u3002<\/li>\n<li>\u63a8\u8350\u7cfb\u7edf\u4e0e\u7528\u6237\u884c\u4e3a\u5206\u6790&#xff1a;\u7ed3\u5408\u7279\u5f81\u91cd\u8981\u6027\u5206\u6790&#xff0c;\u53ef\u8bc6\u522b\u5f71\u54cd\u7528\u6237\u51b3\u7b56\u7684\u5173\u952e\u56e0\u7d20\u3002<\/li>\n<\/ul>\n<p>\u4e0e\u5176\u4ed6\u6a21\u578b\u76f8\u6bd4&#xff0c;\u968f\u673a\u68ee\u6797\u901a\u5e38\u6bd4\u5355\u4e00\u51b3\u7b56\u6811\u66f4\u7a33\u5b9a\u3001\u6cdb\u5316\u80fd\u529b\u66f4\u5f3a&#xff1b;\u4e0e\u68af\u5ea6\u63d0\u5347\u6811&#xff08;\u5982XGBoost\u3001LightGBM&#xff09;\u76f8\u6bd4&#xff0c;\u968f\u673a\u68ee\u6797\u8bad\u7ec3\u901f\u5ea6\u66f4\u5feb\u3001\u8c03\u53c2\u66f4\u7b80\u5355&#xff0c;\u4f46\u5728\u67d0\u4e9b\u4efb\u52a1\u4e0a\u7cbe\u5ea6\u53ef\u80fd\u7565\u4f4e\u3002\u5bf9\u4e8e\u5e0c\u671b\u8fdb\u4e00\u6b65\u6df1\u5165\u5b66\u4e60\u7684\u8bfb\u8005&#xff0c;\u5efa\u8bae&#xff1a;<\/p>\n<li>\u63a2\u7d22\u6781\u7aef\u968f\u673a\u68ee\u6797&#xff08;ExtraTrees&#xff09;&#xff0c;\u4e86\u89e3\u5176\u5728\u8282\u70b9\u5206\u88c2\u65f6\u5f15\u5165\u66f4\u591a\u968f\u673a\u6027\u7684\u53d8\u4f53\u3002<\/li>\n<li>\u5b66\u4e60\u7279\u5f81\u91cd\u8981\u6027\u7684\u591a\u79cd\u8ba1\u7b97\u65b9\u6cd5&#xff08;\u5982\u57fa\u5c3c\u91cd\u8981\u6027\u3001\u7f6e\u6362\u91cd\u8981\u6027&#xff09;\u3002<\/li>\n<li>\u638c\u63e1\u8d85\u53c2\u6570\u4f18\u5316\u7684\u9ad8\u7ea7\u65b9\u6cd5&#xff08;\u5982\u8d1d\u53f6\u65af\u4f18\u5316\u3001\u9057\u4f20\u7b97\u6cd5&#xff09;\u3002<\/li>\n<li>\u5c1d\u8bd5\u5c06\u968f\u673a\u68ee\u6797\u4e0e\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u7ed3\u5408&#xff0c;\u6784\u5efa\u6df7\u5408\u6a21\u578b\u4ee5\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<li>\u9605\u8bfb\u968f\u673a\u68ee\u6797\u7684\u539f\u59cb\u8bba\u6587&#xff08;Breiman, 2001&#xff09;\u4ee5\u6df1\u5165\u7406\u89e3\u5176\u7406\u8bba\u6839\u57fa\u3002<\/li>\n<p>\u968f\u673a\u68ee\u6797\u4f5c\u4e3a\u7ecf\u5178\u4e14\u5f3a\u5927\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u81f3\u4eca\u4ecd\u5728\u4f17\u591a\u5b9e\u9645\u573a\u666f\u4e2d\u53d1\u6325\u7740\u91cd\u8981\u4f5c\u7528\u3002\u638c\u63e1\u5176\u539f\u7406\u5e76\u719f\u7ec3\u8fd0\u7528&#xff0c;\u5c06\u4e3a\u4f60\u7684\u6570\u636e\u79d1\u5b66\u4e4b\u65c5\u5960\u5b9a\u575a\u5b9e\u57fa\u7840\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u7cfb\u7edf\u4ecb\u7ecd\u4e86\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u7684\u6838\u5fc3\u6982\u5ff5\u3001\u7279\u70b9\u3001\u4f18\u7f3a\u70b9\u53caAPI\u4f7f\u7528\u65b9\u6cd5&#xff0c;\u5e76\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5e94\u7528\u968f\u673a\u68ee\u6797\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002\u6587\u7ae0\u9996\u5148\u9610\u8ff0\u4e86\u968f\u673a\u68ee\u6797\u4f5c\u4e3a\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406&#xff0c;\u7136\u540e\u8be6\u7ec6\u5206\u6790\u4e86\u5176\u6570\u636e\u91c7\u6837\u968f\u673a\u3001\u7279\u5f81\u9009\u53d6\u968f\u673a\u7b49\u6838\u5fc3\u7279\u70b9&#xff0c;\u63a5\u7740\u5217\u4e3e\u4e86\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u548c\u5173\u952eAPI\u53c2\u6570&#xff0c;\u6700\u540e\u901a\u8fc7Spambase\u6570\u636e\u96c6\u5b9e\u6218\u6f14\u793a\u4e86\u4ece\u6570\u636e\u9884\u5904\u7406\u3001\u53c2\u6570\u8c03\u4f18\u5230\u6a21\u578b\u8bc4\u4f30\u7684\u5168\u6d41\u7a0b&#xff0c;\u4e3a\u8bfb\u8005\u63d0\u4f9b\u4e86\u4ece\u7406\u8bba\u5230\u5b9e<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[50,207,2887],"topic":[],"class_list":["post-90469","post","type-post","status-publish","format-standard","hentry","category-server","tag-50","tag-207","tag-2887"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/90469.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6458\u8981&#xff1a;\u672c\u6587\u7cfb\u7edf\u4ecb\u7ecd\u4e86\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u7684\u6838\u5fc3\u6982\u5ff5\u3001\u7279\u70b9\u3001\u4f18\u7f3a\u70b9\u53caAPI\u4f7f\u7528\u65b9\u6cd5&#xff0c;\u5e76\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5e94\u7528\u968f\u673a\u68ee\u6797\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002\u6587\u7ae0\u9996\u5148\u9610\u8ff0\u4e86\u968f\u673a\u68ee\u6797\u4f5c\u4e3a\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406&#xff0c;\u7136\u540e\u8be6\u7ec6\u5206\u6790\u4e86\u5176\u6570\u636e\u91c7\u6837\u968f\u673a\u3001\u7279\u5f81\u9009\u53d6\u968f\u673a\u7b49\u6838\u5fc3\u7279\u70b9&#xff0c;\u63a5\u7740\u5217\u4e3e\u4e86\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u548c\u5173\u952eAPI\u53c2\u6570&#xff0c;\u6700\u540e\u901a\u8fc7Spambase\u6570\u636e\u96c6\u5b9e\u6218\u6f14\u793a\u4e86\u4ece\u6570\u636e\u9884\u5904\u7406\u3001\u53c2\u6570\u8c03\u4f18\u5230\u6a21\u578b\u8bc4\u4f30\u7684\u5168\u6d41\u7a0b&#xff0c;\u4e3a\u8bfb\u8005\u63d0\u4f9b\u4e86\u4ece\u7406\u8bba\u5230\u5b9e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/90469.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-05T03:16:40+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/90469.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/90469.html\",\"name\":\"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-05T03:16:40+00:00\",\"dateModified\":\"2026-08-05T03:16:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/90469.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/90469.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/90469.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/90469.html","og_locale":"zh_CN","og_type":"article","og_title":"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6458\u8981&#xff1a;\u672c\u6587\u7cfb\u7edf\u4ecb\u7ecd\u4e86\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u7684\u6838\u5fc3\u6982\u5ff5\u3001\u7279\u70b9\u3001\u4f18\u7f3a\u70b9\u53caAPI\u4f7f\u7528\u65b9\u6cd5&#xff0c;\u5e76\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684\u5783\u573e\u90ae\u4ef6\u4e8c\u5206\u7c7b\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5e94\u7528\u968f\u673a\u68ee\u6797\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002\u6587\u7ae0\u9996\u5148\u9610\u8ff0\u4e86\u968f\u673a\u68ee\u6797\u4f5c\u4e3a\u96c6\u6210\u5b66\u4e60\u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406&#xff0c;\u7136\u540e\u8be6\u7ec6\u5206\u6790\u4e86\u5176\u6570\u636e\u91c7\u6837\u968f\u673a\u3001\u7279\u5f81\u9009\u53d6\u968f\u673a\u7b49\u6838\u5fc3\u7279\u70b9&#xff0c;\u63a5\u7740\u5217\u4e3e\u4e86\u7b97\u6cd5\u7684\u4f18\u7f3a\u70b9\u548c\u5173\u952eAPI\u53c2\u6570&#xff0c;\u6700\u540e\u901a\u8fc7Spambase\u6570\u636e\u96c6\u5b9e\u6218\u6f14\u793a\u4e86\u4ece\u6570\u636e\u9884\u5904\u7406\u3001\u53c2\u6570\u8c03\u4f18\u5230\u6a21\u578b\u8bc4\u4f30\u7684\u5168\u6d41\u7a0b&#xff0c;\u4e3a\u8bfb\u8005\u63d0\u4f9b\u4e86\u4ece\u7406\u8bba\u5230\u5b9e","og_url":"https:\/\/www.wsisp.com\/helps\/90469.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-05T03:16:40+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/90469.html","url":"https:\/\/www.wsisp.com\/helps\/90469.html","name":"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-05T03:16:40+00:00","dateModified":"2026-08-05T03:16:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/90469.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/90469.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/90469.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u968f\u673a\u68ee\u6797\u7b97\u6cd5\u5b9e\u6218\uff1a\u5783\u573e\u90ae\u4ef6\u5206\u7c7b\u5168\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/90469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=90469"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/90469\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=90469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=90469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=90469"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=90469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}