predictor = Predictor(output=['z']) def iter_function(epoch, error, test_error, test_error_gradient, test_accuracy): print( 'epoch: {iter}, error: {error}, test_error: {test_error}, test_error_gradient: {test_error_gradient}, test_accuracy: {test_accuracy}'.format( iter=epoch, error=error, test_error=test_error, test_error_gradient=test_error_gradient, accuracy=predictor.train_accuracy, test_accuracy=test_accuracy)) predictor.learn(from_data=data_frame, callback_on_iter=iter_function) print('accuracy') print(predictor.train_accuracy) print('accuracy over all dataset') print(predictor.calculate_accuracy(from_data=data_frame)) when = {'x': [1], 'y': [0]} print('- multiply when. {when}'.format(when=when)) print(predictor.predict(when=when)) # saving the predictor predictor.save('ok.pkl') # loading the predictor predictor2 = Predictor(load_from_path='ok.pkl') when = {'x': [0, 0, 1, -1, 1], 'y': [0, 1, -1, -1, 1]} print('- multiply when. {when}'.format(when=when)) print(predictor2.predict(when_data=pandas.DataFrame(when))) when = {'x': [0, 3, 1, -5, 1], 'y': [0, 1, -5, -4, 7]} print('- multiply when. {when}'.format(when=when))
def iter_function(epoch, training_error, test_error, test_error_gradient, test_accuracy): print( f'Epoch: {epoch}, Train Error: {training_error}, Test Error: {test_error}, Test Error Gradient: {test_error_gradient}, Test Accuracy: {test_accuracy}' ) predictor.learn(from_data=df_train, callback_on_iter=iter_function, eval_every_x_epochs=200) predictor.save('ok.pkl') predictor = Predictor(load_from_path='ok.pkl') print('Train accuracy: ', predictor.train_accuracy) print('Test accuracy: ', predictor.calculate_accuracy(from_data=df_test)) predictions = predictor.predict(when_data=df_test) print('Confidence mean for both x and y present: ', np.mean(predictions['z']['selfaware_confidences'])) print(list(df_test['z'])[30:60]) print(predictions['z']['predictions'][30:60]) predictions = predictor.predict(when_data=df_test.drop(columns=['x'])) print('Confidence mean for x missing: ', np.mean(predictions['z']['selfaware_confidences'])) predictions = predictor.predict(when_data=df_test.drop(columns=['y'])) print('Confidence mean for y missing: ', np.mean(predictions['z']['selfaware_confidences']))