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 1.6 KB

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  1. import os
  2. from pathlib import Path
  3. import joblib
  4. import numpy as np
  5. import pandas as pd
  6. import src.reddit_utils as r_utils
  7. from src.utilities import dump_yaml, read_yaml
  8. pre_process_params = read_yaml("params.yaml", "pre_process")
  9. model_params = read_yaml("params.yaml", "train")
  10. CHUNK_SIZE = pre_process_params["chunk_size"]
  11. TARGET_LABEL = pre_process_params["target_col"]
  12. COLS_FOR_EVAL = []
  13. if model_params["use_text_cols"]:
  14. COLS_FOR_EVAL += r_utils.TEXT_COL_NAME
  15. if model_params["use_number_category_cols"]:
  16. COLS_FOR_EVAL += r_utils.NUM_COL_NAMES + r_utils.CAT_COL_NAMES
  17. def load_transform_and_eval():
  18. print("loading transformer and model...")
  19. model = joblib.load(r_utils.MODEL_PATH)
  20. y_proba = np.array([])
  21. y_pred = np.array([])
  22. y = np.array([])
  23. print("Loading test data and testing model...")
  24. for i, chunk in enumerate(
  25. pd.read_csv(
  26. os.path.join("data/processed", r_utils.TEST_DF_PATH),
  27. chunksize=CHUNK_SIZE,
  28. )
  29. ):
  30. print(f"Testing on chunk {i+1}...")
  31. df_X = chunk[COLS_FOR_EVAL]
  32. y_proba = np.concatenate((y_pred, model.predict_proba(df_X)[:, 1]))
  33. y_pred = np.concatenate((y_pred, model.predict(df_X)))
  34. y = np.concatenate((y, chunk[TARGET_LABEL]))
  35. print("Calculating metrics")
  36. metrics = r_utils.calculate_metrics(y_pred, y_proba, y)
  37. print("Logging metrics...")
  38. metrics_path = Path("models/metrics/test.yaml")
  39. dump_yaml(metrics, metrics_path)
  40. if __name__ == "__main__":
  41. load_transform_and_eval()
  42. print("Model evaluation done!")
Tip!

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

Comments

Loading...