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

normalize.py 1.9 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
  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2021. Jeffrey J. Nirschl. All rights reserved.
  3. #
  4. # Licensed under the MIT license. See the LICENSE.md file in the project
  5. # root directory for full license information.
  6. #
  7. # Time-stamp: <>
  8. # ======================================================================
  9. import argparse
  10. import os
  11. from pathlib import Path
  12. from src.data import load_data, load_params, save_as_csv
  13. def main(train_path, test_path,
  14. output_dir):
  15. """Normalize data"""
  16. output_dir = Path(output_dir).resolve()
  17. assert (os.path.isdir(output_dir)), NotADirectoryError
  18. # set vars
  19. norm_method = {"min_max", "z_score"}
  20. # load data
  21. train_df, test_df = load_data([train_path, test_path], sep=",", header=0,
  22. index_col="PassengerId")
  23. # load params
  24. params = load_params()
  25. # optionally normalize data
  26. if params["normalize"] in norm_method:
  27. # TODO add function to normalize data
  28. raise NotImplementedError
  29. # save data
  30. save_as_csv([train_df, test_df],
  31. [train_path, test_path],
  32. output_dir,
  33. replace_text="_featurized.csv",
  34. suffix="_processed.csv",
  35. na_rep="nan")
  36. if __name__ == '__main__':
  37. parser = argparse.ArgumentParser()
  38. parser.add_argument("-tr", "--train", dest="train_path",
  39. required=True, help="Train CSV file")
  40. parser.add_argument("-te", "--test", dest="test_path",
  41. required=True, help="Test CSV file")
  42. parser.add_argument("-o", "--out-dir", dest="output_dir",
  43. default=Path("./data/processed").resolve(),
  44. required=False, help="output directory")
  45. args = parser.parse_args()
  46. # convert categorical variables into integer codes
  47. main(args.train_path, args.test_path,
  48. args.output_dir)
Tip!

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

Comments

Loading...