def test_model(hndl_Test, tickers, responseIdx): model = lib_Model.EMF_RegressionDecisionTree() for (i, t) in enumerate(tickers): if i == responseIdx: respVar = hndl_Test.retrieve_test_word(t,'None') model.add_response_variable(respVar) else: model.add_predictor_variable(hndl_Test.retrieve_test_word(t,'None')) model.train_model() plot_data_series(respVar, model)
def test_Current_Level_Cat_pattern(data, hndl_Time): hndl_Srs = EMF_TestSeries_Handle() hndl_Srs.values = data hndl_Srs.dates = hndl_Time.get_dates() trns_kwargs = {NUM_RANGES:10, FIRST_ORDER_DIFF_TIME:10} hndl_Trns = EMF_Transformation_Handle('Futr_Lvl_Cat', trnsKwargs=trns_kwargs) trns_data = hndl_Trns.transform_data(data) hndl_Trns.transform_time(hndl_Time) hndl_Srs_Trns = EMF_TestSeries_Handle() hndl_Srs_Trns.values = trns_data hndl_Srs_Trns.dates = hndl_Time.get_dates() utl_Tst.plot_data_series(hndl_Srs, hndl_Srs_Trns) raise NotImplementedError
def plot_values(self, hndl_Word): ''' Plot the raw data, predicted data, and smoothed data (For testing) ''' from util_Testing import plot_data_series from handle_TestSeries import EMF_TestSeries_Handle raw_key = raw_word_key(hndl_Word) prd_key = prd_word_key(hndl_Word) raw = EMF_TestSeries_Handle() (raw.dates, raw.values) = self.get_values_by_col(raw_key, filter_nulls=True) prd = EMF_TestSeries_Handle() (prd.dates, prd.values) = self.get_values_by_col(prd_key, filter_nulls=True) smooth = EMF_TestSeries_Handle() smooth.values = savitzky_golay(np.array(prd.values)) smooth.dates = prd.dates plot_data_series(raw, prd, smooth)
def testTransformationReversal_Future_FoD(data, dt, hndl_Srs_Original): trnsKwargs={FIRST_ORDER_DIFF_TIME: 10} hndl_Trns = EMF_Transformation_Handle('Futr_Change', trnsKwargs=trnsKwargs) dt_trns = hndl_Trns.transform_time(dt) data_trns = hndl_Trns.transform_data(data) hndl_Srs_Trns = EMF_TestSeries_Handle() hndl_Srs_Trns.set_series_dates(dt_trns) hndl_Srs_Trns.set_series_values(data_trns) # utl_Tst.plot_data_series(hndl_Srs_Original, hndl_Srs_Trns) assert np.all(dt_trns == dt[:-10]) assert data_trns[0] == data[10] - data[00] dt_rvrs = hndl_Trns.reverse_transform_time(dt_trns) data_rvrs = hndl_Trns.reverse_transform_data(data[:-10], predictionDelta=data_trns) hndl_Srs_Rvrs = EMF_TestSeries_Handle() hndl_Srs_Rvrs.set_series_dates(dt_rvrs) hndl_Srs_Rvrs.set_series_values(data_rvrs) utl_Tst.plot_data_series(hndl_Srs_Original, hndl_Srs_Rvrs) assert np.all(dt_rvrs == dt[10:])
def testTransformationReversal_Past_Lvl(data, dt, hndl_Srs_Original): trnsKwargs={'PeriodDiff': 10} hndl_Trns = EMF_Transformation_Handle('Past_Lvl', trnsKwargs=trnsKwargs) dt_trns = hndl_Trns.transform_time(dt) data_trns = hndl_Trns.transform_data(data) hndl_Srs_Trns = EMF_TestSeries_Handle() hndl_Srs_Trns.set_series_dates(dt_trns) hndl_Srs_Trns.set_series_values(data_trns) # utl_Tst.plot_data_series(hndl_Srs_Original, hndl_Srs_Trns) assert np.all(dt_trns == dt[10:]) dt_rvrs = hndl_Trns.reverse_transform_time(dt_trns) data_rvrs = hndl_Trns.reverse_transform_data(data_trns) hndl_Srs_Rvrs = EMF_TestSeries_Handle() hndl_Srs_Rvrs.set_series_dates(dt_rvrs) hndl_Srs_Rvrs.set_series_values(data_rvrs) utl_Tst.plot_data_series(hndl_Srs_Original, hndl_Srs_Rvrs) assert np.all(dt_rvrs == dt[:-10]) assert np.all(data_rvrs == data[:-10])
def test_transformations(): hndl_Test = EMF_Testing_Handle(mode=TEMP_MODE) fn = create_test_data_linear_change (tickers, responseIdx) = save_test_data_fn(hndl_Test, fn, n=100) hndl_Data = EMF_DataSeries_Handle(hndl_Test.hndl_DB, ticker=tickers[0]) # hndl_Trns = EMF_Transformation_Handle('RateOfChange') # hndl_Trns.set_extra_parameter('PeriodDiff', 12) # hndl_Word = EMF_WordSeries_Handle(hndl_Test.hndl_DB, hndl_Data, hndl_Trns) # plot_data_series(hndl_Data, hndl_Word) # hndl_Trns = EMF_Transformation_Handle('RateOfChange_Cat') # hndl_Trns.set_extra_parameter('PeriodDiff', 12) # hndl_Word = EMF_WordSeries_Handle(hndl_Test.hndl_DB, hndl_Data, hndl_Trns) # plot_data_series(hndl_Data, hndl_Word) trnsKwargs = {'PeriodDiff': 10} hndl_Trns = EMF_Transformation_Handle('Futr_Change', trnsKwargs) hndl_Word_Chng = EMF_WordSeries_Handle(hndl_Test.hndl_DB, hndl_Data, hndl_Trns) # hndl_Trns = EMF_Transformation_Handle('Past_Lvl_NormRd',trnsKwargs) # hndl_Word_Acc = EMF_WordSeries_Handle(hndl_Test.hndl_DB, hndl_Data, hndl_Trns) plot_data_series(hndl_Data, hndl_Word_Chng)