Skip to content

Instantly share code, notes, and snippets.

@VictorSaenger
Last active October 9, 2019 08:17
Show Gist options
  • Select an option

  • Save VictorSaenger/cbea40de2850f539c45891e49b9a0302 to your computer and use it in GitHub Desktop.

Select an option

Save VictorSaenger/cbea40de2850f539c45891e49b9a0302 to your computer and use it in GitHub Desktop.
# Plot accuracy curves:
with sns.color_palette("Accent", n_colors=8):
plt.figure(figsize=(8,6))
sns.lineplot(data=np.asarray(m_h.history['acc']))
sns.lineplot(data=np.asarray(m_h.history['val_acc']))
plt.xlabel("Epochs")
plt.ylabel("Accuracy")
plt.title("Accuracy for Media Bias Classification") # change title here
plt.legend(labels=['training', 'validation'],loc='lower right')
plt.text(330,0.755,'val Ac = ' + str(round(accuracy_score(y_test,model.predict_classes(X_test)),2)))
plt.savefig('outlets_bias_acc.svg',format='svg') # edit file title here
# Plot confusion matrix:
plt.figure(figsize=(4, 3))
sns.heatmap(confusion_matrix(y_test,model.predict_classes(X_test)),\
annot=True,linewidths=2, cmap="YlGnBu",fmt="g", \
xticklabels=['Right','Left'],\
yticklabels=['Right','Left']) # Or change labels to ['outlet1','outlet2','outlet3','outlet4'] for outlet classifier
plt.autoscale()
plt.savefig('confusion_matrix_outlet_bias_bal.png',format='PNG',bbox_inches = "tight") # edit file title here
# Plot loss curves:
with sns.color_palette("Accent", n_colors=8):
plt.figure(figsize=(8,6))
sns.lineplot(data=np.asarray(m_h.history['loss']))
sns.lineplot(data=np.asarray(m_h.history['loss']))
plt.xlabel("Epochs")
plt.ylabel("Loss")
plt.title("Loss functions for Media Bias Classification") #change title here
plt.legend(labels=['training', 'validation'])
plt.savefig('outlets_bias_loss.svg',format='SVG') # edit file title here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment