Bugfix: GranularMVFTS and ClusteredMVFTS were not considering data transformations

This commit is contained in:
Petrônio Cândido 2020-01-27 12:09:54 -03:00
parent 94499f0f21
commit 783a77ec0f
2 changed files with 18 additions and 8 deletions

View File

@ -50,7 +50,9 @@ class ClusteredMVFTS(mvfts.MVFTS):
self.model = self.fts_method(partitioner=self.partitioner, **self.fts_params)
ndata = self.check_data(data)
ndata = self.apply_transformations(data)
ndata = self.check_data(ndata)
self.model.train(ndata, fuzzyfied=self.pre_fuzzyfy)
@ -64,13 +66,20 @@ class ClusteredMVFTS(mvfts.MVFTS):
return ndata
def forecast(self, ndata, **kwargs):
def forecast(self, data, **kwargs):
ndata = self.check_data(ndata)
ndata1 = self.apply_transformations(data)
ndata = self.check_data(ndata1)
pre_fuzz = kwargs.get('pre_fuzzyfy', self.pre_fuzzyfy)
return self.model.forecast(ndata, fuzzyfied=pre_fuzz, **kwargs)
ret = self.model.forecast(ndata, fuzzyfied=pre_fuzz, **kwargs)
ret = self.target_variable.apply_inverse_transformations(ret,
params=data[self.target_variable.data_label].values)
return ret
def forecast_interval(self, data, **kwargs):

View File

@ -74,6 +74,7 @@ dataset['data'] = pd.to_datetime([str(y)+'-'+str(m) for y,m in zip(dataset['Ano'
format='%Y-%m')
roi = Transformations.ROI()
'''
train = dataset['Total'].values[:30]
test = dataset['Total'].values[30:]
@ -96,7 +97,7 @@ ax.plot(test)
train = dataset.iloc[:30]
test = dataset.iloc[30:]
from pyFTS.models.multivariate import common, variable, mvfts, wmvfts
from pyFTS.models.multivariate import common, variable, mvfts, wmvfts, granular
from pyFTS.partitioners import Grid, Entropy
from pyFTS.models.seasonal.common import DateTime
from pyFTS.models.seasonal import partitioner as seasonal
@ -106,16 +107,16 @@ vmonth = variable.Variable("Month", data_label="data", partitioner=seasonal.Time
data=train, partitioner_specific=sp)
vtur = variable.Variable("Turistas", data_label="Total", alias='tur',
partitioner=Grid.GridPartitioner, npart=10, transformation=roi,
partitioner=Grid.GridPartitioner, npart=20, transformation=roi,
data=train)
model = wmvfts.WeightedMVFTS(explanatory_variables=[vmonth, vtur], target_variable=vtur)
#model = wmvfts.WeightedMVFTS(explanatory_variables=[vmonth, vtur], target_variable=vtur)
model = granular.GranularWMVFTS(explanatory_variables=[vmonth, vtur], target_variable=vtur, order=2, knn=1)
model.fit(train)
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[10,5])
ax.plot(test['Total'].values)
'''
forecast = model.predict(test)