|
298 | 298 | "\n", |
299 | 299 | "from tensorflow.keras.utils import to_categorical\n", |
300 | 300 | "from sklearn.model_selection import train_test_split\n", |
| 301 | + "import numpy as np\n", |
301 | 302 | "\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", |
305 | 306 | "\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", |
308 | 309 | "\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)" |
312 | 317 | ], |
313 | 318 | "metadata": { |
314 | 319 | "id": "Jw3uR_FBOy67" |
|
0 commit comments