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: &...