Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

evaluate.py 902 B

You have to be logged in to leave a comment. Sign In
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
37
38
39
  1. import sys
  2. import os
  3. from sklearn.metrics import precision_recall_curve
  4. import sklearn.metrics as metrics
  5. try:
  6. import cPickle as pickle
  7. except ImportError:
  8. import pickle
  9. if len(sys.argv) != 4:
  10. sys.stderr.write('Arguments error. Usage:\n')
  11. sys.stderr.write('\tpython evaluate.py model features output\n')
  12. sys.exit(1)
  13. model_file = sys.argv[1]
  14. matrix_file = os.path.join(sys.argv[2], 'test.pkl')
  15. metrics_file = sys.argv[3]
  16. with open(model_file, 'rb') as fd:
  17. model = pickle.load(fd)
  18. with open(matrix_file, 'rb') as fd:
  19. matrix = pickle.load(fd)
  20. labels = matrix[:, 1].toarray()
  21. x = matrix[:, 2:]
  22. predictions_by_class = model.predict_proba(x)
  23. predictions = predictions_by_class[:, 1]
  24. precision, recall, thresholds = precision_recall_curve(labels, predictions)
  25. auc = metrics.auc(recall, precision)
  26. with open(metrics_file, 'w') as fd:
  27. fd.write('{:4f}\n'.format(auc))
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...