Learn practical skills, build real-world projects, and advance your career

Image Classification using Logistic Regression on the Sign Language MNIST

This python script aims to construct an Image Classification model using Logistic Regression. The Sign Language MNIST dataset from Sign Language MNIST is used to train and evaluate the model. Each row in the csv file represents a label and a single 28x28 pixel image represented using 784 pixel values ranging from 0-255, much like the original MNIST dataset. However, the sign language MNIST only contains 27,455 cases for the training dataset and 7,172 cases for the test dataset which are much fewer as compared to the original MNIST.

The label in the dataset denotes a number ranging from 0-25 to represent its english letter equivalent (e.g. 0 = a). However, there is no label match for the letters "J" and "Z" due to the motion required to denote the letter.

First let's install the necessary libraries for the script to work.

This assumes that you are working in anaconda. The pytorch and torchvision libraries are for the machine learning functions. On the other hand, Pandas and Numpy are used for data handling while Matplotlib is for data/image visualization. The jovian library is used to save the notebook to the jovian.ml platform.

# Uncomment and run the commands below if imports fail
# !conda install numpy pytorch torchvision cpuonly -c pytorch -y
# !pip install matplotlib --upgrade --quiet
!pip install jovian --upgrade --quiet
WARNING: You are using pip version 20.1; however, version 20.1.1 is available. You should consider upgrading via the '/opt/conda/bin/python3.7 -m pip install --upgrade pip' command.
# Imports
import torch
import jovian
import torchvision
import string
import torch.nn as nn
import matplotlib.pyplot as plt
import torch.nn.functional as F
import pandas as pd
import numpy as np
from torch.utils.data import random_split
from torch.utils.data import DataLoader
from torch.utils.data import TensorDataset