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


Python timeseries.TimeSeries类代码示例

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


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

示例1: smoothing_test

    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,代码行数:25,代码来源:methodtest.py

示例2: test_confidence_interval

    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,代码行数:27,代码来源:regressiontest.py

示例3: double_initialize_test

    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,代码行数:33,代码来源:errormeasuretest.py

示例4: start_and_enddate_test

    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,代码行数:28,代码来源:errormeasuretest.py

示例5: execute

    def execute(self, timeSeries):
        """Creates a new TimeSeries containing the SMA values for the predefined windowsize.

        :param TimeSeries timeSeries:    The TimeSeries used to calculate the simple moving average values.

        :return:    TimeSeries object containing the smooth moving average.
        :rtype:     TimeSeries

        :raise:   Raises a :py:exc:`ValueError` wif the defined windowsize is larger than the number of elements
            in timeSeries

        :note:    This implementation aims to support independent for loop execution.
        """
        windowsize    = self._parameters["windowsize"]

        if len (timeSeries) < windowsize:
            raise ValueError("windowsize is larger than the number of elements in timeSeries.")

        tsLength      = len(timeSeries)
        nbrOfLoopRuns = tsLength - windowsize + 1

        res = TimeSeries()
        for idx in xrange(nbrOfLoopRuns):
            end = idx + windowsize
            data = timeSeries[idx:end]

            timestamp = data[windowsize//2][0]
            value     = sum([i[1] for i in data])/windowsize

            res.add_entry(timestamp, value)

        res.sort_timeseries()
        return res
开发者ID:T-002,项目名称:pycast,代码行数:33,代码来源:simplemovingaverage.py

示例6: calculate_parameters_one_empty_list_test

    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,代码行数:7,代码来源:regressiontest.py

示例7: initialization_test

    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,代码行数:31,代码来源:errormeasuretest.py

示例8: train_target

 def train_target(self, data_list, model_list):# data_list: [date, value]
     orig = TimeSeries(isNormalized=True)
     for i in range(len(data_list)):
         orig.add_entry(data_list[i][0], data_list[i][1])
     gridSearch = GridSearch(SMAPE)
     optimal_forecasting, error, optimal_params = gridSearch.optimize(orig, model_list)
     #print "======" + str(optimal_forecasting._parameters)
     return optimal_forecasting
开发者ID:THUIR,项目名称:TianchiCompetition,代码行数:8,代码来源:pycast_predictor.py

示例9: timeseries___setitem___test

    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,代码行数:8,代码来源:timeseriesmiscellaneoustest.py

示例10: energy_data

def energy_data(request):
	"""
		Connects to the database and loads Readings for device 8.
	"""
	cur = db.cursor().execute("""SELECT timestamp, current FROM Readings""")
	original = TimeSeries()
	original.initialize_from_sql_cursor(cur)
	original.normalize("day", fusionMethod = "sum")
	return Response(json.dumps(original, cls=PycastEncoder), content_type='application/json') 
开发者ID:fleupold,项目名称:pycast,代码行数:9,代码来源:server.py

示例11: list_serialization_formatfree_test

    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,代码行数:9,代码来源:timeseriesmiscellaneoustest.py

示例12: calculate_parameter_duplicate_dates_test

    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,代码行数:10,代码来源:regressiontest.py

示例13: calculate_parameter_with_short_timeseries_test

    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,代码行数:10,代码来源:regressiontest.py

示例14: timeseries_sort_test

    def timeseries_sort_test(self):
        """Tests the sort_timeseries function."""
        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]]
        ts   = TimeSeries.from_twodim_list(data)
        
        ts.sort_timeseries()
        ts.sort_timeseries(False)

        ts = TimeSeries(isSorted=True)
        ts.sort_timeseries()
开发者ID:fleupold,项目名称:pycast,代码行数:10,代码来源:timeseriesmiscellaneoustest.py

示例15: list_serialization_format_test

    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,代码行数:10,代码来源:timeseriesmiscellaneoustest.py


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