{"id":6318,"date":"2024-07-16T10:12:37","date_gmt":"2024-07-16T02:12:37","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6318"},"modified":"2024-07-16T10:12:37","modified_gmt":"2024-07-16T02:12:37","slug":"%e4%bb%a3%e7%a0%81%e7%89%b9%e5%be%81%e5%b7%a5%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6318","title":{"rendered":"\u4ee3\u7801\u7279\u5f81\u5de5\u7a0b"},"content":{"rendered":"<p>\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210<br \/>\n\u95ee\uff1a\u751f\u6210\u5f0f\u4ee3\u7801\u5de5\u5177\uff0c\u91c7\u7eb3\u7387\u4e0d\u9ad8\uff0c\u5982\u4f55\u5bf9\u672a\u91c7\u7eb3\u7684\u6570\u636e\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u5206\u6790\uff0c\u8fdb\u884c\u4f18\u5316\uff0c\u63d0\u5347\u91c7\u7eb3\u7387<\/p>\n<p>\u8981\u63d0\u5347\u751f\u6210\u5f0f\u4ee3\u7801\u5de5\u5177\u7684\u91c7\u7eb3\u7387\uff0c\u53ef\u4ee5\u901a\u8fc7\u5bf9\u672a\u91c7\u7eb3\u7684\u6570\u636e\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u5206\u6790\uff0c\u4ee5\u8bc6\u522b\u548c\u4f18\u5316\u5173\u952e\u7279\u5f81\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7cfb\u7edf\u5316\u7684\u6b65\u9aa4\u6307\u5357\uff1a<\/p>\n<h3>1. \u6570\u636e\u6536\u96c6<\/h3>\n<p>\u6536\u96c6\u6709\u5173\u672a\u91c7\u7eb3\u4ee3\u7801\u7684\u6570\u636e\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u751f\u6210\u4e0a\u4e0b\u6587<\/li>\n<li>\u751f\u6210\u4ee3\u7801\u7684\u7279\u6027\uff08\u5982\u4ee3\u7801\u957f\u5ea6\u3001\u590d\u6742\u5ea6\u3001\u6ce8\u91ca\u60c5\u51b5\u7b49\uff09<\/li>\n<li>\u7528\u6237\u53cd\u9988\uff08\u5982\u4e3a\u4ec0\u4e48\u4e0d\u91c7\u7eb3\uff0c\u5177\u4f53\u95ee\u9898\u5728\u54ea\u91cc\uff09<\/li>\n<li>\u7528\u6237\u4e2a\u4eba\u7279\u5f81\uff08\u5982\u7f16\u7a0b\u7ecf\u9a8c\u3001\u4f7f\u7528\u573a\u666f\u7b49\uff09<\/li>\n<\/ul>\n<h3>2. \u6570\u636e\u9884\u5904\u7406<\/h3>\n<p>\u5bf9\u6536\u96c6\u5230\u7684\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u9884\u5904\u7406\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u7f3a\u5931\u503c\u5904\u7406<\/li>\n<li>\u6570\u636e\u6807\u51c6\u5316\u6216\u5f52\u4e00\u5316<\/li>\n<li>\u6570\u636e\u5206\u5272\uff08\u8bad\u7ec3\u96c6\u3001\u9a8c\u8bc1\u96c6\u3001\u6d4b\u8bd5\u96c6\uff09<\/li>\n<\/ul>\n<h3>3. \u7279\u5f81\u5de5\u7a0b<\/h3>\n<p>\u8bc6\u522b\u548c\u6784\u5efa\u53ef\u80fd\u5f71\u54cd\u4ee3\u7801\u91c7\u7eb3\u7387\u7684\u7279\u5f81\uff1a<\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u7279\u5f81<\/strong>\uff1a\u4ee3\u7801\u884c\u6570\u3001\u6ce8\u91ca\u6570\u91cf\u3001\u590d\u6742\u5ea6\u3001\u51fd\u6570\/\u65b9\u6cd5\u6570\u91cf\u3001\u53d8\u91cf\u547d\u540d\u89c4\u8303\u7b49\u3002<\/li>\n<li><strong>\u7528\u6237\u7279\u5f81<\/strong>\uff1a\u7528\u6237\u7684\u7f16\u7a0b\u7ecf\u9a8c\u3001\u9879\u76ee\u7c7b\u578b\u3001\u4f7f\u7528\u9891\u7387\u7b49\u3002<\/li>\n<li><strong>\u4e0a\u4e0b\u6587\u7279\u5f81<\/strong>\uff1a\u4ee3\u7801\u751f\u6210\u65f6\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u5982\u5f53\u524d\u6587\u4ef6\u7c7b\u578b\u3001\u8bed\u8a00\u73af\u5883\u7b49\u3002<\/li>\n<li><strong>\u53cd\u9988\u7279\u5f81<\/strong>\uff1a\u7528\u6237\u53cd\u9988\u4e2d\u7684\u5173\u952e\u8bcd\u63d0\u53d6\u3001\u60c5\u611f\u5206\u6790\u7b49\u3002<\/li>\n<\/ul>\n<h3>4. \u6570\u636e\u5206\u6790<\/h3>\n<p>\u4f7f\u7528\u7edf\u8ba1\u548c\u53ef\u89c6\u5316\u65b9\u6cd5\u5206\u6790\u7279\u5f81\u4e0e\u91c7\u7eb3\u7387\u4e4b\u95f4\u7684\u5173\u7cfb\uff1a<\/p>\n<ul>\n<li><strong>\u76f8\u5173\u6027\u5206\u6790<\/strong>\uff1a\u8bc6\u522b\u54ea\u4e9b\u7279\u5f81\u4e0e\u91c7\u7eb3\u7387\u9ad8\u5ea6\u76f8\u5173\u3002<\/li>\n<li><strong>\u805a\u7c7b\u5206\u6790<\/strong>\uff1a\u5c06\u672a\u91c7\u7eb3\u4ee3\u7801\u5206\u6210\u4e0d\u540c\u7684\u7c7b\u522b\uff0c\u5bfb\u627e\u5171\u540c\u7279\u5f81\u3002<\/li>\n<li><strong>\u56de\u5f52\u5206\u6790<\/strong>\uff1a\u5efa\u7acb\u56de\u5f52\u6a21\u578b\u9884\u6d4b\u91c7\u7eb3\u7387\uff0c\u8bc6\u522b\u91cd\u8981\u7279\u5f81\u3002<\/li>\n<\/ul>\n<h3>5. \u6a21\u578b\u6784\u5efa<\/h3>\n<p>\u6784\u5efa\u548c\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u9884\u6d4b\u4ee3\u7801\u91c7\u7eb3\u7387\uff1a<\/p>\n<ul>\n<li><strong>\u5206\u7c7b\u6a21\u578b<\/strong>\uff1a\u5982\u51b3\u7b56\u6811\u3001\u968f\u673a\u68ee\u6797\u3001\u652f\u6301\u5411\u91cf\u673a\u7b49\uff0c\u5206\u7c7b\u4ee3\u7801\u662f\u5426\u4f1a\u88ab\u91c7\u7eb3\u3002<\/li>\n<li><strong>\u56de\u5f52\u6a21\u578b<\/strong>\uff1a\u9884\u6d4b\u4ee3\u7801\u91c7\u7eb3\u7387\u7684\u5177\u4f53\u6570\u503c\u3002<\/li>\n<li><strong>\u63a8\u8350\u7cfb\u7edf<\/strong>\uff1a\u57fa\u4e8e\u5386\u53f2\u6570\u636e\uff0c\u4e3a\u7528\u6237\u63a8\u8350\u66f4\u9002\u5408\u7684\u4ee3\u7801\u751f\u6210\u9009\u9879\u3002<\/li>\n<\/ul>\n<h3>6. \u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316<\/h3>\n<p>\u8bc4\u4f30\u6a21\u578b\u6027\u80fd\u5e76\u8fdb\u884c\u4f18\u5316\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u4ea4\u53c9\u9a8c\u8bc1\u8bc4\u4f30\u6a21\u578b\u7684\u51c6\u786e\u6027\u3001\u53ec\u56de\u7387\u3001F1\u5206\u6570\u7b49\u3002<\/li>\n<li>\u8c03\u6574\u6a21\u578b\u53c2\u6570\uff0c\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/li>\n<\/ul>\n<h3>7. \u5b9e\u9a8c\u548c\u8fed\u4ee3<\/h3>\n<p>\u8fdb\u884cA\/B\u6d4b\u8bd5\u548c\u7528\u6237\u5b9e\u9a8c\uff0c\u9a8c\u8bc1\u6a21\u578b\u4f18\u5316\u6548\u679c\uff1a<\/p>\n<ul>\n<li>\u5b9e\u9a8c\u4e0d\u540c\u7684\u751f\u6210\u7b56\u7565\uff0c\u8bb0\u5f55\u7528\u6237\u53cd\u9988\u548c\u91c7\u7eb3\u7387\u3002<\/li>\n<li>\u6839\u636e\u5b9e\u9a8c\u7ed3\u679c\u4e0d\u65ad\u8fed\u4ee3\u6a21\u578b\u548c\u751f\u6210\u7b56\u7565\u3002<\/li>\n<\/ul>\n<h3>8. \u53cd\u9988\u5faa\u73af<\/h3>\n<p>\u5efa\u7acb\u6301\u7eed\u7684\u53cd\u9988\u5faa\u73af\u673a\u5236\uff1a<\/p>\n<ul>\n<li>\u6301\u7eed\u6536\u96c6\u65b0\u7684\u7528\u6237\u53cd\u9988\u548c\u6570\u636e\u3002<\/li>\n<li>\u5b9a\u671f\u66f4\u65b0\u6a21\u578b\u548c\u7279\u5f81\u5de5\u7a0b\uff0c\u9002\u5e94\u7528\u6237\u9700\u6c42\u53d8\u5316\u3002<\/li>\n<\/ul>\n<h3>\u793a\u4f8b\u4ee3\u7801\uff08Python + Sklearn\uff09<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u7528\u4e8e\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u548c\u6a21\u578b\u6784\u5efa\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import classification_report, accuracy_score\n\n# \u6570\u636e\u52a0\u8f7d\ndata = pd.read_csv(&#039;code_feedback.csv&#039;)\n\n# \u7279\u5f81\u5de5\u7a0b\ndata[&#039;code_length&#039;] = data[&#039;code&#039;].apply(len)\ndata[&#039;num_comments&#039;] = data[&#039;code&#039;].apply(lambda x: x.count(&#039;\/\/&#039;))\n# \u53ef\u4ee5\u7ee7\u7eed\u6dfb\u52a0\u5176\u4ed6\u7279\u5f81\n\n# \u6570\u636e\u5206\u5272\nX = data[[&#039;code_length&#039;, &#039;num_comments&#039;]]\ny = data[&#039;accepted&#039;]  # 1 \u8868\u793a\u91c7\u7eb3\uff0c0 \u8868\u793a\u672a\u91c7\u7eb3\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# \u6a21\u578b\u8bad\u7ec3\nmodel = RandomForestClassifier()\nmodel.fit(X_train, y_train)\n\n# \u6a21\u578b\u8bc4\u4f30\ny_pred = model.predict(X_test)\nprint(classification_report(y_test, y_pred))\nprint(f&#039;Accuracy: {accuracy_score(y_test, y_pred)}&#039;)\n\n# \u7279\u5f81\u91cd\u8981\u6027\nfeature_importances = pd.Series(model.feature_importances_, index=X.columns).sort_values(ascending=False)\nprint(feature_importances)<\/code><\/pre>\n<p>\u8fd9\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4ece\u6570\u636e\u4e2d\u63d0\u53d6\u7279\u5f81\uff0c\u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b\uff0c\u4ee5\u53ca\u8bc4\u4f30\u6a21\u578b\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u8fdb\u4e00\u6b65\u4f18\u5316\u548c\u6269\u5c55\u8fd9\u4e2a\u8fc7\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210 \u95ee\uff1a\u751f\u6210\u5f0f\u4ee3\u7801\u5de5\u5177\uff0c\u91c7\u7eb3\u7387\u4e0d\u9ad8\uff0c\u5982\u4f55\u5bf9\u672a\u91c7\u7eb3\u7684\u6570\u636e\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u5206\u6790\uff0c\u8fdb\u884c\u4f18\u5316&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6318\">\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":[121],"tags":[],"class_list":["post-6318","post","type-post","status-publish","format-standard","hentry","category-121"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6318","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=6318"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6318\/revisions"}],"predecessor-version":[{"id":6319,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6318\/revisions\/6319"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}