How to Log Machine Learning Training Results

Python

This code snippet uses the print function to log the current time and the mean absolute error results between our test data and our model predictions to a text file named training_log.

Note that results will be appended to the file each time this code runs so enabling tracking of results.

 1|  from datetime import datetime
 2|  
 3|  now = datetime.now()
 4|  now = str(now.strftime("%d/%m/%Y %H:%M:%S"))
 5|  
 6|  with open("..logs/training_log.txt", "a") as log_file:
 7|  	mae = mean_absolute_error(y_test,predictions)
 8|  	print('MAE:',mae, file=log_file)
 9|  	log_file.close()
Did you find this snippet useful?

Sign up for free to to add this to your code library