# %% # Plot the training iterations vs. the training loss, the valid data mean-absolute-difference, # and the valid data correlation with predicted and true (y_vald) labels. file_name = os.getcwd() + "/models/plot_metrics.png" # file_name = os.path.join(os.getcwd(), name) E2Nnet_sml.plot_iter_metrics(True, file_name) # %% # Predict labels of test data preds = E2Nnet_sml.predict(x_val) preds = np.reshape(preds, (len(preds), 1)) # %% # Compute the metrics. E2Nnet_sml.print_results(preds, y_val) print("predictions raw", preds) print("y_test", y_val) preds_trans = np.zeros((preds.shape)) preds_trans[preds >= 0.5] = 1 preds_trans[preds < 0.5] = 0 print("predictions", preds_trans) accuracy = np.sum(np.sum(y_val != preds_trans)) print("accuracy", accuracy) # %% # We can save the model like this. # test_data = (x_test, y_test) # file_name = "models/test_data.pkl" # with open(file_name, 'wb') as pkl_file:
# WARNING: If you have a high max_iter and no GPU, this could take awhile... E2Nnet_sml.fit(x_train, y_train, x_valid, y_valid) # If no valid data, could put test data here. # %% # Plot the training iterations vs. the training loss, the valid data mean-absolute-difference, # and the valid data correlation with predicted and true (y_vald) labels. E2Nnet_sml.plot_iter_metrics() # %% # Predict labels of test data preds = E2Nnet_sml.predict(x_test) # %% # Compute the metrics. E2Nnet_sml.print_results(preds, y_test) # %% # We can save the model like this. E2Nnet_sml.save('models/E2Nnet_sml.pkl') # %% # Now let's try removing and loading the saved model. del E2Nnet_sml del preds # %% # Load the model like this. E2Nnet_sml = load_model('models/E2Nnet_sml.pkl') # %%