n_samples = 400 sigma = 2e-1 X, T = datasets.make_moons(n_samples, noise=sigma) half = int(n_samples / 2) X_train = X[0:half, :] T_train = T[0:half] X_test = X[half:, :] T_test = T[half:] # Fit the neural network max_iter = int(1e3) tol = 1e-5 nn = NeuralNetwork( [Layer('Tanh', (2, 5)), Layer('Tanh', (5, 1))], max_iter=max_iter, tol=tol) nn.fit(X_train, T_train) # Predcition prediction = nn.predict(X_test) score = nn.score(X_test, T_test) print(score) # Visualization plt.scatter(X_train[:, 0], X_train[:, 1], s=40, zorder=10, c=T_train,
import numpy as np from matplotlib import pyplot as plt from sklearn import datasets from mlpy.model import Layer, NeuralNetwork # Generate dataset n_samples = 400 sigma = 2e-1 X, T = datasets.make_moons(n_samples, noise=sigma) # Fit the neural network max_iter = int(1e2) tol = 1e-5 nn = NeuralNetwork( [Layer('Sigmoid', (2, 3)), Layer('Sigmoid', (3, 4)), Layer('Sigmoid', (4, 5)), Layer('Sigmoid', (5, 1)) ], max_iter=max_iter, tol=tol) nn.check_gradient(X, T)