Skip to content

Commit b0e92cb

Browse files
confusion matrix
1 parent f933370 commit b0e92cb

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

Audio_Classification_Using_CNNs.ipynb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
{
256256
"cell_type": "code",
257257
"source": [
258+
"## Complected...Done!\n",
258259
"## Load each directory's images and label\n",
259260
"\n",
260261
"class_mapping = {\n",
@@ -294,6 +295,7 @@
294295
{
295296
"cell_type": "code",
296297
"source": [
298+
"## Complected...Done!\n",
297299
"## because your data is in list, convert them to np.array\n",
298300
"\n",
299301
"from tensorflow.keras.utils import to_categorical\n",
@@ -377,6 +379,8 @@
377379
{
378380
"cell_type": "code",
379381
"source": [
382+
"## Complected...Done!\n",
383+
"\n",
380384
"from keras.models import Sequential\n",
381385
"from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\n",
382386
"from keras.optimizers import Adam\n",
@@ -430,6 +434,8 @@
430434
{
431435
"cell_type": "code",
432436
"source": [
437+
"## Complected...Done!\n",
438+
"\n",
433439
"hist = model.fit(\n",
434440
" x_train_norm, y_train_encoded,\n",
435441
" epochs=100,\n",
@@ -455,6 +461,8 @@
455461
{
456462
"cell_type": "code",
457463
"source": [
464+
"## Complected...Done!\n",
465+
"\n",
458466
"acc = hist.history['accuracy']\n",
459467
"val_acc = hist.history['val_accuracy']\n",
460468
"epochs = range(1, len(acc) + 1)\n",
@@ -487,15 +495,18 @@
487495
{
488496
"cell_type": "code",
489497
"source": [
498+
"## Complected...Done!\n",
499+
"\n",
490500
"from sklearn.metrics import confusion_matrix\n",
491501
"import seaborn as sns\n",
492502
"sns.set()\n",
493503
"\n",
494-
"##############################################\n",
495-
"############# YOUR CODES GO HERE #############\n",
496-
"y_predicted = ....\n",
497-
"mat = confusion_matrix(..., ...)\n",
498-
"##############################################\n",
504+
"# Predict class indices\n",
505+
"y_predicted = np.argmax(model.predict(x_test_norm), axis=1)\n",
506+
"y_true = np.argmax(y_test_encoded, axis=1)\n",
507+
"\n",
508+
"# Compute confusion matrix\n",
509+
"mat = confusion_matrix(y_true, y_predicted)\n",
499510
"\n",
500511
"class_labels = ['background', 'chainsaw', 'engine', 'storm']\n",
501512
"\n",
@@ -504,7 +515,7 @@
504515
" yticklabels=class_labels)\n",
505516
"\n",
506517
"plt.xlabel('Predicted label')\n",
507-
"plt.ylabel('Actual label')"
518+
"plt.ylabel('Actual label')\n"
508519
],
509520
"metadata": {
510521
"id": "LQKAXBpkVBd-"

0 commit comments

Comments
 (0)