From 22d888d2cc0c9636601775eaadf998bc4a87e291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20N=C3=B3brega?= Date: Thu, 4 Apr 2019 23:04:45 -0300 Subject: [PATCH 1/5] Use tanh instead of sigmoid, and also print the confusion matrix --- ann.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ann.py b/ann.py index a8a3d54..5376087 100644 --- a/ann.py +++ b/ann.py @@ -58,7 +58,7 @@ classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu')) # Adding the output layer -classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) +classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'tanh')) # Compiling the ANN classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) @@ -74,4 +74,4 @@ # Making the Confusion Matrix from sklearn.metrics import confusion_matrix -cm = confusion_matrix(y_test, y_pred) \ No newline at end of file +cm = confusion_matrix(y_test, y_pred) From e3dfd01c17e83e783702ab6806d8cf256864b72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20N=C3=B3brega?= Date: Thu, 4 Apr 2019 23:57:32 -0300 Subject: [PATCH 2/5] the previous commit wasn't printing --- ann.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ann.py b/ann.py index 5376087..96ee812 100644 --- a/ann.py +++ b/ann.py @@ -75,3 +75,4 @@ # Making the Confusion Matrix from sklearn.metrics import confusion_matrix cm = confusion_matrix(y_test, y_pred) +print(cm) From 097c8fe36c9011ef8fa0fc27b053c8d66fe92082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20N=C3=B3brega?= Date: Sat, 6 Apr 2019 11:34:30 -0300 Subject: [PATCH 3/5] Changing the second hidden layer's activation function --- ArtificialNeuralNetwork.ipynb | 347 ++++++++++++++++++++++++++++++++-- ann.py | 2 +- 2 files changed, 327 insertions(+), 22 deletions(-) diff --git a/ArtificialNeuralNetwork.ipynb b/ArtificialNeuralNetwork.ipynb index 6fa36fd..8606ab8 100644 --- a/ArtificialNeuralNetwork.ipynb +++ b/ArtificialNeuralNetwork.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -22,16 +22,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: tensorflow==1.13.1 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (1.13.1)\n", + "Requirement already satisfied: numpy==1.16.2 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (1.16.2)\n", + "Requirement already satisfied: pandas==0.24.2 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (0.24.2)\n", + "Requirement already satisfied: matplotlib==3.0.3 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (3.0.3)\n", + "Requirement already satisfied: Keras==2.2.4 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (2.2.4)\n", + "Requirement already satisfied: sklearn==0.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 6)) (0.0)\n", + "Requirement already satisfied: keras-applications>=1.0.6 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.0.7)\n", + "Requirement already satisfied: protobuf>=3.6.1 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (3.6.1)\n", + "Requirement already satisfied: grpcio>=1.8.6 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.16.1)\n", + "Requirement already satisfied: absl-py>=0.1.6 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.7.0)\n", + "Requirement already satisfied: gast>=0.2.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.2.2)\n", + "Requirement already satisfied: keras-preprocessing>=1.0.5 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.0.9)\n", + "Requirement already satisfied: tensorboard<1.14.0,>=1.13.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.13.1)\n", + "Requirement already satisfied: tensorflow-estimator<1.14.0rc0,>=1.13.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.13.0)\n", + "Requirement already satisfied: six>=1.10.0 in /home/alunos/.local/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.11.0)\n", + "Requirement already satisfied: wheel>=0.26 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.33.1)\n", + "Requirement already satisfied: astor>=0.6.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.7.1)\n", + "Requirement already satisfied: termcolor>=1.1.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.1.0)\n", + "Requirement already satisfied: python-dateutil>=2.5.0 in /home/alunos/anaconda3/lib/python3.6/site-packages (from pandas==0.24.2->-r requirements.txt (line 3)) (2.8.0)\n", + "Requirement already satisfied: pytz>=2011k in /home/alunos/.local/lib/python3.6/site-packages (from pandas==0.24.2->-r requirements.txt (line 3)) (2018.4)\n", + "Requirement already satisfied: cycler>=0.10 in /home/alunos/anaconda3/lib/python3.6/site-packages (from matplotlib==3.0.3->-r requirements.txt (line 4)) (0.10.0)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /home/alunos/anaconda3/lib/python3.6/site-packages (from matplotlib==3.0.3->-r requirements.txt (line 4)) (1.0.1)\n", + "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/alunos/anaconda3/lib/python3.6/site-packages (from matplotlib==3.0.3->-r requirements.txt (line 4)) (2.3.1)\n", + "Requirement already satisfied: scipy>=0.14 in /home/alunos/anaconda3/lib/python3.6/site-packages (from Keras==2.2.4->-r requirements.txt (line 5)) (1.2.1)\n", + "Requirement already satisfied: pyyaml in /home/alunos/anaconda3/lib/python3.6/site-packages (from Keras==2.2.4->-r requirements.txt (line 5)) (5.1)\n", + "Requirement already satisfied: h5py in /home/alunos/anaconda3/lib/python3.6/site-packages (from Keras==2.2.4->-r requirements.txt (line 5)) (2.9.0)\n", + "Requirement already satisfied: scikit-learn in /home/alunos/anaconda3/lib/python3.6/site-packages (from sklearn==0.0->-r requirements.txt (line 6)) (0.20.3)\n", + "Requirement already satisfied: setuptools in /home/alunos/.local/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==1.13.1->-r requirements.txt (line 1)) (39.2.0)\n", + "Requirement already satisfied: markdown>=2.6.8 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (3.0.1)\n", + "Requirement already satisfied: werkzeug>=0.11.15 in /home/alunos/anaconda3/lib/python3.6/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (0.14.1)\n" + ] + } + ], "source": [ "!pip install -r requirements.txt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -43,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -55,9 +92,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/alunos/anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/_encoders.py:371: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.\n", + "If you want the future behaviour and silence this warning, you can specify \"categories='auto'\".\n", + "In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.\n", + " warnings.warn(msg, FutureWarning)\n", + "/home/alunos/anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/_encoders.py:392: DeprecationWarning: The 'categorical_features' keyword is deprecated in version 0.20 and will be removed in 0.22. You can use the ColumnTransformer instead.\n", + " \"use the ColumnTransformer instead.\", DeprecationWarning)\n" + ] + } + ], "source": [ "# Encoding categorical data\n", "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", @@ -72,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -83,7 +133,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -96,9 +146,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using TensorFlow backend.\n" + ] + } + ], "source": [ "# Part 2 - Now let's make the ANN!\n", "\n", @@ -110,9 +168,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WARNING:tensorflow:From /home/alunos/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Colocations handled automatically by placer.\n" + ] + } + ], "source": [ "# Initialising the ANN\n", "classifier = Sequential()\n", @@ -121,10 +189,10 @@ "classifier.add(Dense(units = 6, 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 = 6, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", "\n", "# Adding the output layer\n", - "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", + "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'tanh'))\n", "\n", "# Compiling the ANN\n", "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])" @@ -132,9 +200,235 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WARNING:tensorflow:From /home/alunos/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n", + "Instructions for updating:\n", + "Use tf.cast instead.\n", + "Epoch 1/100\n", + "8000/8000 [==============================] - 2s 205us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 2/100\n", + "8000/8000 [==============================] - 1s 118us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 3/100\n", + "8000/8000 [==============================] - 1s 134us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 4/100\n", + "8000/8000 [==============================] - 1s 129us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 5/100\n", + "8000/8000 [==============================] - 1s 120us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 6/100\n", + "8000/8000 [==============================] - 1s 110us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 7/100\n", + "8000/8000 [==============================] - 1s 112us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 8/100\n", + "8000/8000 [==============================] - 1s 117us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 9/100\n", + "8000/8000 [==============================] - 1s 124us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 10/100\n", + "8000/8000 [==============================] - 1s 112us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 11/100\n", + "8000/8000 [==============================] - 1s 124us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 12/100\n", + "8000/8000 [==============================] - 1s 130us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 13/100\n", + "8000/8000 [==============================] - 1s 125us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 14/100\n", + "8000/8000 [==============================] - 1s 139us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 15/100\n", + "8000/8000 [==============================] - 1s 126us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 16/100\n", + "8000/8000 [==============================] - 1s 132us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 17/100\n", + "8000/8000 [==============================] - 1s 157us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 18/100\n", + "8000/8000 [==============================] - 1s 130us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 19/100\n", + "8000/8000 [==============================] - 1s 113us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 20/100\n", + "8000/8000 [==============================] - 1s 113us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 21/100\n", + "8000/8000 [==============================] - 1s 113us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 22/100\n", + "8000/8000 [==============================] - 1s 119us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 23/100\n", + "8000/8000 [==============================] - 1s 112us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 24/100\n", + "8000/8000 [==============================] - 1s 116us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 25/100\n", + "8000/8000 [==============================] - 1s 111us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 26/100\n", + "8000/8000 [==============================] - 1s 116us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 27/100\n", + "8000/8000 [==============================] - 1s 125us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 28/100\n", + "8000/8000 [==============================] - 1s 158us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 29/100\n", + "8000/8000 [==============================] - 1s 111us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 30/100\n", + "8000/8000 [==============================] - 1s 115us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 31/100\n", + "8000/8000 [==============================] - 1s 132us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 32/100\n", + "8000/8000 [==============================] - 1s 116us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 33/100\n", + "8000/8000 [==============================] - 1s 128us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 34/100\n", + "8000/8000 [==============================] - 1s 122us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 35/100\n", + "8000/8000 [==============================] - 1s 116us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 36/100\n", + "8000/8000 [==============================] - 1s 134us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 37/100\n", + "8000/8000 [==============================] - 1s 138us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 38/100\n", + "8000/8000 [==============================] - 1s 115us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 39/100\n", + "8000/8000 [==============================] - 1s 123us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 40/100\n", + "8000/8000 [==============================] - 1s 123us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 41/100\n", + "8000/8000 [==============================] - 1s 121us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 42/100\n", + "8000/8000 [==============================] - 1s 158us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 43/100\n", + "8000/8000 [==============================] - 1s 108us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 44/100\n", + "8000/8000 [==============================] - 1s 122us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 45/100\n", + "8000/8000 [==============================] - 1s 128us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 46/100\n", + "8000/8000 [==============================] - 1s 142us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 47/100\n", + "8000/8000 [==============================] - 1s 102us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 48/100\n", + "8000/8000 [==============================] - 1s 107us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 49/100\n", + "8000/8000 [==============================] - 1s 127us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 50/100\n", + "8000/8000 [==============================] - 1s 97us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 51/100\n", + "8000/8000 [==============================] - 1s 118us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 52/100\n", + "8000/8000 [==============================] - 1s 146us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 53/100\n", + "8000/8000 [==============================] - 1s 131us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 54/100\n", + "8000/8000 [==============================] - 1s 170us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 55/100\n", + "8000/8000 [==============================] - 1s 107us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 56/100\n", + "8000/8000 [==============================] - 1s 142us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 57/100\n", + "8000/8000 [==============================] - 1s 113us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 58/100\n", + "8000/8000 [==============================] - 1s 104us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 59/100\n", + "8000/8000 [==============================] - 1s 145us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 60/100\n", + "8000/8000 [==============================] - 1s 129us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 61/100\n", + "8000/8000 [==============================] - 1s 111us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 62/100\n", + "8000/8000 [==============================] - 1s 98us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 63/100\n", + "8000/8000 [==============================] - 1s 119us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 64/100\n", + "8000/8000 [==============================] - 1s 100us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 65/100\n", + "8000/8000 [==============================] - 1s 98us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 66/100\n", + "8000/8000 [==============================] - 1s 120us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 67/100\n", + "8000/8000 [==============================] - 1s 120us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 68/100\n", + "8000/8000 [==============================] - 1s 124us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 69/100\n", + "8000/8000 [==============================] - 1s 124us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 70/100\n", + "8000/8000 [==============================] - 1s 96us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 71/100\n", + "8000/8000 [==============================] - 1s 93us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 72/100\n", + "8000/8000 [==============================] - 1s 105us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 73/100\n", + "8000/8000 [==============================] - 1s 118us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 74/100\n", + "8000/8000 [==============================] - 1s 108us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 75/100\n", + "8000/8000 [==============================] - 1s 185us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 76/100\n", + "8000/8000 [==============================] - 1s 139us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 77/100\n", + "8000/8000 [==============================] - 1s 173us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 78/100\n", + "8000/8000 [==============================] - 1s 136us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 79/100\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8000/8000 [==============================] - 1s 151us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 80/100\n", + "8000/8000 [==============================] - 1s 131us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 81/100\n", + "8000/8000 [==============================] - 1s 133us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 82/100\n", + "8000/8000 [==============================] - 1s 127us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 83/100\n", + "8000/8000 [==============================] - 1s 125us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 84/100\n", + "8000/8000 [==============================] - 1s 115us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 85/100\n", + "8000/8000 [==============================] - 1s 128us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 86/100\n", + "8000/8000 [==============================] - 1s 130us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 87/100\n", + "8000/8000 [==============================] - 1s 107us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 88/100\n", + "8000/8000 [==============================] - 1s 100us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 89/100\n", + "8000/8000 [==============================] - 1s 107us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 90/100\n", + "8000/8000 [==============================] - 1s 100us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 91/100\n", + "8000/8000 [==============================] - 1s 128us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 92/100\n", + "8000/8000 [==============================] - 1s 133us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 93/100\n", + "8000/8000 [==============================] - 1s 138us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 94/100\n", + "8000/8000 [==============================] - 2s 193us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 95/100\n", + "8000/8000 [==============================] - 1s 131us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 96/100\n", + "8000/8000 [==============================] - 1s 143us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 97/100\n", + "8000/8000 [==============================] - 1s 134us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 98/100\n", + "8000/8000 [==============================] - 1s 138us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 99/100\n", + "8000/8000 [==============================] - 1s 143us/step - loss: 3.2881 - acc: 0.7960\n", + "Epoch 100/100\n", + "8000/8000 [==============================] - 1s 131us/step - loss: 3.2881 - acc: 0.7960\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Fitting the ANN to the Training set\n", "classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)" @@ -142,7 +436,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -160,10 +454,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1595 0]\n", + " [ 405 0]]\n" + ] + } + ], + "source": [ + "print(cm)" + ] } ], "metadata": { diff --git a/ann.py b/ann.py index 96ee812..bb18aea 100644 --- a/ann.py +++ b/ann.py @@ -55,7 +55,7 @@ classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11)) # Adding the second hidden layer -classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu')) +classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'sigmoid')) # Adding the output layer classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'tanh')) From eca3542b10d9486d60160bcb01627cdceee175d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20N=C3=B3brega?= Date: Mon, 22 Apr 2019 19:42:15 -0300 Subject: [PATCH 4/5] Adding results for the unchanged tuning --- ArtificialNeuralNetwork.ipynb | 10 ++-------- evaluating_improving_tuning.py | 9 ++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ArtificialNeuralNetwork.ipynb b/ArtificialNeuralNetwork.ipynb index 8606ab8..7b87534 100644 --- a/ArtificialNeuralNetwork.ipynb +++ b/ArtificialNeuralNetwork.ipynb @@ -366,13 +366,7 @@ "8000/8000 [==============================] - 1s 173us/step - loss: 3.2881 - acc: 0.7960\n", "Epoch 78/100\n", "8000/8000 [==============================] - 1s 136us/step - loss: 3.2881 - acc: 0.7960\n", - "Epoch 79/100\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + "Epoch 79/100\n", "8000/8000 [==============================] - 1s 151us/step - loss: 3.2881 - acc: 0.7960\n", "Epoch 80/100\n", "8000/8000 [==============================] - 1s 131us/step - loss: 3.2881 - acc: 0.7960\n", @@ -487,7 +481,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/evaluating_improving_tuning.py b/evaluating_improving_tuning.py index 42a9c67..da10679 100644 --- a/evaluating_improving_tuning.py +++ b/evaluating_improving_tuning.py @@ -149,4 +149,11 @@ def build_classifier(optimizer): grid_search = grid_search.fit(X_train, y_train) best_parameters = grid_search.best_params_ -best_accuracy = grid_search.best_score_ \ No newline at end of file +best_accuracy = grid_search.best_score_ + +# Results with nothing changed +# Best params: {'batch_size': 32, 'epochs': 50, 'optimizer': 'adam'} +# Best accuracy 0.83625 + +print("Best params: ", best_parameters) +print("Best accuracy", best_accuracy) From 5299f9541be4df7e3b990b6c51b5a1efe392f0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20N=C3=B3brega?= Date: Fri, 26 Apr 2019 22:35:51 -0300 Subject: [PATCH 5/5] Adding results of new experiments --- evaluating_improving_tuning.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/evaluating_improving_tuning.py b/evaluating_improving_tuning.py index da10679..e3927c3 100644 --- a/evaluating_improving_tuning.py +++ b/evaluating_improving_tuning.py @@ -61,7 +61,8 @@ # classifier.add(Dropout(rate = 0.1)) # Adding the output layer -classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) +classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = + 'tanh')) # Compiling the ANN classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) @@ -108,7 +109,8 @@ def build_classifier(): classifier.add(Dropout(rate = 0.1)) classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu')) classifier.add(Dropout(rate = 0.1)) - classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) + classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = + 'tanh')) classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) return classifier classifier = KerasClassifier(build_fn = build_classifier, batch_size = 10, epochs = 10) @@ -131,14 +133,15 @@ def build_classifier(optimizer): classifier.add(Dropout(rate = 0.1)) classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu')) classifier.add(Dropout(rate = 0.1)) - classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) + classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = + 'tanh')) classifier.compile(optimizer = optimizer, loss = 'binary_crossentropy', metrics = ['accuracy']) return classifier classifier = KerasClassifier(build_fn = build_classifier) -parameters = {'batch_size': [25, 32], - 'epochs': [10, 50], +parameters = {'batch_size': [25, 30], + 'epochs': [20, 40], 'optimizer': ['adam', 'rmsprop']} grid_search = GridSearchCV(estimator = classifier, @@ -155,5 +158,14 @@ def build_classifier(optimizer): # Best params: {'batch_size': 32, 'epochs': 50, 'optimizer': 'adam'} # Best accuracy 0.83625 +# Results with epochs set to [20, 40], batch_size set to [25, 30] and using tanh +# in the output layer +# Best params: {'batch_size': 30, 'epochs': 40, 'optimizer': 'adam'} +# Best accuracy 0.843125 + +# Changing all sequentials to use tanh +# Best params: {'batch_size': 25, 'epochs': 20, 'optimizer': 'rmsprop'} +# Best accuracy 0.844375 + print("Best params: ", best_parameters) print("Best accuracy", best_accuracy)