import ssl
import certifi
ssl._create_default_https_context =
ssl._create_unverified_context
import tensorflow as tf
from tensorflow.keras import layers, models
# Load the MNIST dataset (handwritten digits 0-9)
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Normalize the data (scale pixel values to between 0 and 1)
x_train, x_test = x_train / 255.0, x_test / 255.0
# Build a simple Sequential model
model = models.Sequential([
layers.Flatten(input_shape=(28, 28)), # Flatten 28x28
images into a 1D vector
layers.Dense(128, activation='relu'), # Hidden layer with
128 neurons and ReLU activation
layers.Dense(10, activation='softmax') # Output layer with
10 classes (digits 0-9)
])
# Compile the model with optimizer, loss function, and metric
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train the model on the training data
model.fit(x_train, y_train, epochs=5)
# Evaluate the model on the test data
test_loss, test_acc = model.evaluate(x_test, y_test)
print(f'\nTest accuracy: {test_acc}')