While working on a Machine Learning project, I wrote this pair of Python 3 functions in Jupyter Notebook to:
- Manually calculate confusion matrix from test_y and test_predictions (manually_calculate_tp_tn_fp_fn.py)
- Nicely format the confusion matrix output in a table (display_confusion_matrix.py)
I have also written a blog article about this here:
http://bluegalaxy.info/codewalk/2017/12/20/data-science-how-to-calculate-confusion-matrix/