From 517a715a1d9fc6a25e0c504718dade5b2399dff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido?= Date: Thu, 7 Nov 2019 16:03:52 -0300 Subject: [PATCH] =?UTF-8?q?PWFTS=20bugfix=20on=20Na=C3=AFve=20forecast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyFTS/models/pwfts.py | 2 +- pyFTS/tests/general.py | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pyFTS/models/pwfts.py b/pyFTS/models/pwfts.py index 2f706bf..b3d381d 100644 --- a/pyFTS/models/pwfts.py +++ b/pyFTS/models/pwfts.py @@ -247,7 +247,7 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS): if flrg.get_key() in self.flrgs: return self.flrgs[flrg.get_key()].frequency_count / self.global_frequency_count else: - return 0.0 + return 1.0 #self.add_new_PWFLGR(flrg) #return self.flrg_lhs_unconditional_probability(flrg) diff --git a/pyFTS/tests/general.py b/pyFTS/tests/general.py index 830ed04..9b46860 100644 --- a/pyFTS/tests/general.py +++ b/pyFTS/tests/general.py @@ -16,13 +16,43 @@ from pyFTS.models.ensemble import ensemble from pyFTS.common import Transformations, Membership, Util from pyFTS.benchmarks import arima, quantreg, BSTS, gaussianproc, knn from pyFTS.fcm import fts, common, GA - from pyFTS.common import Transformations tdiff = Transformations.Differential(1) boxcox = Transformations.BoxCox(0) +df = pd.read_csv('https://query.data.world/s/l3u4gqbrbm5ymo6ghxl7jmxed7sgyk') +dados = df.iloc[2710:2960 , 0:1].values # somente a 1 coluna sera usada +dados = dados.flatten().tolist() + +qtde_dt_tr = 150 +dados_treino = dados[:qtde_dt_tr] + +#print(dados_treino) + +ttr = list(range(len(dados_treino))) + +ordem = 1 # ordem do modelo, indica quantos ultimos valores serao usados + +dados_teste = dados[qtde_dt_tr - ordem:250] +tts = list(range(len(dados_treino) - ordem, len(dados_treino) + len(dados_teste) - ordem)) + +particionador = Grid.GridPartitioner(data = dados_treino, npart = 30, func = Membership.trimf) + +modelo = pwfts.ProbabilisticWeightedFTS(partitioner = particionador, order = ordem) + +modelo.fit(dados_treino) + +print(modelo) + +# Todo o procedimento de inferência é feito pelo método predict +predicoes = modelo.predict(dados_teste[38:40]) + +print(predicoes) + + +''' from pyFTS.data import TAIEX, NASDAQ, SP500 from pyFTS.common import Util @@ -45,18 +75,17 @@ from pyFTS.benchmarks import ResidualAnalysis as ra ra.plot_residuals_by_model(test, [model]) horizon = 10 -''' + forecasts = model.predict(test[9:20], type='point') intervals = model.predict(test[9:20], type='interval') distributions = model.predict(test[9:20], type='distribution') forecasts = model.predict(test[9:20], type='point', steps_ahead=horizon) intervals = model.predict(test[9:20], type='interval', steps_ahead=horizon) -''' + #distributions = model.predict(test[9:20], type='distribution', steps_ahead=horizon) -''' train = TAIEX.get_data()[:800] test = TAIEX.get_data()[800:1000]