{"id":2404,"date":"2024-09-02T21:09:59","date_gmt":"2024-09-02T12:09:59","guid":{"rendered":"https:\/\/secondlife.lol\/?p=2404"},"modified":"2024-09-02T21:10:00","modified_gmt":"2024-09-02T12:10:00","slug":"python-random-forest-classification","status":"publish","type":"post","link":"https:\/\/secondlife.lol\/ja\/python-random-forest-classification\/","title":{"rendered":"Python\u3067\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u30e2\u30c7\u30eb\u3092\u5b9f\u88c5\u3059\u308b"},"content":{"rendered":"<p>\u6a5f\u68b0\u5b66\u7fd2\u3067 <a href=\"https:\/\/ailib.secondlife.lol\/random-forest-complete-guide\/\">\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8(Random Forest)<\/a> \u30e2\u30c7\u30eb\u306f\u4e88\u6e2c\u6027\u80fd\u304c\u9ad8\u304f\u3001\u69d8\u3005\u306a\u554f\u984c\u306b\u52b9\u679c\u7684\u306b\u9069\u7528\u3067\u304d\u308b\u4eba\u6c17\u306e\u3042\u308b\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002 \u3053\u306e\u30dd\u30b9\u30c8\u3067\u306f <strong>Python<\/strong>\u305d\u3057\u3066 <code><a href=\"https:\/\/scikit-learn.org\/\" data-type=\"link\" data-id=\"https:\/\/scikit-learn.org\/\" target=\"_blank\" rel=\"noopener\">scikit-learn<\/a><\/code> \u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u5668\u3092\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u751f\u6210\u3057\u3066\u5b66\u7fd2\u3057\u3001\u30e2\u30c7\u30eb\u306e\u4e88\u6e2c\u7cbe\u5ea6\u3092\u8a55\u4fa1\u3059\u308b\u904e\u7a0b\u3092\u4e00\u7dd2\u306b\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002 \u6a5f\u68b0\u5b66\u7fd2\u521d\u5fc3\u8005\u3067\u3082\u7c21\u5358\u306b\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30b3\u30fc\u30c9\u3068\u8aac\u660e\u3092\u6bb5\u968e\u7684\u306b\u63d0\u4f9b\u3057\u307e\u3059\u3002 <strong>Python\u306e\u6a5f\u68b0\u5b66\u7fd2<\/strong>\u306b\u8208\u5473\u304c\u3042\u308b\u306a\u3089\u3001\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u306e\u57fa\u790e\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{color:var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{color:var(--global-palette2, #2B6CB0);font-size:28px;font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list{color:var(--global-palette1, #3182CE);line-height:2em;font-weight:regular;font-style:normal;margin-top:var(--global-kb-spacing-sm, 1.5rem);margin-right:0px;margin-bottom:0px;margin-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list .kb-table-of-contents__entry:hover{color:var(--global-palette6, #718096);}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}@media all and (max-width: 767px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}<\/style>\n\n\n<h2 class=\"wp-block-heading\">\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u3092\u7406\u89e3\u3059\u308b<\/h2>\n\n\n\n<p><strong>\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8(Random Forest)<\/strong>\u306f\u3001\u8907\u6570\u306e\u6c7a\u5b9a\u6728(Decision Trees)\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4e88\u6e2c\u3092\u884c\u3046\u30a2\u30f3\u30b5\u30f3\u30d6\u30eb\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002 \u5404\u6c7a\u5b9a\u6728\u306f\u3001\u30c7\u30fc\u30bf\u306e\u30b5\u30d6\u30bb\u30c3\u30c8\u3092\u4f7f\u7528\u3057\u3066\u5b66\u7fd2\u3055\u308c\u3001\u6700\u7d42\u7684\u306a\u4e88\u6e2c\u306f\u3053\u308c\u3089\u306e\u6728\u306e\u591a\u6570\u6c7a\u6295\u7968\u306b\u3088\u3063\u3066\u6c7a\u5b9a\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u69cb\u9020\u306f\u3001\u904e\u9069\u5408(Overfitting)\u3092\u6e1b\u3089\u3057\u3001\u4e88\u6e2c\u6027\u80fd\u3092\u5411\u4e0a\u3055\u305b\u308b\u306e\u306b\u5927\u304d\u306a\u5229\u70b9\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>Python<\/strong>\u306e <code>scikit-learn<\/code> \u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u308b\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3057\u3066\u3001\u3053\u306e\u30c7\u30fc\u30bf\u3092\u57fa\u76e4\u306b\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u5668\u3092\u5b66\u7fd2\u3055\u305b\u308b\u904e\u7a0b\u3092\u30b3\u30fc\u30c9\u3068\u4e00\u7dd2\u306b\u8aac\u660e\u3057\u307e\u3059\u3002 \u307e\u305a\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u5229\u7528\u3057\u3066\u5b9f\u884c\u3057\u3066\u307f\u305f\u3044\u65b9\u306f\u3001\u6025\u3044\u3067\u3044\u308b\u65b9\u306f <a href=\"#total_code\">\u6295\u7a3f\u306e\u6700\u5f8c\u306b\u660e\u8a18\u3057\u3066\u3044\u308b\u5b8c\u5168\u306a\u30b3\u30fc\u30c9<\/a>\u3092\u8cbc\u308a\u4ed8\u3051\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python\u30b3\u30fc\u30c9\u306e\u6bb5\u968e\u7684\u306a\u8aac\u660e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30dd\u30fc\u30c8<\/h3>\n\n\n\n<p>\u307e\u305a\u3001\u30e2\u30c7\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.ensemble import RandomForestClassifier import\nsklearn.datasets from sklearn.datasets import make_classification\nsklearn.model_selection from sklearn.model_selection import train_test_split\nimport accuracy_score from sklearn.metrics import accuracy_score<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>RandomForestClassifier<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u30e2\u30c7\u30eb\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>make_classification<\/code>\u3092\u6307\u5b9a\u3057\u307e\u3059\uff1a\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3059\u308b\u95a2\u6570\u3067\u3001\u5206\u985e\u554f\u984c\u306b\u9069\u3057\u305f\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>train_test_split<\/code>\u3092\u6307\u5b9a\u3057\u307e\u3059\uff1a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u3051\u308b\u95a2\u6570\u3067\u3059\u3002<\/li>\n\n\n\n<li><code>accuracy_score<\/code>: \u30e2\u30c7\u30eb\u306e\u4e88\u6e2c\u7cbe\u5ea6\u3092\u8a55\u4fa1\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u4f5c\u6210<\/h3>\n\n\n\n<p>\u6b21\u306b\u3001\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u3092\u5b66\u7fd2\u3055\u305b\u308b\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u751f\u6210\nX, y = make_classification(n_samples=1000, n_features=20, n_informative=15, n_clusters_per_class=1, random_state=42)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>n_samples=1000<\/code>: 1000\u500b\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>n_features=20<\/code>: \u5404\u30b5\u30f3\u30d7\u30eb\u304c20\u500b\u306e\u7279\u5fb4\u3092\u6301\u3064\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>n_informative=15<\/code>.\u3092\u793a\u3057\u307e\u3059\uff1a20\u500b\u306e\u7279\u5fb4\u306e\u3046\u306115\u500b\u306f\u6709\u610f\u7fa9\u306a\u60c5\u5831\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>n_clusters_per_class=1<\/code>: \u5404\u30af\u30e9\u30b9\u306f1\u3064\u306e\u30af\u30e9\u30b9\u30bf\u30fc\u306b\u307e\u3068\u3081\u3089\u308c\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>random_state=42<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\uff1a\u30e9\u30f3\u30c0\u30e0\u30b7\u30fc\u30c9\u5024\u3092\u8a2d\u5b9a\u3057\u3001\u7d50\u679c\u3092\u518d\u73fe\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u96e2\u3059\u308b\u3002<\/h3>\n\n\n\n<p>\u751f\u6210\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u96e2\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u3051\u308b\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>test_size=0.3<\/code>.\u30c7\u30fc\u30bf\u306e30%\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a\u30c7\u30fc\u30bf\u306e30%\u3092\u30c6\u30b9\u30c8\u7528\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>random_state=42<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\uff1a\u30e9\u30f3\u30c0\u30e0\u30b7\u30fc\u30c9\u5024\u3092\u8a2d\u5b9a\u3057\u3001\u7d50\u679c\u3092\u518d\u73fe\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u751f\u6210<\/h3>\n\n\n\n<p>\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u751f\u6210\nmodel = RandomForestClassifier(n_estimators=100, random_state=42)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>n_estimators=100<\/code>: 100\u500b\u306e\u6c7a\u5b9a\u6728\u3092\u751f\u6210\u3057\u3066\u30a2\u30f3\u30b5\u30f3\u30d6\u30eb\u30e2\u30c7\u30eb\u3092\u69cb\u6210\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>random_state=42<\/code>\u3092\u8a2d\u5b9a\u3057\u307e\u3059\uff1a\u30e9\u30f3\u30c0\u30e0\u30b7\u30fc\u30c9\u5024\u3092\u8a2d\u5b9a\u3057\u3001\u7d50\u679c\u3092\u518d\u73fe\u53ef\u80fd\u306b\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u30e2\u30c7\u30eb\u5b66\u7fd2<\/h3>\n\n\n\n<p>\u5b66\u7fd2\u7528\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u30e2\u30c7\u30eb\u3092\u5b66\u7fd2\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u30e2\u30c7\u30eb\u5b66\u7fd2\nmodel.fit(X_train, y_train)<\/code><\/pre>\n\n\n\n<p><code>\u30d5\u30a3\u30c3\u30c8<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u305f\u5b66\u7fd2\u7528\u30c7\u30fc\u30bf <code>X_train<\/code>\u305d\u3057\u3066 <code>y_train<\/code>\u3092\u4f7f\u3063\u3066\u30e2\u30c7\u30eb\u3092\u5b66\u7fd2\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u30e2\u30c7\u30eb\u4e88\u6e2c<\/h3>\n\n\n\n<p>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4f7f\u7528\u3057\u3066\u5b66\u7fd2\u3055\u308c\u305f\u30e2\u30c7\u30eb\u3067\u4e88\u6e2c\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4e88\u6e2c\ny_pred = model.predict(X_test)<\/code><\/pre>\n\n\n\n<p><code>\u4e88\u6e2c\u3059\u308b<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf <code>X_test<\/code>\u306e\u4e88\u6e2c\u7d50\u679c\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7.\u7cbe\u5ea6\u8a55\u4fa1<\/h3>\n\n\n\n<p>\u30e2\u30c7\u30eb\u306e\u4e88\u6e2c\u7d50\u679c\u306b\u57fa\u3065\u3044\u3066\u7cbe\u5ea6\u3092\u8a55\u4fa1\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7cbe\u5ea6\u8a55\u4fa1\naccuracy = accuracy_score(y_test, y_pred)\nprint(f\"Accuracy: {accuracy:.2f}\")<\/code><\/pre>\n\n\n\n<p><code>accuracy_score<\/code> \u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u5b9f\u969b\u306e\u30e9\u30d9\u30eb <code>y_test<\/code>\u3068\u4e88\u6e2c\u5024 <code>y_pred<\/code>\u3092\u6bd4\u8f03\u3057\u3066\u30e2\u30c7\u30eb\u306e\u7cbe\u5ea6\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"total_code\">\u5b8c\u5168\u306a\u7d71\u5408\u30b3\u30fc\u30c9<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from sklearn.ensemble import RandomForestClassifier import\nsklearn.datasets from sklearn.datasets import make_classification\nsklearn.model_selection from sklearn.model_selection import train_test_split\nimport accuracy_score from sklearn.metrics import accuracy_score\n\n# \u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u751f\u6210\nX, y = make_classification(n_samples=1000, n_features=20, n_informative=15, n_clusters_per_class=1, random_state=42)\n\n#\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u96e2\u3057\u307e\u3059\u3002\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n\n# \u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u30e2\u30c7\u30eb\u751f\u6210\nmodel = RandomForestClassifier(n_estimators=100, random_state=42)\n\n#\u30e2\u30c7\u30eb\u5b66\u7fd2\nmodel.fit(X_train, y_train)\n\n# \u4e88\u6e2c\ny_pred = model.predict(X_test)\n\n# \u7cbe\u5ea6\u8a55\u4fa1\naccuracy = accuracy_score(y_test, y_pred)\nprint(f\"Accuracy: {accuracy:.2f}\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5168\u30b3\u30fc\u30c9\u5b9f\u884c\u7d50\u679c<\/h2>\n\n\n\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u5168\u4f53\u3092random_forest.py\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u3066Python\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u51fa\u307e\u3059\u3002 \u51fa\u529b\u3055\u308c\u305f\u7d50\u679c\u3067\u3042\u308bAccuracy: 0.96\u306f\u30e2\u30c7\u30eb\u304c\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u306696%\u306e\u7cbe\u5ea6\u3092\u898b\u305b\u305f\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002 \u3064\u307e\u308a\u3001100\u500b\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u3046\u306196\u500b\u3092\u6b63\u78ba\u306b\u4e88\u6e2c\u3057\u305f\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image.jpg\"><img decoding=\"async\" width=\"600\" height=\"39\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image-600x39.jpg\" alt=\"\" class=\"wp-image-2405\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image-600x39.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image-300x20.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image-768x50.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/image.jpg 872w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u3092\u4f7f\u7528\u3057\u3066\u751f\u6210\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3067\u5206\u985e\u4f5c\u696d\u3092\u884c\u3044\u3001\u975e\u5e38\u306b\u9ad8\u3044\u7cbe\u5ea6(96%)\u3092\u9054\u6210\u3057\u305f\u4f8b\u3067\u3059\u3002\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u306f\u3001\u8907\u6570\u306e\u610f\u601d\u6c7a\u5b9a\u6728\u3092\u4f7f\u7528\u3057\u3066\u4e88\u6e2c\u6027\u80fd\u3092\u5411\u4e0a\u3055\u305b\u308b\u5f37\u529b\u306a\u6a5f\u68b0\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3042\u308a\u3001\u3053\u306e\u7d50\u679c\u304b\u3089\u3001\u30e2\u30c7\u30eb\u304c\u30c7\u30fc\u30bf\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u3046\u307e\u304f\u5b66\u7fd2\u3057\u305f\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u3088\u304f\u3042\u308b\u8cea\u554f\uff08FAQ\uff09<\/h2>\n\n\n\n<p><strong>Q1. \u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8(Random Forest)\u3068\u306f\u4f55\u3067\u3059\u304b\uff1f<\/strong><br>A1.\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u306f\u3001\u8907\u6570\u306e\u6c7a\u5b9a\u6728(Decision Trees)\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4e88\u6e2c\u3092\u884c\u3046\u30a2\u30f3\u30b5\u30f3\u30d6\u30eb\u5b66\u7fd2\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3067\u3059\u3002\u500b\u3005\u306e\u30c4\u30ea\u30fc\u306e\u5f31\u70b9\u3092\u88dc\u5b8c\u3057\u3001\u904e\u9069\u5408\u3092\u6e1b\u3089\u3059\u306e\u306b\u52b9\u679c\u7684\u3067\u3059\u3002<\/p>\n\n\n\n<p><strong>Q2. \u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u306e <code>n_estimators<\/code> \u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u306f\u3069\u3046\u3044\u3046\u610f\u5473\u3067\u3059\u304b\uff1f<\/strong><br>A2. <code>n_estimators<\/code>\u306f\u751f\u6210\u3059\u308b\u6c7a\u5b9a\u6728\u306e\u6570\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u30c4\u30ea\u30fc\u6570\u304c\u591a\u3051\u308c\u3070\u591a\u3044\u307b\u3069\u3001\u4e88\u6e2c\u6027\u80fd\u306f\u5411\u4e0a\u3057\u307e\u3059\u304c\u3001\u5b66\u7fd2\u6642\u9593\u304c\u9577\u304f\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>Q3.\u30e2\u30c7\u30eb\u306e\u7cbe\u5ea6(Accuracy)\u3092\u4e0a\u3052\u308b\u65b9\u6cd5\u306f\u3042\u308a\u307e\u3059\u304b\uff1f<\/strong><br>A3.\u30e2\u30c7\u30eb\u306e\u7cbe\u5ea6\u3092\u4e0a\u3052\u308b\u305f\u3081\u306b\u306f\u3001\u3088\u308a\u591a\u304f\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u304b\u3001\u307e\u305f\u306f\u3001 <a href=\"https:\/\/ailib.secondlife.lol\/hyperparameter-tuning-guide\/\">\u30cf\u30a4\u30d1\u30fc\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u65b9\u6cd5<\/a>\u307e\u305f\u3001\u4ed6\u306e\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3068\u6bd4\u8f03\u3057\u3066\u6700\u9069\u306a\u30e2\u30c7\u30eb\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u3082\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p><strong>Q4.\u306a\u305c <code>random_state<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304b\uff1f<\/strong><br>A4. <code>random_state<\/code>\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30b3\u30fc\u30c9\u5b9f\u884c\u6642\u306b\u540c\u3058\u7d50\u679c\u3092\u5f97\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30b3\u30fc\u30c9\u306e\u518d\u73fe\u6027\u3092\u4fdd\u8a3c\u3059\u308b\u305f\u3081\u306b\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6574\u7406\u3059\u308b<\/h2>\n\n\n\n<p>\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u306f <strong>Python<\/strong>\u305d\u3057\u3066 <code>scikit-learn<\/code>\u3092\u4f7f\u3063\u3066\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u5206\u985e\u5668\u3092\u5b9f\u88c5\u3057\u3001\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3067\u30e2\u30c7\u30eb\u3092\u5b66\u7fd2\u3055\u305b\u305f\u5f8c\u3001\u4e88\u6e2c\u7cbe\u5ea6\u3092\u8a55\u4fa1\u3059\u308b\u904e\u7a0b\u3092\u898b\u3066\u307f\u307e\u3057\u305f\u3002 <strong>Python\u306e\u6a5f\u68b0\u5b66\u7fd2<\/strong>\u306e\u57fa\u672c\u7684\u306a\u4f8b\u3068\u3057\u3066\u3001\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u306e\u57fa\u672c\u7684\u306a\u6982\u5ff5\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u5f79\u7acb\u3064\u3068\u601d\u3044\u307e\u3059\u3002\u4eca\u5f8c\u3001\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3084\u554f\u984c\u306b\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u3092\u9069\u7528\u3057\u3066\u5b9f\u8df5\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>","protected":false},"excerpt":{"rendered":"<p>\u6a5f\u68b0\u5b66\u7fd2\u306b\u304a\u3044\u3066\u3001\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8(Random Forest)\u30e2\u30c7\u30eb\u306f\u4e88\u6e2c\u6027\u80fd\u304c\u512a\u308c\u3066\u304a\u308a\u3001\u69d8\u3005\u306a\u554f\u984c\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>","protected":false},"author":3,"featured_media":2406,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[3],"tags":[208,207,209,206],"class_list":["post-2404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-coding","tag-sklearn-","tag-207","tag-209","tag-206"],"taxonomy_info":{"category":[{"value":3,"label":"\ud30c\uc774\uc36c(Python)"}],"post_tag":[{"value":208,"label":"Sklearn \ud29c\ud1a0\ub9ac\uc5bc"},{"value":207,"label":"\ub79c\ub364 \ud3ec\ub808\uc2a4\ud2b8"},{"value":209,"label":"\ubd84\ub958 \ubaa8\ub378"},{"value":206,"label":"\ud30c\uc774\uc36c \uba38\uc2e0\ub7ec\ub2dd"}]},"featured_image_src_large":["https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/09\/\ub79c\ub364\ud3ec\ub808\uc2a4\ud2b8-\ubd84\ub958\ubaa8\ub378-\uc2dc\uac01\ud654-\uc378\ub124\uc77c-600x600.webp",600,600,true],"author_info":{"display_name":"TERE","author_link":"https:\/\/secondlife.lol\/ja\/author\/tere\/"},"comment_info":0,"category_info":[{"term_id":3,"name":"\ud30c\uc774\uc36c(Python)","slug":"python-coding","term_group":0,"term_taxonomy_id":3,"taxonomy":"category","description":"","parent":20,"count":116,"filter":"raw","cat_ID":3,"category_count":116,"category_description":"","cat_name":"\ud30c\uc774\uc36c(Python)","category_nicename":"python-coding","category_parent":20}],"tag_info":[{"term_id":208,"name":"Sklearn \ud29c\ud1a0\ub9ac\uc5bc","slug":"sklearn-%ed%8a%9c%ed%86%a0%eb%a6%ac%ec%96%bc","term_group":0,"term_taxonomy_id":208,"taxonomy":"post_tag","description":"","parent":0,"count":3,"filter":"raw"},{"term_id":207,"name":"\ub79c\ub364 \ud3ec\ub808\uc2a4\ud2b8","slug":"%eb%9e%9c%eb%8d%a4-%ed%8f%ac%eb%a0%88%ec%8a%a4%ed%8a%b8","term_group":0,"term_taxonomy_id":207,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":209,"name":"\ubd84\ub958 \ubaa8\ub378","slug":"%eb%b6%84%eb%a5%98-%eb%aa%a8%eb%8d%b8","term_group":0,"term_taxonomy_id":209,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"},{"term_id":206,"name":"\ud30c\uc774\uc36c \uba38\uc2e0\ub7ec\ub2dd","slug":"%ed%8c%8c%ec%9d%b4%ec%8d%ac-%eb%a8%b8%ec%8b%a0%eb%9f%ac%eb%8b%9d","term_group":0,"term_taxonomy_id":206,"taxonomy":"post_tag","description":"","parent":0,"count":3,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/posts\/2404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/comments?post=2404"}],"version-history":[{"count":1,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/posts\/2404\/revisions"}],"predecessor-version":[{"id":2407,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/posts\/2404\/revisions\/2407"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/media\/2406"}],"wp:attachment":[{"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/media?parent=2404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/categories?post=2404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secondlife.lol\/ja\/wp-json\/wp\/v2\/tags?post=2404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}