-
Notifications
You must be signed in to change notification settings - Fork 0
/
confusion_matrix.py
30 lines (23 loc) · 1019 Bytes
/
confusion_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import keras
import numpy as np
from sklearn.metrics import confusion_matrix
import argparse
parser = argparse.ArgumentParser(description='Create a confusion matrix from a model \
and a testing set.')
parser.add_argument('model', type=str,
help='The model to create a confusion matrix on.')
parser.add_argument('--test-features', type=str,
help='Path to a .npy file containing the feature array \
of the testing set.')
parser.add_argument('--test-labels', type=str,
help='Path to a .npy file containing the label array \
of the testing set.')
args = parser.parse_args()
X_test = np.load(args.test_features)
y_test = np.load(args.test_labels)
model = keras.models.load_model(args.model)
y_pred = model.predict(X_test, verbose=1)
y_pred = np.argmax(y_pred, axis=1)
y_test = np.argmax(y_test, axis=1)
matrix = confusion_matrix(y_test, y_pred)
print(matrix)