March 2020
Beginner to intermediate
342 pages
8h 38m
English
This is the time we’ve been waiting for. We’re about to unleash our multiclass classifier on MNIST. Here is the classifier’s code, in all its glory:
| | import numpy as np |
| | |
| | |
| | def sigmoid(z): |
| | return 1 / (1 + np.exp(-z)) |
| | |
| | |
| | def forward(X, w): |
| | weighted_sum = np.matmul(X, w) |
| | return sigmoid(weighted_sum) |
| | |
| | |
| | def classify(X, w): |
| | y_hat = forward(X, w) |
| | labels = np.argmax(y_hat, axis=1) |
| | return labels.reshape(-1, 1) |
| | |
| | |
| | def loss(X, Y, w): |
| | y_hat = forward(X, w) |
| | first_term = Y * np.log(y_hat) |
| | second_term = (1 - Y) * np.log(1 - y_hat) |
| | return -np.sum(first_term + second_term) / X.shape[0] |
| | |
| | |
| | def gradient(X, Y, w): |
| | return np.matmul(X.T, (forward(X, ... |
Read now
Unlock full access