Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7f8d87

Browse files
...
1 parent 4240787 commit f7f8d87

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

Neural_Networks/convolutional_neural_network_MNIST_digits.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"# Libraries\n",
3131
"import os\n",
3232
"import numpy as np\n",
33+
"import pandas as pd\n",
34+
"import matplotlib.pyplot as plt\n",
3335
"\n",
3436
"# Set TensorFlow log level to suppress warnings and info messages\n",
3537
"os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n",
@@ -127,7 +129,7 @@
127129
},
128130
{
129131
"cell_type": "code",
130-
"execution_count": 20,
132+
"execution_count": 13,
131133
"id": "0c0cc3db",
132134
"metadata": {},
133135
"outputs": [],
@@ -176,7 +178,7 @@
176178
"model.fit(X_train, \n",
177179
" y_train, \n",
178180
" batch_size=batch_size, \n",
179-
" epochs=epochs, \n",
181+
" epochs=epochs,\n",
180182
" validation_split=0.1)"
181183
]
182184
},

Neural_Networks/multi_layer_perceptron_model_apartment_data.ipynb

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939
"source": [
4040
"# Libraries\n",
4141
"import os\n",
42-
"import numpy as np\n",
4342
"import pandas as pd\n",
44-
"from sklearn import tree\n",
4543
"import matplotlib.pyplot as plt\n",
4644
"from sklearn.metrics import r2_score\n",
4745
"from sklearn.preprocessing import MinMaxScaler\n",
48-
"from sklearn.neural_network import MLPRegressor\n",
4946
"from sklearn.model_selection import train_test_split\n",
5047
"\n",
51-
"os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'\n",
48+
"# Set TensorFlow log level to suppress warnings and info messages\n",
49+
"os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n",
50+
"\n",
51+
"from tensorflow import keras\n",
5252
"from tensorflow.keras.models import Sequential\n",
5353
"from tensorflow.keras.layers import Dense, Dropout\n",
5454
"\n",
@@ -128,7 +128,7 @@
128128
},
129129
{
130130
"cell_type": "code",
131-
"execution_count": 18,
131+
"execution_count": 244,
132132
"id": "6d76a5cc",
133133
"metadata": {},
134134
"outputs": [],
@@ -200,35 +200,34 @@
200200
"# Define the number of features\n",
201201
"num_features = X_train.shape[1]\n",
202202
"\n",
203-
"# Define the model with dropout\n",
204-
"model = Sequential([\n",
205-
" Dense(64, activation='relu', input_shape=(num_features,)), # Hidden layer 1\n",
206-
" Dropout(0.2), # Dropout layer 1\n",
207-
" Dense(32, activation='relu'), # Hidden layer 2\n",
208-
" Dropout(0.2), # Dropout layer 2\n",
209-
" Dense(16, activation='relu'), # Hidden layer 3\n",
210-
" Dropout(0.2), # Dropout layer 3\n",
211-
" Dense(1) # Output layer\n",
203+
"# Define the model\n",
204+
"model = keras.Sequential([\n",
205+
" keras.Input(shape=(num_features,)),\n",
206+
" keras.layers.Dense(256, activation='relu'),\n",
207+
" keras.layers.Dense(128, activation='relu'),\n",
208+
" keras.layers.Dense(64, activation='relu'),\n",
209+
" keras.layers.Dense(32, activation='relu'),\n",
210+
" keras.layers.Dense(1),\n",
212211
"])\n",
213212
"\n",
214213
"# Compile the model\n",
215-
"model.compile(optimizer='adam', loss='mse', metrics=['mae'])\n",
214+
"model.compile(optimizer='adam', loss='mse', metrics=['mape'])\n",
216215
"\n",
217216
"# Train the model\n",
218217
"history = model.fit(X_train, \n",
219218
" y_train, \n",
220219
" epochs=100, \n",
221220
" validation_split=0.20, \n",
222221
" batch_size=32,\n",
223-
" verbose=1)\n",
224-
"\n",
225-
"# Evaluate the model on the test set using the mean absolute error (MAE)\n",
226-
"test_loss, test_mae = model.evaluate(X_test, y_test)\n",
227-
"# print(f\"Test MAE: {test_mae}\")\n",
222+
" verbose=0)\n",
228223
"\n",
229224
"# Predict the response for test dataset\n",
230225
"y_pred = model.predict(X_test)\n",
231226
"\n",
227+
"# Evaluate the model on the test set using the mean absolute error (MAPE)\n",
228+
"test_loss, test_mape = model.evaluate(X_test, y_test)\n",
229+
"print(f\"\\nMAPE: {test_mape:.2f}\")\n",
230+
"\n",
232231
"# Calculate R2 score\n",
233232
"r2 = r2_score(y_test, y_pred)\n",
234233
"print(f\"R2 score: {r2:.4f}\")\n"
@@ -259,10 +258,10 @@
259258
"plt.show()\n",
260259
"\n",
261260
"# Plot training & validation MAE values\n",
262-
"plt.plot(history.history['mae'])\n",
263-
"plt.plot(history.history['val_mae'])\n",
264-
"plt.title('Model MAE')\n",
265-
"plt.ylabel('MAE')\n",
261+
"plt.plot(history.history['mape'])\n",
262+
"plt.plot(history.history['val_mape'])\n",
263+
"plt.title('Model MAPE')\n",
264+
"plt.ylabel('MAPE')\n",
266265
"plt.xlabel('Epoch')\n",
267266
"plt.legend(['Train', 'Validation'], loc='upper right')\n",
268267
"plt.show()"

0 commit comments

Comments
 (0)