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 2.0 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  1. import os
  2. import re
  3. from sklearn.metrics import (
  4. roc_auc_score,
  5. average_precision_score,
  6. accuracy_score,
  7. precision_score,
  8. recall_score,
  9. f1_score,
  10. )
  11. # ----- Cloud Details -----
  12. PROJECT_NAME = "talos-project"
  13. BIGQUERY_PROJECT = "project-talos"
  14. GCLOUD_CRED_ENV_VAR = "GOOGLE_APPLICATION_CREDENTIALS"
  15. # ----- Constants -----
  16. NUM_COL_NAMES = ["title_len", "body_len", "hour", "minute", "dayofweek", "dayofyear"]
  17. CAT_COL_NAMES = [
  18. "has_thumbnail",
  19. "flair_Clickbait",
  20. "flair_Discussion",
  21. "flair_Inaccurate",
  22. "flair_Misleading",
  23. "flair_News",
  24. "flair_None",
  25. "flair_Project",
  26. "flair_Research",
  27. "flair_Shameless Self Promo",
  28. ]
  29. TEXT_COL_NAME = ["title_and_body"]
  30. # ----- Paths -----
  31. MODELS_DIR = "./models"
  32. TFIDF_PATH = MODELS_DIR + "/tfidf.pkl"
  33. MODEL_PATH = MODELS_DIR + "/model.pkl"
  34. RAW_DF_PATH = "rML-raw-data.csv"
  35. TRAIN_DF_PATH = "rML-train.csv"
  36. TEST_DF_PATH = "rML-test.csv"
  37. # ----- Functions -----
  38. def calculate_metrics(y_pred, y_proba, y):
  39. return {
  40. "roc_auc": roc_auc_score(y, y_proba),
  41. "average_precision": average_precision_score(y, y_proba),
  42. "accuracy": accuracy_score(y, y_pred),
  43. "precision": precision_score(y, y_pred),
  44. "recall": recall_score(y, y_pred),
  45. "f1": f1_score(y, y_pred),
  46. }
  47. def get_remote_gs_wfs():
  48. print("Retreiving location of remote working file system...")
  49. stream = os.popen("dvc remote list --local")
  50. output = stream.read()
  51. remote_wfs_loc = output.split("\t")[1].split("\n")[0]
  52. return remote_wfs_loc
  53. # Prepare a dictionary of either hyperparams or metrics for logging.
  54. def prepare_log(d, prefix=""):
  55. if prefix:
  56. prefix = f"{prefix}__"
  57. # Ensure all logged values are suitable for logging - complex objects aren't supported.
  58. def sanitize(value):
  59. return (
  60. value
  61. if value is None or type(value) in [str, int, float, bool]
  62. else str(value)
  63. )
  64. 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...