Forked from Vikrant79/Coupon Purchase Prediction - BTB Script.ipynb
Created
January 29, 2018 05:11
-
-
Save ocoyawale/e284fc8cde5a042c8cdd71a3b462f74c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import xgboost as xgb\n", | |
"from datetime import datetime\n", | |
"\n", | |
"\n", | |
"def get_data():\n", | |
" train = pd.read_csv(\"../input/train.csv\")\n", | |
" test = pd.read_csv(\"../input/test.csv\")\n", | |
"\n", | |
" features = train.select_dtypes(include=['float']).columns\n", | |
" features = np.setdiff1d(features,['ID','target'])\n", | |
"\n", | |
" test_ids = test.ID\n", | |
" y_train = train.target\n", | |
"\n", | |
" x_train = train[features]\n", | |
" x_test = test[features]\n", | |
"\n", | |
" return x_train, y_train, x_test, test_ids\n", | |
"\n", | |
"ts = datetime.now()\n", | |
"x_train, y_train, x_test, test_ids = get_data()\n", | |
"\n", | |
"\n", | |
"xgb_params = {\"objective\": \"binary:logistic\", \"max_depth\": 10, \"silent\": 1}\n", | |
"num_rounds = 200\n", | |
"\n", | |
"dtrain = xgb.DMatrix(x_train, label=y_train)\n", | |
"dtest = xgb.DMatrix(x_test)\n", | |
"gbdt = xgb.train(xgb_params, dtrain, num_rounds)\n", | |
"\n", | |
"preds = gbdt.predict(dtest)\n", | |
"\n", | |
"\n", | |
"submission = pd.DataFrame({\"ID\": test_ids, \"target\": preds})\n", | |
"submission = submission.set_index('ID')\n", | |
"submission.to_csv('xgb_benchmark.csv')\n", | |
"\n", | |
"te = datetime.now()\n", | |
"print('elapsed time: {0}'.format(te-ts))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment