-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting.py
36 lines (31 loc) · 1.22 KB
/
reporting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pickle
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from sklearn import metrics
import matplotlib.pyplot as plt
import seaborn as sns
import json
import os
from diagnostics import model_predictions
#Load config.json and get path variables
with open('config.json','r') as f:
config = json.load(f)
model_path = os.path.join(config['output_model_path'])
test_data_path = os.path.join(config['test_data_path'])
def score_model():
"""
Function for reporting - calculate a confusion matrix using the test data and the deployed model, and write the confusion matrix to the workspace"""
y_pred, df_y = model_predictions(None)
df_cm = metrics.confusion_matrix(df_y, y_pred)
fig, ax = plt.subplots(figsize=(7.5, 7.5))
ax.matshow(df_cm, cmap=plt.cm.Blues, alpha=0.3)
for i in range(df_cm.shape[0]):
for j in range(df_cm.shape[1]):
ax.text(x=j, y=i,s=df_cm[i, j], va='center', ha='center', size='xx-large')
plt.xlabel('Predictions', fontsize=18)
plt.ylabel('Actuals', fontsize=18)
plt.title('Confusion Matrix', fontsize=18)
plt.savefig(os.path.join(model_path, "confusionmatrix2.png"))
if __name__ == '__main__':
score_model()