Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 141 additions & 19 deletions ArtificialNeuralNetwork.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -22,16 +22,62 @@
},
{
"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/marco/dl_env/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (1.13.1)\n",
"Requirement already satisfied: numpy==1.16.2 in /home/marco/dl_env/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (1.16.2)\n",
"Requirement already satisfied: pandas==0.24.2 in /home/marco/dl_env/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (0.24.2)\n",
"Requirement already satisfied: matplotlib==3.0.3 in /home/marco/dl_env/lib/python3.6/site-packages (from -r requirements.txt (line 4)) (3.0.3)\n",
"Requirement already satisfied: Keras==2.2.4 in /home/marco/dl_env/lib/python3.6/site-packages (from -r requirements.txt (line 5)) (2.2.4)\n",
"Collecting sklearn==0.0 (from -r requirements.txt (line 6))\n",
" Downloading https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz\n",
"Requirement already satisfied: keras-applications>=1.0.6 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.0.7)\n",
"Requirement already satisfied: tensorboard<1.14.0,>=1.13.0 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.13.1)\n",
"Requirement already satisfied: keras-preprocessing>=1.0.5 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.0.9)\n",
"Requirement already satisfied: protobuf>=3.6.1 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (3.7.1)\n",
"Requirement already satisfied: gast>=0.2.0 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.2.2)\n",
"Requirement already satisfied: absl-py>=0.1.6 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.7.1)\n",
"Requirement already satisfied: grpcio>=1.8.6 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.19.0)\n",
"Requirement already satisfied: astor>=0.6.0 in /home/marco/dl_env/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/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.1.0)\n",
"Requirement already satisfied: tensorflow-estimator<1.14.0rc0,>=1.13.0 in /home/marco/dl_env/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/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (1.12.0)\n",
"Requirement already satisfied: wheel>=0.26 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow==1.13.1->-r requirements.txt (line 1)) (0.33.1)\n",
"Requirement already satisfied: pytz>=2011k in /home/marco/dl_env/lib/python3.6/site-packages (from pandas==0.24.2->-r requirements.txt (line 3)) (2018.9)\n",
"Requirement already satisfied: python-dateutil>=2.5.0 in /home/marco/dl_env/lib/python3.6/site-packages (from pandas==0.24.2->-r requirements.txt (line 3)) (2.8.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /home/marco/dl_env/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/marco/dl_env/lib/python3.6/site-packages (from matplotlib==3.0.3->-r requirements.txt (line 4)) (2.3.1)\n",
"Requirement already satisfied: cycler>=0.10 in /home/marco/dl_env/lib/python3.6/site-packages (from matplotlib==3.0.3->-r requirements.txt (line 4)) (0.10.0)\n",
"Requirement already satisfied: h5py in /home/marco/dl_env/lib/python3.6/site-packages (from Keras==2.2.4->-r requirements.txt (line 5)) (2.9.0)\n",
"Requirement already satisfied: scipy>=0.14 in /home/marco/dl_env/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/marco/dl_env/lib/python3.6/site-packages (from Keras==2.2.4->-r requirements.txt (line 5)) (5.1)\n",
"Requirement already satisfied: scikit-learn in /home/marco/dl_env/lib/python3.6/site-packages (from sklearn==0.0->-r requirements.txt (line 6)) (0.20.3)\n",
"Requirement already satisfied: werkzeug>=0.11.15 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (0.15.2)\n",
"Requirement already satisfied: markdown>=2.6.8 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorboard<1.14.0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (3.1)\n",
"Requirement already satisfied: setuptools in /home/marco/dl_env/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow==1.13.1->-r requirements.txt (line 1)) (41.0.0)\n",
"Requirement already satisfied: mock>=2.0.0 in /home/marco/dl_env/lib/python3.6/site-packages (from tensorflow-estimator<1.14.0rc0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (2.0.0)\n",
"Requirement already satisfied: pbr>=0.11 in /home/marco/dl_env/lib/python3.6/site-packages (from mock>=2.0.0->tensorflow-estimator<1.14.0rc0,>=1.13.0->tensorflow==1.13.1->-r requirements.txt (line 1)) (5.1.3)\n",
"Building wheels for collected packages: sklearn\n",
" Building wheel for sklearn (setup.py) ... \u001b[?25ldone\n",
"\u001b[?25h Stored in directory: /home/marco/.cache/pip/wheels/76/03/bb/589d421d27431bcd2c6da284d5f2286c8e3b2ea3cf1594c074\n",
"Successfully built sklearn\n",
"Installing collected packages: sklearn\n",
"Successfully installed sklearn-0.0\n"
]
}
],
"source": [
"!pip install -r requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -55,9 +101,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/marco/dl_env/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/marco/dl_env/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",
Expand All @@ -72,7 +131,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -83,7 +142,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -96,9 +155,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",
Expand All @@ -110,18 +177,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"# Initialising the ANN\n",
"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 = 6, kernel_initializer = 'uniform', activation = 'sigmoid', 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 = 'tanh'))\n",
"\n",
"# Adding the output layer\n",
"classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n",
Expand All @@ -132,17 +199,54 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"8000/8000 [==============================] - 1s 171us/step - loss: 0.5102 - acc: 0.7947\n",
"Epoch 2/10\n",
"8000/8000 [==============================] - 1s 116us/step - loss: 0.4465 - acc: 0.7975\n",
"Epoch 3/10\n",
"8000/8000 [==============================] - 1s 127us/step - loss: 0.4314 - acc: 0.8070\n",
"Epoch 4/10\n",
"8000/8000 [==============================] - 1s 124us/step - loss: 0.4292 - acc: 0.8047\n",
"Epoch 5/10\n",
"8000/8000 [==============================] - 1s 131us/step - loss: 0.4288 - acc: 0.8055\n",
"Epoch 6/10\n",
"8000/8000 [==============================] - 1s 137us/step - loss: 0.4282 - acc: 0.8061\n",
"Epoch 7/10\n",
"8000/8000 [==============================] - 1s 138us/step - loss: 0.4270 - acc: 0.8064\n",
"Epoch 8/10\n",
"8000/8000 [==============================] - 1s 127us/step - loss: 0.4251 - acc: 0.8086\n",
"Epoch 9/10\n",
"8000/8000 [==============================] - 1s 120us/step - loss: 0.4227 - acc: 0.8145\n",
"Epoch 10/10\n",
"8000/8000 [==============================] - 1s 125us/step - loss: 0.4195 - acc: 0.8174\n"
]
},
{
"data": {
"text/plain": [
"<keras.callbacks.History at 0x7f41bb873cc0>"
]
},
"execution_count": 29,
"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)"
"classifier.fit(X_train, y_train, batch_size = 10, epochs = 10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -158,6 +262,24 @@
"cm = confusion_matrix(y_test, y_pred)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1532 63]\n",
" [ 284 121]]\n"
]
}
],
"source": [
"print(cm)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -182,7 +304,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.5"
}
},
"nbformat": 4,
Expand Down
Loading