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

data_split.py 831 B

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
  1. import hydra
  2. import pandas as pd
  3. from omegaconf.omegaconf import OmegaConf
  4. from typing import Text
  5. from sklearn.model_selection import train_test_split
  6. @hydra.main(config_path="../configs", config_name="configs")
  7. def data_split(cfg: Text) -> None:
  8. OmegaConf.to_yaml(cfg, resolve=True)
  9. """Split dataset into train/test.
  10. Args:
  11. cfg {Text}: path to config
  12. """
  13. dataset = pd.read_csv(cfg.train.dataset_csv)
  14. train_dataset, test_dataset = train_test_split(
  15. dataset,
  16. test_size=cfg.train.test_size,
  17. random_state=cfg.train.random_state
  18. )
  19. train_csv_path = cfg.train.trainset_path
  20. test_csv_path = cfg.train.testset_path
  21. train_dataset.to_csv(train_csv_path, index=False)
  22. test_dataset.to_csv(test_csv_path, index=False)
  23. if __name__ == '__main__':
  24. data_split()
Tip!

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

Comments

Loading...