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

featurization.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
  1. """
  2. Create feature CSVs for train and test datasets
  3. """
  4. import json
  5. import numpy as np
  6. import pandas as pd
  7. def featurization():
  8. # Load data-sets
  9. print("Loading data sets...")
  10. train_data = pd.read_csv('./data/train_data.csv', header=None, dtype=float)
  11. test_data = pd.read_csv('./data/test_data.csv', header=None, dtype=float)
  12. print("done.")
  13. # Normalize the train data
  14. print("Normalizing data...")
  15. print(np.mean(train_data.head(2).mean()))
  16. # We choose all columns except the first, since that is where our labels are
  17. train_mean = np.mean(train_data.loc[:, 1:].mean())
  18. train_std = np.std(train_data.values[:, 1:])
  19. #print("{} -- ".format(train_mean ))
  20. # Normalize train and test data according to the train data distribution
  21. train_data.values[:, 1:] -= train_mean
  22. #train_data.values[:, 1:] /= train_std
  23. test_data.values[:, 1:] -= train_mean
  24. #test_data.values[:, 1:] /= train_std
  25. #print(train_data.values[0 :1, :])
  26. print("done.")
  27. print("Saving processed datasets and normalization parameters...")
  28. # Save normalized data-sets
  29. np.save('./data/processed_train_data', train_data)
  30. np.save('./data/processed_test_data', test_data)
  31. # Save mean and std for future inference
  32. with open('./data/norm_params.json', 'w') as f:
  33. json.dump({'mean': train_mean}, f)
  34. print("done.")
  35. if __name__ == '__main__':
  36. featurization()
Tip!

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

Comments

Loading...