{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Import packages" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "import datetime as dt\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import numpy as np\n", "import visualizeNN as VisNN\n", "\n", "# SKLEARN\n", "from sklearn.preprocessing import LabelEncoder\n", "from sklearn.model_selection import train_test_split, GridSearchCV\n", "from sklearn.tree import DecisionTreeClassifier, plot_tree\n", "from sklearn.metrics import classification_report, roc_curve, auc, confusion_matrix\n", "from sklearn.neural_network import MLPClassifier\n", "\n", "from itertools import product\n", "\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "pd.options.display.float_format = '{:.2f}'.format # show only two digits\n", "pd.set_option('display.max_columns', 100) # show up to 100 columns\n", "np.random.seed(2023)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# CASE STUDY - CREDIT RISK" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Credit risk dataset+" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Credit_rating | \n", "Age | \n", "Income | \n", "Credit_cards | \n", "Education | \n", "Car_loans | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "Bad | \n", "36.22 | \n", "Medium | \n", "5 or more | \n", "College | \n", "More than 2 | \n", "
| 1 | \n", "Bad | \n", "21.99 | \n", "Medium | \n", "5 or more | \n", "College | \n", "More than 2 | \n", "
| 2 | \n", "Bad | \n", "29.17 | \n", "Low | \n", "5 or more | \n", "High school | \n", "More than 2 | \n", "
| 3 | \n", "Bad | \n", "32.75 | \n", "Low | \n", "5 or more | \n", "College | \n", "None or 1 | \n", "
| 4 | \n", "Bad | \n", "36.77 | \n", "Medium | \n", "5 or more | \n", "College | \n", "More than 2 | \n", "
MLPClassifier(hidden_layer_sizes=(5, 5, 5), random_state=2023)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
MLPClassifier(hidden_layer_sizes=(5, 5, 5), random_state=2023)
GridSearchCV(cv=5, estimator=MLPClassifier(), n_jobs=-1,\n",
" param_grid={'activation': ['relu', 'identity', 'logistic', 'tanh'],\n",
" 'alpha': [0.0001, 0.001, 0.01, 0.1],\n",
" 'hidden_layer_sizes': [(7, 4, 3), (7, 4, 4), (7, 4, 5),\n",
" (7, 5, 3), (7, 5, 4), (7, 5, 5),\n",
" (7, 6, 3), (7, 6, 4), (7, 6, 5),\n",
" (8, 4, 3), (8, 4, 4), (8, 4, 5),\n",
" (8, 5, 3), (8, 5, 4), (8, 5, 5),\n",
" (8, 6, 3), (8, 6, 4), (8, 6, 5),\n",
" (9, 4, 3), (9, 4, 4), (9, 4, 5),\n",
" (9, 5, 3), (9, 5, 4), (9, 5, 5),\n",
" (9, 6, 3), (9, 6, 4),\n",
" (9, 6, 5)]},\n",
" scoring='f1')In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. GridSearchCV(cv=5, estimator=MLPClassifier(), n_jobs=-1,\n",
" param_grid={'activation': ['relu', 'identity', 'logistic', 'tanh'],\n",
" 'alpha': [0.0001, 0.001, 0.01, 0.1],\n",
" 'hidden_layer_sizes': [(7, 4, 3), (7, 4, 4), (7, 4, 5),\n",
" (7, 5, 3), (7, 5, 4), (7, 5, 5),\n",
" (7, 6, 3), (7, 6, 4), (7, 6, 5),\n",
" (8, 4, 3), (8, 4, 4), (8, 4, 5),\n",
" (8, 5, 3), (8, 5, 4), (8, 5, 5),\n",
" (8, 6, 3), (8, 6, 4), (8, 6, 5),\n",
" (9, 4, 3), (9, 4, 4), (9, 4, 5),\n",
" (9, 5, 3), (9, 5, 4), (9, 5, 5),\n",
" (9, 6, 3), (9, 6, 4),\n",
" (9, 6, 5)]},\n",
" scoring='f1')MLPClassifier()
MLPClassifier()