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

reddit_utils.py 1.4 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
  1. from sklearn.metrics import (
  2. roc_auc_score,
  3. average_precision_score,
  4. accuracy_score,
  5. precision_score,
  6. recall_score,
  7. f1_score,
  8. )
  9. # ----- Constants -----
  10. NUM_COL_NAMES = ["title_len", "body_len", "hour", "minute", "dayofweek", "dayofyear"]
  11. CAT_COL_NAMES = [
  12. "has_thumbnail",
  13. "flair_Clickbait",
  14. "flair_Discussion",
  15. "flair_Inaccurate",
  16. "flair_Misleading",
  17. "flair_News",
  18. "flair_None",
  19. "flair_Project",
  20. "flair_Research",
  21. "flair_Shameless Self Promo",
  22. ]
  23. # ----- Paths -----
  24. MODELS_DIR = "./models"
  25. TFIDF_PATH = MODELS_DIR + "/tfidf.pkl"
  26. MODEL_PATH = MODELS_DIR + "/model.pkl"
  27. # ----- Functions -----
  28. def calculate_metrics(y_pred, y_proba, y):
  29. return {
  30. 'roc_auc': roc_auc_score(y, y_proba),
  31. 'average_precision': average_precision_score(y, y_proba),
  32. 'accuracy': accuracy_score(y, y_pred),
  33. 'precision': precision_score(y, y_pred),
  34. 'recall': recall_score(y, y_pred),
  35. 'f1': f1_score(y, y_pred),
  36. }
  37. # Prepare a dictionary of either hyperparams or metrics for logging.
  38. def prepare_log(d, prefix=""):
  39. if prefix:
  40. prefix = f"{prefix}__"
  41. # Ensure all logged values are suitable for logging - complex objects aren't supported.
  42. def sanitize(value):
  43. return (
  44. value
  45. if value is None or type(value) in [str, int, float, bool]
  46. else str(value)
  47. )
  48. return {f"{prefix}{k}": sanitize(v) for k, v in d.items()}
Tip!

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

Comments

Loading...