Module model_tools.model_plot_tools
A module for calculating various statistics not included in the sklearn or scipy packages.
Source code
# -*- coding: utf-8 -*-
"""
A module for calculating various statistics not included
in the sklearn or scipy packages.
"""
import matplotlib.pyplot as plt
import numpy as np
def plot_ROC_curve(fpr, tpr):
fig, ax = plt.subplots(figsize=(9, 8))
ax.plot(fpr, tpr)
ax.plot([0, 1], [0, 1], linestyle='--', linewidth=2)
ax.set_ylabel('True Positive Rate', fontsize=15)
ax.set_xlabel('False Positive Rate', fontsize=15)
return fig, ax
def plot_variance_covariance_matrix(variance_covariance_matrix, feature_labels):
"""
returns a matplotlib figure and axis of a pcolormesh
plot of the input matrix
"""
varcov = np.array(variance_covariance_matrix)
fig, ax = plt.subplots(figsize=(9, 8))
cbar = ax.pcolormesh(np.array(varcov), vmin=-0.01, vmax=0.01, cmap='seismic')
fig.colorbar(cbar, label='covariance')
ax.set_xticks(np.arange(0.5, 7, 1))
ax.set_yticks(np.arange(0.5, 7, 1))
ax.set_xticklabels(np.concatenate([('intercept',),np.array(feature_labels)]), rotation=90)
ax.set_yticklabels(np.concatenate([('intercept',),np.array(feature_labels)]), rotation=0)
for n,mc in enumerate(np.array(varcov)):
for i,m in enumerate(mc):
varcov_value = np.format_float_scientific(np.round(m, 5))
ax.text(x=n+0.15, y=i+0.35, s=varcov_value, color='black', fontsize=10)
return fig, ax
Functions
def plot_ROC_curve(fpr, tpr)
-
Source code
def plot_ROC_curve(fpr, tpr): fig, ax = plt.subplots(figsize=(9, 8)) ax.plot(fpr, tpr) ax.plot([0, 1], [0, 1], linestyle='--', linewidth=2) ax.set_ylabel('True Positive Rate', fontsize=15) ax.set_xlabel('False Positive Rate', fontsize=15) return fig, ax
def plot_variance_covariance_matrix(variance_covariance_matrix, feature_labels)
-
returns a matplotlib figure and axis of a pcolormesh plot of the input matrix
Source code
def plot_variance_covariance_matrix(variance_covariance_matrix, feature_labels): """ returns a matplotlib figure and axis of a pcolormesh plot of the input matrix """ varcov = np.array(variance_covariance_matrix) fig, ax = plt.subplots(figsize=(9, 8)) cbar = ax.pcolormesh(np.array(varcov), vmin=-0.01, vmax=0.01, cmap='seismic') fig.colorbar(cbar, label='covariance') ax.set_xticks(np.arange(0.5, 7, 1)) ax.set_yticks(np.arange(0.5, 7, 1)) ax.set_xticklabels(np.concatenate([('intercept',),np.array(feature_labels)]), rotation=90) ax.set_yticklabels(np.concatenate([('intercept',),np.array(feature_labels)]), rotation=0) for n,mc in enumerate(np.array(varcov)): for i,m in enumerate(mc): varcov_value = np.format_float_scientific(np.round(m, 5)) ax.text(x=n+0.15, y=i+0.35, s=varcov_value, color='black', fontsize=10) return fig, ax