|
19 | 19 | from tensorflow.keras.utils import to_categorical
|
20 | 20 |
|
21 | 21 | # Load and preprocess the MNIST data
|
22 |
| -(X_train, y_train), (X_test, y_test) = mnist.load_data() |
| 22 | +(x_train, y_train), (x_test, y_test) = mnist.load_data() |
23 | 23 |
|
24 | 24 | # Normalize the pixel values (0 to 1)
|
25 |
| -X_train = X_train.reshape(-1, 28, 28, 1).astype("float32") / 255 |
26 |
| -X_test = X_test.reshape(-1, 28, 28, 1).astype("float32") / 255 |
| 25 | +x_train = x_train.reshape(-1, 28, 28, 1).astype("float32") / 255 |
| 26 | +x_test = x_test.reshape(-1, 28, 28, 1).astype("float32") / 255 |
27 | 27 |
|
28 | 28 | # Convert labels to one-hot encoding
|
29 | 29 | y_train = to_categorical(y_train, 10)
|
|
64 | 64 |
|
65 | 65 | # Train the model
|
66 | 66 | history = model.fit(
|
67 |
| - X_train, y_train, epochs=5, batch_size=32, validation_data=(X_test, y_test) |
| 67 | + x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test) |
68 | 68 | )
|
69 | 69 |
|
70 | 70 | # Evaluate the model on test data
|
71 |
| -test_loss, test_acc = model.evaluate(X_test, y_test, verbose=2) |
| 71 | +test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2) |
72 | 72 | print(f"\nTest accuracy: {test_acc}")
|
0 commit comments