{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\nfrom sklearn.linear_model import LinearRegression\nimport xgboost\nfrom sklearn.svm import SVR\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train = pd.read_csv(\"../input/train.csv\")\nhtrans = pd.read_csv(\"../input/historical_transactions.csv\")\nmerc = pd.read_csv(\"../input/merchants.csv\")\nnmerc = pd.read_csv(\"../input/new_merchant_transactions.csv\")\ntest = pd.read_csv(\"../input/test.csv\")\nsub = pd.read_csv(\"../input/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"32bdbe1813b56d2bafc54122338dda2dd8e2b8f8"},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d5c48224c44b11b82338f9539a58fd0fde140502"},"cell_type":"code","source":"train.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"961d27310eeb657baecce87afd859582cb56d6a9"},"cell_type":"code","source":"train.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aafe7a21cae80c5132e0693e83dfba99a3bb0868"},"cell_type":"code","source":"train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"46c3ad22180910082bd289103765d7b9dc597d71"},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4fd3977b0ee5c3f8fd23e29137d6878dedbbfe04"},"cell_type":"code","source":"train[\"first_active\"]=pd.to_datetime(train[\"first_active_month\"])\ntrain[\"day\"]=train[\"first_active\"].dt.month\ntrain[\"year\"]=train[\"first_active\"].dt.year","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5295f53327270fb3f6aa8d0f317da94f54217dda"},"cell_type":"code","source":"test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0e321437e4951c04d4b6dbfe318e5f120c276013"},"cell_type":"code","source":"test=test.fillna(\"2017-09\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39c3bf492780f4e93524170e99af9d595951f9bc"},"cell_type":"code","source":"test[\"first_active\"]=pd.to_datetime(test[\"first_active_month\"])\ntest[\"day\"]=test[\"first_active\"].dt.month\ntest[\"year\"]=test[\"first_active\"].dt.year","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"230edf81a45c590adf0bf6f8d474f01cf4f3170e"},"cell_type":"code","source":"train = train.drop(['first_active','first_active_month','card_id'],axis=1)\ntest  = test.drop(['first_active','first_active_month','card_id'],axis=1)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"688beba79f1d925440f65fd69cc91ed2bf8821f8"},"cell_type":"code","source":"y=train[\"target\"]\nx=train.drop([\"target\"],axis=1)\nfrom sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.4, random_state=11)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8e5275e9a7f8dc86ab18c00fd4c2ba0a998d1ca9"},"cell_type":"code","source":"from math import *\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.ensemble import RandomForestRegressor\nrfr = RandomForestRegressor(n_estimators=100,random_state = 42)\nrfr.fit(x_train, y_train)\ny_pred=rfr.predict(x_test)\nprint(math.sqrt(mean_squared_error(y_test, y_pred)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"63b70a67c153dacfe2b41f4e01985b7a03f0a5fd"},"cell_type":"code","source":"params = {}\nparams[\"objective\"] = \"reg:linear\"\nparams[\"eta\"] = 0.03\nparams[\"min_child_weight\"] = 10\nparams[\"subsample\"] = 0.8\nparams[\"colsample_bytree\"] = 0.7\nparams[\"silent\"] = 1\nparams[\"max_depth\"] = 18\n#params[\"max_delta_step\"]=2\nparams[\"seed\"] = 0\n #params['eval_metric'] = \"auc\"\nplst1 = list(params.items())\nnum_rounds1 = 1100\nimport xgboost as xgb\nxgdmat=xgb.DMatrix(x_train,y_train)\n\nfinal_gb1=xgb.train(plst1,xgdmat,num_rounds1)\n\ntesdmat=xgb.DMatrix(x_test)\ny_pred=final_gb1.predict(tesdmat)\nprint(np.sqrt(mean_squared_error(y_test, y_pred)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d060e59c33b6c547c6e8a5e3ffcdc6575bce0da8"},"cell_type":"code","source":"testmat=xgb.DMatrix(test)\nanswer=final_gb1.predict(testmat)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6eaa9e1be3e9ecfe0dde6cc8fccdac7ec967ccf8"},"cell_type":"code","source":"sub.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74cead5ada770f2ae99f5de9a87cb38cfe8a15e0"},"cell_type":"code","source":"sub[\"target\"]=answer","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fbdf967ba4e14d9489e3f2d77d6eddfc768443f0"},"cell_type":"code","source":"sub.to_csv(\"sample_submission.csv\",index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d0e102124a5ddd263575e8b3c658b3ec56cf6f5"},"cell_type":"code","source":"","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}