0% found this document useful (0 votes)
11 views6 pages

SiddharthShah 1032221195 DivC 50 DL LabAssignment3

Description

Uploaded by

1032221195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

SiddharthShah 1032221195 DivC 50 DL LabAssignment3

Description

Uploaded by

1032221195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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}')

You might also like