当前位置: 首页>>代码示例>>Python>>正文


Python TimeSeries.from_twodim_list方法代码示例

本文整理汇总了Python中pycast.common.timeseries.TimeSeries.from_twodim_list方法的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries.from_twodim_list方法的具体用法?Python TimeSeries.from_twodim_list怎么用?Python TimeSeries.from_twodim_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycast.common.timeseries.TimeSeries的用法示例。


在下文中一共展示了TimeSeries.from_twodim_list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: double_initialize_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def double_initialize_test(self):
        """Test for the error ocuring when the same error measure is initialized twice."""
        data   = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]]
        tsOrg  = TimeSeries.from_twodim_list(data)
        tsCalc = TimeSeries.from_twodim_list(data)


        bem = BaseErrorMeasure()

        bem_calculate  = bem._calculate
        bem_local_error = bem.local_error
        
        def return_zero(ignoreMe, ignoreMeToo):
            return 0

        ## remove the NotImplementedErrors for initialization
        bem.local_error = return_zero
        bem._calculate   = return_zero
        
        ## correct initialize call
        bem.initialize(tsOrg, tsCalc)

        ## incorrect initialize call
        for cnt in xrange(10):
            try:
                bem.initialize(tsOrg, tsCalc)        
            except StandardError:
                pass
            else:
                assert False    # pragma: no cover

        bem.local_error = bem_calculate
        bem._calculate   = bem_local_error
开发者ID:744996162,项目名称:ali_match,代码行数:35,代码来源:errormeasuretest.py

示例2: smoothing_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def smoothing_test(self):
        """Test smoothing part of ExponentialSmoothing."""
        data  = [[0, 10.0], [1, 18.0], [2, 29.0], [3, 15.0], [4, 30.0], [5, 30.0], [6, 12.0], [7, 16.0]]
        tsSrc = TimeSeries.from_twodim_list(data)
        tsSrc.normalize("second")

        ## Initialize a correct result.
        ### The numbers look a little bit odd, based on the binary translation problem
        data  = [[1.5, 10.0],[2.5, 12.4],[3.5, 17.380000000000003],[4.5, 16.666],[5.5, 20.6662],[6.5, 23.46634],[7.5, 20.026438]]
        tsDst = TimeSeries.from_twodim_list(data)

        ## Initialize the method
        es = ExponentialSmoothing(0.3, 0)
        res = tsSrc.apply(es)

        if not res == tsDst: raise AssertionError

        data.append([8.5, 18.8185066])
        tsDst = TimeSeries.from_twodim_list(data)

        ## Initialize the method
        es = ExponentialSmoothing(0.3)
        res = tsSrc.apply(es)

        if not res == tsDst: raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:27,代码来源:methodtest.py

示例3: start_and_enddate_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def start_and_enddate_test(self):
        """Testing for startDate, endDate exceptions."""
        data   = [[0.0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]]
        tsOrg  = TimeSeries.from_twodim_list(data)
        tsCalc = TimeSeries.from_twodim_list(data)

        bem = MeanSquaredError()
        bem.initialize(tsOrg, tsCalc)

        for startDate in [0.0, 1, 2, 3]:
            bem.get_error(startDate=startDate, endDate=4)

        for endDate in [1, 2, 3, 4]:
            bem.get_error(startDate=0.0, endDate=endDate)

        try:
            bem.get_error(startDate=23)
        except ValueError:
            pass
        else:
            assert False    # pragma: no cover

        try:
            bem.get_error(endDate=-1)
        except ValueError:
            pass
        else:
            assert False    # pragma: no cover
开发者ID:744996162,项目名称:ali_match,代码行数:30,代码来源:errormeasuretest.py

示例4: test_confidence_interval

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def test_confidence_interval(self):
        """
        Test if given two timeseries and a desired confidence interval,
        regression gives us the correct over and underestimation.
        """
        data_x = zip(range(100), range(100))
        overestimations  = [[90, 90 - 1], [91, 91 - 3], [92, 92 - 1], [93, 93 - 40], [94, 94 - 1]]
        underestimations = [[95, 95 + 5], [96, 96 + 1 ], [97,97 + 4], [98, 98 + 3], [99, 99 + 1]]
        data_y = data_x[:90] + overestimations + underestimations

        ts_x = TimeSeries.from_twodim_list(data_x)
        ts_y = TimeSeries.from_twodim_list(data_y)

        #Mock the random.sample method so that we can use our outliers as samples
        with patch('pycast.common.timeseries.random.sample') as sample_mock:
            sample_mock.return_value = underestimations+overestimations

            reg = Regression()
            n, m, error = reg.calculate_parameters_with_confidence(ts_x, ts_y, .6)

            #Since all values are the same the params should be n=0, m=1
            self.assertEquals(0,n)
            self.assertEquals(1,m)

            #assert under/overestimation
            self.assertEquals(error[0], -1)
            self.assertEquals(error[1], 3)
