{"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":"import pickle\n\nimport pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:29:37.67869Z","iopub.execute_input":"2022-04-22T00:29:37.679011Z","iopub.status.idle":"2022-04-22T00:29:37.685287Z","shell.execute_reply.started":"2022-04-22T00:29:37.67898Z","shell.execute_reply":"2022-04-22T00:29:37.684102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def pickle_variables(variable_names, delete_variables=False):\n    \"\"\"\n    saves to current directory\n    if delete_variables=True, will also delete variables\n\n    pickle variables with format <variable_name>.pkl\n    \"\"\"\n    for variable_name in variable_names:\n        with open(f\"{variable_name}.pkl\", \"wb\") as f:\n            pickle.dump(globals()[variable_name], f)\n        if delete_variables:\n            del globals()[variable_name]","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:32:18.359675Z","iopub.execute_input":"2022-04-22T00:32:18.360032Z","iopub.status.idle":"2022-04-22T00:32:18.366375Z","shell.execute_reply.started":"2022-04-22T00:32:18.359995Z","shell.execute_reply":"2022-04-22T00:32:18.365441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntransactions_train = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\",\n                           dtype={\"t_dat\": \"object\", \"customer_id\": \"object\", \"article_id\": \"object\", \"price\": float, \"sales_channel_id\": int})\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\": \"object\"})","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:30:27.310737Z","iopub.execute_input":"2022-04-22T00:30:27.311016Z","iopub.status.idle":"2022-04-22T00:31:38.077908Z","shell.execute_reply.started":"2022-04-22T00:30:27.310986Z","shell.execute_reply":"2022-04-22T00:31:38.076971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pickle_variables([\"transactions_train\", \"customers\", \"articles\"])","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:32:19.529412Z","iopub.execute_input":"2022-04-22T00:32:19.530245Z","iopub.status.idle":"2022-04-22T00:32:39.909586Z","shell.execute_reply.started":"2022-04-22T00:32:19.530201Z","shell.execute_reply":"2022-04-22T00:32:39.908916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_50pct = customers.sample(frac=0.5, replace=False).reset_index(drop=True)\ncustomers_50pct_ids = set(customers_50pct[\"customer_id\"])\ntransactions_train_50pct = transactions_train.query(\"customer_id in @customers_50pct_ids\").reset_index(drop=True)\npickle_variables([\"transactions_train_50pct\", \"customers_50pct\"], delete_variables=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:36:16.400232Z","iopub.execute_input":"2022-04-22T00:36:16.40123Z","iopub.status.idle":"2022-04-22T00:36:39.086005Z","shell.execute_reply.started":"2022-04-22T00:36:16.401171Z","shell.execute_reply":"2022-04-22T00:36:39.085015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_5pct = customers.sample(frac=0.05, replace=False).reset_index(drop=True)\ncustomers_5pct_ids = set(customers_5pct[\"customer_id\"])\ntransactions_train_5pct = transactions_train.query(\"customer_id in @customers_5pct_ids\").reset_index(drop=True)\npickle_variables([\"transactions_train_5pct\", \"customers_5pct\"], delete_variables=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-22T00:36:53.698152Z","iopub.execute_input":"2022-04-22T00:36:53.699009Z","iopub.status.idle":"2022-04-22T00:36:59.532121Z","shell.execute_reply.started":"2022-04-22T00:36:53.698962Z","shell.execute_reply":"2022-04-22T00:36:59.53112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}