PWFTS bugfix on Naïve forecast

This commit is contained in:
Petrônio Cândido 2019-11-07 16:03:52 -03:00
parent 4f693ea9bb
commit 517a715a1d
2 changed files with 34 additions and 5 deletions

View File

@ -247,7 +247,7 @@ class ProbabilisticWeightedFTS(ifts.IntervalFTS):
if flrg.get_key() in self.flrgs: if flrg.get_key() in self.flrgs:
return self.flrgs[flrg.get_key()].frequency_count / self.global_frequency_count return self.flrgs[flrg.get_key()].frequency_count / self.global_frequency_count
else: else:
return 0.0 return 1.0
#self.add_new_PWFLGR(flrg) #self.add_new_PWFLGR(flrg)
#return self.flrg_lhs_unconditional_probability(flrg) #return self.flrg_lhs_unconditional_probability(flrg)

View File

@ -16,13 +16,43 @@ from pyFTS.models.ensemble import ensemble
from pyFTS.common import Transformations, Membership, Util from pyFTS.common import Transformations, Membership, Util
from pyFTS.benchmarks import arima, quantreg, BSTS, gaussianproc, knn from pyFTS.benchmarks import arima, quantreg, BSTS, gaussianproc, knn
from pyFTS.fcm import fts, common, GA from pyFTS.fcm import fts, common, GA
from pyFTS.common import Transformations from pyFTS.common import Transformations
tdiff = Transformations.Differential(1) tdiff = Transformations.Differential(1)
boxcox = Transformations.BoxCox(0) 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.data import TAIEX, NASDAQ, SP500
from pyFTS.common import Util from pyFTS.common import Util
@ -45,18 +75,17 @@ from pyFTS.benchmarks import ResidualAnalysis as ra
ra.plot_residuals_by_model(test, [model]) ra.plot_residuals_by_model(test, [model])
horizon = 10 horizon = 10
'''
forecasts = model.predict(test[9:20], type='point') forecasts = model.predict(test[9:20], type='point')
intervals = model.predict(test[9:20], type='interval') intervals = model.predict(test[9:20], type='interval')
distributions = model.predict(test[9:20], type='distribution') distributions = model.predict(test[9:20], type='distribution')
forecasts = model.predict(test[9:20], type='point', steps_ahead=horizon) forecasts = model.predict(test[9:20], type='point', steps_ahead=horizon)
intervals = model.predict(test[9:20], type='interval', 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) #distributions = model.predict(test[9:20], type='distribution', steps_ahead=horizon)
'''
train = TAIEX.get_data()[:800] train = TAIEX.get_data()[:800]
test = TAIEX.get_data()[800:1000] test = TAIEX.get_data()[800:1000]