{"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":"# AN EDA notebooks","metadata":{}},{"cell_type":"code","source":"import os\nimport sys\n\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nsns.set()\n%matplotlib inline","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-21T13:05:19.937786Z","iopub.execute_input":"2022-02-21T13:05:19.938579Z","iopub.status.idle":"2022-02-21T13:05:21.053772Z","shell.execute_reply.started":"2022-02-21T13:05:19.938530Z","shell.execute_reply":"2022-02-21T13:05:21.052871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_path = '../input/h-and-m-personalized-fashion-recommendations'\nimage_paths = 'images/'\n\ndf_articles = pd.read_csv(os.path.join(input_path, 'articles.csv'))\ndf_customers = pd.read_csv(os.path.join(input_path, 'customers.csv'))\ntransactions_train = pd.read_csv(os.path.join(input_path, 'transactions_train.csv'))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:05:21.055063Z","iopub.execute_input":"2022-02-21T13:05:21.055274Z","iopub.status.idle":"2022-02-21T13:06:26.383569Z","shell.execute_reply.started":"2022-02-21T13:05:21.055250Z","shell.execute_reply":"2022-02-21T13:06:26.382581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA of customers.csv","metadata":{}},{"cell_type":"code","source":"df_customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:54.793682Z","iopub.execute_input":"2022-02-21T02:21:54.794053Z","iopub.status.idle":"2022-02-21T02:21:54.829881Z","shell.execute_reply.started":"2022-02-21T02:21:54.794003Z","shell.execute_reply":"2022-02-21T02:21:54.828599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Check data types\ncheck what kind of data is in each columns and count nulls.","metadata":{}},{"cell_type":"code","source":"print('FN uniques are:', df_customers['FN'].unique())\nprint('Active uniques are:', df_customers['Active'].unique())\nprint('club_member_status uniques are:', df_customers['club_member_status'].unique())\nprint('fashion_news_frequency uniques are:', df_customers['fashion_news_frequency'].unique())\nprint('null/not null count in ages are:', df_customers['age'].isnull().sum(), '/', len(df_customers))\nprint('percentage where ages are null are', df_customers['age'].isnull().sum()/len(df_customers)*100, '%')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:54.831270Z","iopub.execute_input":"2022-02-21T02:21:54.831506Z","iopub.status.idle":"2022-02-21T02:21:55.187256Z","shell.execute_reply.started":"2022-02-21T02:21:54.831477Z","shell.execute_reply":"2022-02-21T02:21:55.186131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Fill NaN\nfill NaN values for visualization","metadata":{}},{"cell_type":"code","source":"df_customers['FN'] = df_customers['FN'].fillna(0)\ndf_customers['Active'] = df_customers['Active'].fillna(0)\ndf_customers['club_member_status'] = df_customers['club_member_status'].fillna('NON_MEMBER')\ndf_customers['fashion_news_frequency'] = df_customers['fashion_news_frequency'].fillna('NONE')\ndf_customers['fashion_news_frequency'] = df_customers['fashion_news_frequency'].replace('None', 'NONE')\n\ndf_customer = df_customers.dropna()\nlen(df_customer['age'])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:55.190274Z","iopub.execute_input":"2022-02-21T02:21:55.190540Z","iopub.status.idle":"2022-02-21T02:21:56.476604Z","shell.execute_reply.started":"2022-02-21T02:21:55.190510Z","shell.execute_reply":"2022-02-21T02:21:56.475428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Ploting a simple histogram of ages","metadata":{}},{"cell_type":"code","source":"plt.title(\"histogram of age\")\nplt.xlabel(\"age\")\nplt.ylabel(\"number of people\")\nplt.hist(df_customer[\"age\"], bins=9, range=(0, 90))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:56.478032Z","iopub.execute_input":"2022-02-21T02:21:56.478282Z","iopub.status.idle":"2022-02-21T02:21:56.838151Z","shell.execute_reply.started":"2022-02-21T02:21:56.478252Z","shell.execute_reply":"2022-02-21T02:21:56.837098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_hist, age_bins = np.histogram(df_customer['age'], bins=9, range=(10,100))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:56.840181Z","iopub.execute_input":"2022-02-21T02:21:56.840445Z","iopub.status.idle":"2022-02-21T02:21:56.868383Z","shell.execute_reply.started":"2022-02-21T02:21:56.840415Z","shell.execute_reply":"2022-02-21T02:21:56.867361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Creating data for ploting colored bar plots\n- count uniqe FN\n- count unique active\n- count unique club member status\n- count unique fashion news frequency","metadata":{}},{"cell_type":"code","source":"# FN\nfn_0_ages = []\nfn_1_ages = []\n\n# Active\nactive_1_ages = []\nactive_0_ages = []\n\n# club member status => cms\ncms_active_ages = []\ncms_nonmember_ages = []\ncms_precreate_ages = []\ncms_leftclub_ages = []\n\n# fashion_news_frequency => fnf\nfnf_regulary_age = []\nfnf_monthly_age = []\nfnf_none_age = []\n\nfor i, age in enumerate(age_bins):\n    if i == 0:\n        df_bin = df_customer.query(f\"age < {age}\")\n    else:\n        df_bin = df_customer.query(f\"{age_bins[i-1]} < age < {age}\")\n        \n    fn_0_ages.append(len(df_bin.query('FN == 0')))\n    fn_1_ages.append(len(df_bin.query('FN == 1')))\n    \n    active_1_ages.append(len(df_bin.query('Active == 1')))\n    active_0_ages.append(len(df_bin.query('Active == 0')))\n\n    cms_active_ages.append(len(df_bin.query('club_member_status == \"ACTIVE\"')))\n    cms_nonmember_ages.append(len(df_bin.query('club_member_status == \"NON_MEMBER\"')))\n    cms_precreate_ages.append(len(df_bin.query('club_member_status == \"PRE-CREATE\"')))\n    cms_leftclub_ages.append(len(df_bin.query('club_member_status == \"LEFT CLUB\"')))\n\n    fnf_regulary_age.append(len(df_bin.query('fashion_news_frequency == \"Regularly\"')))\n    fnf_monthly_age.append(len(df_bin.query('fashion_news_frequency == \"Monthly\"')))\n    fnf_none_age.append(len(df_bin.query('fashion_news_frequency == \"NONE\"')))","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:56.870339Z","iopub.execute_input":"2022-02-21T02:21:56.871219Z","iopub.status.idle":"2022-02-21T02:21:58.843143Z","shell.execute_reply.started":"2022-02-21T02:21:56.871141Z","shell.execute_reply":"2022-02-21T02:21:58.842414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot_fn = pd.DataFrame({\n    \"0\": fn_0_ages,\n    \"1\": fn_1_ages\n    },index=age_bins\n)\n\ndf_plot_active = pd.DataFrame({\n    \"0\": active_0_ages,\n    \"1\": active_1_ages\n    },index=age_bins\n)\n\ndf_plot_cms = pd.DataFrame({\n    \"active\": cms_active_ages,\n    \"non-member\": cms_nonmember_ages,\n    \"pre-create\": cms_precreate_ages,\n    \"left-club\": cms_leftclub_ages\n    },index=age_bins\n)\n\n\ndf_plot_fnf = pd.DataFrame({\n    \"regulary\": fnf_regulary_age,\n    \"monthly\": fnf_monthly_age,\n    \"none\": fnf_none_age\n    },index=age_bins\n)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:21:58.844786Z","iopub.execute_input":"2022-02-21T02:21:58.845710Z","iopub.status.idle":"2022-02-21T02:21:58.856094Z","shell.execute_reply.started":"2022-02-21T02:21:58.845664Z","shell.execute_reply":"2022-02-21T02:21:58.855058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot_fn.plot(kind=\"bar\", stacked=True)\nplt.title(\"Bar plot of FN actives and ages\")\nplt.xlabel(\"age\")\nplt.ylabel(\"number of people\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:24:18.889487Z","iopub.execute_input":"2022-02-21T02:24:18.889876Z","iopub.status.idle":"2022-02-21T02:24:19.242458Z","shell.execute_reply.started":"2022-02-21T02:24:18.889841Z","shell.execute_reply":"2022-02-21T02:24:19.241354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot_active.plot(kind=\"bar\", stacked=True)\nplt.title(\"Bar plot of active and ages\")\nplt.xlabel(\"age\")\nplt.ylabel(\"number of people\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:24:32.807719Z","iopub.execute_input":"2022-02-21T02:24:32.808030Z","iopub.status.idle":"2022-02-21T02:24:33.151158Z","shell.execute_reply.started":"2022-02-21T02:24:32.807999Z","shell.execute_reply":"2022-02-21T02:24:33.149974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot_cms.plot(kind=\"bar\", stacked=True)\nplt.title(\"Bar plot of FN Club member status and ages\")\nplt.xlabel(\"age\")\nplt.ylabel(\"number of people\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:24:57.791327Z","iopub.execute_input":"2022-02-21T02:24:57.791604Z","iopub.status.idle":"2022-02-21T02:24:58.193922Z","shell.execute_reply.started":"2022-02-21T02:24:57.791575Z","shell.execute_reply":"2022-02-21T02:24:58.193301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plot_fnf.plot(kind=\"bar\", stacked=True)\nplt.title(\"Bar plot of Fashion new frequency and ages\")\nplt.xlabel(\"age\")\nplt.ylabel(\"number of people\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:25:21.957556Z","iopub.execute_input":"2022-02-21T02:25:21.958354Z","iopub.status.idle":"2022-02-21T02:25:22.550769Z","shell.execute_reply.started":"2022-02-21T02:25:21.958305Z","shell.execute_reply":"2022-02-21T02:25:22.549847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA of articles.csv","metadata":{}},{"cell_type":"code","source":"df_articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T02:26:23.062467Z","iopub.execute_input":"2022-02-21T02:26:23.063422Z","iopub.status.idle":"2022-02-21T02:26:23.093960Z","shell.execute_reply.started":"2022-02-21T02:26:23.063377Z","shell.execute_reply":"2022-02-21T02:26:23.092710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles.columns","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:07:56.179303Z","iopub.execute_input":"2022-02-21T13:07:56.180139Z","iopub.status.idle":"2022-02-21T13:07:56.188700Z","shell.execute_reply.started":"2022-02-21T13:07:56.180085Z","shell.execute_reply":"2022-02-21T13:07:56.187698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_uniques(input_df, column_name):\n    uniques = input_df[column_name].unique()\n    counts = len(uniques)\n    print(f\"{counts} uniques vales in columns '{column_name}', the unique values are {uniques}\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:26:22.772343Z","iopub.execute_input":"2022-02-21T13:26:22.772968Z","iopub.status.idle":"2022-02-21T13:26:22.777882Z","shell.execute_reply.started":"2022-02-21T13:26:22.772921Z","shell.execute_reply":"2022-02-21T13:26:22.777175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of product type name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"product_type_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:26:23.623724Z","iopub.execute_input":"2022-02-21T13:26:23.624398Z","iopub.status.idle":"2022-02-21T13:26:23.637222Z","shell.execute_reply.started":"2022-02-21T13:26:23.624356Z","shell.execute_reply":"2022-02-21T13:26:23.636496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### vales of product group name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"product_group_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:27:36.054209Z","iopub.execute_input":"2022-02-21T13:27:36.054682Z","iopub.status.idle":"2022-02-21T13:27:36.068559Z","shell.execute_reply.started":"2022-02-21T13:27:36.054613Z","shell.execute_reply":"2022-02-21T13:27:36.067823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of graphical apperance name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"graphical_appearance_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:28:09.742205Z","iopub.execute_input":"2022-02-21T13:28:09.742825Z","iopub.status.idle":"2022-02-21T13:28:09.756021Z","shell.execute_reply.started":"2022-02-21T13:28:09.742787Z","shell.execute_reply":"2022-02-21T13:28:09.755019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of colour group name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"colour_group_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:28:34.107856Z","iopub.execute_input":"2022-02-21T13:28:34.108201Z","iopub.status.idle":"2022-02-21T13:28:34.120531Z","shell.execute_reply.started":"2022-02-21T13:28:34.108164Z","shell.execute_reply":"2022-02-21T13:28:34.119931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of perceived colour master name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"perceived_colour_master_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:29:11.307029Z","iopub.execute_input":"2022-02-21T13:29:11.307896Z","iopub.status.idle":"2022-02-21T13:29:11.322035Z","shell.execute_reply.started":"2022-02-21T13:29:11.307842Z","shell.execute_reply":"2022-02-21T13:29:11.321151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of department name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"department_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:29:37.689931Z","iopub.execute_input":"2022-02-21T13:29:37.690528Z","iopub.status.idle":"2022-02-21T13:29:37.705718Z","shell.execute_reply.started":"2022-02-21T13:29:37.690477Z","shell.execute_reply":"2022-02-21T13:29:37.704808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of index name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"index_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:30:02.524947Z","iopub.execute_input":"2022-02-21T13:30:02.525477Z","iopub.status.idle":"2022-02-21T13:30:02.538479Z","shell.execute_reply.started":"2022-02-21T13:30:02.525438Z","shell.execute_reply":"2022-02-21T13:30:02.537496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of index group name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"index_group_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:30:59.155595Z","iopub.execute_input":"2022-02-21T13:30:59.155895Z","iopub.status.idle":"2022-02-21T13:30:59.167068Z","shell.execute_reply.started":"2022-02-21T13:30:59.155862Z","shell.execute_reply":"2022-02-21T13:30:59.166041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of section name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"section_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:31:25.264480Z","iopub.execute_input":"2022-02-21T13:31:25.265262Z","iopub.status.idle":"2022-02-21T13:31:25.279179Z","shell.execute_reply.started":"2022-02-21T13:31:25.265215Z","shell.execute_reply":"2022-02-21T13:31:25.278350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### values of garment group name","metadata":{}},{"cell_type":"code","source":"show_uniques(df_articles, \"garment_group_name\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T13:31:50.784241Z","iopub.execute_input":"2022-02-21T13:31:50.785117Z","iopub.status.idle":"2022-02-21T13:31:50.798274Z","shell.execute_reply.started":"2022-02-21T13:31:50.785062Z","shell.execute_reply":"2022-02-21T13:31:50.797351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}