Browse Source

output_confusion_matrix is changed to be a function.

master
yemaozi88 4 years ago
parent
commit
9baa0f8641
  1. BIN
      accent_classification/__pycache__/output_confusion_matrix.cpython-36.pyc
  2. 48
      accent_classification/output_confusion_matrix.py

BIN
accent_classification/__pycache__/output_confusion_matrix.cpython-36.pyc

Binary file not shown.

48
accent_classification/output_confusion_matrix.py

@ -9,14 +9,6 @@ from sklearn.metrics import accuracy_score @@ -9,14 +9,6 @@ from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
currDir = 'C:\\Users\\Aki\\source\\repos\\rug_VS\\dialect_identification\\dialect_identification'
sys.path.append(os.path.join(os.path.dirname(sys.path[0]), currDir))
regionLabels = ['Groningen_and_Drenthe', 'Oost_Overijsel-Gelderland', 'Limburg']
regionLabels2 = ['Groningen_and_Drenthe', 'Limburg']
dirOut = currDir + '\\result\\same-utterance_with_cities'
def plot_confusion_matrix(cm, classes,
normalize=False,
title='Confusion matrix',
@ -56,24 +48,32 @@ def plot_confusion_matrix(cm, classes, @@ -56,24 +48,32 @@ def plot_confusion_matrix(cm, classes,
plt.xlabel('Predicted label', fontsize=_fontsize-4)
pred = np.load(dirOut + '\\pred_per_pid_3regions.npy')
if __name__ == "__main__":
currDir = 'C:\\Users\\Aki\\source\\repos\\rug_VS\\dialect_identification\\dialect_identification'
sys.path.append(os.path.join(os.path.dirname(sys.path[0]), currDir))
regionLabels = ['Groningen_and_Drenthe', 'Oost_Overijsel-Gelderland', 'Limburg']
regionLabels2 = ['Groningen_and_Drenthe', 'Limburg']
dirOut = currDir + '\\result\\same-utterance_with_cities'
pred = np.load(dirOut + '\\pred_per_pid_3regions.npy')
#accuracy = accuracy_score(pred[:, 1], pred[:, 2], normalize=True, sample_weight=None)
#print('accuracy: {}%'.format(accuracy * 100))
#accuracy = accuracy_score(pred[:, 1], pred[:, 2], normalize=True, sample_weight=None)
#print('accuracy: {}%'.format(accuracy * 100))
# confusion matrix
cm = confusion_matrix(pred[:, 1], pred[:, 2], labels=regionLabels)
# human perception (2 regions)
#cm = np.array([[39, 57], [6, 104]])
# human perception (3 regions)
#cm = np.array([[22, 14, 52], [23, 21, 52], [5, 5, 100]])
print(cm)
# confusion matrix
cm = confusion_matrix(pred[:, 1], pred[:, 2], labels=regionLabels)
# human perception (2 regions)
#cm = np.array([[39, 57], [6, 104]])
# human perception (3 regions)
#cm = np.array([[22, 14, 52], [23, 21, 52], [5, 5, 100]])
print(cm)
np.set_printoptions(precision=2)
np.set_printoptions(precision=2)
plt.figure()
plot_confusion_matrix(cm, classes=['GD', 'OG', 'LB'], normalize=True)
#plot_confusion_matrix(cm, classes=['GD', 'LB'], normalize=True)
plt.figure()
plot_confusion_matrix(cm, classes=['GD', 'OG', 'LB'], normalize=True)
#plot_confusion_matrix(cm, classes=['GD', 'LB'], normalize=True)
#plt.show()
plt.savefig(dirOut + '\\cm_machine_3regions_normalized.png')
#plt.show()
plt.savefig(dirOut + '\\cm_machine_3regions_normalized.png')
Loading…
Cancel
Save