{"metadata": {"language_info": {"pygments_lexer": "ipython3", "version": "3.6.3", "mimetype": "text/x-python", "name": "python", "codemirror_mode": {"version": 3, "name": "ipython"}, "nbconvert_exporter": "python", "file_extension": ".py"}, "kernelspec": {"language": "python", "name": "python3", "display_name": "Python 3"}}, "nbformat": 4, "cells": [{"source": ["# Simple voting on your submissions\n", "\n", "This kernel applies simple voting to your existing submissions. Could help you to improve LB score a little."], "metadata": {"_cell_guid": "5641ad99-9e7b-46c8-9e1e-708da7111c57", "_uuid": "8ba1b077efba905666f5f60b2e831e0534165826"}, "cell_type": "markdown"}, {"source": ["import pandas as pd\n", "import numpy as np\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))"], "metadata": {"_cell_guid": "a38ab7c6-c4a7-4b0c-8017-7e99c92dc582", "_uuid": "2bb68d3eed8fc347514d89e292773f3e6147760b"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["Choose several of your best submissions and load .csv:"], "metadata": {"_cell_guid": "7570eb0d-1298-4108-be3a-1a6dce2b60a6", "_uuid": "45de5f4d56f5360d5050215aa2dfad179bd6842f"}, "cell_type": "markdown"}, {"source": ["# lb 0.69279\n", "subm1 = pd.read_csv('../input/cdiscount-image-classification-submission-samples/submission_sample_1.csv')\n", "# lb 0.69280\n", "subm2 = pd.read_csv('../input/cdiscount-image-classification-submission-samples/submission_sample_2.csv')\n", "# lb 0.69281\n", "subm3 = pd.read_csv('../input/cdiscount-image-classification-submission-samples/submission_sample_3.csv')\n", "# lb 0.68966\n", "subm4 = pd.read_csv('../input/cdiscount-image-classification-submission-samples/submission_sample_4.csv')"], "metadata": {"collapsed": true, "_cell_guid": "7866a1a8-d622-4f7a-9452-c315ccbc5e90", "_uuid": "620cac09bbc80730a92f47d1545f2391d778e7e9"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["Merge datasets by '_id' column:"], "metadata": {"_cell_guid": "9b3d4aa1-718f-4082-871f-3d183fdb1707", "_uuid": "7f48c31a78d0a30f4279409f74fe16a88e671999"}, "cell_type": "markdown"}, {"source": ["subm_all = subm1.merge(subm2,on='_id').merge(subm3,on='_id').merge(subm4,on='_id')\n", "subm_all.head()"], "metadata": {"_cell_guid": "d341b42d-be6b-4220-856a-7c09d1d13f5c", "_uuid": "7735c266b8870dd6d9289159c7a7bbfbd6171e6c"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["Apply voting by getting most frequent category for each item (__takes several minutes on my laptop__):"], "metadata": {"_cell_guid": "d4a69038-aa49-424c-8c1b-9047f8a76a32", "_uuid": "04f5ab996bab9a54f0e66630610d61393ff10683"}, "cell_type": "markdown"}, {"source": ["subm_all_voting = subm_all.mode(axis=1)\n", "subm_all_voting.head()"], "metadata": {"_cell_guid": "7eef2605-b116-4db5-b014-212e9fbd9145", "_uuid": "db8ca49072f4b5e699ec4e68db39fd80a47c3d1d"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["Save results to a new .csv file:"], "metadata": {"_cell_guid": "9b8fc903-56c3-4a9c-a4bf-272be6d91103", "_uuid": "f3e778a37512229314666a76e4f48eaa8c1c419a"}, "cell_type": "markdown"}, {"source": ["result = pd.DataFrame()\n", "result['_id'] = subm_all['_id']\n", "result['category_id'] = subm_all_voting[0].astype(int)\n", "result.to_csv('submission_voting.csv', index=False)"], "metadata": {"collapsed": true, "_cell_guid": "c2062a11-6646-49e7-99c3-061eaa6345c4", "_uuid": "4091aa437e8e783efa83120577ceede653deaea0"}, "execution_count": null, "cell_type": "code", "outputs": []}], "nbformat_minor": 1}