In [1]:
    
! sudo pip install matplotlib
%matplotlib inline
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn.externals import joblib
    
    
In [2]:
    
models = joblib.load('models.pkl')
    
In [4]:
    
categories = ["spam", "OK", "vandalism", "attack"]
    
In [7]:
    
def plot_precision_recall_for_category(category):
    N = len(models)
    precision_values = [x["metrics_for_" + category][0] for x in models]
    recall_values = [x["metrics_for_" + category][1] for x in models]
    
    ind = np.arange(N)    # the x locations for the groups
    width = 0.35       # the width of the bars: can also be len(x) sequence
    p1 = plt.bar(ind, precision_values, width, color='#d62728')
    p2 = plt.bar(ind, recall_values, width,
             bottom=precision_values)
    plt.xlabel('Algorithms')
    plt.title('Precision and Recall per Model for ' + category)
    plt.xticks(ind, ([x["name"][0:4] for x in models]))
    plt.yticks(np.arange(0, 2, 0.1))
    plt.legend((p1[0], p2[0]), ('Precision', 'Recall'))
    plt.show()
    
In [ ]:
    
## Precision/Recall per category
    
In [8]:
    
for category in categories:
    plot_precision_recall_for_category(category)
    
    
    
    
    
In [9]:
    
N = len(models)
precision_values = [x["mean_precision"] for x in models]
recall_values = [x["mean_recall"] for x in models]
    
In [10]:
    
ind = np.arange(N)    # the x locations for the groups
width = 0.35       # the width of the bars: can also be len(x) sequence
p1 = plt.bar(ind, precision_values, width, color='#d62728')
p2 = plt.bar(ind, recall_values, width,
             bottom=precision_values)
plt.xlabel('Algorithms')
plt.title('Precision and Recall per Model')
plt.xticks(ind, ([x["name"][0:4] for x in models]))
plt.yticks(np.arange(0, 1.7, 0.1))
plt.legend((p1[0], p2[0]), ('Precision', 'Recall'))
plt.show()
    
    
In [ ]: