{"id":192,"date":"2020-10-20T01:54:26","date_gmt":"2020-10-19T16:54:26","guid":{"rendered":"https:\/\/www.ritzcolor.net\/?p=192"},"modified":"2020-12-10T20:08:32","modified_gmt":"2020-12-10T11:08:32","slug":"%e3%81%a9%e7%b4%a0%e4%ba%ba%e3%81%aekaggle3-%e5%8a%9b%e3%81%a5%e3%81%8f%e3%81%a71st-submit","status":"publish","type":"post","link":"https:\/\/www.ritzcolor.net\/?p=192","title":{"rendered":"\u3069\u7d20\u4eba\u306ekaggle3 -\u529b\u3065\u304f\u30671st submit-"},"content":{"rendered":"\n<p>\u524d\u56de\u30c7\u30fc\u30bf\u306e\u6982\u8981\u3092\u307f\u305f\u3068\u3053\u308d\u3067\u3001\u7d50\u5408\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u306a\u3068\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u304c\u3069\u3046\u624b\u3092\u3064\u3051\u3066\u3044\u3044\u3084\u3089\u5168\u304f\u308f\u304b\u3089\u305a\u3002\u3002\u3002<\/p>\n\n\n\n<p>\u4eca\u56de\u4f5c\u3063\u305f\u30b3\u30fc\u30c9\u306f\u524d\u56de\u5206\u3082\u5408\u308f\u305b\u3066\u3001Note\u306b\u307e\u3068\u3081\u3088\u3046\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4e00\u56de\u7acb\u3061\u623b\u3063\u3066\u3001\u4f55\u3092\u4e88\u6e2c\u3059\u308b\u3079\u304d\u304b\u3092\u3082\u3046\u4e00\u5ea6\u898b\u8fd4\u3059\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\u6700\u521d\u304b\u3089\u3057\u3063\u304b\u308a\u3084\u3089\u306a\u3044\u304b\u3089\u3053\u3046\u306a\u308b\u306e\u3067\u3059\u3002\u53cd\u7701\u3067\u3059\u3002\u3068\u3044\u3046\u3053\u3068\u3067\u6539\u3081\u3066Data\u306e\u9805\u76ee\u3092\u78ba\u8a8d\u3057\u305f\u3068\u3053\u308d\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u8868\u8a18\u3002<\/p>\n\n\n\n<h2>File descriptions<\/h2>\n\n\n\n<ul><li><strong>sales_train.csv<\/strong>&nbsp;&#8211; the training set. Daily historical data from January 2013 to October 2015.<\/li><li><strong>test.csv<\/strong>&nbsp;&#8211; the test set.&nbsp;You need to forecast the sales for these shops and products for November 2015.<\/li><\/ul>\n\n\n\n<p>2013.1 &#8211; 2015.10\u306e\u30c7\u30fc\u30bf\u3092\u5143\u306b2015.11\u306e\u58f2\u308a\u4e0a\u3052\u3092\u4e88\u6e2c\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3057\u305f\u3002\u305d\u3046\u8003\u3048\u308b\u3068item\u3084category\u3084shop\u306e\u540d\u524d\u3063\u3066\u305d\u308c\u307b\u3069\u91cd\u8981\u3067\u306f\u306a\u3044\u306e\u3067\u306f\u306a\u3044\u304b\uff1f\u3068\u90fd\u5408\u3088\u304f\u8003\u3048\u51fa\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3088\u308a\u306f\u5e74\u3084\u65e5\u4ed8\u306a\u3069\u6642\u7cfb\u5217\u7684\u306a\u3082\u306e\u306e\u65b9\u304c\u52b9\u304d\u305d\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4e0b\u8a18\u306e\u30b3\u30fc\u30c9\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>train_3[&quot;year&quot;] = train_3[&quot;date&quot;].str[-4:]\ntrain_3[&quot;month&quot;] = train_3[&quot;date&quot;].str[-7:-5]\ntrain_3[[&quot;month&quot;, &quot;item_cnt_day&quot;]].groupby([&quot;month&quot;], as_index=False).sum().sort_values(by=&quot;item_cnt_day&quot;, ascending=True)\ntrain_3[[&quot;year&quot;, &quot;item_cnt_day&quot;]].groupby([&quot;year&quot;], as_index=False).sum().sort_values(by=&quot;item_cnt_day&quot;, ascending=True)<\/code><\/pre><\/div>\n\n\n\n<p>date\u306f\u6587\u5b57\u5217\u306a\u306e\u3067\u3001\u305d\u3053\u304b\u3089\u5e74\u3068\u6708\u3092\u5206\u5272\u3057\u305f\u306e\u3067\u3059\u3002\u3055\u3089\u306b\u305d\u308c\u305e\u308c\u306e\u30d4\u30dc\u30c3\u30c8\u3092\u4f5c\u308a\u3001\u305d\u306e\u50be\u5411\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002\u7d50\u679c\u7684\u306b\u5e74\u306f\u304b\u306a\u308a\u76f8\u95a2\u304c\u3042\u308a\u305d\u3046\u3067\u3057\u305f\u3002\u3064\u3044\u3067\u306b\u65e5\u306b\u3061\u3082\u6708\u3082\u50be\u5411\u307f\u307e\u3057\u305f\u304c\u3001\u5e74\u307b\u3069\u660e\u78ba\u3067\u306f\u306a\u304b\u3063\u305f\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u73fe\u6642\u70b9\u306etrain\u306e\u30c6\u30fc\u30d6\u30eb\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>ID<\/th><th>shop_id<\/th><th>item_id<\/th><th>item_category_id<\/th><th>year<\/th><th>month<\/th><\/tr><\/thead><\/table><\/figure>\n\n\n\n<p>\u5f15\u304d\u63db\u3048test\u306e\u30c6\u30fc\u30d6\u30eb\u306fyear\u3068month\u304c\u629c\u3051\u3066\u3044\u307e\u3057\u305f\u3002\u3053\u306e\u307e\u307e\u3067\u306ftrain\u3068test\u3067\u7279\u5fb4\u91cf\u306e\u6570\u304c\u7570\u306a\u308a\u3001\u8a08\u7b97\u3067\u304d\u306a\u3044\u3088\u3068\u306e\u3053\u3068\u3067\u3057\u305f\u306e\u3067\u3001test\u306b\u3082year\u3068month\u3092\u8ffd\u52a0\u3057\u3088\u3046\u3068\u3002\u5185\u5bb9\u306f\u4eca\u56de\u4e88\u6e2c\u3059\u308b2016\u5e74\u300111\u6708\u306a\u306e\u3067\u3001\u5358\u7d14\u306b\u305d\u308c\u3089\u3092\u6b21\u306e\u30b3\u30fc\u30c9\u3067\u8ffd\u8a18\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>test_3[&quot;year&quot;] = 2016\ntest_3[&quot;month&quot;] = 11<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3067\u7279\u5fb4\u91cf\u306e\u6570\u3082\u4e00\u81f4\u3057\u305f\u306e\u3067\u3001\u65e9\u901f\u30e2\u30c7\u30eb\u4f5c\u308a\u3068\u4e88\u6e2c\u3092\u884c\u3044\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u6c7a\u5b9a\u6728\u3092\u63a1\u7528\u3002\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8\u3082\u8a66\u3057\u3066\u307f\u305f\u306e\u3067\u3059\u304cCPU over\u3067\u8a08\u7b97\u5b8c\u4e86\u305b\u305a\u3002\u3069\u3046\u3057\u305f\u3089\u52d5\u304f\u306e\u3084\u3089\u6b21\u306e\u8ab2\u984c\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u3001train\u30c6\u30fc\u30d6\u30eb\u306e\u7279\u5fb4\u91cf\u3092X_train, \u76ee\u7684\u5909\u6570\u3092Y_train\u3078\u3001test\u30c6\u30fc\u30d6\u30eb\u306e\u7279\u5fb4\u91cf\u3092X_test\u306b\u4ee3\u5165\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u6642ID\u306f\u4e88\u6e2c\u3068\u95a2\u4fc2\u306a\u3044\u306e\u3067\u9664\u53bb\u3002\u3064\u3044\u3067\u306bshape\u3067\u30ab\u30e9\u30e0\u306e\u6570\u304c\u4e00\u81f4\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># \u6a5f\u68b0\u5b66\u7fd2\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.tree import DecisionTreeClassifier\n\n# 1. X_train\u306b\u306f\u3001\u76ee\u7684\u5909\u6570\u4ee5\u5916\u3092\u5165\u529b\nX_train = train_3.drop(&quot;item_cnt_day&quot;, axis=1)\n\n# 2. Y_train\u306b\u306f\u3001\u76ee\u7684\u5909\u6570\u304c\u5165\u3063\u305ftrain_df\u3092\u4ee3\u5165\nY_train = train_3[&quot;item_cnt_day&quot;]\n\n# 3. X_test\u306b\u306f\u3001ID\u3092\u9664\u3044\u305ftest_df\u3092\u4ee3\u5165\nX_test  = test_3.drop(&quot;ID&quot;, axis=1).copy()\n\n# 4. X_train\u3001Y_train\u3001X_test\u306e\u884c\u6570\u3001\u5217\u6570\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\nprint(X_train.shape, Y_train.shape, X_test.shape)\n\n#train\u3092\u5206\u5272\nX_train_lr, X_test_lr, Y_train_lr, Y_test_lr = train_test_split(X_train, Y_train, test_size=0.2)<\/code><\/pre><\/div>\n\n\n\n<p>\u6c7a\u5b9a\u6728\u306b\u3088\u308bmodel\u4f5c\u308a\u3068\u4e88\u6e2c\u3092\u5b9f\u884c\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>decision_tree = DecisionTreeClassifier()\ndecision_tree.fit(X_train, Y_train)\n\nY_pred = decision_tree.predict(X_test)\nacc_decision_tree = round(decision_tree.score(X_train, Y_train) * 100, 2)\n\nprint(acc_decision_tree)<\/code><\/pre><\/div>\n\n\n\n<p>\u6700\u5f8c\u306b\u4e88\u6e2c\u5024\u3092submission\u306esample\u3068\u5408\u308f\u305b\u3066csv\u51fa\u529b\u3002kaggle\u306eoutput\u30d5\u30a9\u30eb\u30c0\u306b\u4fdd\u5b58\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plane\"><code># 1. Predict\u3092CSV\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3002\nsubmission = pd.DataFrame({\n        &quot;ID&quot;: test_3[&quot;ID&quot;],\n        &quot;item_cnt_month&quot;: Y_pred\n    })\n\nsubmission.to_csv(&#39;\/kaggle\/working\/my_submission.csv&#39;, index=False)<\/code><\/pre><\/div>\n\n\n\n<p>\u305d\u3057\u3066\u63d0\u51fa\u3057\u305f\u7d50\u679c\u3001Score\u306f1.53867\u3002\u3002\u3002RMST\u306a\u306e\u3067\u5c0f\u3055\u3044\u65b9\u304c\u826f\u3044\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u9806\u4f4d\u306f\u3068\u3044\u3046\u3068\u9806\u4f4d\u306f9,767\u4eba\u306e\u53c2\u52a0\u8005\u4e2d7,935\u4f4d\u3002\u6b63\u76f4\u307e\u3060\u4e0b\u306b\u3044\u308b\u306e\u304b\u3068\u3044\u3046\u306e\u304c\u672c\u97f3\u3067\u3059\u3002\u3002\u3002<\/p>\n\n\n\n<p>\u3055\u3089\u306b\u70b9\u6570\u3092\u4e0a\u3052\u308b\u8981\u7d20\u3068\u3057\u3066\u306f\u3001\u7279\u5fb4\u91cf\u306e\u898b\u76f4\u3057\u3001\u5b66\u7fd2\u6cd5\u306e\u898b\u76f4\u3057\u3001\u30cf\u30a4\u30d1\u30fc\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u898b\u76f4\u3057\u3001\u3042\u3068\u4eca\u56de\u306e\u5168\u30b3\u30fc\u30c9\u3092note\u306b\u516c\u958b\u3057\u3088\u3046\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u30421\u56de\u76ee\u3067\u63d0\u51fa\u307e\u3067\u51fa\u6765\u305f\u306e\u3067\u3068\u308a\u3042\u3048\u305a\u3088\u3057\u3068\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u30c7\u30fc\u30bf\u306e\u6982\u8981\u3092\u307f\u305f\u3068\u3053\u308d\u3067\u3001\u7d50\u5408\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u306a\u3068\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u304c\u3069\u3046\u624b\u3092\u3064\u3051\u3066\u3044\u3044\u3084\u3089\u5168\u304f\u308f\u304b\u3089\u305a\u3002\u3002\u3002 \u4eca\u56de\u4f5c\u3063\u305f\u30b3\u30fc\u30c9\u306f\u524d\u56de\u5206\u3082\u5408\u308f\u305b\u3066\u3001Note\u306b\u307e\u3068\u3081\u3088\u3046\u304b\u3068\u601d\u3044\u307e\u3059\u3002 \u4e00\u56de\u7acb\u3061\u623b\u3063\u3066\u3001\u4f55\u3092\u4e88\u6e2c\u3059\u308b\u3079\u304d\u304b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":175,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3],"tags":[6,19,20],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.ritzcolor.net\/wp-content\/uploads\/2020\/10\/character_program_smart.png?fit=400%2C400&ssl=1","_links":{"self":[{"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/posts\/192"}],"collection":[{"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=192"}],"version-history":[{"count":3,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions\/195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ritzcolor.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}