{"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 os\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nimport warnings as w\nimport gc\n\nw.filterwarnings(action='ignore')\nplt.style.use('ggplot')\npd.set_option('display.max_column',None)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-01T07:21:38.311815Z","iopub.execute_input":"2022-06-01T07:21:38.312166Z","iopub.status.idle":"2022-06-01T07:21:38.317837Z","shell.execute_reply.started":"2022-06-01T07:21:38.312134Z","shell.execute_reply":"2022-06-01T07:21:38.317124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv',\n                        low_memory=True,\n                        usecols={'customer_id':str,\n                        'FN':np.uint8,\n                        'Active':np.uint8,\n                        'club_member_status':str,\n                        'fashion_news_frequency':str,\n                        'age':np.uint8,\n                        'postal_code':str,\n                    })\narticle = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv',\n                     low_memory=True,\n                      usecols={'article_id':np.uint8,\n                      'product_code':np.uint8,\n                      'product_type_no':np.uint8,\n                      'graphical_appearance_no':np.uint8,\n                      'colour_group_code':np.uint8,\n                      'perceived_colour_value_id':np.uint8,\n                      'perceived_colour_master_id':np.uint8,\n                      'department_no':np.uint8,\n                      'index_code':np.uint8,\n                      'index_group_no':np.uint8,\n                      'section_no':np.uint8,\n                      'garment_group_no':np.uint8\n                         })\n# transaction file is too big so 10000000 data\ntransaction = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv',\n                         low_memory=True,\n                          usecols={\n                          't_dat':str,\n                          'customer_id':str,\n                          'article_id':np.uint8,\n                          'price':np.float16,\n                          'sales_channel_id':np.uint8\n                         },nrows=15000000)\nprint('Customer:',customers.shape)\nprint('article:',article.shape)\nprint('transaction',transaction.shape)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:21:38.438177Z","iopub.execute_input":"2022-06-01T07:21:38.438809Z","iopub.status.idle":"2022-06-01T07:22:10.389753Z","shell.execute_reply.started":"2022-06-01T07:21:38.438772Z","shell.execute_reply":"2022-06-01T07:22:10.388989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Feature explain\n * Customers(User Field)\n     1. customer_id : personal id\n     2. FN : Fashion News?\n     3. Active : ?\n     4. club_member_status : iterally\n     5. fashion_news_frequency: iterally\n     6. age \n     7. post_code : store adress id? customer bought in postal_code","metadata":{}},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:10.391402Z","iopub.execute_input":"2022-06-01T07:22:10.391760Z","iopub.status.idle":"2022-06-01T07:22:10.410966Z","shell.execute_reply.started":"2022-06-01T07:22:10.391724Z","shell.execute_reply":"2022-06-01T07:22:10.410169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:10.412021Z","iopub.execute_input":"2022-06-01T07:22:10.412446Z","iopub.status.idle":"2022-06-01T07:22:10.948999Z","shell.execute_reply.started":"2022-06-01T07:22:10.412411Z","shell.execute_reply":"2022-06-01T07:22:10.947997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:10.951163Z","iopub.execute_input":"2022-06-01T07:22:10.951672Z","iopub.status.idle":"2022-06-01T07:22:11.469836Z","shell.execute_reply.started":"2022-06-01T07:22:10.951627Z","shell.execute_reply":"2022-06-01T07:22:11.469069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.FN.fillna(0,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:11.470915Z","iopub.execute_input":"2022-06-01T07:22:11.471484Z","iopub.status.idle":"2022-06-01T07:22:11.485460Z","shell.execute_reply.started":"2022-06-01T07:22:11.471445Z","shell.execute_reply":"2022-06-01T07:22:11.484773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.FN.value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:11.486608Z","iopub.execute_input":"2022-06-01T07:22:11.486998Z","iopub.status.idle":"2022-06-01T07:22:11.678471Z","shell.execute_reply.started":"2022-06-01T07:22:11.486963Z","shell.execute_reply":"2022-06-01T07:22:11.677695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.Active.fillna(0,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:11.679826Z","iopub.execute_input":"2022-06-01T07:22:11.680734Z","iopub.status.idle":"2022-06-01T07:22:11.693954Z","shell.execute_reply.started":"2022-06-01T07:22:11.680695Z","shell.execute_reply":"2022-06-01T07:22:11.693194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.Active.value_counts().plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:11.696057Z","iopub.execute_input":"2022-06-01T07:22:11.696937Z","iopub.status.idle":"2022-06-01T07:22:11.861419Z","shell.execute_reply.started":"2022-06-01T07:22:11.696901Z","shell.execute_reply":"2022-06-01T07:22:11.860428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.club_member_status.value_counts().plot(kind='bar')\nprint(customers.club_member_status.value_counts())","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:11.862910Z","iopub.execute_input":"2022-06-01T07:22:11.863550Z","iopub.status.idle":"2022-06-01T07:22:12.420572Z","shell.execute_reply.started":"2022-06-01T07:22:11.863510Z","shell.execute_reply":"2022-06-01T07:22:12.419802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### I think won't Data handling with this columns(Drop Age and postal_code)","metadata":{}},{"cell_type":"code","source":"customers.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:12.424737Z","iopub.execute_input":"2022-06-01T07:22:12.425019Z","iopub.status.idle":"2022-06-01T07:22:13.087728Z","shell.execute_reply.started":"2022-06-01T07:22:12.424987Z","shell.execute_reply":"2022-06-01T07:22:13.086858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### It looks maybe 40,000 data drop","metadata":{}},{"cell_type":"code","source":"customers.isna().sum()\nprint(customers.shape)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.089241Z","iopub.execute_input":"2022-06-01T07:22:13.089636Z","iopub.status.idle":"2022-06-01T07:22:13.615184Z","shell.execute_reply.started":"2022-06-01T07:22:13.089598Z","shell.execute_reply":"2022-06-01T07:22:13.614343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Feature Explain\n   * Article (item Field)\n      1. article_id \n      2. product_code : item category\n      3. prod_name : product name\n      4. product_type_no :  \n      5. product_group_name : product category name\n      6. graphical_appearance_no \n      7. graphical_appearance_name : product pattern style?\n      8. colour_group_code\n      9. color_group_name : product color\n      10. preceived_colour_value_id\n      11. perceived_colour_value_name : product detail color\n      12. ETC....\n      ","metadata":{}},{"cell_type":"code","source":"article.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.616345Z","iopub.execute_input":"2022-06-01T07:22:13.617066Z","iopub.status.idle":"2022-06-01T07:22:13.629676Z","shell.execute_reply.started":"2022-06-01T07:22:13.617027Z","shell.execute_reply":"2022-06-01T07:22:13.628782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.info()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.631159Z","iopub.execute_input":"2022-06-01T07:22:13.631587Z","iopub.status.idle":"2022-06-01T07:22:13.657205Z","shell.execute_reply.started":"2022-06-01T07:22:13.631549Z","shell.execute_reply":"2022-06-01T07:22:13.656374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.660018Z","iopub.execute_input":"2022-06-01T07:22:13.660317Z","iopub.status.idle":"2022-06-01T07:22:13.679899Z","shell.execute_reply.started":"2022-06-01T07:22:13.660279Z","shell.execute_reply":"2022-06-01T07:22:13.679200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.dropna(inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.680909Z","iopub.execute_input":"2022-06-01T07:22:13.681323Z","iopub.status.idle":"2022-06-01T07:22:13.703637Z","shell.execute_reply.started":"2022-06-01T07:22:13.681272Z","shell.execute_reply":"2022-06-01T07:22:13.702925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Feature Explain\n   * transaction\n      1. sales_channel_id : 1 is offline, 2 is online ","metadata":{}},{"cell_type":"code","source":"transaction.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.704741Z","iopub.execute_input":"2022-06-01T07:22:13.705144Z","iopub.status.idle":"2022-06-01T07:22:13.719038Z","shell.execute_reply.started":"2022-06-01T07:22:13.705107Z","shell.execute_reply":"2022-06-01T07:22:13.715367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction.sales_channel_id.value_counts(normalize=True).plot(kind='bar')","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.720233Z","iopub.execute_input":"2022-06-01T07:22:13.721151Z","iopub.status.idle":"2022-06-01T07:22:13.958014Z","shell.execute_reply.started":"2022-06-01T07:22:13.721113Z","shell.execute_reply":"2022-06-01T07:22:13.957191Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"user_field = customers.merge(transaction,on='customer_id',how='inner')","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:13.959198Z","iopub.execute_input":"2022-06-01T07:22:13.959578Z","iopub.status.idle":"2022-06-01T07:22:23.905546Z","shell.execute_reply.started":"2022-06-01T07:22:13.959541Z","shell.execute_reply":"2022-06-01T07:22:23.904669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del transaction,customers\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:23.906685Z","iopub.execute_input":"2022-06-01T07:22:23.907044Z","iopub.status.idle":"2022-06-01T07:22:24.042547Z","shell.execute_reply.started":"2022-06-01T07:22:23.907011Z","shell.execute_reply":"2022-06-01T07:22:24.041153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:24.043891Z","iopub.execute_input":"2022-06-01T07:22:24.044436Z","iopub.status.idle":"2022-06-01T07:22:24.061877Z","shell.execute_reply.started":"2022-06-01T07:22:24.044400Z","shell.execute_reply":"2022-06-01T07:22:24.061219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"user_field.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:24.064275Z","iopub.execute_input":"2022-06-01T07:22:24.064544Z","iopub.status.idle":"2022-06-01T07:22:24.082559Z","shell.execute_reply.started":"2022-06-01T07:22:24.064511Z","shell.execute_reply":"2022-06-01T07:22:24.081797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### merge User_field & item_field","metadata":{}},{"cell_type":"code","source":"df = article.merge(user_field,on='article_id',how='inner')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:22:24.083943Z","iopub.execute_input":"2022-06-01T07:22:24.084532Z","iopub.status.idle":"2022-06-01T07:23:03.865331Z","shell.execute_reply.started":"2022-06-01T07:22:24.084499Z","shell.execute_reply":"2022-06-01T07:23:03.864603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop_duplicates('customer_id',inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:03.866445Z","iopub.execute_input":"2022-06-01T07:23:03.866870Z","iopub.status.idle":"2022-06-01T07:23:15.061447Z","shell.execute_reply.started":"2022-06-01T07:23:03.866833Z","shell.execute_reply":"2022-06-01T07:23:15.060641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del article\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.062864Z","iopub.execute_input":"2022-06-01T07:23:15.063229Z","iopub.status.idle":"2022-06-01T07:23:15.164810Z","shell.execute_reply.started":"2022-06-01T07:23:15.063192Z","shell.execute_reply":"2022-06-01T07:23:15.163910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.sort_values('FN',inplace=True)\ndf","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.166507Z","iopub.execute_input":"2022-06-01T07:23:15.166956Z","iopub.status.idle":"2022-06-01T07:23:15.484771Z","shell.execute_reply.started":"2022-06-01T07:23:15.166918Z","shell.execute_reply":"2022-06-01T07:23:15.483857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### user_field \n   * customer_id,FN\tActive\n   * club_member_status\n   * fashion_news_frequency\n   * age\n   * postal_code\n   * t_dat\n   * price\n   * sales_channel_id\n\n### item_field\n   * product_code\n   * product_type_no\n   * graphical_appearance_no\n   * colour_group_code\n   * perceived_colour_value_id\n   * perceived_colour_master_id\n   * department_no\n   * index_code\n   * index_group_no\n   * section_no\n   * garment_group_no","metadata":{}},{"cell_type":"code","source":"df.drop(['t_dat'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.486254Z","iopub.execute_input":"2022-06-01T07:23:15.486636Z","iopub.status.idle":"2022-06-01T07:23:15.646354Z","shell.execute_reply.started":"2022-06-01T07:23:15.486599Z","shell.execute_reply":"2022-06-01T07:23:15.645513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dense_features = df.iloc[::,1:11].columns.values.tolist()\nsparse_features = df.iloc[::,12:].columns.values.tolist()\nsparse_features.pop(1)\nsparse_features.append('article_id')\ntarget = ['FN']\nprint(dense_features)\nprint('-'*58)\nprint(sparse_features)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.647835Z","iopub.execute_input":"2022-06-01T07:23:15.648215Z","iopub.status.idle":"2022-06-01T07:23:15.798812Z","shell.execute_reply.started":"2022-06-01T07:23:15.648180Z","shell.execute_reply":"2022-06-01T07:23:15.797980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nencoder = LabelEncoder()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.802586Z","iopub.execute_input":"2022-06-01T07:23:15.804415Z","iopub.status.idle":"2022-06-01T07:23:15.917678Z","shell.execute_reply.started":"2022-06-01T07:23:15.804385Z","shell.execute_reply":"2022-06-01T07:23:15.916970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.index_code = encoder.fit_transform(df.index_code)\ndf.club_member_status = encoder.fit_transform(df.club_member_status)\ndf.fashion_news_frequency = encoder.fit_transform(df.fashion_news_frequency)\ndf.customer_id = encoder.fit_transform(df.customer_id)\ndf.postal_code = encoder.fit_transform(df.postal_code)\ndf.article_id = encoder.fit_transform(df.article_id)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:15.918707Z","iopub.execute_input":"2022-06-01T07:23:15.919054Z","iopub.status.idle":"2022-06-01T07:23:22.051803Z","shell.execute_reply.started":"2022-06-01T07:23:15.919017Z","shell.execute_reply":"2022-06-01T07:23:22.050952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr_data = df[df.keys()]\ncmap = plt.cm.PuBu\ncols = corr_data.corr().nlargest(len(df.keys()),'FN')['FN'].index\ncm = np.corrcoef(corr_data[cols].values.T)\nf,ax = plt.subplots(figsize=(15,10))\nsns.heatmap(cm,vmax=1,vmin=-1,annot=True,square=True,linewidths=0.1,cmap=cmap,\n            xticklabels=cols.values,yticklabels=cols.values)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:22.052814Z","iopub.execute_input":"2022-06-01T07:23:22.054580Z","iopub.status.idle":"2022-06-01T07:23:25.494025Z","shell.execute_reply.started":"2022-06-01T07:23:22.054539Z","shell.execute_reply":"2022-06-01T07:23:25.493316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del corr_data,cm,cols\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:25.495018Z","iopub.execute_input":"2022-06-01T07:23:25.496778Z","iopub.status.idle":"2022-06-01T07:23:25.607745Z","shell.execute_reply.started":"2022-06-01T07:23:25.496750Z","shell.execute_reply":"2022-06-01T07:23:25.607004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install deepctr_torch","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:25.608989Z","iopub.execute_input":"2022-06-01T07:23:25.609553Z","iopub.status.idle":"2022-06-01T07:23:52.559960Z","shell.execute_reply.started":"2022-06-01T07:23:25.609514Z","shell.execute_reply":"2022-06-01T07:23:52.558982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nfrom torch.utils.data import Dataset,DataLoader\n\nfrom sklearn.metrics import log_loss, roc_auc_score\nfrom sklearn.model_selection import train_test_split\n\nfrom deepctr_torch.inputs import SparseFeat, DenseFeat, get_feature_names\nfrom deepctr_torch.models import *","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:52.561527Z","iopub.execute_input":"2022-06-01T07:23:52.561920Z","iopub.status.idle":"2022-06-01T07:23:58.173040Z","shell.execute_reply.started":"2022-06-01T07:23:52.561878Z","shell.execute_reply":"2022-06-01T07:23:58.172259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fixlen_feature_columns = [SparseFeat(feat, df[feat].nunique())\n                              for feat in sparse_features] + [DenseFeat(feat, 1, )\n                                                              for feat in dense_features]","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.174104Z","iopub.execute_input":"2022-06-01T07:23:58.174705Z","iopub.status.idle":"2022-06-01T07:23:58.323732Z","shell.execute_reply.started":"2022-06-01T07:23:58.174668Z","shell.execute_reply":"2022-06-01T07:23:58.322937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dnn_feature_columns = fixlen_feature_columns\nlinear_feature_columns = fixlen_feature_columns","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.328427Z","iopub.execute_input":"2022-06-01T07:23:58.330517Z","iopub.status.idle":"2022-06-01T07:23:58.336411Z","shell.execute_reply.started":"2022-06-01T07:23:58.330479Z","shell.execute_reply":"2022-06-01T07:23:58.335617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_names = get_feature_names(linear_feature_columns + dnn_feature_columns)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.340114Z","iopub.execute_input":"2022-06-01T07:23:58.342554Z","iopub.status.idle":"2022-06-01T07:23:58.348212Z","shell.execute_reply.started":"2022-06-01T07:23:58.342513Z","shell.execute_reply":"2022-06-01T07:23:58.347483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train, test = train_test_split(df,test_size=0.2,random_state=2020)\ntrain_model_input = {name:train[name] for name in feature_names}\ntest_model_input = {name:test[name] for name in feature_names}","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.352150Z","iopub.execute_input":"2022-06-01T07:23:58.354384Z","iopub.status.idle":"2022-06-01T07:23:58.649983Z","shell.execute_reply.started":"2022-06-01T07:23:58.354350Z","shell.execute_reply":"2022-06-01T07:23:58.649150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"device = ('cuda' if torch.cuda.is_available() else 'cpu')","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.651427Z","iopub.execute_input":"2022-06-01T07:23:58.651782Z","iopub.status.idle":"2022-06-01T07:23:58.710046Z","shell.execute_reply.started":"2022-06-01T07:23:58.651746Z","shell.execute_reply":"2022-06-01T07:23:58.709216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DeepFM(linear_feature_columns=linear_feature_columns,dnn_feature_columns=dnn_feature_columns,\n              task='binary',device=device)","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:23:58.711478Z","iopub.execute_input":"2022-06-01T07:23:58.711860Z","iopub.status.idle":"2022-06-01T07:24:03.231090Z","shell.execute_reply.started":"2022-06-01T07:23:58.711823Z","shell.execute_reply":"2022-06-01T07:24:03.230294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DeepFM(linear_feature_columns=linear_feature_columns, dnn_feature_columns=dnn_feature_columns,\n                   task='binary',\n                   l2_reg_embedding=1e-5, device=device)\n\nmodel.compile(\"adagrad\", \"binary_crossentropy\",\n              metrics=[\"binary_crossentropy\", \"auc\"], )\n\nhistory = model.fit(train_model_input, train[target].values, batch_size=512, epochs=50, verbose=1,\n                    validation_split=0.2)\npred_ans = model.predict(test_model_input, 256)\nprint(\"\")\nprint(\"test LogLoss\", round(log_loss(test[target].values, pred_ans), 4))\nprint(\"test AUC\", round(roc_auc_score(test[target].values, pred_ans), 4))","metadata":{"execution":{"iopub.status.busy":"2022-06-01T07:24:03.232237Z","iopub.execute_input":"2022-06-01T07:24:03.232602Z","iopub.status.idle":"2022-06-01T07:24:04.006601Z","shell.execute_reply.started":"2022-06-01T07:24:03.232566Z","shell.execute_reply":"2022-06-01T07:24:04.005249Z"},"trusted":true},"execution_count":null,"outputs":[]}]}