Skip to content

Commit 4effeae

Browse files
Data partitioning and normalization
1 parent 3060f14 commit 4effeae

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

Audio_Classification_Using_CNNs.ipynb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,22 @@
298298
"\n",
299299
"from tensorflow.keras.utils import to_categorical\n",
300300
"from sklearn.model_selection import train_test_split\n",
301+
"import numpy as np\n",
301302
"\n",
302-
"##############################################\n",
303-
"############# YOUR CODES GO HERE #############\n",
304-
"x_train, x_test, y_train, y_test = ...\n",
303+
"# Convert lists to numpy arrays\n",
304+
"x = np.array(x)\n",
305+
"y = np.array(y)\n",
305306
"\n",
306-
"x_train_norm = ...\n",
307-
"x_test_norm = ...\n",
307+
"# Split into training and test sets (e.g., 80% train, 20% test)\n",
308+
"x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42, stratify=y)\n",
308309
"\n",
309-
"y_train_encoded = ...\n",
310-
"y_test_encoded = ....\n",
311-
"##############################################"
310+
"# Normalize pixel values\n",
311+
"x_train_norm = x_train / 255.0\n",
312+
"x_test_norm = x_test / 255.0\n",
313+
"\n",
314+
"# One-hot encode the labels\n",
315+
"y_train_encoded = to_categorical(y_train, num_classes=4)\n",
316+
"y_test_encoded = to_categorical(y_test, num_classes=4)"
312317
],
313318
"metadata": {
314319
"id": "Jw3uR_FBOy67"

0 commit comments

Comments
 (0)