{"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\n# for dirname, _, filenames in os.walk('/kaggle/input'):\n#     for filename in filenames:\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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from datetime import datetime, date, timedelta\nfrom typing import List, Tuple, Dict, Union\n\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom scipy import stats\nfrom tqdm import tqdm\n\nsns.set()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.to_dict(\"records\")[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Customer EDA","metadata":{}},{"cell_type":"code","source":"display(\n    customers.head(),\n    f\"[ num of customers: {len(customers)} ]\",\n    f\"[ cols of customers: {list(customers.columns)}]\",\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:10:04.472269Z","iopub.execute_input":"2022-04-13T10:10:04.472535Z","iopub.status.idle":"2022-04-13T10:10:04.49122Z","shell.execute_reply.started":"2022-04-13T10:10:04.472507Z","shell.execute_reply":"2022-04-13T10:10:04.490278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# inspect customer id\n\ndisplay(customers[\"customer_id\"].value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:05:47.114668Z","iopub.execute_input":"2022-04-13T10:05:47.114955Z","iopub.status.idle":"2022-04-13T10:05:49.04952Z","shell.execute_reply.started":"2022-04-13T10:05:47.114925Z","shell.execute_reply":"2022-04-13T10:05:49.048662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# What is FN?\n\ndisplay(\n    customers[\"FN\"].value_counts(),\n    len(customers[customers[\"FN\"] == 1.0]) / len(customers),\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:11:34.623118Z","iopub.execute_input":"2022-04-13T10:11:34.623456Z","iopub.status.idle":"2022-04-13T10:11:34.78789Z","shell.execute_reply.started":"2022-04-13T10:11:34.623424Z","shell.execute_reply":"2022-04-13T10:11:34.786912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Num of Active Customers\ndisplay(\n    customers[\"Active\"].value_counts(),\n    len(customers[customers[\"Active\"] == 1.0]) / len(customers),\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:13:32.083266Z","iopub.execute_input":"2022-04-13T10:13:32.083574Z","iopub.status.idle":"2022-04-13T10:13:32.194254Z","shell.execute_reply.started":"2022-04-13T10:13:32.083542Z","shell.execute_reply":"2022-04-13T10:13:32.193395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 생각해볼점\n- Active와 Dead 상태의 유저를 구분해서 작업해야할 필요가 있지 않을까?\n- Active status가 0인 유저는 상품을 구매할 수 없고, 그렇다면 트렌드에 반영되지 않을수도 있다는 생각?","metadata":{}},{"cell_type":"code","source":"# club_member_status\ndisplay(\n    customers[\"club_member_status\"].value_counts(),\n    f\"\"\"Active Users Ratio: {\n        len(customers[customers['club_member_status'] == 'ACTIVE']) / len(customers),\n    }\"\"\",\n    f\"\"\"PRE-CREATE Users Ratio: {\n        len(customers[customers['club_member_status'] == 'PRE-CREATE']) / len(customers),\n    }\"\"\",\n    f\"\"\"LEFT-CLUB Users Ratio: {\n        len(customers[customers['club_member_status'] == 'LEFT CLUB']) / len(customers),\n    }\"\"\",\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:20:54.691253Z","iopub.execute_input":"2022-04-13T10:20:54.691568Z","iopub.status.idle":"2022-04-13T10:20:55.722964Z","shell.execute_reply.started":"2022-04-13T10:20:54.691534Z","shell.execute_reply":"2022-04-13T10:20:55.721899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Club Member에서 생각해볼점\n- Active User만을 대상으로 모델링해도 괜찮을 것 같음\n- Active, PRE-CREATE까지만 고려해서 모델링하자","metadata":{}},{"cell_type":"code","source":"# fashion_news_frequency\ncustomers[\"fashion_news_frequency\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:24:19.921897Z","iopub.execute_input":"2022-04-13T10:24:19.922164Z","iopub.status.idle":"2022-04-13T10:24:20.142236Z","shell.execute_reply.started":"2022-04-13T10:24:19.922136Z","shell.execute_reply":"2022-04-13T10:24:20.141367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(customers[\"fashion_news_frequency\"].value_counts()).plot(kind=\"bar\")","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:24:56.332605Z","iopub.execute_input":"2022-04-13T10:24:56.332934Z","iopub.status.idle":"2022-04-13T10:24:56.872617Z","shell.execute_reply.started":"2022-04-13T10:24:56.332898Z","shell.execute_reply":"2022-04-13T10:24:56.871779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Age\nage_df = pd.DataFrame(customers[\"age\"].value_counts()).reset_index()\nage_df","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:37:28.612678Z","iopub.execute_input":"2022-04-13T10:37:28.612981Z","iopub.status.idle":"2022-04-13T10:37:28.644279Z","shell.execute_reply.started":"2022-04-13T10:37:28.612951Z","shell.execute_reply":"2022-04-13T10:37:28.643272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\nplt.figure(figsize=(20, 10))\n\nstart_range = 0\nend_range = 20\nsns.barplot(data=age_df[start_range:end_range], x=\"index\", y=\"age\", alpha=0.8, order=age_df[start_range:end_range][\"index\"].values)\nplt.xticks(rotation=45)\nplt.show()\n\nplt.figure(figsize=(20, 10))\n\nstart_range = 20\nend_range = 40\nsns.barplot(data=age_df[start_range:end_range], x=\"index\", y=\"age\", alpha=0.8, order=age_df[start_range:end_range][\"index\"].values)\nplt.xticks(rotation=45)\nplt.show()\n\nplt.figure(figsize=(20, 10))\n\nstart_range = 40\nend_range = 60\nsns.barplot(data=age_df[start_range:end_range], x=\"index\", y=\"age\", alpha=0.8, order=age_df[start_range:end_range][\"index\"].values)\nplt.xticks(rotation=45)\nplt.show()\n\nplt.figure(figsize=(20, 10))\n\nstart_range = 60\nend_range = 100\nsns.barplot(data=age_df[start_range:end_range], x=\"index\", y=\"age\", alpha=0.8, order=age_df[start_range:end_range][\"index\"].values)\nplt.xticks(rotation=45)\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:39:46.962547Z","iopub.execute_input":"2022-04-13T10:39:46.962832Z","iopub.status.idle":"2022-04-13T10:39:48.436828Z","shell.execute_reply.started":"2022-04-13T10:39:46.962802Z","shell.execute_reply":"2022-04-13T10:39:48.435744Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# postcal code\ndisplay(\n    customers[\"postal_code\"].value_counts(),\n)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T10:47:08.918233Z","iopub.execute_input":"2022-04-13T10:47:08.918533Z","iopub.status.idle":"2022-04-13T10:47:09.860617Z","shell.execute_reply.started":"2022-04-13T10:47:08.918499Z","shell.execute_reply":"2022-04-13T10:47:09.859614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 생각해볼점\n- 사실 사용자마다의 주소가 제각각일텐데 어쨌든 이렇게 만 몇개씩 걸리는 거는 문제가 있다고 생각~\n- 제대로 모델링할때 조사해봐야할 부분","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}