Skip to content

Instantly share code, notes, and snippets.

@BinarySpoon
Created January 11, 2021 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinarySpoon/815304be837d8e76b289ede92229de9d to your computer and use it in GitHub Desktop.
Save BinarySpoon/815304be837d8e76b289ede92229de9d to your computer and use it in GitHub Desktop.
#6 Heatmaps -->
lr_cm = metrics.confusion_matrix(y_test, lr_predict) # cm = confusion matrix, so sklearn has a built in for that.
svc_cm = metrics.confusion_matrix(y_test, svc_predict)
rf_cm = metrics.confusion_matrix(y_test, rf_predict)
knn_cm = metrics.confusion_matrix(y_test, knn_predict)
# Logistic regression
plt.figure(figsize=(9,9))
sns.heatmap(lr_cm, annot=True, fmt='.3f', linewidths=.5, square=True, cmap='Blues');
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'Logistic Regression: {0}'.format(lr_score)
plt.title(all_sample_title, size=15);
# Support Vector Machines -->
plt.figure(figsize=(9,9))
sns.heatmap(svc_cm, annot=True, fmt='.3f', linewidths=.5, square=True, cmap='Blues');
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'Support Vector Machines: {0}'.format(svc_score)
plt.title(all_sample_title, size=15);
# Random Forest Classifier -->
plt.figure(figsize=(9,9))
sns.heatmap(rf_cm, annot=True, fmt='.3f', linewidths=.5, square=True, cmap='Blues');
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'Random Forest: {0}'.format(svc_score)
plt.title(all_sample_title, size=15);
# K-Nearest Neighbors -->
plt.figure(figsize=(9,9))
sns.heatmap(knn_cm, annot=True, fmt='.3f', linewidths=.5, square=True, cmap='Blues');
plt.ylabel('Actual label');
plt.xlabel('Predicted label');
all_sample_title = 'K-Nearest Neighbors: {0}'.format(svc_score)
plt.title(all_sample_title, size=15);
# Printout plots -->
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment