Ejemplo n.º 1
0
    def evaluate_model(self):
        '''Evaluate the model after it has been trained.
        '''
        NN.evaluate_model(self)

        self.log("Evaluating model...")
        self.log(
            "First Test Sample: ({}, {}) -> Expected: {} Guessed: {}".format(
                self.test_data[0][0], self.test_data[1][0],
                self.test_labels[0],
                self.model.predict(
                    ([self.test_data[0][0]], [self.test_data[1][0]]))[0][0]))
                         adam_beta2=adam_beta2, adam_epsilon=adam_epsilon, lambda_reg=lambda_reg, drop_rate=drop_rate,
                         seed=seed)

fx_prediction_model.set_layer_dims(x_train_normalized, y_train, hidden_layer_nodes)     # Set Network dimensions

# Set hidden/output layer activation functions
fx_prediction_model.set_activation_functions(hidden_activation=hidden_activation, output_activation=output_activation)

model_parameters['layer_dims'] = fx_prediction_model.layer_dims
model_parameters['activation_functions'] = fx_prediction_model.activation_functions

# Train model ----------------------------------------------------------------------------------------------------------
trained_model, train_set_metrics, train_set_predictions = fx_prediction_model.train_model(x_train_normalized, y_train)

print('Cross-validation set Model Performance ------------------')
cv_set_metrics, cv_set_predictions = fx_prediction_model.evaluate_model(x_cv_normalized, y_cv, trained_model)
print('Test set Model Performance ------------------')
test_set_metrics, test_set_predictions = fx_prediction_model.evaluate_model(x_test_normalized, y_test, trained_model)

print('Total data set Model Performance ------------------')
x_normalized = np.log(x)
full_data_metrics, full_data_predictions = fx_prediction_model.evaluate_model(x_normalized, y, trained_model)

# Daily time series over the entire data set of prediction values ------------------------------------------------------
writer = pd.ExcelWriter(output_root+'predictions_full_data.xlsx')
pd.DataFrame(x.T, index=raw_data.index, columns=raw_data.columns).to_excel(writer, 'inputs')
pd.DataFrame(full_data_predictions, index=raw_data.index, columns=y_labels).to_excel(writer, 'predictions')
pd.DataFrame(y.T, index=raw_data.index, columns=y_labels).to_excel(writer, 'outputs')
writer.close()

# Save parameters ------------------------------------------------------------------------------------------------------
Ejemplo n.º 3
0
usdcad_spot = eval_data['USDCAD Curncy']
eval_data = eval_data.drop('USDCAD Curncy', axis=1)               # usdcad removed as a feature

x = eval_data.T.as_matrix().astype('float32')
y = usdcad_spot.T.as_matrix().astype('float32')
y = y.reshape((1, len(y)))                                        # reshape y to be a vector
y_labels = ['usdcad_spot']

# Model setup ----------------------------------------------------------------------------------------------------------
num_features = x.shape[0]
num_examples = x.shape[1]
assert (y.shape[1] == x.shape[1])                               # Check that input and outputs have same num_examples

# Initialize Neural Network
fx_prediction_model = NN(alpha=m['alpha'], num_epochs=m['num_epochs'], mini_batch_size=m['mini_batch_size'],
                         adam_beta1=m['adam_beta1'], adam_beta2=m['adam_beta2'], adam_epsilon=m['adam_epsilon'],
                         lambda_reg=m['lambda_reg'], drop_rate=m['drop_rate'], seed=m['seed'],
                         layer_dims=m['layer_dims'], activation_functions=m['activation_functions'])


print('Total data set Model Performance ------------------')
x_normalized = np.log(x)
full_data_metrics, full_data_predictions = fx_prediction_model.evaluate_model(x_normalized, y, trained_model)

# Daily time series over the entire data set of prediction values ------------------------------------------------------
writer = pd.ExcelWriter(output_root+'evaluation_full_data.xlsx')
pd.DataFrame(x.T, index=eval_data.index, columns=eval_data.columns).to_excel(writer, 'inputs')
pd.DataFrame(full_data_predictions, index=eval_data.index, columns=y_labels).to_excel(writer, 'predictions')
pd.DataFrame(y.T, index=eval_data.index, columns=y_labels).to_excel(writer, 'outputs')
writer.close()