diff --git a/Gradient Boosting.ipynb b/Gradient Boosting.ipynb index 5a2f97b..b5e83a2 100644 --- a/Gradient Boosting.ipynb +++ b/Gradient Boosting.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 17, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -239,7 +239,7 @@ "[5 rows x 25 columns]" ] }, - "execution_count": 19, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -251,7 +251,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -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" } @@ -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,