Bugfix in Transformations.ROI
This commit is contained in:
parent
ce312220d9
commit
94499f0f21
@ -250,9 +250,7 @@ class ROI(Transformation):
|
|||||||
return modified
|
return modified
|
||||||
|
|
||||||
def inverse(self, data, param=None, **kwargs):
|
def inverse(self, data, param=None, **kwargs):
|
||||||
modified = [param[0]]
|
modified = [(param[i - 1] * data[i]) + param[i - 1] for i in np.arange(1, len(data))]
|
||||||
for i in np.arange(1, len(data)):
|
|
||||||
modified.append((modified[i - 1] * data[i]) + modified[i - 1])
|
|
||||||
return modified
|
return modified
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ detrend = trend.apply(data)
|
|||||||
plt.plot(trend.inverse(detrend, data, date_offset=pd.DateOffset(months=1)))
|
plt.plot(trend.inverse(detrend, data, date_offset=pd.DateOffset(months=1)))
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
'''
|
||||||
data = Enrollments.get_dataframe()
|
data = Enrollments.get_dataframe()
|
||||||
|
|
||||||
trend = Transformations.LinearTrend(data_field='Enrollments', index_field='Year')
|
trend = Transformations.LinearTrend(data_field='Enrollments', index_field='Year')
|
||||||
@ -67,8 +67,64 @@ plt.plot(trend.trend(data)) #)
|
|||||||
detrend = trend.apply(data)
|
detrend = trend.apply(data)
|
||||||
|
|
||||||
plt.plot(trend.inverse(detrend, data))
|
plt.plot(trend.inverse(detrend, data))
|
||||||
|
'''
|
||||||
|
|
||||||
|
dataset = pd.read_csv('https://query.data.world/s/nxst4hzhjrqld4bxhbpn6twmjbwqk7')
|
||||||
|
dataset['data'] = pd.to_datetime([str(y)+'-'+str(m) for y,m in zip(dataset['Ano'].values, dataset['Mes'].values)],
|
||||||
|
format='%Y-%m')
|
||||||
|
roi = Transformations.ROI()
|
||||||
|
|
||||||
|
|
||||||
|
train = dataset['Total'].values[:30]
|
||||||
|
test = dataset['Total'].values[30:]
|
||||||
|
|
||||||
|
fs = Grid.GridPartitioner(data=train, npart=5, transformation=roi)
|
||||||
|
|
||||||
|
from pyFTS.models import hofts, pwfts
|
||||||
|
|
||||||
|
model = pwfts.ProbabilisticWeightedFTS(partitioner=fs, order=2)
|
||||||
|
#model = hofts.WeightedHighOrderFTS(partitioner=fs, order=1)
|
||||||
|
model.append_transformation(roi)
|
||||||
|
|
||||||
|
|
||||||
|
model.fit(train)
|
||||||
|
|
||||||
|
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[10,5])
|
||||||
|
ax.plot(test)
|
||||||
|
|
||||||
|
'''
|
||||||
|
train = dataset.iloc[:30]
|
||||||
|
test = dataset.iloc[30:]
|
||||||
|
|
||||||
|
from pyFTS.models.multivariate import common, variable, mvfts, wmvfts
|
||||||
|
from pyFTS.partitioners import Grid, Entropy
|
||||||
|
from pyFTS.models.seasonal.common import DateTime
|
||||||
|
from pyFTS.models.seasonal import partitioner as seasonal
|
||||||
|
sp = {'seasonality': DateTime.month , 'names': ['Jan','Fev','Mar','Abr','Mai','Jun','Jul', 'Ago','Set','Out','Nov','Dez']}
|
||||||
|
|
||||||
|
vmonth = variable.Variable("Month", data_label="data", partitioner=seasonal.TimeGridPartitioner, npart=12,
|
||||||
|
data=train, partitioner_specific=sp)
|
||||||
|
|
||||||
|
vtur = variable.Variable("Turistas", data_label="Total", alias='tur',
|
||||||
|
partitioner=Grid.GridPartitioner, npart=10, transformation=roi,
|
||||||
|
data=train)
|
||||||
|
|
||||||
|
model = wmvfts.WeightedMVFTS(explanatory_variables=[vmonth, vtur], target_variable=vtur)
|
||||||
|
model.fit(train)
|
||||||
|
|
||||||
|
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[10,5])
|
||||||
|
|
||||||
|
ax.plot(test['Total'].values)
|
||||||
|
'''
|
||||||
|
|
||||||
|
forecast = model.predict(test)
|
||||||
|
|
||||||
|
for k in np.arange(model.order):
|
||||||
|
forecast.insert(0,None)
|
||||||
|
|
||||||
|
ax.plot(forecast)
|
||||||
|
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
print(data)
|
print(dataset)
|
||||||
|
Loading…
Reference in New Issue
Block a user