开发者ID:T-002,项目名称:pycast,代码行数:29,代码来源:regressiontest.py

示例5: initialization_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def initialization_test(self):
        """Test for MASE initialization."""
        dataOrg = [[1.0, 10], [2.0, 12], [3.0, 14], [4.0, 13], [5.0, 17], [6.0, 20], [7.0, 23], [8.0, 26], [9.0, 29], [10.0, 31], [11.0, 26], [12.0, 21], [13.0, 18], [14.0, 14], [15.0, 13], [16.0, 19], [17.0, 24], [18.0, 28], [19.0, 30], [20.0, 32]]
        dataFor = [[1.0, 11], [2.0, 13], [3.0, 14], [4.0, 11], [5.0, 13], [6.0, 18], [7.0, 20], [8.0, 26], [9.0, 21], [10.0, 34], [11.0, 23], [12.0, 23], [13.0, 15], [14.0, 12], [15.0, 14], [16.0, 17], [17.0, 25], [18.0, 22], [19.0, 14], [20.0, 30]]
        
        tsOrg = TimeSeries.from_twodim_list(dataOrg)
        tsFor = TimeSeries.from_twodim_list(dataFor)

        em = MeanAbsoluteScaledError(historyLength=5)
        em.initialize(tsOrg, tsFor)

        assert len(em._errorValues) == len(em._historicMeans), "For each error value an historic mean has to exsist."

        try:
            em.initialize(tsOrg, tsFor)
        except StandardError:
            pass
        else:
            assert False    # pragma: no cover

        em = MeanAbsoluteScaledError(historyLength=20.0)
        em.initialize(tsOrg, tsFor)

        assert len(em._errorValues) == len(em._historicMeans), "For each error value an historic mean has to exsist."
        assert em._historyLength == 4, "The history is %s entries long. 4 were expected." % em._historyLength

        em = MeanAbsoluteScaledError(historyLength=40.0)
        em.initialize(tsOrg, tsFor)

        assert len(em._errorValues) == len(em._historicMeans), "For each error value an historic mean has to exsist."
        assert em._historyLength == 8, "The history is %s entries long. 8 were expected." % em._historyLength
开发者ID:744996162,项目名称:ali_match,代码行数:33,代码来源:errormeasuretest.py

示例6: calculate_parameters_one_empty_list_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def calculate_parameters_one_empty_list_test(self):
        """Test for ValueError if one Timeseries are empty"""
        tsOne = TimeSeries.from_twodim_list([[1, 12.34]])
        tsTwo = TimeSeries.from_twodim_list([])

        reg = Regression()
        self.assertRaises(ValueError, reg.calculate_parameters, tsOne, tsTwo)
开发者ID:T-002,项目名称:pycast,代码行数:9,代码来源:regressiontest.py

示例7: timeseries___setitem___test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def timeseries___setitem___test(self):
        """Test TimeSeries.__setitem__"""
        data  = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        tsOne = TimeSeries.from_twodim_list(data)
        tsTwo = TimeSeries.from_twodim_list(data)

        tsTwo[1] = [0.2, 0.4]
        if tsOne == tsTwo: raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:10,代码来源:timeseriesmiscellaneoustest.py

示例8: list_serialization_formatfree_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def list_serialization_formatfree_test(self):
        """Test the format free list serialization."""
        data = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        tsOne = TimeSeries.from_twodim_list(data)

        data = tsOne.to_twodim_list()
        tsTwo = TimeSeries.from_twodim_list(data)

        assert tsOne == tsTwo
开发者ID:fleupold,项目名称:pycast,代码行数:11,代码来源:timeseriesmiscellaneoustest.py

示例9: calculate_parameter_duplicate_dates_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def calculate_parameter_duplicate_dates_test(self):
        """Test for ValueError if dates in timeseries are not distinct"""
        # Initialize input
        data1 = [[1, 12.23], [4, 23.34]]
        data2 = [[1, 34.23], [1, 16.23]]
        tsSrc1 = TimeSeries.from_twodim_list(data1)
        tsSrc2 = TimeSeries.from_twodim_list(data2)

        reg = Regression()
        self.assertRaises(ValueError, reg.calculate_parameters, tsSrc1, tsSrc2)
开发者ID:T-002,项目名称:pycast,代码行数:12,代码来源:regressiontest.py

示例10: list_serialization_format_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def list_serialization_format_test(self):
        """Test the list serialization including time foramtting instructions."""
        data = [[0.0, 0.0], [1.0, 0.1], [2.0, 0.2], [3.0, 0.3], [4.0, 0.4], [5.0, 0.5]]
        tsOne = TimeSeries.from_twodim_list(data)

        tsOne.set_timeformat("%Y-%m-%d_%H:%M:%S")
        data = tsOne.to_twodim_list()
        tsTwo = TimeSeries.from_twodim_list(data, format="%Y-%m-%d_%H:%M:%S")

        assert tsOne == tsTwo
