import numpy as np
import matplotlib.pyplot as plt
class NeuralNetwork:
def init(self, layers, activation=‘sigmoid’):
self.layers = layers
self.num_layers = len(layers)
self.weights = [np.random.randn(layers[i], layers[i-1]) for i in range(1, self.num_layers)]
self.biases = [np.random.randn(layers[i], 1) for i in range(1, self.num_layers)]
self.activation = activation
def forward_propagation(self, x):
a = np.array(x).reshape(-1, 1)
zs = []
activations = [a]
for w, b in zip(self.weights, self.biases):
z = np.dot(w, a) + b
zs.append(z)
a = self.activate(z)
activations.append(a)
return zs, activations
def backward_propagation(self, zs, activations, y):
delta = self.cost_derivative(activations[-1], y) * self.activation_derivative(zs[-1])
nabla_w = [np.dot(delta, activations[-2].T)]
nabl