Bugfix in models.multivariate.grid

This commit is contained in:
Petrônio Cândido 2019-04-09 22:39:17 -03:00
parent df047661b9
commit eac996b894
3 changed files with 67 additions and 11 deletions

View File

@ -126,7 +126,7 @@ def fuzzyfy(data, partitioner, **kwargs):
:keyword mode: the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership
values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )
:returns a list with the fuzzyfied values, depending on the mode
"""
alpha_cut = kwargs.get('alpha_cut', 0.)
mode = kwargs.get('mode', 'sets')

View File

@ -43,7 +43,7 @@ class MultivariateFuzzySet(Composite.FuzzySet):
def fuzzyfy_instance(data_point, var, tuples=True):
fsets = var.partitioner(data_point, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut)
fsets = var.partitioner.fuzzyfy(data_point, mode='sets', method='fuzzy', alpha_cut=var.alpha_cut)
if tuples:
return [(var.name, fs) for fs in fsets]
else:

View File

@ -14,17 +14,73 @@ from pyFTS.benchmarks import benchmarks as bchmk, Measures
from pyFTS.models import chen, yu, cheng, ismailefendi, hofts, pwfts, tsaur, song, sadaei
from pyFTS.common import Transformations, Membership
from pyFTS.data import TAIEX
dataset = pd.read_csv('https://query.data.world/s/2bgegjggydd3venttp3zlosh3wpjqj', sep=';')
data = TAIEX.get_data()
dataset['data'] = pd.to_datetime(dataset["data"], format='%Y-%m-%d %H:%M:%S')
fs = Grid.GridPartitioner(data=data, npart=23)
train_mv = dataset.iloc[:24505]
test_mv = dataset.iloc[24505:]
from itertools import product
levels = ['VL', 'L', 'M', 'H', 'VH']
sublevels = [str(k) for k in np.arange(0, 7)]
names = []
for combination in product(*[levels, sublevels]):
names.append(combination[0] + combination[1])
print(names)
from pyFTS.models.multivariate import common, variable, mvfts
from pyFTS.models.seasonal import partitioner as seasonal
from pyFTS.models.seasonal.common import DateTime
sp = {'seasonality': DateTime.day_of_year , 'names': ['Jan','Feb','Mar','Apr','May',
'Jun','Jul', 'Aug','Sep','Oct',
'Nov','Dec']}
vmonth = variable.Variable("Month", data_label="data", partitioner=seasonal.TimeGridPartitioner, npart=12,
data=train_mv, partitioner_specific=sp)
sp = {'seasonality': DateTime.minute_of_day, 'names': [str(k)+'hs' for k in range(0,24)]}
vhour = variable.Variable("Hour", data_label="data", partitioner=seasonal.TimeGridPartitioner, npart=24,
data=train_mv, partitioner_specific=sp)
vavg = variable.Variable("Radiation", data_label="glo_avg", alias='rad',
partitioner=Grid.GridPartitioner, npart=35, partitioner_specific={'names': names},
data=train_mv)
from pyFTS.models.multivariate import mvfts, wmvfts, cmvfts, grid
parameters = [
{}, {},
{'order': 2, 'knn': 1},
{'order': 2, 'knn': 2},
{'order': 2, 'knn': 3},
]
for ct, method in enumerate([mvfts.MVFTS, wmvfts.WeightedMVFTS,
cmvfts.ClusteredMVFTS, cmvfts.ClusteredMVFTS, cmvfts.ClusteredMVFTS]):
if method != cmvfts.ClusteredMVFTS:
model = method(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg, **parameters[ct])
else:
fs = grid.GridCluster(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg)
model = method(explanatory_variables=[vmonth, vhour, vavg], target_variable=vavg, partitioner=fs,
**parameters[ct])
model.shortname += str(ct)
model.fit(train_mv)
forecasts = model.predict(test_mv.iloc[:100])
print(model.shortname, forecasts)
test = [2000, 5000, 5500, 12000]
for method in [yu.WeightedFTS, tsaur.MarkovWeightedFTS, song.ConventionalFTS, sadaei.ExponentialyWeightedFTS, ismailefendi.ImprovedWeightedFTS,
chen.ConventionalFTS, cheng.TrendWeightedFTS, hofts.HighOrderFTS, pwfts.ProbabilisticWeightedFTS]:
model = method(partitioner=fs)
model.fit(data)
print(model.forecast(test))