config.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import yaml
  16. from ..ts_base.config import BaseTSConfig
  17. from ....utils.misc import abspath
  18. class TSClassifyConfig(BaseTSConfig):
  19. """TS Classify Config"""
  20. def update_dataset(self, dataset_dir: str, dataset_type: str = None):
  21. """
  22. upadte the dataset
  23. Args:
  24. dataset_dir (str): dataset root path
  25. dataset_type (str, optional): type to set for dataset. Default='TSDataset'
  26. """
  27. if dataset_type is None:
  28. dataset_type = "TSCLSDataset"
  29. dataset_dir = abspath(dataset_dir)
  30. ds_cfg = self._make_custom_dataset_config(dataset_dir)
  31. self.update(ds_cfg)
  32. def update_basic_info(self, info_params: dict):
  33. """
  34. update basic info including time_col, freq, target_cols.
  35. Args:
  36. info_params (dict): upadte basic info
  37. Raises:
  38. TypeError: if info_params is not dict, raising TypeError
  39. """
  40. if isinstance(info_params, dict):
  41. self.update({"info_params": info_params})
  42. else:
  43. raise TypeError("`info_params` must be a dict.")
  44. def _make_custom_dataset_config(self, dataset_root_path: str):
  45. """construct the dataset config that meets the format requirements
  46. Args:
  47. dataset_root_path (str): the root directory of dataset.
  48. Returns:
  49. dict: the dataset config.
  50. """
  51. ds_cfg = {
  52. "dataset": {
  53. "name": "TSCLSDataset",
  54. "dataset_root": dataset_root_path,
  55. "train_path": os.path.join(dataset_root_path, "train.csv"),
  56. "val_path": os.path.join(dataset_root_path, "val.csv"),
  57. },
  58. }
  59. return ds_cfg