-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfusion_matrices.py
35 lines (27 loc) · 1.23 KB
/
confusion_matrices.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
from utilities.data_management import make_path, make_dir, check_existence, load_vector, open_w_pandas, vector_to_file
from model.networks import predict_abusive_intent
from utilities.plotting import confusion_matrix, show
from config import dataset
midpoint = .5
base = make_path('data/processed_data') / dataset / 'analysis' / 'abuse'
data_path = base / 'testing_data.csv'
label_path = base / 'testing_labels.csv'
prediction_path = base / 'testing_predictions.csv'
base_path = make_path('data/processed_data/abusive_data/analysis/intent_abuse')
figure_base = make_path('figures') / dataset / 'analysis'
check_existence([data_path])
make_dir(figure_base)
print('Complete config.')
documents = load_vector(data_path)
labels = load_vector(label_path).astype(bool)
if prediction_path.exists():
print('Loading data')
predictions = load_vector(prediction_path) > midpoint
else:
print('Making abuse predictions')
predictions, _, _ = predict_abusive_intent(documents)
vector_to_file(predictions, prediction_path)
predictions = predictions > midpoint
confusion_matrix(predictions, labels, 'Confusion matrix of abuse model predictions',
figure_base / 'abuse_confusion_matrix.png')
show()