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 dagshub
  2. import os
  3. import pandas as pd
  4. import yaml
  5. import numpy as np
  6. import joblib
  7. import reddit_utils
  8. with open(r"./general_params.yml") as f:
  9. params = yaml.safe_load(f)
  10. with open(r"./model_params.yml") as f:
  11. model_params = yaml.safe_load(f)
  12. CHUNK_SIZE = params["chunk_size"]
  13. TARGET_LABEL = params["target_col"]
  14. COLS_FOR_EVAL = []
  15. if model_params["use_text_cols"]:
  16. COLS_FOR_EVAL += reddit_utils.TEXT_COL_NAME
  17. if model_params["use_number_category_cols"]:
  18. COLS_FOR_EVAL += reddit_utils.NUM_COL_NAMES + reddit_utils.CAT_COL_NAMES
  19. def load_transform_and_eval():
  20. print("loading transformer and model...")
  21. model = joblib.load(reddit_utils.MODEL_PATH)
  22. y_proba = np.array([])
  23. y_pred = np.array([])
  24. y = np.array([])
  25. print("Loading test data and testing model...")
  26. for i, chunk in enumerate(
  27. pd.read_csv(os.path.join('processed', reddit_utils.TEST_DF_PATH), chunksize=CHUNK_SIZE)
  28. ):
  29. print(f"Testing on chunk {i+1}...")
  30. df_X = chunk[COLS_FOR_EVAL]
  31. y_proba = np.concatenate((y_pred, model.predict_proba(df_X)[:, 1]))
  32. y_pred = np.concatenate((y_pred, model.predict(df_X)))
  33. y = np.concatenate((y, chunk[TARGET_LABEL]))
  34. print("Calculating metrics")
  35. metrics = reddit_utils.calculate_metrics(y_pred, y_proba, y)
  36. print("Logging metrics...")
  37. with dagshub.dagshub_logger(should_log_hparams=False, metrics_path='test_metrics.csv') as logger:
  38. logger.log_metrics(reddit_utils.prepare_log(metrics, "test"))
  39. if __name__ == "__main__":
  40. load_transform_and_eval()
  41. print("Model evaluation done!")
Tip!

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

Comments

Loading...