mlplot: Machine Learning Evaluation Plots

mlplot is a Python data visualization library for machine learning evaluation plots. It is based on matplotlib and sklearn.

The code live in Github.

Installation

pip install mlplot

API Reference

Classification Plots

Plots to evaluate classification models.

Module containing all classification model evaluation plots

mlplot.classification.calibration(y_true, y_pred, ax=None, n_bins='auto')

Plot a calibration plot

Calibration plots are used the determine how well the predicted values match the true value.

This plot is as found in sklean.

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)
  • n_bins (int or string) – The number of bins to group y_pred. See numpy.histogram
mlplot.classification.confusion_matrix(y_true, y_pred, class_labels=None, threshold=0.5, ax=None)

Plot a heatmap for the confusion matrix

An example of this heatmap can be found on sklean.

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)
  • threshold (float) – Defines the cutoff to be considered in the asserted class
mlplot.classification.population_histogram(y_true, y_pred, class_labels=None, ax=None)

Plot histograms of the predictions grouped by class

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)
mlplot.classification.precision_recall(y_true, y_pred, x_axis='recall', ax=None)

Plot the precision-recall curve

An example of this plot can be found on sklean.

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)
  • x_axis (str ‘recall’ or ‘threshold’) – Specify the x axis of the plot. Precision recall tends to come in 2 flavors, one precision vs recall and the other precion and recall vs threshold.
mlplot.classification.report_table(y_true, y_pred, class_labels=None, ax=None)

Generate a report table containing key stats about the dataset

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)
mlplot.classification.roc_curve(y_true, y_pred, ax=None)

Reciever operating curve

Parameters:
  • y_true (np.array of str or int) – A vector of size N that contains the true labels. There should be two labels of type string or numeric.
  • y_pred (np.array of float) – A vector of size N that contains predictions as floats from 0 to 1.
  • class_labels (dict, optional) – A dictionary mapping from lables in y_true to class names. Ex: {0: ‘not dog’, 1: ‘is dog’}
  • ax (matplotlib.axes.Axes, optional)