{"cells":[{"metadata":{"trusted":true,"_uuid":"c3da4b9041e91c09e5f03256c4abef8d441e9852"},"cell_type":"code","source":"!ls ../input","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"84a6e463a8484b8bb99ece2455473cee4c49f76c"},"cell_type":"code","source":"import warnings\nwarnings.filterwarnings('ignore')\n\nimport pandas as pd\nimport numpy as np\nimport sys\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\nfrom sklearn import metrics\nfrom time import time","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8b6098da52121b2fe91a50ee5e72846b800060a1"},"cell_type":"markdown","source":"# Exploring data: train, test files."},{"metadata":{"trusted":true,"_uuid":"b8338e4329be6680be6b923ecf98d01c1e10ee2a"},"cell_type":"code","source":"# Remember to change directory path\ntrain = pd.read_csv(\"../input/train.csv\", parse_dates=['first_active_month'])\ntest = pd.read_csv(\"../input/test.csv\", parse_dates=['first_active_month'])\nprint(train.shape)\nprint(test.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"98b9e8edba497a64dcea639df5147206e473ea27"},"cell_type":"code","source":"data = pd.concat([train,test])\nprint(data.head(5))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"baf9663a4e3e9bac9391992bdf568201aa71f618"},"cell_type":"code","source":"data.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"de3d1e826855dbb9be0d7e2572f66556e98a17cf"},"cell_type":"code","source":"data.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1f54cb998ff53325a9a325a4842c385486ec8509"},"cell_type":"code","source":"target_col = \"target\"\n\nplt.figure(figsize=(8,6))\nplt.scatter(range(train.shape[0]), np.sort(train[target_col].values))\nplt.xlabel('index', fontsize=12)\nplt.ylabel('Loyalty Score', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed66a88191d4551562ebebb0aedd6d8529140473"},"cell_type":"code","source":"plt.figure(figsize=(12,8))\nsns.distplot(train[target_col].values, bins=50, kde=False, color=\"red\")\nplt.title(\"Histogram of Loyalty score\")\nplt.xlabel('Loyalty score', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"19bf9e27e6673057e1bcfc377b308f12ec266db2"},"cell_type":"code","source":"(train['target']<-30).sum()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ee8c6e6da8c2deae8942e4ecfcbb3da8c738223a"},"cell_type":"markdown","source":"Check out this 2207 input values that might be either outliers or erros. Take them into consideration.\n\n**Edit: dropping this values to try out the model with new data training**"},{"metadata":{"trusted":true,"_uuid":"97b8c84883e5adf1355ebac98f2406de2042fa13"},"cell_type":"code","source":"'''\ntrain = train.drop(train[train.target<-30].index)\nplt.figure(figsize=(12,8))\nsns.distplot(train[target_col].values, bins=50, kde=False, color=\"red\")\nplt.title(\"Histogram of Loyalty score\")\nplt.xlabel('Loyalty score', fontsize=12)\nplt.show()\n'''","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"13a73509dd75305059014c630683756ce86104dd"},"cell_type":"code","source":"cnt_srs_1 = train['first_active_month'].dt.date.value_counts()\ncnt_srs_1 = cnt_srs_1.sort_index()\ncnt_srs_2 = test['first_active_month'].dt.date.value_counts()\ncnt_srs_2 = cnt_srs_2.sort_index()\n\nsns.set(rc={'figure.figsize':(14, 6)})\nsns.barplot(cnt_srs_1.index, cnt_srs_1.values, alpha = 0.5, color = 'green')\nsns.barplot(cnt_srs_2.index, cnt_srs_2.values, alpha = 0.5, color = 'red')\n#plt.bar(cnt_srs_1.index, cnt_srs_1.values, alpha = 0.5, color = 'green')\n#plt.bar(cnt_srs_2.index, cnt_srs_2.values, alpha = 0.5, color = 'red')\n\nplt.xticks(rotation = 'vertical')\n#plt.xlabel('First active month', fontsize=12)\n#plt.ylabel('Number of cards', fontsize=12)\n#plt.title(\"First active month count in train set\")\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"595ff605c7f11bb7798da758de47009584cc1b13"},"cell_type":"code","source":"print(train.feature_1.unique())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cbf37fd0f570143f983bf73057a401773379d973"},"cell_type":"code","source":"# feature 1\nplt.figure(figsize=(16,8))\nsns.boxplot(x=\"feature_1\", y=train.target, data=train)\nplt.xticks(rotation='vertical')\nplt.xlabel('Feature 1', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Feature 1 distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5585225e06a91121a63007990a1197646d4adf1f"},"cell_type":"code","source":"print(train.feature_2.unique())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a24b75fddb643fa91a07196822ca1c5ecafda632"},"cell_type":"code","source":"# feature 2\nplt.figure(figsize=(16,8))\nsns.boxplot(x=\"feature_2\", y=train.target, data=train)\nplt.xticks(rotation='vertical')\nplt.xlabel('Feature 2', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Feature 2 distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0eb3351bad7e42590bbc39bfcaf1aeff4b31b424"},"cell_type":"code","source":"print(train.feature_3.unique())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"321840b930410ebf922cffe21b3aa073aec64051"},"cell_type":"code","source":"# feature 3\nplt.figure(figsize=(16,8))\nsns.boxplot(x=\"feature_3\", y=train.target, data=train)\nplt.xticks(rotation='vertical')\nplt.xlabel('Feature 3', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Feature 3 distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a0fa59b1f6ada7d08a27f453240d2c0f6947b6ab"},"cell_type":"markdown","source":"# Exploring data: historical_transactions file."},{"metadata":{"trusted":true,"_uuid":"dac7f2c485a6e732ffb59750b7d921afb595a6c2"},"cell_type":"code","source":"hist = pd.read_csv('../input/historical_transactions.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4b4ce4e946439a10f88ca936a7888c3efd1746c4"},"cell_type":"code","source":"hist.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dc4a4c59b019869e47830f63d980f58770c9f222"},"cell_type":"code","source":"hist.dtypes","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1823154b6e2fdbc700805a396c87e355be8cfbe0"},"cell_type":"markdown","source":"## Overview of the columns: historical_transactions file."},{"metadata":{"_uuid":"7ed15a8f1db18bc9fb79e4139adde380fa534b68"},"cell_type":"raw","source":"Overview of the columns\nThe field descriptions are as follows:\n\n    - card_id - Card identifier\n    - month_lag - month lag to reference date\n    - purchase_date - Purchase date\n    - authorized_flag - 'Y' if approved, 'N' if denied\n    - category_3 - anonymized category\n    - installments - number of installments of purchase\n    - category_1 - anonymized category\n    - merchant_category_id - Merchant category identifier (anonymized )\n    - subsector_id - Merchant category group identifier (anonymized )\n    - merchant_id - Merchant identifier (anonymized)\n    - purchase_amount - Normalized purchase amount\n    - city_id - City identifier (anonymized )\n    - state_id - State identifier (anonymized )\n    - category_2 - anonymized category\n    \nNow let us make some features based on the historical transactions and merge them with train and test set."},{"metadata":{"trusted":true,"_uuid":"7bcd02d0fefb43b158689f9f8249fd7a646744b5"},"cell_type":"code","source":"# Number of historical transactions for each card_id\ngdf = hist.groupby('card_id')\n#print(gdf.head(5))\n\ngdf = gdf['purchase_amount'].size().reset_index()\nprint(gdf.head(5))\n\ngdf.columns = ['card_id', 'num_hist_transactions']\ntrain = pd.merge(train, gdf, on='card_id', how='left')\ntest = pd.merge(test, gdf, on='card_id', how='left')\n#data = pd.merge(data, gdf, on='card_id', how='left')\nprint(train.head(5))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e7bdace00c798ba425acc82eb88e01e680df8d6"},"cell_type":"code","source":"bins = [0, 10, 20, 30, 40, 50, 75, 100, 150, 200, 500, 10000]\ntrain['binned_num_hist_transactions'] = pd.cut(train['num_hist_transactions'], bins)\ncnt_srs = train.groupby(\"binned_num_hist_transactions\")['target'].mean()\n\nplt.figure(figsize=(12,8))\nsns.boxplot(x=\"binned_num_hist_transactions\", y='target', data=train, showfliers=False)\nplt.xticks(rotation='vertical')\nplt.xlabel('binned_num_hist_transactions', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"binned_num_hist_transactions distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f6ca6c4e3285e0f488a3eff70b13dc2b68baceee"},"cell_type":"markdown","source":"## Historical transactions, aggregated by different indicators"},{"metadata":{"_uuid":"e1168a9fc2db3a8c1b576803814b2ef5fe60c117"},"cell_type":"markdown","source":"### purchase_amount as indicator"},{"metadata":{"trusted":true,"_uuid":"eebade10a4bf862739d1f251fb707f9fedf5b8cb"},"cell_type":"code","source":"gdf = hist.groupby(\"card_id\")\ngdf = gdf[\"purchase_amount\"].agg(['sum', 'mean', 'std', 'min', 'max']).reset_index()\ngdf.columns = [\"card_id\", \"sum_hist_trans\", \"mean_hist_trans\", \"std_hist_trans\", \"min_hist_trans\", \"max_hist_trans\"]\ntrain = pd.merge(train, gdf, on=\"card_id\", how=\"left\")\ntest = pd.merge(test, gdf, on=\"card_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b953c3f033adfca72372fd191051d7647dff23bb"},"cell_type":"code","source":"bins = np.percentile(train[\"sum_hist_trans\"], range(0,101,10))\ntrain['binned_sum_hist_trans'] = pd.cut(train['sum_hist_trans'], bins)\n#cnt_srs = train_df.groupby(\"binned_sum_hist_trans\")[target_col].mean()\n\nplt.figure(figsize=(12,8))\nsns.boxplot(x=\"binned_sum_hist_trans\", y='target', data=train, showfliers=False)\nplt.xticks(rotation='vertical')\nplt.xlabel('binned_sum_hist_trans', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Sum of historical transaction value (Binned) distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e8bb6dabc17ab6eb5717b5bcc0da4ebb2924017b"},"cell_type":"markdown","source":"### installments as indicator"},{"metadata":{"trusted":true,"_uuid":"5cc88264c49bda1ae1e5f45336b068c93cf315a5"},"cell_type":"code","source":"gdf = hist.groupby(\"card_id\")\ngdf = gdf[\"installments\"].agg(['sum', 'mean', 'std', 'min', 'max']).reset_index()\ngdf.columns = [\"card_id\", \"sum_hist_installments\", \"mean_hist_installments\", \"std_hist_installments\", \n               \"min_hist_installments\", \"max_hist_installments\"]\ntrain = pd.merge(train, gdf, on=\"card_id\", how=\"left\")\ntest = pd.merge(test, gdf, on=\"card_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d5872a8026636701ea13f64dfa1b834c551459e2"},"cell_type":"code","source":"bins = np.percentile(train[\"sum_hist_installments\"], range(0,101,10))\ntrain['binned_sum_hist_installments'] = pd.cut(train['sum_hist_installments'], bins, duplicates = 'drop')\n#cnt_srs = train_df.groupby(\"binned_sum_hist_trans\")[target_col].mean()\n\nplt.figure(figsize=(12,8))\nsns.boxplot(x=\"binned_sum_hist_installments\", y='target', data=train, showfliers=False)\nplt.xticks(rotation='vertical')\nplt.xlabel('binned_sum_hist_installments', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Sum of historical transaction installments (Binned) distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4e2f76b43925acdbb18f13ecd1bebe4c763815bd"},"cell_type":"markdown","source":"# Exploring data: new_merchants_transactions file."},{"metadata":{"trusted":true,"_uuid":"3af85d50b7d6d1904cac1538414750c484c8bf6b"},"cell_type":"code","source":"new_trans = pd.read_csv(\"../input/new_merchant_transactions.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a73a4d67cb42bc89d342138d45a7f787b4eb406"},"cell_type":"code","source":"new_trans.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cfff73e18c6b01de7011db7e9af0658f37e6e523"},"cell_type":"code","source":"new_trans.dtypes","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3dc9a5ed58f50cd5a861b17551d909ac674d2b15"},"cell_type":"markdown","source":"### purchaste_amount as indicator"},{"metadata":{"trusted":true,"_uuid":"bc21ee52bea1fdefdc9b5d4badf6835dbca80fed"},"cell_type":"code","source":"gdf = new_trans.groupby(\"card_id\")\ngdf = gdf[\"purchase_amount\"].size().reset_index()\ngdf.columns = [\"card_id\", \"num_merch_transactions\"]\ntrain = pd.merge(train, gdf, on=\"card_id\", how=\"left\")\ntest = pd.merge(test, gdf, on=\"card_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1a56d89f38b14922ff73eaeffff6bff375166eef"},"cell_type":"code","source":"gdf = new_trans.groupby(\"card_id\")\ngdf = gdf[\"purchase_amount\"].agg(['sum', 'mean', 'std', 'min', 'max']).reset_index()\ngdf.columns = [\"card_id\", \"sum_merch_trans\", \"mean_merch_trans\", \"std_merch_trans\", \n               \"min_merch_trans\", \"max_merch_trans\"]\ntrain = pd.merge(train, gdf, on=\"card_id\", how=\"left\")\ntest = pd.merge(test, gdf, on=\"card_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7b3fc5ee4d752e16fff694d021feeb039e3516ef"},"cell_type":"code","source":"bins = [0, 10, 20, 30, 40, 50, 75, 10000]\ntrain['binned_num_merch_transactions'] = pd.cut(train['num_merch_transactions'], bins)\ncnt_srs = train.groupby(\"binned_num_merch_transactions\")['target'].mean()\n\nplt.figure(figsize=(12,8))\nsns.boxplot(x=\"binned_num_merch_transactions\", y='target', data=train, showfliers=False)\nplt.xticks(rotation='vertical')\nplt.xlabel('binned_num_merch_transactions', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Number of new merchants transaction (Binned) distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9aa6eee4639a67cdad31e2d16d5cd14d7a53411d"},"cell_type":"markdown","source":"### installments as indicator"},{"metadata":{"trusted":true,"_uuid":"38fdef4beeeb761ad06169fa6a16f322d8456305"},"cell_type":"code","source":"gdf = new_trans.groupby(\"card_id\")\ngdf = gdf[\"installments\"].agg(['sum', 'mean', 'std', 'min', 'max']).reset_index()\ngdf.columns = [\"card_id\", \"sum_merch_installments\", \"mean_merch_installments\", \"std_merch_installments\", \n               \"min_merch_installments\", \"max_merch_installments\"]\ntrain = pd.merge(train, gdf, on=\"card_id\", how=\"left\")\ntest = pd.merge(test, gdf, on=\"card_id\", how=\"left\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39d27baa49b9dcc22031fe7205ff747eaedf6e39"},"cell_type":"code","source":"bins = np.nanpercentile(train[\"sum_merch_installments\"], range(0,101,10))\ntrain['binned_sum_merch_installments'] = pd.cut(train['sum_merch_installments'], bins, duplicates = 'drop')\n#cnt_srs = train_df.groupby(\"binned_sum_hist_trans\")[target_col].mean()\n\nplt.figure(figsize=(12,8))\nsns.boxplot(x=\"binned_sum_merch_installments\", y='target', data=train, showfliers=False)\nplt.xticks(rotation='vertical')\nplt.xlabel('binned sum of new merchant transactions installments', fontsize=12)\nplt.ylabel('Loyalty score', fontsize=12)\nplt.title(\"Sum of New merchants transaction installments value (Binned) distribution\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e05f078002a58551c34966a37fece89a5f9c7a21"},"cell_type":"markdown","source":"# Baseline: minable view"},{"metadata":{"trusted":true,"_uuid":"c43fd22dbbfeb75dec361aaccf6b1b2d22c9b4d7"},"cell_type":"code","source":"train[\"year\"] = train[\"first_active_month\"].dt.year\ntrain[\"month\"] = train[\"first_active_month\"].dt.month\ntest[\"month\"] = test[\"first_active_month\"].dt.month\ntest[\"year\"] = test[\"first_active_month\"].dt.year\n\n# data['year'] = data['first_active_month'].dt.year\n# data['month'] = data['first_active_month'].dt.month\n\ncols_to_use = [\"feature_1\", \"feature_2\", \"feature_3\", \"year\", \"month\", \n               \"num_hist_transactions\", \"sum_hist_trans\", \"mean_hist_trans\", \"std_hist_trans\", \n               \"min_hist_trans\", \"max_hist_trans\",\n               \"sum_hist_installments\", \"mean_hist_installments\", \"std_hist_installments\", \n               \"min_hist_installments\", \"max_hist_installments\",            \n               \"num_merch_transactions\", \"sum_merch_trans\", \"mean_merch_trans\", \"std_merch_trans\",\n               \"min_merch_trans\", \"max_merch_trans\",\n               \"sum_merch_installments\", \"mean_merch_installments\", \"std_merch_installments\",\n               \"min_merch_installments\", \"max_merch_installments\",\n              ]\n\n\ntrain_X = train[cols_to_use]\ntrain_y = train['target'].values\ntest_X = test[cols_to_use]\nprint(train_X.shape[0])\nprint(train_y.shape[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d3e78335488e0b33eb14505bcb361e9f407db23"},"cell_type":"code","source":"# checking minable view: get into consideration there are missing values \n# for indicators coming from new_merchants_transactions file.\nprint(train_X.head(5))\nprint(train_X.info(5))\nprint(train_X.isnull().sum())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5f3355685566b595408837af340c4c5ab8a16865"},"cell_type":"code","source":"print(train_y[:5])\nprint(np.info(train_y))\nprint(np.isnan(train_y).sum())","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9714c1832eb2d7736472b9c908e7ec630b3edf9f"},"cell_type":"markdown","source":"# Model tuning"},{"metadata":{"trusted":true,"_uuid":"42a28e95df6b591ce4dc3519c1834d99938d2bc4"},"cell_type":"code","source":"from xgboost.sklearn import XGBRegressor\nimport lightgbm as lgb\n\n#modelname = 'lightgbm'\nmodelname = 'XGBRegressor'\n#model = lgb()\nmodel = XGBRegressor()\n\nparams_lgb = {\n    'num_leaves': 100,\n    'min_data_in_leaf': 30, \n    'objective':'regression',\n    'max_depth': 6,\n    'learning_rate': 0.005,\n    \"min_child_samples\": 20,\n    \"boosting\": \"gbdt\",\n    \"feature_fraction\": 0.9,\n    \"bagging_freq\": 1,\n    \"bagging_fraction\": 0.9 ,\n    \"bagging_seed\": 11,\n    \"metric\": 'rmse',\n    \"lambda_l1\": 0.1,\n    \"verbosity\": -1\n}\n\n\nparams_xgbr = {\n    'nthread':[4], #when use hyperthread, xgboost may become slower\n    'objective':['reg:linear'],\n    'learning_rate': [.03, 0.05, .07], #so called `eta` value\n    'max_depth': [5, 6, 7],\n    'min_child_weight': [4],\n    'silent': [1],\n    'subsample': [0.7],\n    'colsample_bytree': [0.7],\n    'n_estimators': [500]\n}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ec3c84f72b6fa97f1b7c0f0c84d85eda0c21a511"},"cell_type":"code","source":"from sklearn.model_selection import RandomizedSearchCV\n\nstart = time()\nrf_random = RandomizedSearchCV(estimator = model, param_distributions = params_xgbr, \n                               n_iter = 2, cv = 3, verbose = 2, random_state = 42, n_jobs = -1)\n\nrf_random.fit(train_X, train_y)\n# print(time() - start)\nprint('Total of %.5f seconds' % (time() - start))\nprint(rf_random.cv_results_)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c86a1c31b5f946a3d70e671039098fc5daa04181"},"cell_type":"code","source":"final_model = rf_random.best_estimator_\npredictions = final_model.predict(test_X)\nprint(predictions[:5])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"480657269c2fd99ab727c39ae7c8573b9d9f13e7"},"cell_type":"code","source":"test_X.info(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c81ae568e908f2d2742ad8702873d2d6b3711d3b"},"cell_type":"code","source":"test_X.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"94ae2b147360609c6532cc5757a921d150ebe853"},"cell_type":"code","source":"predictions.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ba2ea40ddbb3ba31a6705fc440416a5554723185"},"cell_type":"code","source":"df_submission = pd.DataFrame({'card_id':test['card_id']})\ndf_submission[\"target\"] = predictions\ndf_submission.to_csv(\"newton.csv\", index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}