5. Classification Techniques
Activity 5.01: Ordinary Least Squares Classifier – Binary Classifier
Solution:
- Import the required dependencies:
import struct import numpy as np import gzip import urllib.request import matplotlib.pyplot as plt from array import array from sklearn.linear_model import LinearRegression
- Load the MNIST data into memory:
with gzip.open('../Datasets/train-images-idx3-ubyte.gz', 'rb') as f: Â Â Â Â magic, size, rows, cols = struct.unpack(">IIII", f.read(16)) Â Â Â Â img = np.array(array("B", f.read())).reshape((size, rows, cols)) with gzip.open('../Datasets/train-labels-idx1-ubyte.gz', 'rb') as f: Â Â Â Â magic, size = struct.unpack(">II", f.read(8)) Â Â Â Â labels = np.array(array("B", f.read())) with gzip.open('../Datasets/t10k-images-idx3-ubyte.gz', 'rb') as f: Â &...