uod_clip on mvfts models

This commit is contained in:
Petrônio Cândido 2018-11-13 18:54:18 -02:00
parent 358fdcf473
commit 2db3b0311e
2 changed files with 23 additions and 4 deletions

View File

@ -38,7 +38,11 @@ class MVFTS(fts.FTS):
def apply_transformations(self, data, params=None, updateUoD=False, **kwargs): def apply_transformations(self, data, params=None, updateUoD=False, **kwargs):
ndata = data.copy(deep=True) ndata = data.copy(deep=True)
for var in self.explanatory_variables: for var in self.explanatory_variables:
ndata[var.data_label] = var.apply_transformations(data[var.data_label].values) if self.uod_clip:
ndata[var.data_label] = np.clip(ndata[var.data_label].values,
var.partitioner.min, var.partitioner.max)
ndata[var.data_label] = var.apply_transformations(ndata[var.data_label].values)
return ndata return ndata
@ -130,7 +134,6 @@ class MVFTS(fts.FTS):
def forecast_ahead(self, data, steps, **kwargs): def forecast_ahead(self, data, steps, **kwargs):
generators = kwargs.get('generators',None) generators = kwargs.get('generators',None)
start = kwargs.get('start', 0)
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' +

View File

@ -87,13 +87,29 @@ train_split = 24 * 800
train_mv = dataset.iloc[:train_split] train_mv = dataset.iloc[:train_split]
test_mv = dataset.iloc[train_split:] test_mv = dataset.iloc[train_split:]
#model = Util.load_obj('/home/petronio/Downloads/ClusteredMVFTS4')
vhour = variable.Variable("Hour", data_label="hour", partitioner=seasonal.TimeGridPartitioner, npart=24, vhour = variable.Variable("Hour", data_label="hour", partitioner=seasonal.TimeGridPartitioner, npart=24,
data=dataset, data=dataset,
partitioner_specific={'seasonality': DateTime.hour_of_day, 'type': 'common'}) partitioner_specific={'seasonality': DateTime.hour_of_day, 'type': 'common'})
vprice = variable.Variable("Price", data_label="price", partitioner=Grid.GridPartitioner, npart=10, vprice = variable.Variable("Price", data_label="price", partitioner=Grid.GridPartitioner, npart=55,
data=train_mv) data=train_mv)
model = cmvfts.ClusteredMVFTS(order=2, knn=3)
model.append_variable(vhour)
model.append_variable(vprice)
model.target_variable = vprice
model.fit(train_mv)
data = [[1, 1.0], [2, 2.0]]
df = pd.DataFrame(data, columns=['hour','price'])
forecasts = model.predict(df, steps_ahead=24, generators={'Hour': lambda x : (x+1)%24 })
'''
params = [ params = [
{}, {},
{}, {},
@ -114,4 +130,4 @@ for ct, method in enumerate([mvfts.MVFTS, wmvfts.WeightedMVFTS, cmvfts.Clustered
#print(model1.predict(test_mv, steps_ahead=24, generators={'Hour': lambda x : (x+1)%24 })) #print(model1.predict(test_mv, steps_ahead=24, generators={'Hour': lambda x : (x+1)%24 }))
#""" '''