{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        if filename.endswith(\"csv\"):\n            print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-15T12:46:50.834364Z","iopub.execute_input":"2022-02-15T12:46:50.83474Z","iopub.status.idle":"2022-02-15T12:47:07.436355Z","shell.execute_reply.started":"2022-02-15T12:46:50.834702Z","shell.execute_reply":"2022-02-15T12:47:07.435683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\", dtype={\"article_id\": \"str\"})\ncustomers = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv\")\narticles = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv\", dtype={\"article_id\": \"str\"})","metadata":{"execution":{"iopub.status.busy":"2022-02-15T12:47:25.446066Z","iopub.execute_input":"2022-02-15T12:47:25.447013Z","iopub.status.idle":"2022-02-15T12:48:45.584554Z","shell.execute_reply.started":"2022-02-15T12:47:25.446966Z","shell.execute_reply":"2022-02-15T12:48:45.581987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We are creating 0.1%, 1%, and 5% samples of the original dataset. Keeping the related articles and customers.","metadata":{}},{"cell_type":"code","source":"for sample_repr, sample in [(\"01\", 0.001), (\"1\", 0.01), (\"5\", 0.05)]:\n    print(sample)\n    customers_sample = customers.sample(int(customers.shape[0]*sample), replace=False)\n    customers_sample_ids = set(customers_sample[\"customer_id\"])\n    transactions_sample = transactions[transactions[\"customer_id\"].isin(customers_sample_ids)]\n    articles_sample_ids = set(transactions_sample[\"article_id\"])\n    articles_sample = articles[articles[\"article_id\"].isin(articles_sample_ids)]\n    customers_sample.to_csv(f\"customers_sample{sample_repr}.csv.gz\", index=False)\n    transactions_sample.to_csv(f\"transactions_train_sample{sample_repr}.csv.gz\", index=False)\n    articles_sample.to_csv(f\"articles_train_sample{sample_repr}.csv.gz\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T12:49:10.200358Z","iopub.execute_input":"2022-02-15T12:49:10.200742Z","iopub.status.idle":"2022-02-15T12:49:52.287196Z","shell.execute_reply.started":"2022-02-15T12:49:10.200698Z","shell.execute_reply":"2022-02-15T12:49:52.286406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}