def test_fit_and_predict(self): ann = NeuralNetwork([4, 2], alpha=1e-5) ann.fit(self.X, self.y) T = self.X[[10, 60, 110]] predictions = ann.predict(T) print(predictions) np.testing.assert_array_equal(predictions, np.array([0, 1, 2]))
def test_on_digits(self): data_full = datasets.load_digits() data, resp = utils.shuffle(data_full.data, data_full.target) m = data.shape[0] X, y = data[:m // 2], resp[:m // 2] X_test, y_test = data[m // 2:], resp[m // 2:] ann = NeuralNetwork([20, 5], alpha=1e-5) ann.fit(X, y) y_hat = ann.predict(X_test) acc = metrics.accuracy_score(y_test, y_hat) self.assertGreater(acc, 0.85)
parser.add_argument("--dropout", help="Percent Dropout", default=0.25, type=float) parser.add_argument("--train", help="Train dataset", default='dataset/train', type=str) parser.add_argument("--test", help="Test dataset", default='dataset/test', type=str) if __name__ == "__main__": args = parser.parse_args() ann = NeuralNetwork( tsSize=args.timeseries, lstmSize=args.lstmSize, dropout=args.dropout, ) if os.path.isfile(args.weights): ann.model.load_weights(args.weights) if args.action == "train": ann.fit(args.weights, args.train, args.test, epochs=args.epochs, batch_size=args.batchSize) if args.action == "serve": serve(ann, args.test) if args.action == "cli": while 1: raw = input('Sent > ') print(ann.predict(raw))