{"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        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-14T09:12:53.036236Z","iopub.execute_input":"2022-02-14T09:12:53.036789Z","iopub.status.idle":"2022-02-14T09:13:47.580441Z","shell.execute_reply.started":"2022-02-14T09:12:53.036695Z","shell.execute_reply":"2022-02-14T09:13:47.579301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport cv2\nimport numpy as np\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:35:03.511351Z","iopub.execute_input":"2022-02-14T14:35:03.512022Z","iopub.status.idle":"2022-02-14T14:35:04.720905Z","shell.execute_reply.started":"2022-02-14T14:35:03.511979Z","shell.execute_reply":"2022-02-14T14:35:04.720062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')\ntransactions = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\", dtype = {'article_id': str})\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:35:04.722724Z","iopub.execute_input":"2022-02-14T14:35:04.723053Z","iopub.status.idle":"2022-02-14T14:36:16.063877Z","shell.execute_reply.started":"2022-02-14T14:35:04.723015Z","shell.execute_reply":"2022-02-14T14:36:16.062976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Understanding of Data","metadata":{}},{"cell_type":"code","source":"pd.set_option('display.max_rows',None)\npd.set_option('display.max_columns',None)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:28:31.801663Z","iopub.execute_input":"2022-02-14T14:28:31.801936Z","iopub.status.idle":"2022-02-14T14:28:31.806705Z","shell.execute_reply.started":"2022-02-14T14:28:31.801899Z","shell.execute_reply":"2022-02-14T14:28:31.805672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_new = articles[['article_id', 'prod_name', 'product_type_name', 'index_name', 'colour_group_name', 'department_name']]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:04.949087Z","iopub.execute_input":"2022-02-14T14:38:04.949992Z","iopub.status.idle":"2022-02-14T14:38:04.968995Z","shell.execute_reply.started":"2022-02-14T14:38:04.949948Z","shell.execute_reply":"2022-02-14T14:38:04.967975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[(customers['FN'].isna()) & (customers['Active'].isna()) & (customers['fashion_news_frequency'].isna())])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:06.265354Z","iopub.execute_input":"2022-02-14T14:38:06.266025Z","iopub.status.idle":"2022-02-14T14:38:06.420834Z","shell.execute_reply.started":"2022-02-14T14:38:06.265981Z","shell.execute_reply":"2022-02-14T14:38:06.420099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NA_DF = customers.loc[(customers['FN'].isna()) & (customers['Active'].isna()) & (customers['fashion_news_frequency'].isna())]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:07.206011Z","iopub.execute_input":"2022-02-14T14:38:07.206956Z","iopub.status.idle":"2022-02-14T14:38:07.354246Z","shell.execute_reply.started":"2022-02-14T14:38:07.206898Z","shell.execute_reply":"2022-02-14T14:38:07.353401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NA_DF[500:535]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:14.842778Z","iopub.execute_input":"2022-02-14T14:38:14.843607Z","iopub.status.idle":"2022-02-14T14:38:14.869006Z","shell.execute_reply.started":"2022-02-14T14:38:14.84356Z","shell.execute_reply":"2022-02-14T14:38:14.868278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### From the above results, we can see that if 'FN' Fashion news is NaN means he is not receiving any and thus 'fashion_news_frequency' is Nan as well and he is Not ACTIVE for communications.\n#### Lets impute 'FN' with 0 and ACTIVE as 0 and fashion_news_frequency' as Not receiving","metadata":{}},{"cell_type":"code","source":"customers['FN']= customers['FN'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:17.053327Z","iopub.execute_input":"2022-02-14T14:38:17.05395Z","iopub.status.idle":"2022-02-14T14:38:17.078446Z","shell.execute_reply.started":"2022-02-14T14:38:17.053904Z","shell.execute_reply":"2022-02-14T14:38:17.077614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['Active'] = customers['Active'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:17.739194Z","iopub.execute_input":"2022-02-14T14:38:17.73994Z","iopub.status.idle":"2022-02-14T14:38:17.763736Z","shell.execute_reply.started":"2022-02-14T14:38:17.739898Z","shell.execute_reply":"2022-02-14T14:38:17.762856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['fashion_news_frequency'] = customers['fashion_news_frequency'].fillna('Not Receiving')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:18.55568Z","iopub.execute_input":"2022-02-14T14:38:18.556217Z","iopub.status.idle":"2022-02-14T14:38:18.794257Z","shell.execute_reply.started":"2022-02-14T14:38:18.55618Z","shell.execute_reply":"2022-02-14T14:38:18.793407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"len(customers.loc[(customers['FN'] == 1) & (customers['Active'] == 1) & ((customers['fashion_news_frequency'] == None) | (customers['fashion_news_frequency'] == 'NONE'))])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:22.938553Z","iopub.execute_input":"2022-02-14T14:38:22.9392Z","iopub.status.idle":"2022-02-14T14:38:23.142967Z","shell.execute_reply.started":"2022-02-14T14:38:22.939157Z","shell.execute_reply":"2022-02-14T14:38:23.142202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[(customers['FN'] == 1) & (customers['Active'] == 1) & ((customers['fashion_news_frequency'] == None) | (customers['fashion_news_frequency'] == 'NONE')), 'fashion_news_frequency'] = 'Regularly'","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:25.533433Z","iopub.execute_input":"2022-02-14T14:38:25.534265Z","iopub.status.idle":"2022-02-14T14:38:25.750894Z","shell.execute_reply.started":"2022-02-14T14:38:25.534207Z","shell.execute_reply":"2022-02-14T14:38:25.75001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[(customers['FN'] == 0) & (customers['Active'] == 1) & ((customers['fashion_news_frequency'] == None) | (customers['fashion_news_frequency'] == 'NONE')), 'fashion_news_frequency'] = 'No FN'","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:28.708239Z","iopub.execute_input":"2022-02-14T14:38:28.708546Z","iopub.status.idle":"2022-02-14T14:38:28.922319Z","shell.execute_reply.started":"2022-02-14T14:38:28.708504Z","shell.execute_reply":"2022-02-14T14:38:28.921468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[(customers['FN'] == 1) & (customers['Active'] == 0) & ((customers['fashion_news_frequency'] == None) | (customers['fashion_news_frequency'] == 'NONE')), 'fashion_news_frequency'] = 'Not Active'","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:31.94614Z","iopub.execute_input":"2022-02-14T14:38:31.94643Z","iopub.status.idle":"2022-02-14T14:38:32.161754Z","shell.execute_reply.started":"2022-02-14T14:38:31.946397Z","shell.execute_reply":"2022-02-14T14:38:32.160774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[customers['age'].isna()])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:37.574343Z","iopub.execute_input":"2022-02-14T14:38:37.574997Z","iopub.status.idle":"2022-02-14T14:38:37.598103Z","shell.execute_reply.started":"2022-02-14T14:38:37.574951Z","shell.execute_reply":"2022-02-14T14:38:37.597357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:38:41.693717Z","iopub.execute_input":"2022-02-14T14:38:41.694619Z","iopub.status.idle":"2022-02-14T14:38:41.764197Z","shell.execute_reply.started":"2022-02-14T14:38:41.694569Z","shell.execute_reply":"2022-02-14T14:38:41.763408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(customers['age'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T14:40:04.915771Z","iopub.execute_input":"2022-02-14T14:40:04.9169Z","iopub.status.idle":"2022-02-14T14:40:05.125186Z","shell.execute_reply.started":"2022-02-14T14:40:04.916849Z","shell.execute_reply":"2022-02-14T14:40:05.124038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Here we can see few points outside of whiskers, but there are possibilities that they might be shopping online if not store shopping.","metadata":{}},{"cell_type":"code","source":"\n\ncustomers[['age']] = customers[['age']].values.reshape(-1,1)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T15:24:04.622696Z","iopub.execute_input":"2022-02-14T15:24:04.623297Z","iopub.status.idle":"2022-02-14T15:24:04.665333Z","shell.execute_reply.started":"2022-02-14T15:24:04.623252Z","shell.execute_reply":"2022-02-14T15:24:04.664544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[['age']].shape","metadata":{"execution":{"iopub.status.busy":"2022-02-14T15:24:39.189221Z","iopub.execute_input":"2022-02-14T15:24:39.189635Z","iopub.status.idle":"2022-02-14T15:24:39.198587Z","shell.execute_reply.started":"2022-02-14T15:24:39.189583Z","shell.execute_reply":"2022-02-14T15:24:39.197845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Lets impute  using knn imputer\n\n# from sklearn.impute import KNNImputer\n\n# imputer = KNNImputer()\n# customers['age'] = imputer.fit_transform(customers[['age']].reshape(-1,1))\n\nfrom sklearn.experimental import enable_iterative_imputer  \nfrom sklearn.impute import IterativeImputer\nfrom sklearn.linear_model import LinearRegression\n\n# customers['age_arr'] = customers['age'].values.reshape((-1,1))\n# customers['re_age_arr'] = customers['age_arr'].reshape((-1,1))\nlr = LinearRegression()\nimp = IterativeImputer(estimator=lr,missing_values=np.nan, max_iter=10, verbose=2, imputation_order='roman',random_state=0)\ncustomers[['age']] = imp.fit_transform(customers[['age']])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T15:25:11.120831Z","iopub.execute_input":"2022-02-14T15:25:11.121114Z","iopub.status.idle":"2022-02-14T15:25:11.164672Z","shell.execute_reply.started":"2022-02-14T15:25:11.121082Z","shell.execute_reply":"2022-02-14T15:25:11.163865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[customers['age'].isna()])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T15:25:40.54774Z","iopub.execute_input":"2022-02-14T15:25:40.548011Z","iopub.status.idle":"2022-02-14T15:25:40.556511Z","shell.execute_reply.started":"2022-02-14T15:25:40.547981Z","shell.execute_reply":"2022-02-14T15:25:40.555617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['postal_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T15:38:08.32354Z","iopub.execute_input":"2022-02-14T15:38:08.324057Z","iopub.status.idle":"2022-02-14T15:38:08.959443Z","shell.execute_reply.started":"2022-02-14T15:38:08.324014Z","shell.execute_reply":"2022-02-14T15:38:08.958459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(transactions, articles_new, on = 'article_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:46:19.719134Z","iopub.execute_input":"2022-02-14T12:46:19.719724Z","iopub.status.idle":"2022-02-14T12:46:37.602987Z","shell.execute_reply.started":"2022-02-14T12:46:19.719682Z","shell.execute_reply":"2022-02-14T12:46:37.602215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.477661Z","iopub.status.idle":"2022-02-14T12:17:09.478409Z","shell.execute_reply.started":"2022-02-14T12:17:09.478164Z","shell.execute_reply":"2022-02-14T12:17:09.478194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.479627Z","iopub.status.idle":"2022-02-14T12:17:09.480391Z","shell.execute_reply.started":"2022-02-14T12:17:09.48015Z","shell.execute_reply":"2022-02-14T12:17:09.480179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# customers.loc[customers['FN'].isna(),:]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.481513Z","iopub.status.idle":"2022-02-14T12:17:09.482247Z","shell.execute_reply.started":"2022-02-14T12:17:09.482016Z","shell.execute_reply":"2022-02-14T12:17:09.482044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(df, customers, on = 'customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:46:37.604208Z","iopub.execute_input":"2022-02-14T12:46:37.604491Z","iopub.status.idle":"2022-02-14T12:47:37.841365Z","shell.execute_reply.started":"2022-02-14T12:46:37.604457Z","shell.execute_reply":"2022-02-14T12:47:37.840473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:47:37.842882Z","iopub.execute_input":"2022-02-14T12:47:37.843159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[(customers['FN'].isna() and ,:])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.485544Z","iopub.status.idle":"2022-02-14T12:17:09.486273Z","shell.execute_reply.started":"2022-02-14T12:17:09.486042Z","shell.execute_reply":"2022-02-14T12:17:09.48607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['FN'] = df['FN'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.48741Z","iopub.status.idle":"2022-02-14T12:17:09.488183Z","shell.execute_reply.started":"2022-02-14T12:17:09.48795Z","shell.execute_reply":"2022-02-14T12:17:09.487978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[customers['FN'].isna(),:])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.489322Z","iopub.status.idle":"2022-02-14T12:17:09.490095Z","shell.execute_reply.started":"2022-02-14T12:17:09.489866Z","shell.execute_reply":"2022-02-14T12:17:09.489892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.loc[customers['fashion_news_frequency'].isna(),:])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.491226Z","iopub.status.idle":"2022-02-14T12:17:09.492033Z","shell.execute_reply.started":"2022-02-14T12:17:09.491792Z","shell.execute_reply":"2022-02-14T12:17:09.491825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.loc[customers['fashion_news_frequency'].isna(),:].tail(20)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.493405Z","iopub.status.idle":"2022-02-14T12:17:09.493819Z","shell.execute_reply.started":"2022-02-14T12:17:09.493599Z","shell.execute_reply":"2022-02-14T12:17:09.493621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers['fashion_news_frequency'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.495069Z","iopub.status.idle":"2022-02-14T12:17:09.495474Z","shell.execute_reply.started":"2022-02-14T12:17:09.495247Z","shell.execute_reply":"2022-02-14T12:17:09.495269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['fashion_news_frequency'] = df['fashion_news_frequency'].fillna('Not receiving')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.496739Z","iopub.status.idle":"2022-02-14T12:17:09.497149Z","shell.execute_reply.started":"2022-02-14T12:17:09.496929Z","shell.execute_reply":"2022-02-14T12:17:09.496952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['fashion_news_frequency'] = df['fashion_news_frequency'].replace('NONE','Not receiving')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.498377Z","iopub.status.idle":"2022-02-14T12:17:09.498808Z","shell.execute_reply.started":"2022-02-14T12:17:09.498574Z","shell.execute_reply":"2022-02-14T12:17:09.498595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['fashion_news_frequency'] = df['fashion_news_frequency'].replace('None','Regularly')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.501009Z","iopub.status.idle":"2022-02-14T12:17:09.501865Z","shell.execute_reply.started":"2022-02-14T12:17:09.501636Z","shell.execute_reply":"2022-02-14T12:17:09.50166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['fashion_news_frequency'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.502771Z","iopub.status.idle":"2022-02-14T12:17:09.503502Z","shell.execute_reply.started":"2022-02-14T12:17:09.503249Z","shell.execute_reply":"2022-02-14T12:17:09.503274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Active'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.504577Z","iopub.status.idle":"2022-02-14T12:17:09.505339Z","shell.execute_reply.started":"2022-02-14T12:17:09.505097Z","shell.execute_reply":"2022-02-14T12:17:09.505121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df.loc[df['Active'].isna(), :].tail(20)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.506483Z","iopub.status.idle":"2022-02-14T12:17:09.507225Z","shell.execute_reply.started":"2022-02-14T12:17:09.50699Z","shell.execute_reply":"2022-02-14T12:17:09.507016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df.loc[df['Active'].isna(), :])","metadata":{"execution":{"iopub.status.busy":"2022-02-14T12:17:09.508298Z","iopub.status.idle":"2022-02-14T12:17:09.50908Z","shell.execute_reply.started":"2022-02-14T12:17:09.508846Z","shell.execute_reply":"2022-02-14T12:17:09.508873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles[25:50]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:32:53.700539Z","iopub.execute_input":"2022-02-14T09:32:53.701344Z","iopub.status.idle":"2022-02-14T09:32:53.736922Z","shell.execute_reply.started":"2022-02-14T09:32:53.70129Z","shell.execute_reply":"2022-02-14T09:32:53.736143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:34:16.405522Z","iopub.execute_input":"2022-02-14T09:34:16.405798Z","iopub.status.idle":"2022-02-14T09:34:16.410325Z","shell.execute_reply.started":"2022-02-14T09:34:16.405768Z","shell.execute_reply":"2022-02-14T09:34:16.409251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(len(articles.loc[articles['detail_desc'].isna(),:])/len(articles.index)) * 100","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:54:47.746407Z","iopub.execute_input":"2022-02-14T09:54:47.746694Z","iopub.status.idle":"2022-02-14T09:54:47.766224Z","shell.execute_reply.started":"2022-02-14T09:54:47.746663Z","shell.execute_reply":"2022-02-14T09:54:47.765243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['section_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:04:36.989832Z","iopub.execute_input":"2022-02-14T10:04:36.990511Z","iopub.status.idle":"2022-02-14T10:04:37.012196Z","shell.execute_reply.started":"2022-02-14T10:04:36.990467Z","shell.execute_reply":"2022-02-14T10:04:37.011415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['index_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:03:28.119637Z","iopub.execute_input":"2022-02-14T10:03:28.12033Z","iopub.status.idle":"2022-02-14T10:03:28.144894Z","shell.execute_reply.started":"2022-02-14T10:03:28.120287Z","shell.execute_reply":"2022-02-14T10:03:28.144148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['index_group_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:55:48.244483Z","iopub.execute_input":"2022-02-14T09:55:48.244789Z","iopub.status.idle":"2022-02-14T09:55:48.266806Z","shell.execute_reply.started":"2022-02-14T09:55:48.244757Z","shell.execute_reply":"2022-02-14T09:55:48.266099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles[articles['detail_desc'].isna()]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:49:47.62698Z","iopub.execute_input":"2022-02-14T09:49:47.627641Z","iopub.status.idle":"2022-02-14T09:49:47.861317Z","shell.execute_reply.started":"2022-02-14T09:49:47.627596Z","shell.execute_reply":"2022-02-14T09:49:47.86064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# articles['prod_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:37:51.412486Z","iopub.execute_input":"2022-02-14T09:37:51.41341Z","iopub.status.idle":"2022-02-14T09:37:51.417734Z","shell.execute_reply.started":"2022-02-14T09:37:51.413363Z","shell.execute_reply":"2022-02-14T09:37:51.416846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"110065002 in articles['article_id'].tolist()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:48:29.806021Z","iopub.execute_input":"2022-02-14T09:48:29.806307Z","iopub.status.idle":"2022-02-14T09:48:29.818493Z","shell.execute_reply.started":"2022-02-14T09:48:29.806275Z","shell.execute_reply":"2022-02-14T09:48:29.817528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['colour_group_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:42:07.131263Z","iopub.execute_input":"2022-02-14T09:42:07.132105Z","iopub.status.idle":"2022-02-14T09:42:07.140875Z","shell.execute_reply.started":"2022-02-14T09:42:07.132046Z","shell.execute_reply":"2022-02-14T09:42:07.140019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['graphical_appearance_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:24:01.93254Z","iopub.execute_input":"2022-02-14T10:24:01.933106Z","iopub.status.idle":"2022-02-14T10:24:01.947502Z","shell.execute_reply.started":"2022-02-14T10:24:01.933064Z","shell.execute_reply":"2022-02-14T10:24:01.946393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['product_group_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:39:55.771167Z","iopub.execute_input":"2022-02-14T09:39:55.771827Z","iopub.status.idle":"2022-02-14T09:39:55.795805Z","shell.execute_reply.started":"2022-02-14T09:39:55.771782Z","shell.execute_reply":"2022-02-14T09:39:55.794944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles['product_type_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:38:06.235164Z","iopub.execute_input":"2022-02-14T09:38:06.235665Z","iopub.status.idle":"2022-02-14T09:38:06.257314Z","shell.execute_reply.started":"2022-02-14T09:38:06.235626Z","shell.execute_reply":"2022-02-14T09:38:06.2566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:20:54.019329Z","iopub.execute_input":"2022-02-14T09:20:54.019588Z","iopub.status.idle":"2022-02-14T09:20:54.546146Z","shell.execute_reply.started":"2022-02-14T09:20:54.01956Z","shell.execute_reply":"2022-02-14T09:20:54.545408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:20:55.462755Z","iopub.execute_input":"2022-02-14T09:20:55.463339Z","iopub.status.idle":"2022-02-14T09:20:55.476597Z","shell.execute_reply.started":"2022-02-14T09:20:55.463306Z","shell.execute_reply":"2022-02-14T09:20:55.475846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:20:57.644763Z","iopub.execute_input":"2022-02-14T09:20:57.645033Z","iopub.status.idle":"2022-02-14T09:20:57.655992Z","shell.execute_reply.started":"2022-02-14T09:20:57.645001Z","shell.execute_reply":"2022-02-14T09:20:57.65512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:20:58.803424Z","iopub.execute_input":"2022-02-14T09:20:58.803807Z","iopub.status.idle":"2022-02-14T09:20:58.815146Z","shell.execute_reply.started":"2022-02-14T09:20:58.803774Z","shell.execute_reply":"2022-02-14T09:20:58.814481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions['t_dat'].max()\n","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:15:05.726135Z","iopub.execute_input":"2022-02-14T09:15:05.72784Z","iopub.status.idle":"2022-02-14T09:15:07.48226Z","shell.execute_reply.started":"2022-02-14T09:15:05.727618Z","shell.execute_reply":"2022-02-14T09:15:07.48101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_images_from_folder(folder):\n    images = []\n    for filename in os.listdir(folder):\n        if filename.endswith(\".jpg\"):\n            img = cv2.imread(os.path.join(folder, filename))\n            if img is not None:\n                images.append(img)\n    return images","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:03.6426Z","iopub.execute_input":"2022-02-14T09:21:03.642868Z","iopub.status.idle":"2022-02-14T09:21:03.648266Z","shell.execute_reply.started":"2022-02-14T09:21:03.642831Z","shell.execute_reply":"2022-02-14T09:21:03.647235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"root_folder = '../input/h-and-m-personalized-fashion-recommendations/images'\nfolders = [os.path.join(root_folder, '0'+str(x)) for x in range(10, 20)]\nall_images = [img for folder in folders for img in load_images_from_folder(folder)]","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:05.267981Z","iopub.execute_input":"2022-02-14T09:21:05.268726Z","iopub.status.idle":"2022-02-14T09:21:13.225435Z","shell.execute_reply.started":"2022-02-14T09:21:05.268677Z","shell.execute_reply":"2022-02-14T09:21:13.224614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(all_images)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:13.226869Z","iopub.execute_input":"2022-02-14T09:21:13.227114Z","iopub.status.idle":"2022-02-14T09:21:13.232916Z","shell.execute_reply.started":"2022-02-14T09:21:13.227078Z","shell.execute_reply":"2022-02-14T09:21:13.232229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef show_image(img):\n    plt.imshow(img)\n\nplt.figure(figsize = (20,20))\nfor i in range(1,10):\n    plt.subplot(3,3,i)\n    show_image(all_images[i])    ","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:19.138466Z","iopub.execute_input":"2022-02-14T09:21:19.139111Z","iopub.status.idle":"2022-02-14T09:21:22.992662Z","shell.execute_reply.started":"2022-02-14T09:21:19.139074Z","shell.execute_reply":"2022-02-14T09:21:22.990243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Lets look into transactions data\n\n","metadata":{}},{"cell_type":"code","source":"(transactions.isnull().sum()/len(transactions.index) * 100)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:29.013263Z","iopub.execute_input":"2022-02-14T09:21:29.013791Z","iopub.status.idle":"2022-02-14T09:21:35.158386Z","shell.execute_reply.started":"2022-02-14T09:21:29.013752Z","shell.execute_reply":"2022-02-14T09:21:35.157728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:27:05.974545Z","iopub.execute_input":"2022-02-14T09:27:05.974826Z","iopub.status.idle":"2022-02-14T09:27:05.979048Z","shell.execute_reply.started":"2022-02-14T09:27:05.974794Z","shell.execute_reply":"2022-02-14T09:27:05.978158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions['t_dat'] = pd.to_datetime(transactions['t_dat'], infer_datetime_format=True)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:14:38.751015Z","iopub.execute_input":"2022-02-14T10:14:38.751662Z","iopub.status.idle":"2022-02-14T10:14:39.591124Z","shell.execute_reply.started":"2022-02-14T10:14:38.751618Z","shell.execute_reply":"2022-02-14T10:14:39.590345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions['t_dat'].dtypes","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:14:41.922051Z","iopub.execute_input":"2022-02-14T10:14:41.922618Z","iopub.status.idle":"2022-02-14T10:14:41.929103Z","shell.execute_reply.started":"2022-02-14T10:14:41.922574Z","shell.execute_reply":"2022-02-14T10:14:41.928402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# transactions['t_dat'].value_counts().sort_values(ascending = False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.shape","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:21:48.814755Z","iopub.execute_input":"2022-02-14T09:21:48.815367Z","iopub.status.idle":"2022-02-14T09:21:48.820877Z","shell.execute_reply.started":"2022-02-14T09:21:48.815325Z","shell.execute_reply":"2022-02-14T09:21:48.820008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.bar(transactions['t_dat'].dt.year,transactions['article_id'])\n# plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions['price'].head(20)","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:23:54.970227Z","iopub.execute_input":"2022-02-14T10:23:54.970562Z","iopub.status.idle":"2022-02-14T10:23:55.053191Z","shell.execute_reply.started":"2022-02-14T10:23:54.970477Z","shell.execute_reply":"2022-02-14T10:23:55.052082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(customers.index)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(transactions.index)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(articles.index)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df = pd.merge(customers, transactions, on = 'customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:22:00.75475Z","iopub.execute_input":"2022-02-14T09:22:00.755005Z","iopub.status.idle":"2022-02-14T09:22:21.802209Z","shell.execute_reply.started":"2022-02-14T09:22:00.754977Z","shell.execute_reply":"2022-02-14T09:22:21.801459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.merge(articles, transactions, on='article_id')","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:23:24.740224Z","iopub.execute_input":"2022-02-14T10:23:24.740852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T09:29:52.082901Z","iopub.execute_input":"2022-02-14T09:29:52.083342Z","iopub.status.idle":"2022-02-14T09:29:52.100943Z","shell.execute_reply.started":"2022-02-14T09:29:52.083302Z","shell.execute_reply":"2022-02-14T09:29:52.099754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.set_index('t_dat')['article_id'].plot()","metadata":{"execution":{"iopub.status.busy":"2022-02-14T10:16:32.738163Z","iopub.execute_input":"2022-02-14T10:16:32.738897Z","iopub.status.idle":"2022-02-14T10:19:48.793266Z","shell.execute_reply.started":"2022-02-14T10:16:32.738852Z","shell.execute_reply":"2022-02-14T10:19:48.791461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{},"execution_count":null,"outputs":[]}]}