import numpy as np
import scipy.io as sio
data = sio.loadmat('ex3data1.mat')
raw_X = data['X']
raw_y = data['y']
X = np.insert(raw_X,0,values=1,axis=1)
X.shape
y = raw_y.flatten()
y.shape
theta = sio.loadmat('ex3weights.mat')
theta.keys()
theta1 = theta['Theta1']
theta2 = theta['Theta2']
theta1.shape,theta2.shape
def sigmoid(z):
return 1/ (1 + np.exp(-z))
a1 = X
z2 = X @theta1.T
a2 = sigmoid(z2)
a2.shape
a2 = np.insert(a2,0,values=1,axis=1)
a2.shape
z3 = a2 @ theta2.T
a3 = sigmoid(z3)
a3.shape
y_pred = np.argmax(a3,axis=1)
y_pred = y_pred + 1
acc = np.mean(y_pred == y)
acc
a3