def test_shuffle(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=100, eta=0.1, minibatches=1, shuffle_init=True, shuffle_epoch=False, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) assert round(acc, 2) == 0.99, "Acc: %s" % acc nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=100, eta=0.1, minibatches=1, shuffle_init=True, shuffle_epoch=True, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) assert round(acc, 2) == 0.99, "Acc: %s" % acc
def test_gradient_descent(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=10, eta=0.01, minibatches=1, shuffle=True, random_state=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) #print(acc) assert(round(acc, 2) == 0.87)
def test_binary(): X0 = X_std[0:100] # class 0 and class 1 y0 = y[0:100] # class 0 and class 1 nn = NeuralNetMLP(n_output=2, n_features=X0.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=100, eta=0.1, minibatches=10, shuffle_init=True, shuffle_epoch=True, random_seed=1) nn.fit(X0, y0) y_pred = nn.predict(X0) acc = np.sum(y0 == y_pred, axis=0) / float(X0.shape[0]) assert round(acc, 2) == 1.0, "Acc: %s" % acc
def test_gradient_descent(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=100, eta=0.1, random_weights=[-1.0, 1.0], minibatches=1, shuffle_init=False, shuffle_epoch=False, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) assert(round(acc, 2) == 0.97)
def test_minibatch(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=15, alpha=2.0, eta=0.05, minibatches=10, shuffle_init=True, shuffle_epoch=False, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) print(acc) assert(round(acc, 2) == 0.97)
def test_minibatch(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=15, alpha=2.0, eta=0.05, minibatches=10, shuffle_init=True, shuffle_epoch=False, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) print(acc) assert (round(acc, 2) == 0.97)
def test_gradient_descent(): nn = NeuralNetMLP(n_output=3, n_features=X.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=100, eta=0.1, random_weights=[-1.0, 1.0], minibatches=1, shuffle_init=False, shuffle_epoch=False, random_seed=1) nn.fit(X_std, y) y_pred = nn.predict(X_std) acc = np.sum(y == y_pred, axis=0) / float(X_std.shape[0]) assert (round(acc, 2) == 0.97)
def test_binary(): X0 = X_std[0:100] # class 0 and class 1 y0 = y[0:100] # class 0 and class 1 nn = NeuralNetMLP(n_output=1, n_features=X0.shape[1], n_hidden=10, l2=0.0, l1=0.0, epochs=10, eta=0.01, minibatches=10, shuffle=True, random_state=1) nn.fit(X0, y0) y_pred = nn.predict(X0) acc = np.sum(y0 == y_pred, axis=0) / float(X0.shape[0]) #print(y_pred) assert(round(acc, 2) == 1.0)
n_features=X.shape[1], n_hidden=50, l2=0.00, l1=0.0, epochs=300, eta=0.01, alpha=0.0, decrease_const=0.0, minibatches=1, shuffle_init=False, shuffle_epoch=False, random_seed=1, print_progress=3) nn = nn.fit(X, y) y_pred = nn.predict(X) acc = np.sum(y == y_pred, axis=0) / X.shape[0] print('Accuracy: %.2f%%' % (acc * 100)) plot_decision_regions(X, y, clf=nn, legend=2) plt.title("Logistic regression - gd") plt.show() plt.plot(range(len(nn.cost_)), nn.cost_) plt.ylim([0, 300]) plt.xlabel('Epochs') plt.ylabel('Cost') plt.show()
n_hidden = 50, l2 = 0.00, l1 = 0.0, epochs = 300, eta = 0.01, alpha = 0.0, decrease_const = 0.0, minibatches = 1, shuffle_init = False, shuffle_epoch = False, random_seed = 1, print_progress = 3) nn = nn.fit(X, y) y_pred = nn.predict(X) acc = np.sum(y == y_pred, axis=0) / X.shape[0] print('Accuracy: %.2f%%' % (acc * 100)) plot_decision_regions(X, y, clf=nn, legend=2) plt.title("Logistic regression - gd") plt.show() plt.plot(range(len(nn.cost_)), nn.cost_) plt.ylim([0, 300]) plt.xlabel('Epochs') plt.ylabel('Cost') plt.show()