From 61707f94a66db3ef4c055e0487b5ed75e426ecf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Sun, 23 Jun 2019 11:07:34 -0300 Subject: [PATCH] Small bugfix in pwfts.forecast_ahead_distribution --- pyFTS/models/pwfts.py | 5 ++++- pyFTS/tests/ensemble.py | 42 +++++++++++++++++------------------------ 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/pyFTS/models/pwfts.py b/pyFTS/models/pwfts.py index 7fdff2a..d0aad02 100644 --- a/pyFTS/models/pwfts.py +++ b/pyFTS/models/pwfts.py @@ -541,7 +541,10 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): start = kwargs.get('start_at', 0) - fuzzyfied = kwargs.pop('fuzzyfied') + if 'fuzzyfied' in kwargs: + fuzzyfied = kwargs.pop('fuzzyfied') + else: + fuzzyfied = False sample = data[start: start + self.max_lag] diff --git a/pyFTS/tests/ensemble.py b/pyFTS/tests/ensemble.py index 4ccc2cd..c58c8b7 100644 --- a/pyFTS/tests/ensemble.py +++ b/pyFTS/tests/ensemble.py @@ -18,39 +18,31 @@ from pyFTS.models.ensemble import ensemble from pyFTS.models import hofts from pyFTS.data import TAIEX -data = TAIEX.get_data() +from pyFTS.data import TAIEX, NASDAQ, SP500 +from pyFTS.common import Util +train = TAIEX.get_data()[1000:1800] +test = TAIEX.get_data()[1800:2000] +from pyFTS.models import hofts -model1 = ensemble.SimpleEnsembleFTS() +model = ensemble.SimpleEnsembleFTS( + fts_method=hofts.WeightedHighOrderFTS, + orders=[1, 2, 3], + partitions=np.arange(10,50,5) +) -from pyFTS.benchmarks import arima, quantreg, BSTS - -methods = [ensemble.SimpleEnsembleFTS, arima.ARIMA, quantreg.QuantileRegression, BSTS.ARIMA] -parameters = [{},{'order': (2,0,0)}, {'order': 1, 'dist': True}, {'order': (2,0,0)}] - - -from pyFTS.benchmarks import Measures - -horizon = 5 - -for ct, train, test, in Util.sliding_window(data,1000,0.8,.5): - print('data window {}'.format(ct)) - for ct, method in enumerate(methods): - model = method(**parameters[ct]) - model.fit(train) - start = model.order + 1 - end = start + horizon - intervals = model.predict(test[:10], type='interval', alpha=.25, steps_ahead=horizon) - distributions = model.predict(test[:10], type='distribution', smooth='histogram', steps_ahead=horizon, num_bins=100) - print(model.name, Measures.get_interval_ahead_statistics(test[start:end], intervals)) - print(model.name, Measures.get_distribution_ahead_statistics(test[start:end], distributions)) - -print('end') +model.fit(train) +horizon=10 +intervals05 = model.predict(test[:horizon], type='interval', alpha=.05) +print(intervals05) +intervals25 = model.predict(test[:horizon], type='interval', alpha=.25) +print(intervals25) +distributions = model.predict(test[:horizon], type='distribution', smooth='histogram', num_bins=100)