Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 68 additions & 6 deletions Gradient Boosting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -239,7 +239,7 @@
"[5 rows x 25 columns]"
]
},
"execution_count": 19,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -251,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -628,7 +628,7 @@
"default.payment.next.month 0.00 0.0 0.00 1.0 "
]
},
"execution_count": 20,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -731,6 +731,68 @@
"pyplot.show()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train/Valid/Test sizes: 16800 4200 9000\n"
]
}
],
"source": [
"#model training and testing \n",
"test_data.rename(columns={'default.payment.next.month':'default'}, inplace=True)\n",
"\n",
"data_x = test_data.drop(['default'], axis = 1)\n",
"data_y = test_data.default\n",
"\n",
"X_temp, X_test, y_temp, y_test = \\\n",
" train_test_split(data_x, data_y, test_size=0.3, random_state=123, stratify=data_y)\n",
"\n",
"X_train, X_valid, y_train, y_valid = \\\n",
" train_test_split(X_temp, y_temp, test_size=0.2, random_state=123, stratify=y_temp)\n",
"\n",
"print('Train/Valid/Test sizes:', y_train.shape[0], y_valid.shape[0], y_test.shape[0])\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training Accuracy: 0.92\n",
"Validation Accuracy: 0.81\n",
"Test Accuracy: 0.82\n"
]
}
],
"source": [
"from sklearn.ensemble import GradientBoostingClassifier\n",
"\n",
"\n",
"boost = GradientBoostingClassifier(\n",
" learning_rate=0.1,\n",
" n_estimators=100,\n",
" max_depth=8,\n",
" random_state=1)\n",
"\n",
"boost.fit(X_train, y_train)\n",
" \n",
" \n",
"print(\"Training Accuracy: %0.2f\" % boost.score(X_train, y_train))\n",
"print(\"Validation Accuracy: %0.2f\" % boost.score(X_valid, y_valid))\n",
"print(\"Test Accuracy: %0.2f\" % boost.score(X_test, y_test))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down