Kaggle link: https://www.kaggle.com/code/rasikasrimal/handwrittendigitidentifymodel
Welcome to Basic Image Classification with TensorFlow.
This graph describes the problem that we are trying to solve visually. We want to create and train a model that takes an image of a handwritten digit as input and predicts the class of that digit, i.e., it predicts the digit or the class of the input image.
We will use the MNIST dataset, which consists of handwritten digit images.
- Import MNIST: We import the dataset and split it into training and test sets.
- Shapes of Imported Arrays: We check the shapes of the training and test sets.
- Plot an Image Example: We plot an example image from the training set.
- Display Labels: We display the labels of the training set.
We convert the labels into a one-hot encoded format.
Original Label | One-Hot Encoded Label |
---|---|
5 | [0, 0, 0, 0, 0, 1, 0, 0, 0, 0] |
7 | [0, 0, 0, 0, 0, 0, 0, 1, 0, 0] |
1 | [0, 1, 0, 0, 0, 0, 0, 0, 0, 0] |
A linear equation represents the relationship between inputs and outputs.
This equation can be vectorized as:
Neural networks consist of multiple layers of neurons, which allow them to learn complex functions.
We reshape the training and test images into vectors.
We normalize the data to have a mean of 0 and a standard deviation of 1.
We create a neural network model with two hidden layers.
The activation function introduces non-linearity into the model:
We compile the model with a specific optimizer and loss function.
We train the model on the normalized training data.
We evaluate the model on the normalized test data and print the accuracy.
We make predictions on the test set and plot the results.