Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Vikrant79/d14da7541a364e6232b7 to your computer and use it in GitHub Desktop.
Save Vikrant79/d14da7541a364e6232b7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import sys\n",
"sys.path.append('C:\\\\Users\\\\Vikrant\\\\xgboost\\\\python-package')\n",
"import xgboost as xgb\n",
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"train = pd.read_csv('train_Spring.csv')\n",
"test = pd.read_csv('test_Spring.csv')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def get_data():\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"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ts = datetime.now()\n",
"x_train, y_train, x_test, test_ids = get_data()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"xgb_params = {\"objective\": \"binary:logistic\", \"max_depth\": 10, \"silent\": 1}\n",
"num_rounds = 200"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"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)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"elapsed time: 0:11:31.227000\n"
]
}
],
"source": [
"submission = pd.DataFrame({\"ID\": test_ids, \"target\": preds})\n",
"submission = submission.set_index('ID')\n",
"submission.to_csv('Springleaf1.csv')\n",
"\n",
"te = datetime.now()\n",
"print('elapsed time: {0}'.format(te-ts))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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