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

eval.py 974 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
40
  1. """
  2. Evaluate model performance
  3. """
  4. import pickle
  5. import json
  6. import numpy as np
  7. from sklearn.metrics import accuracy_score, precision_score, recall_score, roc_auc_score
  8. def eval_model():
  9. # Load test data
  10. print("Loading data and model...")
  11. test_data = np.load('./data/processed_test_data.npy')
  12. # Load trained model
  13. with open('./data/model.pkl', 'rb') as f:
  14. model = pickle.load(f)
  15. print("done.")
  16. # Divide loaded data-set into data and labels
  17. labels = test_data[:, 0]
  18. data = test_data[:, 1:]
  19. # Run model on test data
  20. print("Running model on test data...")
  21. predictions = model.predict(data)
  22. print("done.")
  23. # Calculate metric scores
  24. print("Calculating metrics...")
  25. metrics = {'accuracy': accuracy_score(labels, predictions)}
  26. # Save metrics to json file
  27. with open('./metrics/eval.json', 'w') as f:
  28. json.dump(metrics, f)
  29. print("done.")
  30. if __name__ == '__main__':
  31. eval_model()
Tip!

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

Comments

Loading...