Metrics¶
Functions:
|
Generates a confusion matrix for the given predictions. |
|
Generates classification metrics precision, recall and F1 for the given predictions. |
|
Saves/appends all experiment parameters and results to .csv file. |
|
Saves training history dictionary as numpy arrays in .npz file. |
|
Saves predictions to .csv file. |
|
Saves test metrics to a .txt file. |
-
metrics.plot_confusion_matrix(true_labels, predicted_labels, labels, matrix_dim=15, normalise=False, title=None, fig_size=(10, 10), font_size=15)¶ Generates a confusion matrix for the given predictions.
Uses sklearn to generate the confusion matrix. Uses matplotlib and seaborn to generate the figure.
- Parameters
true_labels (np.array) – The ground truth labels for the data
predicted_labels (np.array) – The predicted labels for the data
labels (list) – List of label names
title (str) – The title for the figure
matrix_dim (int) – The number of classes to show on the matrix, if None or -1 creates full matrix
normalise (bool) – Whether to normalise the matrix or use original values
fig_size (tuple) – Tuple for the horizontal and vertical size the figure
font_size (int) – Font size for figure labels.
- Returns
The confusion matrix figure matrix (numpy array): The 2d confusion matrix array
- Return type
fig (matplotlib figure)
-
metrics.precision_recall_f1(true_labels, predicted_labels, labels)¶ Generates classification metrics precision, recall and F1 for the given predictions.
- Parameters
true_labels (np.array) – The ground truth labels for the data
predicted_labels (np.array) – The predicted labels for the data
labels (list) – List of label names
- Returns
Dictionary of micro, macro and weighted precision, recall and F1 scores cls_report_str (str): Formatted string with metric data for all classes and totals cls_report_dct (dict): Dictionary containing all metric data of metrics string
- Return type
metrics_dict (dict)
-
metrics.save_experiment(file_name, params, train_loss, train_acc, val_loss, val_acc, test_loss, test_acc, metrics)¶ Saves/appends all experiment parameters and results to .csv file.
-
metrics.save_history(file_name, history)¶ Saves training history dictionary as numpy arrays in .npz file.
-
metrics.save_predictions(file_name, true_labels, predicted_labels, predictions)¶ Saves predictions to .csv file.
-
metrics.save_results(file_name, test_loss, test_accuracy, metrics)¶ Saves test metrics to a .txt file.