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.3 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
  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. # We choose all columns except the first, since that is where our labels are
  16. train_mean = train_data.values[:, 1:].mean()
  17. train_std = train_data.values[:, 1:].std()
  18. # Normalize train and test data according to the train data distribution
  19. train_data.values[:, 1:] -= train_mean
  20. train_data.values[:, 1:] /= train_std
  21. test_data.values[:, 1:] -= train_mean
  22. test_data.values[:, 1:] /= train_std
  23. print("done.")
  24. print("Saving processed datasets and normalization parameters...")
  25. # Save normalized data-sets
  26. np.save('./data/processed_train_data', train_data)
  27. np.save('./data/processed_test_data', test_data)
  28. # Save mean and std for future inference
  29. with open('./data/norm_params.json', 'w') as f:
  30. json.dump({'mean': train_mean, 'std': train_std}, f)
  31. print("done.")
  32. if __name__ == '__main__':
  33. featurization()
Tip!

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

Comments

Loading...