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

train.py 2.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  1. import numpy as np
  2. import pandas as pd
  3. import joblib
  4. import matplotlib.pyplot as plt
  5. import seaborn as sns
  6. from src import *
  7. from config import *
  8. dataset_path = DATA_DIR + "/01_mobile_price_classification"
  9. cfg = {
  10. "num_col_names": [
  11. "battery_power",
  12. "clock_speed",
  13. "int_memory",
  14. "m_dep",
  15. "mobile_wt",
  16. "px_height",
  17. "px_width",
  18. "ram",
  19. "sc_h",
  20. "sc_w",
  21. "talk_time",
  22. ],
  23. "cat_col_names": [
  24. "blue",
  25. "dual_sim",
  26. "fc",
  27. "four_g",
  28. "n_cores",
  29. "pc",
  30. "three_g",
  31. "touch_screen",
  32. "wifi",
  33. ],
  34. "target_col_name": ["price_range"],
  35. "n_splits": 5,
  36. "shuffle": True,
  37. "SEED": 1234
  38. }
  39. def read_data(dataset_path):
  40. """
  41. load CSV data
  42. """
  43. train = pd.read_csv(dataset_path + '/train.csv')
  44. test = pd.read_csv(dataset_path + '/test.csv')
  45. train["type"] = "train"
  46. test["type"] = "test"
  47. df = pd.concat([train, test], axis=0)
  48. df = df.drop(columns="id")
  49. return df
  50. if __name__ == "__main__":
  51. ###################
  52. # Read Data
  53. ###################
  54. df = read_data(dataset_path)
  55. # set configuration
  56. df[cfg["num_col_names"]] = df[cfg["num_col_names"]].astype("float")
  57. df[cfg["cat_col_names"]] = df[cfg["cat_col_names"]].astype("category")
  58. df[cfg["target_col_name"]] = df[cfg["target_col_name"]].astype("category")
  59. ###################
  60. # Prerocessing
  61. ###################
  62. df = categorical_imputer(
  63. df=df,
  64. cat_col_names=cfg["cat_col_names"]
  65. )
  66. #df = rarelabel_encoder(
  67. # df=df,
  68. # cat_col_names=cfg["cat_col_names"]
  69. #)
  70. df = ordinal_encoder(
  71. df=df,
  72. cat_col_names=cfg["cat_col_names"]
  73. )
  74. df = equal_freq_discretiser(
  75. df=df,
  76. num_col_names=cfg["num_col_names"]
  77. )
  78. df = variable_transformer(
  79. df=df,
  80. num_col_names=cfg["num_col_names"],
  81. variable_type="power_transformer"
  82. )
  83. df = censor_outliers(
  84. df=df,
  85. num_col_names=cfg["num_col_names"]
  86. )
  87. df = drop_constant_features(df)
  88. ###################
  89. # Train Test Split
  90. ###################
  91. train, test = df[df["type"]=="train"].drop(columns="type"), df[df["type"]=="test"].drop(columns="type")
  92. train, val, test = data_splitting(
  93. df=target_transformer(df=train, target=cfg["target_col_name"]),
  94. target=cfg["target_col_name"],
  95. n_splits=cfg["n_splits"],
  96. shuffle=cfg["shuffle"],
  97. random_state=cfg["SEED"]
  98. )
  99. ###################
  100. # Train and Evaluate
  101. ###################
  102. trainer = Trainer(
  103. model=get_model(),
  104. target=cfg["target_col_name"],
  105. model_path="./model",
  106. logs_path="./logs",
  107. random_state=cfg["SEED"]
  108. )
Tip!

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

Comments

Loading...