You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_SimpleExponentialSmoothing.py 2.7 kB

first commit Former-commit-id: 08bc23ba02cffbce3cf63962390a65459a132e48 [formerly 0795edd4834b9b7dc66db8d10d4cbaf42bbf82cb] [formerly b5010b42541add7e2ea2578bf2da537efc457757 [formerly a7ca09c2c34c4fc8b3d8e01fcfa08eeeb2cae99d]] [formerly 615058473a2177ca5b89e9edbb797f4c2a59c7e5 [formerly 743d8dfc6843c4c205051a8ab309fbb2116c895e] [formerly bb0ea98b1e14154ef464e2f7a16738705894e54b [formerly 960a69da74b81ef8093820e003f2d6c59a34974c]]] [formerly 2fa3be52c1b44665bc81a7cc7d4cea4bbf0d91d5 [formerly 2054589f0898627e0a17132fd9d4cc78efc91867] [formerly 3b53730e8a895e803dfdd6ca72bc05e17a4164c1 [formerly 8a2fa8ab7baf6686d21af1f322df46fd58c60e69]] [formerly 87d1e3a07a19d03c7d7c94d93ab4fa9f58dada7c [formerly f331916385a5afac1234854ee8d7f160f34b668f] [formerly 69fb3c78a483343f5071da4f7e2891b83a49dd18 [formerly 386086f05aa9487f65bce2ee54438acbdce57650]]]] Former-commit-id: a00aed8c934a6460c4d9ac902b9a74a3d6864697 [formerly 26fdeca29c2f07916d837883983ca2982056c78e] [formerly 0e3170d41a2f99ecf5c918183d361d4399d793bf [formerly 3c12ad4c88ac5192e0f5606ac0d88dd5bf8602dc]] [formerly d5894f84f2fd2e77a6913efdc5ae388cf1be0495 [formerly ad3e7bc670ff92c992730d29c9d3aa1598d844e8] [formerly 69fb3c78a483343f5071da4f7e2891b83a49dd18]] Former-commit-id: 3c19c9fae64f6106415fbc948a4dc613b9ee12f8 [formerly 467ddc0549c74bb007e8f01773bb6dc9103b417d] [formerly 5fa518345d958e2760e443b366883295de6d991c [formerly 3530e130b9fdb7280f638dbc2e785d2165ba82aa]] Former-commit-id: 9f5d473d42a435ec0d60149939d09be1acc25d92 [formerly be0b25c4ec2cde052a041baf0e11f774a158105d] Former-commit-id: 9eca71cb73ba9edccd70ac06a3b636b8d4093b04
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import unittest
  2. from d3m import container, utils
  3. from d3m.metadata import base as metadata_base
  4. from timeseries_processing import SimpleExponentialSmoothing
  5. import pandas as pd
  6. class SimpleExponentialSmoothingTestCase(unittest.TestCase):
  7. def test_basic(self):
  8. main = container.DataFrame({'timestamp': [20201, 20202, 20203], 'value_0': [100,200,300],}, {
  9. 'top_level': 'main',
  10. }, generate_metadata=True)
  11. self.assertEqual(utils.to_json_structure(main.metadata.to_internal_simple_structure()), [{
  12. 'selector': [],
  13. 'metadata': {
  14. 'top_level': 'main',
  15. 'schema': metadata_base.CONTAINER_SCHEMA_VERSION,
  16. 'structural_type': 'd3m.container.pandas.DataFrame',
  17. 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/Table'],
  18. 'dimension': {
  19. 'name': 'rows',
  20. 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularRow'],
  21. 'length': 3,
  22. },
  23. },
  24. }, {
  25. 'selector': ['__ALL_ELEMENTS__'],
  26. 'metadata': {
  27. 'dimension': {
  28. 'name': 'columns',
  29. 'semantic_types': ['https://metadata.datadrivendiscovery.org/types/TabularColumn'],
  30. 'length': 2,
  31. },
  32. },
  33. }, {
  34. 'selector': ['__ALL_ELEMENTS__', 0],
  35. 'metadata': {'structural_type': 'numpy.int64', 'name': 'timestamp'},
  36. }, {
  37. 'selector': ['__ALL_ELEMENTS__', 1],
  38. 'metadata': {'structural_type': 'numpy.int64', 'name': 'value_0'},
  39. }])
  40. hyperparams_class = SimpleExponentialSmoothing.SimpleExponentialSmoothing.metadata.get_hyperparams()
  41. primitive = SimpleExponentialSmoothing.SimpleExponentialSmoothing(hyperparams=hyperparams_class.defaults())
  42. # primitive.set_training_data(inputs=main)
  43. # primitive.fit()
  44. output_main = primitive.produce(inputs=main).value
  45. # new_main_drop = new_main.iloc[2:]
  46. # new_main_drop = new_main_drop.reset_index(drop = True)
  47. print ( "output", output_main)
  48. expected_result = container.DataFrame(data = { 'timestamp' : [20201,20202,20203], 'value_0': [100,100,120]})
  49. print ("expected_result", expected_result)
  50. # output_main.reset_index()
  51. self.assertEqual(output_main[['timestamp','value_0_simple_exponential_smoothing']].values.tolist(), expected_result[['timestamp','value_0']].values.tolist())
  52. params = primitive.get_params()
  53. primitive.set_params(params=params)
  54. if __name__ == '__main__':
  55. unittest.main()

全栈的自动化机器学习系统,主要针对多变量时间序列数据的异常检测。TODS提供了详尽的用于构建基于机器学习的异常检测系统的模块,它们包括:数据处理(data processing),时间序列处理( time series processing),特征分析(feature analysis),检测算法(detection algorithms),和强化模块( reinforcement module)。这些模块所提供的功能包括常见的数据预处理、时间序列数据的平滑或变换,从时域或频域中抽取特征、多种多样的检测算