Git Product home page Git Product logo

nn-project-based-experiment's Introduction

Project Based Experiments

Objective :

Build a Multilayer Perceptron (MLP) to classify handwritten digits in python

Steps to follow:

Dataset Acquisition:

Download the MNIST dataset. You can use libraries like TensorFlow or PyTorch to easily access the dataset.

Data Preprocessing:

Normalize pixel values to the range [0, 1]. Flatten the 28x28 images into 1D arrays (784 elements).

Data Splitting:

Split the dataset into training, validation, and test sets. Model Architecture:

Design an MLP architecture.

You can start with a simple architecture with one input layer, one or more hidden layers, and an output layer. Experiment with different activation functions, such as ReLU for hidden layers and softmax for the output layer.

Compile the Model:

Choose an appropriate loss function (e.g., categorical crossentropy for multiclass classification).Select an optimizer (e.g., Adam). Choose evaluation metrics (e.g., accuracy).

Training:

Train the MLP using the training set.Use the validation set to monitor the model's performance and prevent overfitting.Experiment with different hyperparameters, such as the number of hidden layers, the number of neurons in each layer, learning rate, and batch size.

Evaluation:

Evaluate the model on the test set to get a final measure of its performance.Analyze metrics like accuracy, precision, recall, and confusion matrix.

Fine-tuning:

If the model is not performing well, experiment with different architectures, regularization techniques, or optimization algorithms to improve performance.

Visualization:

Visualize the training/validation loss and accuracy over epochs to understand the training process. Visualize some misclassified examples to gain insights into potential improvements.

Program:

DEVELOPED BY: JANARTHANAN V K
REG NO: 212222230051
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten

(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train, x_test = x_train / 255.0, x_test / 255.0

model = Sequential([
    Flatten(input_shape=(28, 28)),
    Dense(128, activation='relu'),
    Dense(64, activation='relu'),
    Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test))

test_loss, test_accuracy = model.evaluate(x_test, y_test)
print(f'Test accuracy: {test_accuracy}')

import matplotlib.pyplot as plt

predictions = model.predict(x_test)

plt.figure(figsize=(10, 5))
for i in range(5):
    plt.subplot(1, 5, i + 1)
    plt.imshow(x_test[i], cmap='gray')
    plt.axis('off')
    plt.title(f"Predicted: {tf.argmax(predictions[i]).numpy()}\nActual: {y_test[i]}")
plt.show()

Output:

download

RESULT:

Thus, a Multilayer Perceptron (MLP) to classify handwritten digits in python is successfully executed

nn-project-based-experiment's People

Contributors

janarthanan2 avatar lavanyajoyce avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.