Changing the MVFTS.forecast_ahead generators behavior

This commit is contained in:
Petrônio Cândido 2019-02-18 15:00:25 -03:00
parent ff951546e1
commit b73b369ed4
4 changed files with 22 additions and 15 deletions

Binary file not shown.

View File

@ -100,7 +100,7 @@ class FTS(object):
:keyword nodes: a list with the dispy cluster nodes addresses
:keyword explain: try to explain, step by step, the one-step-ahead point forecasting result given the input data.
:keyword generators: for multivariate methods on multi step ahead forecasting, generators is a dict where the keys
are the variables names (except the target_variable) and the values are lambda functions that
are the dataframe columun names (except the target_variable) and the values are lambda functions that
accept one value (the actual value of the variable) and return the next value or trained FTS
models that accept the actual values and forecast new ones.

View File

@ -162,7 +162,7 @@ class MVFTS(fts.FTS):
if generators is None:
raise Exception('You must provide parameter \'generators\'! generators is a dict where the keys' +
' are the variables names (except the target_variable) and the values are ' +
' are the dataframe column names (except the target_variable) and the values are ' +
'lambda functions that accept one value (the actual value of the variable) '
' and return the next value or trained FTS models that accept the actual values and '
'forecast new ones.')
@ -182,18 +182,18 @@ class MVFTS(fts.FTS):
new_data_point = {}
for var in self.explanatory_variables:
if var.name != self.target_variable.name:
if isinstance(generators[var.name], LambdaType):
for data_label in generators.keys():
if data_label != self.target_variable.data_label:
if isinstance(generators[data_label], LambdaType):
last_data_point = ndata.loc[sample.index[-1]]
new_data_point[var.data_label] = generators[var.name](last_data_point[var.data_label])
elif isinstance(generators[var.name], fts.FTS):
model = generators[var.name]
new_data_point[data_label] = generators[data_label](last_data_point[data_label])
elif isinstance(generators[data_label], fts.FTS):
model = generators[data_label]
last_data_point = ndata.loc[[sample.index[-model.order]]]
if not model.is_multivariate:
last_data_point = last_data_point[var.data_label].values
last_data_point = last_data_point[data_label].values
new_data_point[var.data_label] = model.forecast(last_data_point)[0]
new_data_point[data_label] = model.forecast(last_data_point)[0]
new_data_point[self.target_variable.data_label] = tmp

View File

@ -133,16 +133,23 @@ from pyFTS.models.multivariate import mvfts, wmvfts, cmvfts, grid
mtemp = wmvfts.WeightedMVFTS(explanatory_variables=[vhour, vmonth, vtemp], target_variable=vtemp)
mtemp.fit(train_mv)
Util.persist_obj(mtemp, 'mtemp')
from pyFTS.models import hofts
#mtemp = hofts.WeightedHighOrderFTS(order=2, partitioner=vtemp.partitioner)
#mtemp.fit(train_mv['temperature'].values)
from pyFTS.models.multivariate import mvfts, wmvfts, cmvfts, grid
mload = wmvfts.WeightedMVFTS(explanatory_variables=[vhour, vday, vtemp, vload], target_variable=vload)
mload = wmvfts.WeightedMVFTS(explanatory_variables=[vtemp, vload], target_variable=vload)
mload.fit(train_mv)
Util.persist_obj(mload, 'mload')
time_generator = lambda x : pd.to_datetime(x) + pd.to_timedelta(1, unit='h')
temp_generator = mtemp
forecasts = mload.predict(test_mv.iloc[:1], steps_ahead=48, generators={'Hour': time_generator,
'DayOfWeek': time_generator,
"Temperature": mtemp})
forecasts = mload.predict(test_mv.iloc[:1], steps_ahead=48, generators={'date': time_generator,
'temperature': mtemp})