{"id":4931,"date":"2021-02-21T16:48:00","date_gmt":"2021-02-21T07:48:00","guid":{"rendered":"https:\/\/yorozu.cloudfree.jp\/wordpress\/?p=4931"},"modified":"2024-12-04T16:42:52","modified_gmt":"2024-12-04T07:42:52","slug":"%e3%82%a2%e3%83%a4%e3%83%a1%e3%81%ae%e7%a8%ae%e9%a1%9e%e5%88%a4%e5%88%a5%ef%bc%88%e3%81%9d%e3%81%ae%ef%bc%96%ef%bc%89","status":"publish","type":"post","link":"https:\/\/yorozu.cloudfree.jp\/wordpress\/?p=4931","title":{"rendered":"\u30a2\u30e4\u30e1\u306e\u7a2e\u985e\u5224\u5225\uff08\u305d\u306e\uff16\uff09"},"content":{"rendered":"\n<p>\u5b9f\u884c\u4f8b\u306f\u300csaka.mokumoku\u300d\u306e\u300cGoogle Colabotry\u300d\u74b0\u5883\u306b\u4fdd\u5b58\u3057\u3066\u3042\u308b<br>\u3000\u3000\u5b66\u7fd2\u30e2\u30c7\u30eb\u306bRandomForest\u3092\u4f7f\u7528\u3059\u308b<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\uff11\uff0e\u4e8b\u524d\u6e96\u5099<\/strong><\/h4>\n\n\n\n<p>\u3000\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u3001\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<br>\u3000\u3000\u30004\u3064\u306e\u8aac\u660e\u5909\u6570<br>\u3000\u3000\u3000\u3000\u3000sepal length (cm) : \u304c\u304f\u7247\u306e\u9577\u3055<br>\u3000\u3000\u3000\u3000\u3000sepal width (cm) : \u304c\u304f\u7247\u306e\u5e45<br>\u3000\u3000\u3000\u3000\u3000petal length (cm) : \u82b1\u5f01\u306e\u9577\u3055<br>\u3000\u3000\u3000\u3000\u3000petal width (cm) : \u82b1\u5f01\u306e\u5e45<br><br>\u3000\u3000\u3000target\u306b3\u3064\u306e\u54c1\u7a2e\u304c\u3042\u308b<br>\u3000\u3000\u3000\u3000\u3000setosa, versicolor, virginica\u306e\uff13\u54c1\u7a2e\u540d<br>\u3000\u3000\u3000\u3000\u3000\u8aac\u660e\u5909\u6570\u3068\u540c\u3058\u3088\u3046\u306b\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306b\u5165\u308c\u308b<br>\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u76ee\u7684\u5909\u6570\u306e\u5024\u3092\u78ba\u8a8d\u3059\u308b<br>\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u30000 : setosa<br>\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u30001 : versicolor<br>\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u30002 : virginica<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#\n#\u3000\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u3001\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3001\u5148\u982d5\u884c\u306e\u8868\u793a\n#\nfrom sklearn.datasets import load_iris\nimport pandas as pd\niris = load_iris()\ndata = iris.data\n#\n#\u3000\u8aac\u660e\u5909\u6570\u306e\u78ba\u8a8d\n#\nfeature_names = iris.feature_names\ndf = pd.DataFrame(data=data, columns=feature_names)\ndf.head()\n#\ndf.shape\n#\n#\u3000\u76ee\u7684\u5909\u6570\u306e\u78ba\u8a8d\n#\ntarget = iris.target\ntarget_names = iris.target_names\nprint(target_names)\n#\ndf_target = pd.DataFrame(data=target, columns=[&#39;target&#39;])\nprint((df_target.head())\n#\nprint(df_target[&#39;target&#39;].unique()) <\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\uff12\uff0e\u6a5f\u68b0\u5b66\u7fd2<\/strong><\/h4>\n\n\n\n<p>\u3000\u30c7\u30fc\u30bf\u5206\u5272<br>\u3000\u3000\u3000\u30c7\u30fc\u30bf\u3092\u5b66\u7fd2\u7528\u3068\u30c6\u30b9\u30c8\u7528\u306b\u5206\u5272\u3059\u308b<br>\u3000\u3000\u3000\u3000\u3000train_test_split()\u3067\u7c21\u5358\u306b\u5206\u5272\u3067\u304d\u308b<br>\u3000\u3000\u3000\u3000\u3000\u30c7\u30d5\u30a9\u30eb\u30c8\u306725%\u306e\u30c7\u30fc\u30bf\u304c\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf<br>\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u5909\u66f4\u3059\u308b\u5834\u5408\u306f\u5f15\u6570\u306btest_size\u3092\u8ffd\u52a0\u3059\u308b\u30010.2~0.4\u304c\u304a\u52e7\u3081<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from sklearn.model_selection import train_test_split\nx_train, x_test, y_train, y_test = train_test_split(data, df_target)\nprint(&#39;x_train : &#39;, x_train.shape) \nprint(&#39;x_test : &#39;, x_test.shape) \nprint(&#39;y_train : &#39;, y_train.shape) \nprint(&#39;y_test : &#39;, y_test.shape) <\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\uff13\uff0e\u6a5f\u68b0\u5b66\u7fd2<\/strong><\/h4>\n\n\n\n<p>\u3000\u5b66\u7fd2\u30e2\u30c7\u30eb\u306bRandomForest\u3092\u4f7f\u7528\u3059\u308b<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from sklearn.ensemble import RandomForestClassifier\nmodel = RandomForestClassifier()\n#\nmodel.fit(x_train, y_train)<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u30e2\u30c7\u30eb\u306e\u7cbe\u5ea6\u3092\u78ba\u8a8d\u3059\u308b<br>\u3000\u3000\u3000\u7cbe\u5ea6\u306e\u78ba\u8a8d\u306b\u306faccuracy_score\u3092\u4f7f\u7528\u3059\u308b<br>\u3000\u3000\u3000\u7cbe\u5ea6\u306f 97.4%<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pred = model.predict(x_test)\n#\nfrom sklearn.metrics import accuracy_score\naccuracy_score(y_test, pred) <\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30fb\u300c\u3042\u3084\u3081\u300d\u306e\u7a2e\u985e\u3092\u5224\u5225\u3059\u308b\u6a5f\u68b0\u5b66\u7fd2\u306b\u3064\u3044\u3066<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[24],"class_list":["post-4931","post","type-post","status-publish","format-standard","hentry","category-99_","tag-24"],"_links":{"self":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4931"}],"version-history":[{"count":20,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4931\/revisions"}],"predecessor-version":[{"id":4955,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4931\/revisions\/4955"}],"wp:attachment":[{"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yorozu.cloudfree.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}