MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / plot_confusion_matrix

Function plot_confusion_matrix

alphapy/plots.py:598–690  ·  view source on GitHub ↗

r"""Draw the confusion matrix. Parameters ---------- model : alphapy.Model The model object with plotting specifications. partition : alphapy.Partition Reference to the dataset. Returns ------- None : None References ---------- http://sciki

(model, partition)

Source from the content-addressed store, hash-verified

596#
597
598def plot_confusion_matrix(model, partition):
599 r"""Draw the confusion matrix.
600
601 Parameters
602 ----------
603 model : alphapy.Model
604 The model object with plotting specifications.
605 partition : alphapy.Partition
606 Reference to the dataset.
607
608 Returns
609 -------
610 None : None
611
612 References
613 ----------
614
615 http://scikit-learn.org/stable/modules/model_evaluation.html#confusion-matrix
616
617 """
618
619 logger.info("Generating Confusion Matrices")
620 plot_dir = get_plot_directory(model)
621 pstring = datasets[partition]
622
623 # For classification only
624
625 if model.specs['model_type'] != ModelType.classification:
626 logger.info('Confusion Matrix is for classification only')
627 return None
628
629 # Get X, Y for correct partition.
630 X, y = get_partition_data(model, partition)
631
632 # Plot Parameters
633 np.set_printoptions(precision=2)
634 cmap = plt.cm.Blues
635 fmt = '.2f'
636
637 # Generate a Confusion Matrix for each algorithm
638
639 for algo in model.algolist:
640 logger.info("Confusion Matrix for Algorithm: %s", algo)
641
642 # get predictions for this partition
643 y_pred = model.preds[(algo, partition)]
644
645 # compute confusion matrix
646 cm = confusion_matrix(y, y_pred)
647 logger.info('Confusion Matrix:')
648 logger.info('%s', cm)
649
650 # normalize confusion matrix
651 cm_pct = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
652
653 # initialize plot
654 _, ax = plt.subplots()
655

Callers 1

generate_plotsFunction · 0.85

Calls 3

get_plot_directoryFunction · 0.85
get_partition_dataFunction · 0.85
write_plotFunction · 0.85

Tested by

no test coverage detected