diff --git a/.gitignore b/.gitignore index 87620ac..85dc1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .ipynb_checkpoints/ +venv/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c7e57ad --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "venv/bin/python3.5" +} \ No newline at end of file diff --git a/ArtificialNeuralNetwork.ipynb b/ArtificialNeuralNetwork.ipynb index 7d3246d..6037ff0 100644 --- a/ArtificialNeuralNetwork.ipynb +++ b/ArtificialNeuralNetwork.ipynb @@ -1,14 +1,5 @@ { "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# REDES NEURAIS ARTIFICIAIS\n", - "\n", - "[Aula 3 de Deep Learning](http://bit.ly/dn-unb03) da Engenharia de Software da UnB" - ] - }, { "cell_type": "code", "execution_count": 1, @@ -17,113 +8,39 @@ { "name": "stdout", "output_type": "stream", - "text": [ - "Collecting git+git://github.com/Theano/Theano.git\n", - " Cloning git://github.com/Theano/Theano.git to /private/var/folders/xv/6xdsnhm10jg5y1g0bm3kp9140000gp/T/pip-req-build-8g5oafk2\n", - " Running command git clone -q git://github.com/Theano/Theano.git /private/var/folders/xv/6xdsnhm10jg5y1g0bm3kp9140000gp/T/pip-req-build-8g5oafk2\n", - "Building wheels for collected packages: Theano\n", - " Building wheel for Theano (setup.py) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for Theano: filename=Theano-1.0.4+21.g8f510a1f0-cp36-none-any.whl size=2666379 sha256=041cb3a9e761cab5d820669c49be2cb71215f819b38d3ca8810aee93f4551093\n", - " Stored in directory: /private/var/folders/xv/6xdsnhm10jg5y1g0bm3kp9140000gp/T/pip-ephem-wheel-cache-pri53nb7/wheels/ae/32/7c/62beb8371953eb20c271b3bac7d0e56e1a2020d46994346b52\n", - "Successfully built Theano\n", - "Installing collected packages: Theano\n", - " Found existing installation: Theano 1.0.4+21.g8f510a1f0\n", - " Uninstalling Theano-1.0.4+21.g8f510a1f0:\n", - " Successfully uninstalled Theano-1.0.4+21.g8f510a1f0\n", - "Successfully installed Theano-1.0.4+21.g8f510a1f0\n", - "Collecting tensorflow\n", - " Using cached https://files.pythonhosted.org/packages/27/8c/7608ba709bd536bc2bccb0d1abbb70aafe9cf7e0170353b4b720ed54cb71/tensorflow-1.14.0-cp36-cp36m-macosx_10_11_x86_64.whl\n", - "Requirement already satisfied, skipping upgrade: wrapt>=1.11.1 in /Users/dorgam/.local/lib/python3.6/site-packages (from tensorflow) (1.11.1)\n", - "Requirement already satisfied, skipping upgrade: termcolor>=1.1.0 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.1.0)\n", - "Requirement already satisfied, skipping upgrade: six>=1.10.0 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.11.0)\n", - "Requirement already satisfied, skipping upgrade: wheel>=0.26 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (0.31.1)\n", - "Requirement already satisfied, skipping upgrade: grpcio>=1.8.6 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.16.0)\n", - "Collecting absl-py>=0.7.0 (from tensorflow)\n", - "Collecting tensorboard<1.15.0,>=1.14.0 (from tensorflow)\n", - " Using cached https://files.pythonhosted.org/packages/91/2d/2ed263449a078cd9c8a9ba50ebd50123adf1f8cfbea1492f9084169b89d9/tensorboard-1.14.0-py3-none-any.whl\n", - "Requirement already satisfied, skipping upgrade: keras-applications>=1.0.6 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.0.8)\n", - "Collecting tensorflow-estimator<1.15.0rc0,>=1.14.0rc0 (from tensorflow)\n", - " Using cached https://files.pythonhosted.org/packages/3c/d5/21860a5b11caf0678fbc8319341b0ae21a07156911132e0e71bffed0510d/tensorflow_estimator-1.14.0-py2.py3-none-any.whl\n", - "Requirement already satisfied, skipping upgrade: astor>=0.6.0 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (0.7.1)\n", - "Requirement already satisfied, skipping upgrade: numpy<2.0,>=1.14.5 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.17.2)\n", - "Collecting google-pasta>=0.1.6 (from tensorflow)\n", - " Using cached https://files.pythonhosted.org/packages/d0/33/376510eb8d6246f3c30545f416b2263eee461e40940c2a4413c711bdf62d/google_pasta-0.1.7-py3-none-any.whl\n", - "Requirement already satisfied, skipping upgrade: protobuf>=3.6.1 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (3.6.1)\n", - "Requirement already satisfied, skipping upgrade: gast>=0.2.0 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (0.2.0)\n", - "Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in /anaconda3/lib/python3.6/site-packages (from tensorflow) (1.1.0)\n", - "Requirement already satisfied, skipping upgrade: werkzeug>=0.11.15 in /anaconda3/lib/python3.6/site-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow) (0.14.1)\n", - "Collecting setuptools>=41.0.0 (from tensorboard<1.15.0,>=1.14.0->tensorflow)\n", - " Using cached https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl\n", - "Requirement already satisfied, skipping upgrade: markdown>=2.6.8 in /anaconda3/lib/python3.6/site-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow) (3.0.1)\n", - "Requirement already satisfied, skipping upgrade: h5py in /anaconda3/lib/python3.6/site-packages (from keras-applications>=1.0.6->tensorflow) (2.7.1)\n", - "\u001b[31mERROR: rasa-core 0.11.12 has requirement tensorflow==1.10.0, but you'll have tensorflow 1.14.0 which is incompatible.\u001b[0m\n", - "Installing collected packages: absl-py, setuptools, tensorboard, tensorflow-estimator, google-pasta, tensorflow\n", - " Found existing installation: absl-py 0.6.1\n", - " Uninstalling absl-py-0.6.1:\n", - " Successfully uninstalled absl-py-0.6.1\n", - " Found existing installation: setuptools 39.1.0\n", - " Uninstalling setuptools-39.1.0:\n", - " Successfully uninstalled setuptools-39.1.0\n", - " Found existing installation: tensorboard 1.13.1\n", - " Uninstalling tensorboard-1.13.1:\n", - " Successfully uninstalled tensorboard-1.13.1\n", - " Found existing installation: tensorflow-estimator 1.13.0\n", - " Uninstalling tensorflow-estimator-1.13.0:\n", - " Successfully uninstalled tensorflow-estimator-1.13.0\n", - " Found existing installation: tensorflow 1.13.1\n", - " Uninstalling tensorflow-1.13.1:\n", - " Successfully uninstalled tensorflow-1.13.1\n", - "Successfully installed absl-py-0.8.0 google-pasta-0.1.7 setuptools-41.2.0 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0\n", - "Requirement already up-to-date: keras in /anaconda3/lib/python3.6/site-packages (2.2.5)\n", - "Requirement already satisfied, skipping upgrade: numpy>=1.9.1 in /anaconda3/lib/python3.6/site-packages (from keras) (1.17.2)\n", - "Requirement already satisfied, skipping upgrade: scipy>=0.14 in /anaconda3/lib/python3.6/site-packages (from keras) (1.1.0)\n", - "Requirement already satisfied, skipping upgrade: keras-applications>=1.0.8 in /anaconda3/lib/python3.6/site-packages (from keras) (1.0.8)\n", - "Requirement already satisfied, skipping upgrade: keras-preprocessing>=1.1.0 in /anaconda3/lib/python3.6/site-packages (from keras) (1.1.0)\n", - "Requirement already satisfied, skipping upgrade: pyyaml in /anaconda3/lib/python3.6/site-packages (from keras) (3.12)\n", - "Requirement already satisfied, skipping upgrade: six>=1.9.0 in /anaconda3/lib/python3.6/site-packages (from keras) (1.11.0)\n", - "Requirement already satisfied, skipping upgrade: h5py in /anaconda3/lib/python3.6/site-packages (from keras) (2.7.1)\n", - "Requirement already up-to-date: pip in /anaconda3/lib/python3.6/site-packages (19.2.3)\n", - "Requirement already up-to-date: pandas in /anaconda3/lib/python3.6/site-packages (0.25.1)\n", - "Requirement already up-to-date: numpy in /anaconda3/lib/python3.6/site-packages (1.17.2)\n", - "Requirement already up-to-date: matplotlib in /anaconda3/lib/python3.6/site-packages (3.1.1)\n", - "Requirement already up-to-date: sklearn in /anaconda3/lib/python3.6/site-packages (0.0)\n", - "Requirement already satisfied, skipping upgrade: python-dateutil>=2.6.1 in /anaconda3/lib/python3.6/site-packages (from pandas) (2.7.3)\n", - "Requirement already satisfied, skipping upgrade: pytz>=2017.2 in /anaconda3/lib/python3.6/site-packages (from pandas) (2018.4)\n", - "Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /anaconda3/lib/python3.6/site-packages (from matplotlib) (2.2.0)\n", - "Requirement already satisfied, skipping upgrade: cycler>=0.10 in /anaconda3/lib/python3.6/site-packages (from matplotlib) (0.10.0)\n", - "Requirement already satisfied, skipping upgrade: kiwisolver>=1.0.1 in /anaconda3/lib/python3.6/site-packages (from matplotlib) (1.0.1)\n", - "Requirement already satisfied, skipping upgrade: scikit-learn in /anaconda3/lib/python3.6/site-packages (from sklearn) (0.19.1)\n", - "Requirement already satisfied, skipping upgrade: six>=1.5 in /anaconda3/lib/python3.6/site-packages (from python-dateutil>=2.6.1->pandas) (1.11.0)\n", - "Requirement already satisfied, skipping upgrade: setuptools in /anaconda3/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib) (41.2.0)\n" - ] + "text": "Requirement already satisfied: tensorflow in ./venv/lib/python3.5/site-packages (1.13.1)\nRequirement already satisfied: gast>=0.2.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (0.3.2)\nRequirement already satisfied: keras-applications>=1.0.6 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.0.8)\nRequirement already satisfied: tensorflow-estimator<1.14.0rc0,>=1.13.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.13.0)\nRequirement already satisfied: wheel>=0.26 in ./venv/lib/python3.5/site-packages (from tensorflow) (0.33.6)\nRequirement already satisfied: keras-preprocessing>=1.0.5 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.1.0)\nRequirement already satisfied: grpcio>=1.8.6 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.25.0)\nRequirement already satisfied: astor>=0.6.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (0.8.0)\nRequirement already satisfied: termcolor>=1.1.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.1.0)\nRequirement already satisfied: numpy>=1.13.3 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.17.4)\nRequirement already satisfied: tensorboard<1.14.0,>=1.13.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.13.1)\nRequirement already satisfied: six>=1.10.0 in ./venv/lib/python3.5/site-packages (from tensorflow) (1.13.0)\nRequirement already satisfied: protobuf>=3.6.1 in ./venv/lib/python3.5/site-packages (from tensorflow) (3.11.0)\nRequirement already satisfied: absl-py>=0.1.6 in ./venv/lib/python3.5/site-packages (from tensorflow) (0.8.1)\nRequirement already satisfied: h5py in ./venv/lib/python3.5/site-packages (from keras-applications>=1.0.6->tensorflow) (2.10.0)\nRequirement already satisfied: mock>=2.0.0 in ./venv/lib/python3.5/site-packages (from tensorflow-estimator<1.14.0rc0,>=1.13.0->tensorflow) (3.0.5)\nRequirement already satisfied: markdown>=2.6.8 in ./venv/lib/python3.5/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow) (3.1.1)\nRequirement already satisfied: werkzeug>=0.11.15 in ./venv/lib/python3.5/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow) (0.16.0)\nRequirement already satisfied: setuptools in ./venv/lib/python3.5/site-packages (from protobuf>=3.6.1->tensorflow) (42.0.1)\nRequirement already up-to-date: keras in ./venv/lib/python3.5/site-packages (2.3.1)\nRequirement already satisfied, skipping upgrade: keras-applications>=1.0.6 in ./venv/lib/python3.5/site-packages (from keras) (1.0.8)\nRequirement already satisfied, skipping upgrade: scipy>=0.14 in ./venv/lib/python3.5/site-packages (from keras) (1.3.3)\nRequirement already satisfied, skipping upgrade: h5py in ./venv/lib/python3.5/site-packages (from keras) (2.10.0)\nRequirement already satisfied, skipping upgrade: six>=1.9.0 in ./venv/lib/python3.5/site-packages (from keras) (1.13.0)\nRequirement already satisfied, skipping upgrade: numpy>=1.9.1 in ./venv/lib/python3.5/site-packages (from keras) (1.17.4)\nRequirement already satisfied, skipping upgrade: keras-preprocessing>=1.0.5 in ./venv/lib/python3.5/site-packages (from keras) (1.1.0)\nRequirement already satisfied, skipping upgrade: pyyaml in ./venv/lib/python3.5/site-packages (from keras) (5.1.2)\n/bin/sh: 1: Syntax error: Unterminated quoted string\n" } ], "source": [ + "# Artificial Neural Network\n", + "\n", "# Installing Theano\n", - "! pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git\n", + "# ! pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git\n", "\n", "# Installing Tensorflow\n", - "! pip install --upgrade tensorflow\n", + "# pip install tensorflow\n", "\n", "# Installing Keras\n", - "! pip install --upgrade keras\n", + "# pip install --upgrade keras\n", "\n", - "# Install other packages\n", - "! pip install --upgrade pip pandas numpy matplotlib sklearn" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Parte 1 - Preprocessamento dos Dados" + "# pip install --upgrade pip pandas numpy matplotlib sklearn\"\n", + "\n", + "# Part 1 - Data Preprocessing" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 1, "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "\u001b[31mERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'\u001b[0m\n" + } + ], "source": [ - "### Importar as libs" + "!pip install -r requirements.txt" ] }, { @@ -132,82 +49,50 @@ "metadata": {}, "outputs": [], "source": [ + "# Importing the libraries\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Importar o dataset" - ] - }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "X >>\n", - " [[619 'France' 'Female' ... 1 1 101348.88]\n", - " [608 'Spain' 'Female' ... 0 1 112542.58]\n", - " [502 'France' 'Female' ... 1 0 113931.57]\n", - " ...\n", - " [709 'France' 'Female' ... 0 1 42085.58]\n", - " [772 'Germany' 'Male' ... 1 0 92888.52]\n", - " [792 'France' 'Female' ... 1 0 38190.78]]\n", - "y >>\n", - " [1 0 1 ... 1 1 0]\n" + "ename": "FileNotFoundError", + "evalue": "[Errno 2] File b'Churn_Modelling.csv' does not exist: b'Churn_Modelling.csv'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Importing the dataset\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdataset\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Churn_Modelling.csv'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdataset\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m13\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdataset\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m13\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/subjects/2019-2/deep_learning/building-ann/venv/lib/python3.5/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36mparser_f\u001b[0;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)\u001b[0m\n\u001b[1;32m 700\u001b[0m skip_blank_lines=skip_blank_lines)\n\u001b[1;32m 701\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 702\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_read\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 703\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 704\u001b[0m \u001b[0mparser_f\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/subjects/2019-2/deep_learning/building-ann/venv/lib/python3.5/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_read\u001b[0;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[1;32m 427\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 428\u001b[0m \u001b[0;31m# Create the parser.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 429\u001b[0;31m \u001b[0mparser\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mTextFileReader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 430\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mchunksize\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0miterator\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/subjects/2019-2/deep_learning/building-ann/venv/lib/python3.5/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[1;32m 893\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'has_index_names'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'has_index_names'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 894\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 895\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_make_engine\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mengine\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 896\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 897\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/subjects/2019-2/deep_learning/building-ann/venv/lib/python3.5/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m_make_engine\u001b[0;34m(self, engine)\u001b[0m\n\u001b[1;32m 1120\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_make_engine\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mengine\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'c'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1121\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mengine\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'c'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1122\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_engine\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCParserWrapper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1123\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1124\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mengine\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'python'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/subjects/2019-2/deep_learning/building-ann/venv/lib/python3.5/site-packages/pandas/io/parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, src, **kwds)\u001b[0m\n\u001b[1;32m 1851\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'usecols'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0musecols\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1852\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1853\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_reader\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparsers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTextReader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msrc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1854\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munnamed_cols\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_reader\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munnamed_cols\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1855\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader.__cinit__\u001b[0;34m()\u001b[0m\n", + "\u001b[0;32mpandas/_libs/parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader._setup_parser_source\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] File b'Churn_Modelling.csv' does not exist: b'Churn_Modelling.csv'" ] } ], "source": [ + "# Importing the dataset\n", "dataset = pd.read_csv('Churn_Modelling.csv')\n", "X = dataset.iloc[:, 3:13].values\n", - "y = dataset.iloc[:, 13].values\n", - "print(\"X >>\\n\",X)\n", - "print(\"y >>\\n\",y)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Transformando os dados categóricos\n" + "y = dataset.iloc[:, 13].values" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 0, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "X >>\n", - " [[0.0000000e+00 0.0000000e+00 6.1900000e+02 ... 1.0000000e+00\n", - " 1.0000000e+00 1.0134888e+05]\n", - " [0.0000000e+00 1.0000000e+00 6.0800000e+02 ... 0.0000000e+00\n", - " 1.0000000e+00 1.1254258e+05]\n", - " [0.0000000e+00 0.0000000e+00 5.0200000e+02 ... 1.0000000e+00\n", - " 0.0000000e+00 1.1393157e+05]\n", - " ...\n", - " [0.0000000e+00 0.0000000e+00 7.0900000e+02 ... 0.0000000e+00\n", - " 1.0000000e+00 4.2085580e+04]\n", - " [1.0000000e+00 0.0000000e+00 7.7200000e+02 ... 1.0000000e+00\n", - " 0.0000000e+00 9.2888520e+04]\n", - " [0.0000000e+00 0.0000000e+00 7.9200000e+02 ... 1.0000000e+00\n", - " 0.0000000e+00 3.8190780e+04]]\n" - ] - } - ], + "outputs": [], "source": [ + "# Encoding categorical data\n", "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", "labelencoder_X_1 = LabelEncoder()\n", "X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])\n", @@ -215,62 +100,42 @@ "X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])\n", "onehotencoder = OneHotEncoder(categorical_features = [1])\n", "X = onehotencoder.fit_transform(X).toarray()\n", - "X = X[:, 1:]\n", - "print(\"X >>\\n\",X)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Dividindo o dataset em conjunto de treinamento e conjunto de teste" + "X = X[:, 1:]" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ + "# Splitting the dataset into the Training set and Test set\n", "from sklearn.model_selection import train_test_split\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Feature Scaling" - ] - }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ + "# Feature Scaling\n", "from sklearn.preprocessing import StandardScaler\n", "sc = StandardScaler()\n", "X_train = sc.fit_transform(X_train)\n", "X_test = sc.transform(X_test)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "# Parte 2 -Vamos construir uma ANN!\n", - "\n", - "## Importando o Keras\n" - ] - }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ + "# Part 2 - Now let's make the ANN!\n", + "\n", + "# Importing the Keras libraries and packages\n", "import keras\n", "from keras.models import Sequential\n", "from keras.layers import Dense" @@ -278,7 +143,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ @@ -286,10 +151,10 @@ "classifier = Sequential()\n", "\n", "# Adding the input layer and the first hidden layer\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", + "classifier.add(Dense(units = 11, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", "\n", "# Adding the second hidden layer\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", + "classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu'))\n", "\n", "# Adding the output layer\n", "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", @@ -298,950 +163,40 @@ "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Ajustando a ANN ao conjunto de treinamento" - ] - }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "WARNING:tensorflow:From /anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1033: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n", - "\n", - "Epoch 1/100\n", - "8000/8000 [==============================] - 2s 222us/step - loss: 0.4930 - acc: 0.8002\n", - "Epoch 2/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.4089 - acc: 0.8222\n", - "Epoch 3/100\n", - "8000/8000 [==============================] - 1s 178us/step - loss: 0.3939 - acc: 0.8297\n", - "Epoch 4/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 0.3856 - acc: 0.8314\n", - "Epoch 5/100\n", - "8000/8000 [==============================] - 2s 199us/step - loss: 0.3789 - acc: 0.8296\n", - "Epoch 6/100\n", - "8000/8000 [==============================] - 2s 210us/step - loss: 0.3734 - acc: 0.8394\n", - "Epoch 7/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 0.3687 - acc: 0.8481\n", - "Epoch 8/100\n", - "8000/8000 [==============================] - 2s 279us/step - loss: 0.3670 - acc: 0.8480\n", - "Epoch 9/100\n", - "8000/8000 [==============================] - 2s 277us/step - loss: 0.3627 - acc: 0.8516\n", - "Epoch 10/100\n", - "8000/8000 [==============================] - 2s 235us/step - loss: 0.3606 - acc: 0.8531\n", - "Epoch 11/100\n", - "8000/8000 [==============================] - 2s 300us/step - loss: 0.3583 - acc: 0.8534\n", - "Epoch 12/100\n", - "8000/8000 [==============================] - 2s 217us/step - loss: 0.3567 - acc: 0.8546\n", - "Epoch 13/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3549 - acc: 0.8546\n", - "Epoch 14/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 0.3531 - acc: 0.8552\n", - "Epoch 15/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 0.3511 - acc: 0.8562\n", - "Epoch 16/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3495 - acc: 0.8567\n", - "Epoch 17/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3487 - acc: 0.8549\n", - "Epoch 18/100\n", - "8000/8000 [==============================] - 2s 199us/step - loss: 0.3480 - acc: 0.8610\n", - "Epoch 19/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3468 - acc: 0.8570\n", - "Epoch 20/100\n", - "8000/8000 [==============================] - 1s 174us/step - loss: 0.3456 - acc: 0.8576\n", - "Epoch 21/100\n", - "8000/8000 [==============================] - 1s 185us/step - loss: 0.3447 - acc: 0.8615\n", - "Epoch 22/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3432 - acc: 0.8615\n", - "Epoch 23/100\n", - "8000/8000 [==============================] - 1s 184us/step - loss: 0.3421 - acc: 0.8597\n", - "Epoch 24/100\n", - "8000/8000 [==============================] - 1s 186us/step - loss: 0.3434 - acc: 0.8612\n", - "Epoch 25/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3420 - acc: 0.8622\n", - "Epoch 26/100\n", - "8000/8000 [==============================] - 1s 174us/step - loss: 0.3403 - acc: 0.8631\n", - "Epoch 27/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3410 - acc: 0.8611\n", - "Epoch 28/100\n", - "8000/8000 [==============================] - 1s 172us/step - loss: 0.3401 - acc: 0.8615\n", - "Epoch 29/100\n", - "8000/8000 [==============================] - 1s 169us/step - loss: 0.3400 - acc: 0.8602\n", - "Epoch 30/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3390 - acc: 0.8594\n", - "Epoch 31/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3397 - acc: 0.8606\n", - "Epoch 32/100\n", - "8000/8000 [==============================] - 1s 184us/step - loss: 0.3389 - acc: 0.8616\n", - "Epoch 33/100\n", - "8000/8000 [==============================] - 2s 210us/step - loss: 0.3382 - acc: 0.8625\n", - "Epoch 34/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3388 - acc: 0.8625\n", - "Epoch 35/100\n", - "8000/8000 [==============================] - 1s 185us/step - loss: 0.3378 - acc: 0.8625\n", - "Epoch 36/100\n", - "8000/8000 [==============================] - 1s 174us/step - loss: 0.3379 - acc: 0.8615\n", - "Epoch 37/100\n", - "8000/8000 [==============================] - 1s 170us/step - loss: 0.3371 - acc: 0.8625\n", - "Epoch 38/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3382 - acc: 0.8615\n", - "Epoch 39/100\n", - "8000/8000 [==============================] - 2s 192us/step - loss: 0.3378 - acc: 0.8601\n", - "Epoch 40/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 0.3369 - acc: 0.8616\n", - "Epoch 41/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3374 - acc: 0.8619\n", - "Epoch 42/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3378 - acc: 0.8610\n", - "Epoch 43/100\n", - "8000/8000 [==============================] - 1s 177us/step - loss: 0.3368 - acc: 0.8630\n", - "Epoch 44/100\n", - "8000/8000 [==============================] - 2s 192us/step - loss: 0.3372 - acc: 0.8600\n", - "Epoch 45/100\n", - "8000/8000 [==============================] - 2s 203us/step - loss: 0.3360 - acc: 0.8635\n", - "Epoch 46/100\n", - "8000/8000 [==============================] - 2s 205us/step - loss: 0.3364 - acc: 0.8635\n", - "Epoch 47/100\n", - "8000/8000 [==============================] - 2s 232us/step - loss: 0.3362 - acc: 0.8627\n", - "Epoch 48/100\n", - "8000/8000 [==============================] - 1s 184us/step - loss: 0.3361 - acc: 0.8636\n", - "Epoch 49/100\n", - "8000/8000 [==============================] - 1s 177us/step - loss: 0.3366 - acc: 0.8629\n", - "Epoch 50/100\n", - "8000/8000 [==============================] - 1s 185us/step - loss: 0.3361 - acc: 0.8611\n", - "Epoch 51/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3357 - acc: 0.8627\n", - "Epoch 52/100\n", - "8000/8000 [==============================] - 1s 184us/step - loss: 0.3359 - acc: 0.8615\n", - "Epoch 53/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 0.3364 - acc: 0.8626\n", - "Epoch 54/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 0.3358 - acc: 0.8627\n", - "Epoch 55/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3350 - acc: 0.8619\n", - "Epoch 56/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3362 - acc: 0.8621\n", - "Epoch 57/100\n", - "8000/8000 [==============================] - 1s 173us/step - loss: 0.3360 - acc: 0.8619\n", - "Epoch 58/100\n", - "8000/8000 [==============================] - 1s 169us/step - loss: 0.3362 - acc: 0.8631\n", - "Epoch 59/100\n", - "8000/8000 [==============================] - 1s 177us/step - loss: 0.3354 - acc: 0.8614\n", - "Epoch 60/100\n", - "8000/8000 [==============================] - 1s 175us/step - loss: 0.3356 - acc: 0.8626\n", - "Epoch 61/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 0.3351 - acc: 0.8617\n", - "Epoch 62/100\n", - "8000/8000 [==============================] - 1s 172us/step - loss: 0.3356 - acc: 0.8657\n", - "Epoch 63/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3357 - acc: 0.8624\n", - "Epoch 64/100\n", - "8000/8000 [==============================] - 1s 173us/step - loss: 0.3355 - acc: 0.8620\n", - "Epoch 65/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3355 - acc: 0.8605\n", - "Epoch 66/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3345 - acc: 0.8625\n", - "Epoch 67/100\n", - "8000/8000 [==============================] - 1s 173us/step - loss: 0.3361 - acc: 0.8639\n", - "Epoch 68/100\n", - "8000/8000 [==============================] - 2s 190us/step - loss: 0.3352 - acc: 0.8620\n", - "Epoch 69/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3343 - acc: 0.8624\n", - "Epoch 70/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3356 - acc: 0.8639\n", - "Epoch 71/100\n", - "8000/8000 [==============================] - 1s 172us/step - loss: 0.3349 - acc: 0.8647\n", - "Epoch 72/100\n", - "8000/8000 [==============================] - 1s 181us/step - loss: 0.3351 - acc: 0.8619\n", - "Epoch 73/100\n", - "8000/8000 [==============================] - 1s 167us/step - loss: 0.3349 - acc: 0.8621\n", - "Epoch 74/100\n", - "8000/8000 [==============================] - 1s 175us/step - loss: 0.3354 - acc: 0.8647\n", - "Epoch 75/100\n", - "8000/8000 [==============================] - 2s 222us/step - loss: 0.3355 - acc: 0.8624\n", - "Epoch 76/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3347 - acc: 0.8617\n", - "Epoch 77/100\n", - "8000/8000 [==============================] - 1s 171us/step - loss: 0.3362 - acc: 0.8609\n", - "Epoch 78/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3349 - acc: 0.8626\n", - "Epoch 79/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 0.3337 - acc: 0.8637\n", - "Epoch 80/100\n", - "8000/8000 [==============================] - 1s 171us/step - loss: 0.3347 - acc: 0.8619\n", - "Epoch 81/100\n", - "8000/8000 [==============================] - 2s 190us/step - loss: 0.3349 - acc: 0.8634\n", - "Epoch 82/100\n", - "8000/8000 [==============================] - 2s 224us/step - loss: 0.3358 - acc: 0.8617\n", - "Epoch 83/100\n", - "8000/8000 [==============================] - 1s 184us/step - loss: 0.3348 - acc: 0.8632\n", - "Epoch 84/100\n", - "8000/8000 [==============================] - 1s 185us/step - loss: 0.3343 - acc: 0.8646\n", - "Epoch 85/100\n", - "8000/8000 [==============================] - 1s 180us/step - loss: 0.3354 - acc: 0.8600\n", - "Epoch 86/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3348 - acc: 0.8619\n", - "Epoch 87/100\n", - "8000/8000 [==============================] - 1s 173us/step - loss: 0.3352 - acc: 0.8632\n", - "Epoch 88/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3338 - acc: 0.8640\n", - "Epoch 89/100\n", - "8000/8000 [==============================] - 1s 178us/step - loss: 0.3346 - acc: 0.8629\n", - "Epoch 90/100\n", - "8000/8000 [==============================] - 1s 175us/step - loss: 0.3348 - acc: 0.8622\n", - "Epoch 91/100\n", - "8000/8000 [==============================] - 1s 172us/step - loss: 0.3348 - acc: 0.8631\n", - "Epoch 92/100\n", - "8000/8000 [==============================] - 1s 168us/step - loss: 0.3344 - acc: 0.8631\n", - "Epoch 93/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3349 - acc: 0.8624\n", - "Epoch 94/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3350 - acc: 0.8635\n", - "Epoch 95/100\n", - "8000/8000 [==============================] - 1s 179us/step - loss: 0.3349 - acc: 0.8610\n", - "Epoch 96/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 0.3349 - acc: 0.8606\n", - "Epoch 97/100\n", - "8000/8000 [==============================] - 1s 180us/step - loss: 0.3350 - acc: 0.8635\n", - "Epoch 98/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3339 - acc: 0.8645\n", - "Epoch 99/100\n", - "8000/8000 [==============================] - 1s 173us/step - loss: 0.3338 - acc: 0.8621\n", - "Epoch 100/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3339 - acc: 0.8655\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Parte 3 - Fazendo predições e avaliando o modelo\n", - "\n", - "## Prevendo os resultados com o conjunto de testes" - ] - }, - { - "cell_type": "code", - "execution_count": 10, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ - "y_pred = classifier.predict(X_test)\n", - "y_pred = (y_pred > 0.5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Criando uma Confusion Matrix" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1510 85]\n", - " [ 196 209]]\n" - ] - } - ], - "source": [ - "from sklearn.metrics import confusion_matrix\n", - "cm = confusion_matrix(y_test, y_pred)\n", - "print(cm)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Initiate activation function experimentation\n", - "\n", - "# Initialising the 2nd ANN" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 1/100\n", - "8000/8000 [==============================] - 2s 242us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 2/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 3/100\n", - "8000/8000 [==============================] - 2s 194us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 4/100\n", - "8000/8000 [==============================] - 2s 254us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 5/100\n", - "8000/8000 [==============================] - 2s 218us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 6/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 7/100\n", - "8000/8000 [==============================] - 1s 185us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 8/100\n", - "8000/8000 [==============================] - 1s 180us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 9/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 10/100\n", - "8000/8000 [==============================] - 2s 190us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 11/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 12/100\n", - "8000/8000 [==============================] - 2s 199us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 13/100\n", - "8000/8000 [==============================] - 2s 244us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 14/100\n", - "8000/8000 [==============================] - 4s 523us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 15/100\n", - "8000/8000 [==============================] - 2s 256us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 16/100\n", - "8000/8000 [==============================] - 2s 209us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 17/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 18/100\n", - "8000/8000 [==============================] - 2s 214us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 19/100\n", - "8000/8000 [==============================] - 2s 204us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 20/100\n", - "8000/8000 [==============================] - 1s 186us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 21/100\n", - "8000/8000 [==============================] - 2s 218us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 22/100\n", - "8000/8000 [==============================] - 2s 265us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 23/100\n", - "8000/8000 [==============================] - 2s 252us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 24/100\n", - "8000/8000 [==============================] - 2s 200us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 25/100\n", - "8000/8000 [==============================] - 2s 213us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 26/100\n", - "8000/8000 [==============================] - 2s 199us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 27/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 28/100\n", - "8000/8000 [==============================] - 2s 208us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 29/100\n", - "8000/8000 [==============================] - 2s 203us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 30/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 31/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 32/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 33/100\n", - "8000/8000 [==============================] - 2s 206us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 34/100\n", - "8000/8000 [==============================] - 2s 194us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 35/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 36/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 37/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 38/100\n", - "8000/8000 [==============================] - 2s 203us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 39/100\n", - "8000/8000 [==============================] - 2s 194us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 40/100\n", - "8000/8000 [==============================] - 2s 198us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 41/100\n", - "8000/8000 [==============================] - 2s 199us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 42/100\n", - "8000/8000 [==============================] - 2s 249us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 43/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 44/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 45/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 46/100\n", - "8000/8000 [==============================] - 2s 220us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 47/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 48/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 49/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 50/100\n", - "8000/8000 [==============================] - 1s 180us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 51/100\n", - "8000/8000 [==============================] - 2s 258us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 52/100\n", - "8000/8000 [==============================] - 2s 238us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 53/100\n", - "8000/8000 [==============================] - 2s 226us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 54/100\n", - "8000/8000 [==============================] - 2s 291us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 55/100\n", - "8000/8000 [==============================] - 2s 201us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 56/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 57/100\n", - "8000/8000 [==============================] - 2s 196us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 58/100\n", - "8000/8000 [==============================] - 2s 258us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 59/100\n", - "8000/8000 [==============================] - 2s 239us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 60/100\n", - "8000/8000 [==============================] - 3s 384us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 61/100\n", - "8000/8000 [==============================] - 2s 256us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 62/100\n", - "8000/8000 [==============================] - 2s 258us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 63/100\n", - "8000/8000 [==============================] - 3s 358us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 64/100\n", - "8000/8000 [==============================] - 2s 230us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 65/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 66/100\n", - "8000/8000 [==============================] - 2s 228us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 67/100\n", - "8000/8000 [==============================] - 3s 399us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 68/100\n", - "8000/8000 [==============================] - 3s 368us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 69/100\n", - "8000/8000 [==============================] - 2s 258us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 70/100\n", - "8000/8000 [==============================] - 2s 208us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 71/100\n", - "8000/8000 [==============================] - 2s 195us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 72/100\n", - "8000/8000 [==============================] - 2s 220us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 73/100\n", - "8000/8000 [==============================] - 2s 214us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 74/100\n", - "8000/8000 [==============================] - 2s 227us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 75/100\n", - "8000/8000 [==============================] - 3s 345us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 76/100\n", - "8000/8000 [==============================] - 2s 231us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 77/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 78/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 79/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 80/100\n", - "8000/8000 [==============================] - 2s 281us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 81/100\n", - "8000/8000 [==============================] - 2s 293us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 82/100\n", - "8000/8000 [==============================] - 2s 279us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 83/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 84/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 85/100\n", - "8000/8000 [==============================] - 2s 206us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 86/100\n", - "8000/8000 [==============================] - 2s 211us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 87/100\n", - "8000/8000 [==============================] - 1s 186us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 88/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 89/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 90/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 91/100\n", - "8000/8000 [==============================] - 2s 226us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 92/100\n", - "8000/8000 [==============================] - 2s 192us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 93/100\n", - "8000/8000 [==============================] - 1s 186us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 94/100\n", - "8000/8000 [==============================] - 2s 222us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 95/100\n", - "8000/8000 [==============================] - 2s 209us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 96/100\n", - "8000/8000 [==============================] - 2s 232us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 97/100\n", - "8000/8000 [==============================] - 2s 234us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 98/100\n", - "8000/8000 [==============================] - 2s 284us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 99/100\n", - "8000/8000 [==============================] - 2s 250us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 100/100\n", - "8000/8000 [==============================] - 2s 266us/step - loss: 3.2881 - acc: 0.7960\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "del classifier\n", - "\n", - "classifier = Sequential()\n", - "\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'sigmoid', input_dim = 11))\n", - "\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", - "\n", - "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'tanh'))\n", - "\n", - "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", - "\n", + "# Fitting the ANN to the Training set\n", "classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ - "y_pred = classifier.predict(X_test)\n", - "y_pred = (y_pred > 0.5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Making the Confusion Matrix" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1595 0]\n", - " [ 405 0]]\n" - ] - } - ], - "source": [ - "from sklearn.metrics import confusion_matrix\n", - "cm = confusion_matrix(y_test, y_pred)\n", - "print(cm)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Initialising the 3rd ANN" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Epoch 1/100\n", - "8000/8000 [==============================] - 2s 242us/step - loss: 0.5123 - acc: 0.7960\n", - "Epoch 2/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 0.4461 - acc: 0.7960\n", - "Epoch 3/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 0.4341 - acc: 0.7956\n", - "Epoch 4/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 0.4297 - acc: 0.7982\n", - "Epoch 5/100\n", - "8000/8000 [==============================] - 2s 190us/step - loss: 0.4280 - acc: 0.8000\n", - "Epoch 6/100\n", - "8000/8000 [==============================] - 1s 186us/step - loss: 0.4276 - acc: 0.8030\n", - "Epoch 7/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 0.4266 - acc: 0.8042\n", - "Epoch 8/100\n", - "8000/8000 [==============================] - 2s 226us/step - loss: 0.4271 - acc: 0.8045\n", - "Epoch 9/100\n", - "8000/8000 [==============================] - 2s 252us/step - loss: 0.4268 - acc: 0.8049\n", - "Epoch 10/100\n", - "8000/8000 [==============================] - 2s 193us/step - loss: 0.4266 - acc: 0.8056\n", - "Epoch 11/100\n", - "8000/8000 [==============================] - 2s 196us/step - loss: 0.4259 - acc: 0.8057\n", - "Epoch 12/100\n", - "8000/8000 [==============================] - 2s 191us/step - loss: 0.4252 - acc: 0.8084\n", - "Epoch 13/100\n", - "8000/8000 [==============================] - 2s 204us/step - loss: 0.4240 - acc: 0.8142\n", - "Epoch 14/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 0.4225 - acc: 0.8169\n", - "Epoch 15/100\n", - "8000/8000 [==============================] - 2s 195us/step - loss: 0.4206 - acc: 0.8206\n", - "Epoch 16/100\n", - "8000/8000 [==============================] - 2s 200us/step - loss: 0.4188 - acc: 0.8235\n", - "Epoch 17/100\n", - "8000/8000 [==============================] - 2s 195us/step - loss: 0.4175 - acc: 0.8249\n", - "Epoch 18/100\n", - "8000/8000 [==============================] - 2s 192us/step - loss: 0.4161 - acc: 0.8255\n", - "Epoch 19/100\n", - "8000/8000 [==============================] - 2s 222us/step - loss: 0.4146 - acc: 0.8277\n", - "Epoch 20/100\n", - "8000/8000 [==============================] - 2s 200us/step - loss: 0.4133 - acc: 0.8282\n", - "Epoch 21/100\n", - "8000/8000 [==============================] - 2s 201us/step - loss: 0.4123 - acc: 0.8296\n", - "Epoch 22/100\n", - "8000/8000 [==============================] - 2s 225us/step - loss: 0.4114 - acc: 0.8307\n", - "Epoch 23/100\n", - "8000/8000 [==============================] - 2s 230us/step - loss: 0.4106 - acc: 0.8302\n", - "Epoch 24/100\n", - "8000/8000 [==============================] - 2s 205us/step - loss: 0.4097 - acc: 0.8315\n", - "Epoch 25/100\n", - "8000/8000 [==============================] - 2s 247us/step - loss: 0.4093 - acc: 0.8317\n", - "Epoch 26/100\n", - "8000/8000 [==============================] - 2s 259us/step - loss: 0.4085 - acc: 0.8325\n", - "Epoch 27/100\n", - "8000/8000 [==============================] - 2s 283us/step - loss: 0.4082 - acc: 0.8324\n", - "Epoch 28/100\n", - "8000/8000 [==============================] - 3s 385us/step - loss: 0.4077 - acc: 0.8336\n", - "Epoch 29/100\n", - "8000/8000 [==============================] - 2s 208us/step - loss: 0.4073 - acc: 0.8341\n", - "Epoch 30/100\n", - "8000/8000 [==============================] - 2s 204us/step - loss: 0.4068 - acc: 0.8329\n", - "Epoch 31/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 0.4063 - acc: 0.8341\n", - "Epoch 32/100\n", - "8000/8000 [==============================] - 2s 198us/step - loss: 0.4060 - acc: 0.8350\n", - "Epoch 33/100\n", - "8000/8000 [==============================] - 2s 200us/step - loss: 0.4057 - acc: 0.8351\n", - "Epoch 34/100\n", - "8000/8000 [==============================] - 2s 220us/step - loss: 0.4055 - acc: 0.8342\n", - "Epoch 35/100\n", - "8000/8000 [==============================] - 2s 205us/step - loss: 0.4051 - acc: 0.8347\n", - "Epoch 36/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 0.4049 - acc: 0.8340\n", - "Epoch 37/100\n", - "8000/8000 [==============================] - 2s 202us/step - loss: 0.4046 - acc: 0.8336\n", - "Epoch 38/100\n", - "8000/8000 [==============================] - 2s 203us/step - loss: 0.4042 - acc: 0.8341\n", - "Epoch 39/100\n", - "8000/8000 [==============================] - 2s 224us/step - loss: 0.4043 - acc: 0.8336\n", - "Epoch 40/100\n", - "8000/8000 [==============================] - 2s 232us/step - loss: 0.4039 - acc: 0.8342\n", - "Epoch 41/100\n", - "8000/8000 [==============================] - 2s 269us/step - loss: 0.4038 - acc: 0.8342\n", - "Epoch 42/100\n", - "8000/8000 [==============================] - 2s 224us/step - loss: 0.4033 - acc: 0.8337\n", - "Epoch 43/100\n", - "8000/8000 [==============================] - 2s 304us/step - loss: 0.4030 - acc: 0.8340\n", - "Epoch 44/100\n", - "8000/8000 [==============================] - 1s 187us/step - loss: 0.4031 - acc: 0.8339\n", - "Epoch 45/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.4025 - acc: 0.8341\n", - "Epoch 46/100\n", - "8000/8000 [==============================] - 2s 189us/step - loss: 0.4023 - acc: 0.8337\n", - "Epoch 47/100\n", - "8000/8000 [==============================] - 2s 220us/step - loss: 0.4019 - acc: 0.8329\n", - "Epoch 48/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 0.4019 - acc: 0.8337\n", - "Epoch 49/100\n", - "8000/8000 [==============================] - 2s 197us/step - loss: 0.4017 - acc: 0.8341\n", - "Epoch 50/100\n", - "8000/8000 [==============================] - 2s 200us/step - loss: 0.4015 - acc: 0.8342\n", - "Epoch 51/100\n", - "8000/8000 [==============================] - 2s 195us/step - loss: 0.4011 - acc: 0.8340\n", - "Epoch 52/100\n", - "8000/8000 [==============================] - 2s 196us/step - loss: 0.4010 - acc: 0.8337\n", - "Epoch 53/100\n", - "8000/8000 [==============================] - 2s 198us/step - loss: 0.4006 - acc: 0.8351\n", - "Epoch 54/100\n", - "8000/8000 [==============================] - 2s 201us/step - loss: 0.4003 - acc: 0.8354\n", - "Epoch 55/100\n", - "8000/8000 [==============================] - 2s 207us/step - loss: 0.4004 - acc: 0.8340\n", - "Epoch 56/100\n", - "8000/8000 [==============================] - 2s 212us/step - loss: 0.4000 - acc: 0.8337\n", - "Epoch 57/100\n", - "8000/8000 [==============================] - 2s 210us/step - loss: 0.3998 - acc: 0.8340\n", - "Epoch 58/100\n", - "8000/8000 [==============================] - 2s 195us/step - loss: 0.3993 - acc: 0.8345\n", - "Epoch 59/100\n", - "8000/8000 [==============================] - 2s 214us/step - loss: 0.3991 - acc: 0.8344\n", - "Epoch 60/100\n", - "8000/8000 [==============================] - 2s 208us/step - loss: 0.3989 - acc: 0.8337\n", - "Epoch 61/100\n", - "8000/8000 [==============================] - 2s 210us/step - loss: 0.3988 - acc: 0.8347\n", - "Epoch 62/100\n", - "8000/8000 [==============================] - 3s 375us/step - loss: 0.3986 - acc: 0.8345\n", - "Epoch 63/100\n", - "8000/8000 [==============================] - 3s 382us/step - loss: 0.3982 - acc: 0.8342\n", - "Epoch 64/100\n", - "8000/8000 [==============================] - 2s 301us/step - loss: 0.3981 - acc: 0.8341\n", - "Epoch 65/100\n", - "8000/8000 [==============================] - 2s 219us/step - loss: 0.3978 - acc: 0.8347\n", - "Epoch 66/100\n", - "8000/8000 [==============================] - 1s 183us/step - loss: 0.3976 - acc: 0.8347\n", - "Epoch 67/100\n", - "8000/8000 [==============================] - 2s 237us/step - loss: 0.3973 - acc: 0.8349\n", - "Epoch 68/100\n", - "8000/8000 [==============================] - 2s 228us/step - loss: 0.3972 - acc: 0.8352\n", - "Epoch 69/100\n", - "8000/8000 [==============================] - 1s 171us/step - loss: 0.3971 - acc: 0.8342\n", - "Epoch 70/100\n", - "8000/8000 [==============================] - 1s 176us/step - loss: 0.3968 - acc: 0.8350\n", - "Epoch 71/100\n", - "8000/8000 [==============================] - 1s 175us/step - loss: 0.3965 - acc: 0.8355\n", - "Epoch 72/100\n", - "8000/8000 [==============================] - 2s 222us/step - loss: 0.3965 - acc: 0.8351\n", - "Epoch 73/100\n", - "8000/8000 [==============================] - 2s 188us/step - loss: 0.3963 - acc: 0.8355\n", - "Epoch 74/100\n", - "8000/8000 [==============================] - 2s 249us/step - loss: 0.3959 - acc: 0.8354\n", - "Epoch 75/100\n", - "8000/8000 [==============================] - 3s 416us/step - loss: 0.3958 - acc: 0.8354\n", - "Epoch 76/100\n", - "8000/8000 [==============================] - 3s 410us/step - loss: 0.3958 - acc: 0.8357\n", - "Epoch 77/100\n", - "8000/8000 [==============================] - 4s 475us/step - loss: 0.3954 - acc: 0.8350\n", - "Epoch 78/100\n", - "8000/8000 [==============================] - 4s 444us/step - loss: 0.3955 - acc: 0.8339\n", - "Epoch 79/100\n", - "8000/8000 [==============================] - 4s 438us/step - loss: 0.3953 - acc: 0.8352\n", - "Epoch 80/100\n", - "8000/8000 [==============================] - 4s 459us/step - loss: 0.3951 - acc: 0.8350\n", - "Epoch 81/100\n", - "8000/8000 [==============================] - 4s 496us/step - loss: 0.3949 - acc: 0.8352\n", - "Epoch 82/100\n", - "8000/8000 [==============================] - 5s 573us/step - loss: 0.3947 - acc: 0.8351\n", - "Epoch 83/100\n", - "8000/8000 [==============================] - 5s 567us/step - loss: 0.3949 - acc: 0.8355\n", - "Epoch 84/100\n", - "8000/8000 [==============================] - 4s 484us/step - loss: 0.3944 - acc: 0.8359\n", - "Epoch 85/100\n", - "8000/8000 [==============================] - 4s 441us/step - loss: 0.3944 - acc: 0.8362\n", - "Epoch 86/100\n", - "8000/8000 [==============================] - 2s 241us/step - loss: 0.3941 - acc: 0.8365\n", - "Epoch 87/100\n", - "8000/8000 [==============================] - 3s 351us/step - loss: 0.3937 - acc: 0.8362\n", - "Epoch 88/100\n", - "8000/8000 [==============================] - 2s 295us/step - loss: 0.3939 - acc: 0.8360\n", - "Epoch 89/100\n", - "8000/8000 [==============================] - 2s 271us/step - loss: 0.3938 - acc: 0.8369\n", - "Epoch 90/100\n", - "8000/8000 [==============================] - 3s 348us/step - loss: 0.3937 - acc: 0.8369\n", - "Epoch 91/100\n", - "8000/8000 [==============================] - 2s 297us/step - loss: 0.3935 - acc: 0.8374\n", - "Epoch 92/100\n", - "8000/8000 [==============================] - 2s 206us/step - loss: 0.3935 - acc: 0.8346\n", - "Epoch 93/100\n", - "8000/8000 [==============================] - 5s 604us/step - loss: 0.3933 - acc: 0.8354\n", - "Epoch 94/100\n", - "8000/8000 [==============================] - 4s 466us/step - loss: 0.3931 - acc: 0.8360\n", - "Epoch 95/100\n", - "8000/8000 [==============================] - 4s 511us/step - loss: 0.3930 - acc: 0.8347\n", - "Epoch 96/100\n", - "8000/8000 [==============================] - 4s 518us/step - loss: 0.3928 - acc: 0.8369\n", - "Epoch 97/100\n", - "8000/8000 [==============================] - 5s 589us/step - loss: 0.3928 - acc: 0.8367\n", - "Epoch 98/100\n", - "8000/8000 [==============================] - 4s 474us/step - loss: 0.3924 - acc: 0.8371\n", - "Epoch 99/100\n", - "8000/8000 [==============================] - 3s 407us/step - loss: 0.3923 - acc: 0.8367\n", - "Epoch 100/100\n", - "8000/8000 [==============================] - 3s 352us/step - loss: 0.3921 - acc: 0.8371\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "del classifier\n", - "\n", - "classifier = Sequential()\n", - "\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'sigmoid', input_dim = 11))\n", - "\n", - "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", - "\n", - "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", - "\n", - "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", + "# Part 3 - Making predictions and evaluating the model\n", "\n", - "classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [], - "source": [ + "# Predicting the Test set results\n", "y_pred = classifier.predict(X_test)\n", - "y_pred = (y_pred > 0.5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Making the Confusion Matrix" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1547 48]\n", - " [ 265 140]]\n" - ] - } - ], - "source": [ - "from sklearn.metrics import confusion_matrix\n", - "cm = confusion_matrix(y_test, y_pred)\n", - "print(cm)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "# Parte 4 - Evaluating, Improving and Tuning the ANN\n", + "y_pred = (y_pred > 0.5)\n", "\n", - "## Evaluating the ANN" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from keras.wrappers.scikit_learn import KerasClassifier\n", - "from sklearn.model_selection import cross_val_score\n", - "from keras.models import Sequential\n", - "from keras.layers import Dense\n", - "\n", - "def build_classifier():\n", - " classifier = Sequential()\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", - " classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", - " classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", - " return classifier\n", - "\n", - "classifier = KerasClassifier(build_fn = build_classifier, batch_size = 10, epochs = 10)\n", - "accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)\n", - "mean = accuracies.mean()\n", - "variance = accuracies.std()\n", - "print(\"accuracies:%s\\nmean:%s\\nvariance:%s\".format(accuracies, mean, variance))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Improving the ANN\n", - "# Dropout Regularization to reduce overfitting if needed" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from keras.layers import Dropout\n", - "\n", - "def build_classifier():\n", - " classifier = Sequential()\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", - " classifier.add(Dropout(rate = 0.1))\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", - " classifier.add(Dropout(rate = 0.1))\n", - " classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", - " classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", - " return classifier\n", - "\n", - "classifier = KerasClassifier(build_fn = build_classifier, batch_size = 10, epochs = 10)\n", - "accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)\n", - "mean = accuracies.mean()\n", - "variance = accuracies.std()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Tuning the ANN" + "# Making the Confusion Matrix\n", + "from sklearn.metrics import confusion_matrix\n", + "cm = confusion_matrix(y_test, y_pred)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": {}, "outputs": [], "source": [ - "from keras.wrappers.scikit_learn import KerasClassifier\n", - "from sklearn.model_selection import GridSearchCV\n", - "from keras.models import Sequential\n", - "from keras.layers import Dense\n", - "\n", - "def build_classifier(optimizer):\n", - " classifier = Sequential()\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", - " classifier.add(Dropout(rate = 0.1))\n", - " classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", - " classifier.add(Dropout(rate = 0.1))\n", - " classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", - " classifier.compile(optimizer = optimizer, loss = 'binary_crossentropy', metrics = ['accuracy'])\n", - " return classifier\n", - "\n", - "classifier = KerasClassifier(build_fn = build_classifier)" + "cm" ] }, { @@ -1249,36 +204,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "parameters = {'batch_size': [10, 24, 32],\n", - " 'epochs': [50, 100, 200],\n", - " 'optimizer': ['adam', 'rmsprop']}\n", - "\n", - "grid_search = GridSearchCV(estimator = classifier,\n", - " scoring = 'accuracy',\n", - " param_grid = parameters,\n", - " cv = 10)\n", - "\n", - "grid_search = grid_search.fit(X_train, y_train)\n", - "\n", - "best_parameters = grid_search.best_params_\n", - "best_accuracy = grid_search.best_score_" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# FIM" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "> Professor Diego Dorgam \n", - "> [@diegodorgam](https://twitter.com/diegodorgam)" - ] + "source": [] } ], "metadata": { @@ -1297,9 +223,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file