开发者ID:fleupold,项目名称:pycast,代码行数:12,代码来源:timeseriesmiscellaneoustest.py

示例11: calculate_parameter_with_short_timeseries_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def calculate_parameter_with_short_timeseries_test(self):
        """Test for ValueError if Timeseries has only one matching date"""
        # Initialize input
        data1 = [[1, 12.23], [4, 23.34]]
        data2 = [[1, 34.23]]
        tsSrc1 = TimeSeries.from_twodim_list(data1)
        tsSrc2 = TimeSeries.from_twodim_list(data2)

        reg = Regression()
        self.assertRaises(ValueError, reg.calculate_parameters, tsSrc1, tsSrc2)
开发者ID:T-002,项目名称:pycast,代码行数:12,代码来源:regressiontest.py

示例12: forecasting_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def forecasting_test(self):
        data = [362.0, 385.0, 432.0, 341.0, 382.0, 409.0, 498.0, 387.0, 473.0, 513.0, 582.0, 474.0, 544.0, 582.0, 681.0, 557.0, 628.0, 707.0, 773.0, 592.0, 627.0, 725.0, 854.0, 661.0]
        tsSrc = TimeSeries.from_twodim_list(zip(range(len(data)),data))
        expected = [[0.0, 362.0],[1.0, 379.93673257607463],[2.0, 376.86173719924875],[3.0, 376.0203652542205],[4.0, 408.21988583215574],[5.0, 407.16235446485433],[6.0, 430.0950666716297],[7.0, 429.89797609228435],[8.0, 489.4888959723074],[9.0, 507.8407281475308],[10.0, 506.3556647249702],[11.0, 523.9422448655133],[12.0, 556.0311543025242],[13.0, 573.6520991970604],[14.0, 590.2149136780341],[15.0, 611.8813425659495],[16.0, 637.0393967524727],[17.0, 684.6600411792656],[18.0, 675.9589298142507],[19.0, 659.0266828674846],[20.0, 644.0903317144154],[21.0, 690.4507762388047],[22.0, 735.3219292023371],[23.0, 737.9752345691215],[24.0, 669.767091965978],[25.0, 737.5272444120604],[26.0, 805.3947787747426],[27.0, 902.1522777060334]]

        hwm = HoltWintersMethod(.7556, 0.0000001, .9837, 4, valuesToForecast = 4)
        res = tsSrc.apply(hwm)

        #print res
        assert len(res) == len(tsSrc) + 4
        assert res == TimeSeries.from_twodim_list(expected)
开发者ID:fleupold,项目名称:pycast,代码行数:13,代码来源:methodtest.py

示例13: calculate_parameters_without_match_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def calculate_parameters_without_match_test(self):
        """Test for ValueError, if the input timeseries have no macthing dates"""
        # Initialize input
        data1  = [[1, 12.42], [6, 12.32], [8, 12.45]]
        data2  = [[2, 32.45], [4, 23.12], [7, 65.34]]
        tsOne = TimeSeries.from_twodim_list(data1)
        tsTwo = TimeSeries.from_twodim_list(data2)

        reg = Regression()

        self.assertRaises(ValueError, reg.calculate_parameters, tsOne, tsTwo)
开发者ID:T-002,项目名称:pycast,代码行数:13,代码来源:regressiontest.py

示例14: normalize_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def normalize_test(self):
        """Test timeseries normalization."""
        dataOne = [[0.0, 0.0], [1.0, 1.0], [2.0, 2.0], [5.1, 5.0]]
        dataTwo = [[0.5, 0.0], [1.5, 1.0], [2.5, 2.0], [3.5, 3.0], [4.5, 4.0], [5.5, 5.0]]

        tsOne   = TimeSeries.from_twodim_list(dataOne)
        tsTwo   = TimeSeries.from_twodim_list(dataTwo)
        
        tsOne.normalize("second")

        if not len(tsOne) == len(tsTwo): raise AssertionError
        if not tsOne == tsTwo:           raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:14,代码来源:timeseriesmiscellaneoustest.py

示例15: addition_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import from_twodim_list [as 别名]
    def addition_test(self):
        """Test the addition operator for TimeSeries instances."""
        dataOne = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        dataTwo = [[0.0, 0.0], [0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]
        dataThree = dataOne + dataTwo
        dataThree.sort(key=lambda item:item[0])

        tsOne = TimeSeries.from_twodim_list(dataOne)
        tsTwo = TimeSeries.from_twodim_list(dataTwo)
        tsThree = TimeSeries.from_twodim_list(dataThree)

        if not tsThree == tsOne + tsTwo: raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:14,代码来源:timeseriesmiscellaneoustest.py


注:本文中的pycast.common.timeseries.TimeSeries.from_twodim_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。