def predict_it(train_result, test_id, test_set): nn, tr, train_time = result predict_start = time.time() prediction_result = nn.predict(test_set[0]) pred_time = time.time() - predict_start report = NeuralNet.score_report(test_set[1], prediction_result.predicted) print( "[{id}][{train_time:3.1f}/{pred_time:3.1f}]:{nn}:\n{report}\n".format( id=test_id, train_time=train_time, pred_time=pred_time, nn=nn, report=NeuralNet.format_score(report))) return prediction_result, report, pred_time
def _start_job(self, job_id): job = self.job_list[job_id] job.create_neuralnet() job.status = 'training:started' job.neuralnet.train( lambda neuralnet, train_data: self._train_callback(job, train_data)) job.status = 'prediction:started' for test_set_id, test_set in job.test_sets.items(): test_set_x, test_set_y = test_set prediction_result = job.neuralnet.predict(test_set_x) score = NeuralNet.score_report( test_set_y, prediction_result.predicted) self.add_to_prediction_log(job, test_set_id, score) # print("{0}:\n{1}\n".format( # job.neuralnet, NeuralNet.format_score_report(score))) job.status = 'completed' return job
# plt.show(block=False) classifier = NeuralNetWithAdam(train_x, train_y, hidden_layers=(6,), iteration_count=1000, learning_rate=0.005, minibatch_size=64, epochs=3, learning_rate_decay=0.2, # beta1=0.8, shuffle=True) train_result = classifier.train(train_cb) prediction = classifier.predict(test_x) report = NeuralNet.score_report(test_y, prediction.predicted) print("Classification report for {0}:\n{1}\n".format( classifier, NeuralNet.format_score(report))) classifier = svm.SVC(gamma=0.001) classifier.fit(train_x, train_y) predicted = classifier.predict(test_x) report = NeuralNet.score_report(test_y, predicted) print("Classification report for {0}:\n{1}\n".format( classifier, NeuralNet.format_score(report))) # analyse(classifier, expected, predicted) # print("train MLp")
valid_x = valid_set[0] valid_y = valid_set[1] return (train_x, train_y), (test_x, test_y), (valid_x, valid_y) (train_x, train_y), (test_x, test_y), (valid_x, valid_y) = get_datasets() def train_callback(nn, it): if (it.total_iteration_index % 10 == 0): print("it:{it:>5}, cost:{cost:6.2f}".format( it=it.total_iteration_index, cost=it.cost)) nn = NeuralNetWithAdam(train_x, train_y, hidden_layers=(15, ), iteration_count=200, learning_rate=0.01, minibatch_size=0, epochs=1) print("Training ...") train_result = nn.train(train_callback) prediction_result = nn.predict(test_x) report = NeuralNet.score_report(test_y, prediction_result.predicted) print("{0}:\n{1}\n".format(nn, NeuralNet.format_score(report)))