{"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":"markdown","source":"## Simple EDA\n\nThis is a simple EDA on the data set.\nI will update it as needed.\n\nThis EDA uses a Self-producing package called \"kz-pipe\".\nTo install it, execute the following command.\n\n```\n!pip install git+https://github.com/kazuki-komori/kz-pipe.git\n```","metadata":{}},{"cell_type":"code","source":"%config Completer.use_jedi = False\n\n!pip install git+https://github.com/kazuki-komori/kz-pipe.git","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-05T15:17:05.063954Z","iopub.execute_input":"2022-04-05T15:17:05.064945Z","iopub.status.idle":"2022-04-05T15:17:18.884781Z","shell.execute_reply.started":"2022-04-05T15:17:05.06479Z","shell.execute_reply":"2022-04-05T15:17:18.883665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport numpy as np\nsns.set_theme(style=\"darkgrid\")\n\nfrom kz_pipe import eda, Timer, shaper","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:17:18.888147Z","iopub.execute_input":"2022-04-05T15:17:18.888521Z","iopub.status.idle":"2022-04-05T15:17:20.015305Z","shell.execute_reply.started":"2022-04-05T15:17:18.888476Z","shell.execute_reply":"2022-04-05T15:17:20.014625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load Dataset","metadata":{}},{"cell_type":"code","source":"with Timer(prefix=\"laoding data...\"):\n    df_article = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\n    df_customers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\n    df_transactions = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:17:20.016477Z","iopub.execute_input":"2022-04-05T15:17:20.017605Z","iopub.status.idle":"2022-04-05T15:18:39.467945Z","shell.execute_reply.started":"2022-04-05T15:17:20.017537Z","shell.execute_reply":"2022-04-05T15:18:39.466273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Features of Customers","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8, 6))\n_df = pd.DataFrame(df_customers[\"FN\"].fillna(0).astype(int))\neda.plt_count(col=\"FN\", data=_df, title=\"Frequency of FN\", ax=ax)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:39.472674Z","iopub.execute_input":"2022-04-05T15:18:39.473092Z","iopub.status.idle":"2022-04-05T15:18:39.875986Z","shell.execute_reply.started":"2022-04-05T15:18:39.473054Z","shell.execute_reply":"2022-04-05T15:18:39.874975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8, 6))\n_df_1 = df_customers[\"Active\"].fillna(0).astype(int)\n_df_2 = df_customers[\"FN\"].fillna(0).astype(int)\neda.plt_venn(_df_1, _df_2, left_lab=\"Active\", right_lab=\"FN\", title=\"Active or FN User\", ax=ax)","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-04-05T15:18:39.877546Z","iopub.execute_input":"2022-04-05T15:18:39.877827Z","iopub.status.idle":"2022-04-05T15:18:40.397435Z","shell.execute_reply.started":"2022-04-05T15:18:39.877793Z","shell.execute_reply":"2022-04-05T15:18:40.396608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(8, 6))\ndf_customers[\"club_member_status\"] = df_customers[\"club_member_status\"].fillna(\"Blanck\")\neda.plt_count(col=\"club_member_status\", data=df_customers, title=\"Frequency of club_member_status\", ax=ax)\n\nfig, ax = plt.subplots(figsize=(8, 6))\ndf_customers[\"fashion_news_frequency\"] = df_customers[\"fashion_news_frequency\"].fillna(\"Blanck\")\neda.plt_count(col=\"fashion_news_frequency\", data=df_customers, title=\"Frequency of fashion_news_frequency\", ax=ax)\n","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:40.398935Z","iopub.execute_input":"2022-04-05T15:18:40.399583Z","iopub.status.idle":"2022-04-05T15:18:43.774445Z","shell.execute_reply.started":"2022-04-05T15:18:40.399531Z","shell.execute_reply":"2022-04-05T15:18:43.773234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Distribution of customer age","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 6))\neda.plt_by_age(df=df_customers, col=\"age\", max_age=100, min_age=15, ax=ax, xlab=\"age\")","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:43.776348Z","iopub.execute_input":"2022-04-05T15:18:43.776692Z","iopub.status.idle":"2022-04-05T15:18:44.317497Z","shell.execute_reply.started":"2022-04-05T15:18:43.776647Z","shell.execute_reply":"2022-04-05T15:18:44.316517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Active status by age","metadata":{}},{"cell_type":"code","source":"n_cols = 3\nn_rows = 4\n_labs = [\"{0}-{1}\".format(i, i + 5) for i in range(15, 70, 5)]\ndf_customers[\"age_range\"] = shaper.str_by_age(df=df_customers, col=\"age\")\n\nfig, axes = plt.subplots(figsize=(4 * n_cols, 3 * n_rows), ncols=n_cols, nrows=n_rows)\nfor _lab, ax in zip(_labs, np.ravel(axes)):\n    eda.plt_count(\n        title=f\"active of {_lab}\",\n        data = df_customers.query(f\"age_range == '{_lab}'\"),\n        col = \"club_member_status\",\n        ax=ax,\n        x_rotate=True\n    )","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:44.318925Z","iopub.execute_input":"2022-04-05T15:18:44.319144Z","iopub.status.idle":"2022-04-05T15:18:49.459116Z","shell.execute_reply.started":"2022-04-05T15:18:44.319118Z","shell.execute_reply":"2022-04-05T15:18:49.458291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Features of Articles","metadata":{}},{"cell_type":"code","source":"df_article.info() ","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:49.460295Z","iopub.execute_input":"2022-04-05T15:18:49.460874Z","iopub.status.idle":"2022-04-05T15:18:49.654582Z","shell.execute_reply.started":"2022-04-05T15:18:49.460838Z","shell.execute_reply":"2022-04-05T15:18:49.653945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_article.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:49.656822Z","iopub.execute_input":"2022-04-05T15:18:49.657202Z","iopub.status.idle":"2022-04-05T15:18:49.834607Z","shell.execute_reply.started":"2022-04-05T15:18:49.657172Z","shell.execute_reply":"2022-04-05T15:18:49.833949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- different number of `product_type_no` and `product_type_name`.\n- different number of `department_no` and `department_name`.\n- different number of `section_no` and `section_name`.","metadata":{}},{"cell_type":"code","source":"df_article.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:49.835727Z","iopub.execute_input":"2022-04-05T15:18:49.836077Z","iopub.status.idle":"2022-04-05T15:18:50.00416Z","shell.execute_reply.started":"2022-04-05T15:18:49.836049Z","shell.execute_reply":"2022-04-05T15:18:50.003448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 服の種類","metadata":{}},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=df_article, y='index_name')\nax.set_xlabel('count by index name')\nax.set_ylabel('index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:50.005207Z","iopub.execute_input":"2022-04-05T15:18:50.005796Z","iopub.status.idle":"2022-04-05T15:18:50.436368Z","shell.execute_reply.started":"2022-04-05T15:18:50.005763Z","shell.execute_reply":"2022-04-05T15:18:50.435203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=df_article, y='garment_group_name', hue='index_group_name', multiple=\"stack\")\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T16:02:02.198662Z","iopub.execute_input":"2022-04-05T16:02:02.199071Z","iopub.status.idle":"2022-04-05T16:02:03.214778Z","shell.execute_reply.started":"2022-04-05T16:02:02.199035Z","shell.execute_reply":"2022-04-05T16:02:03.213318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(df_article.groupby(['index_group_name', 'index_name']).count()['article_id'])","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:51.414174Z","iopub.execute_input":"2022-04-05T15:18:51.414485Z","iopub.status.idle":"2022-04-05T15:18:51.610621Z","shell.execute_reply.started":"2022-04-05T15:18:51.414443Z","shell.execute_reply":"2022-04-05T15:18:51.609674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.DataFrame(df_article.groupby(['product_group_name', 'product_type_name']).count()['article_id'])","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:51.611759Z","iopub.execute_input":"2022-04-05T15:18:51.611995Z","iopub.status.idle":"2022-04-05T15:18:51.803528Z","shell.execute_reply.started":"2022-04-05T15:18:51.611967Z","shell.execute_reply":"2022-04-05T15:18:51.802538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_customers.groupby('postal_code', as_index=False).count().sort_values('customer_id', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:51.804869Z","iopub.execute_input":"2022-04-05T15:18:51.805252Z","iopub.status.idle":"2022-04-05T15:18:54.127106Z","shell.execute_reply.started":"2022-04-05T15:18:51.80522Z","shell.execute_reply":"2022-04-05T15:18:54.126055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Number of product types","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(20, 6))\n_df = df_article.groupby(\"product_type_no\")[\"article_id\"].nunique().sort_values(ascending=False).head(50)\nsns.barplot(x = _df.index, y = _df.values, ax=ax, order=_df.index)\nplt.title(\"Frequently included product type\")","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:18:54.128432Z","iopub.execute_input":"2022-04-05T15:18:54.12866Z","iopub.status.idle":"2022-04-05T15:18:55.666583Z","shell.execute_reply.started":"2022-04-05T15:18:54.128633Z","shell.execute_reply":"2022-04-05T15:18:55.665383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_customers[\"Active\"] = df_customers[\"Active\"].fillna(0)\nfig, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=df_customers, x='age', bins=df_customers['age'].nunique(), hue='Active', stat=\"percent\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-05T15:29:49.530303Z","iopub.execute_input":"2022-04-05T15:29:49.530661Z","iopub.status.idle":"2022-04-05T15:29:50.749574Z","shell.execute_reply.started":"2022-04-05T15:29:49.530622Z","shell.execute_reply":"2022-04-05T15:29:50.748683Z"},"trusted":true},"execution_count":null,"outputs":[]}]}