Changing the MVFTS.forecast_ahead generators behavior
This commit is contained in:
parent
ff951546e1
commit
b73b369ed4
BIN
docs/build/doctrees/environment.pickle
vendored
BIN
docs/build/doctrees/environment.pickle
vendored
Binary file not shown.
@ -100,7 +100,7 @@ class FTS(object):
|
|||||||
:keyword nodes: a list with the dispy cluster nodes addresses
|
: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 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
|
: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
|
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.
|
models that accept the actual values and forecast new ones.
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ class MVFTS(fts.FTS):
|
|||||||
|
|
||||||
if generators is None:
|
if generators is None:
|
||||||
raise Exception('You must provide parameter \'generators\'! generators is a dict where the keys' +
|
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) '
|
'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 '
|
' and return the next value or trained FTS models that accept the actual values and '
|
||||||
'forecast new ones.')
|
'forecast new ones.')
|
||||||
@ -182,18 +182,18 @@ class MVFTS(fts.FTS):
|
|||||||
|
|
||||||
new_data_point = {}
|
new_data_point = {}
|
||||||
|
|
||||||
for var in self.explanatory_variables:
|
for data_label in generators.keys():
|
||||||
if var.name != self.target_variable.name:
|
if data_label != self.target_variable.data_label:
|
||||||
if isinstance(generators[var.name], LambdaType):
|
if isinstance(generators[data_label], LambdaType):
|
||||||
last_data_point = ndata.loc[sample.index[-1]]
|
last_data_point = ndata.loc[sample.index[-1]]
|
||||||
new_data_point[var.data_label] = generators[var.name](last_data_point[var.data_label])
|
new_data_point[data_label] = generators[data_label](last_data_point[data_label])
|
||||||
elif isinstance(generators[var.name], fts.FTS):
|
elif isinstance(generators[data_label], fts.FTS):
|
||||||
model = generators[var.name]
|
model = generators[data_label]
|
||||||
last_data_point = ndata.loc[[sample.index[-model.order]]]
|
last_data_point = ndata.loc[[sample.index[-model.order]]]
|
||||||
if not model.is_multivariate:
|
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
|
new_data_point[self.target_variable.data_label] = tmp
|
||||||
|
|
||||||
|
@ -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 = wmvfts.WeightedMVFTS(explanatory_variables=[vhour, vmonth, vtemp], target_variable=vtemp)
|
||||||
mtemp.fit(train_mv)
|
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
|
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)
|
mload.fit(train_mv)
|
||||||
|
|
||||||
|
Util.persist_obj(mload, 'mload')
|
||||||
|
|
||||||
|
|
||||||
time_generator = lambda x : pd.to_datetime(x) + pd.to_timedelta(1, unit='h')
|
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,
|
forecasts = mload.predict(test_mv.iloc[:1], steps_ahead=48, generators={'date': time_generator,
|
||||||
'DayOfWeek': time_generator,
|
'temperature': mtemp})
|
||||||
"Temperature": mtemp})
|
|
Loading…
Reference in New Issue
Block a user