PYFTS / pyFTS

An open source library for Fuzzy Time Series in Python
http://pyfts.github.io/pyFTS/
GNU General Public License v3.0
262 stars 54 forks source link

Non datetime generator for MVTS #15

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hey i read part 1 and part 2 of your tutorial on medium but i'm still struggling to understand how to generator concept would work for a multi variate time series whose variable is a non date time, do you have any example code on that.

petroniocandido commented 5 years ago

Hi! Thank you for contacting us!

Generators are for predictable variables. If you can't predict how an explainable variable will behave for multiple steps ahead you can use several approaches, like repeat the last value (naïve/persistence approach) or, if the data is seasonal, repeat the data for the nth lag, where n is the seasonal index.

Well... Your question also give-me good ideas for improving the generator mechanics for this kind of variable... Thanks! ;-)

Give-me a couple of hours (I have a meeting now) to make a good example and past it here.

ghost commented 5 years ago

Thanks for the reply

So this is what i had in mind lets say we have the endogenous variable that we are trying to predict df['TAIEX'] , and say we want to add some additional information to the model like this

df['TAIEX Rolling STD'] = df['TAIEX'].rolling(window=12).std() ... preprocessing model.fit()

when we get to model.predict() and we want to create the generator for df['TAIEX Rolling STD'] would it be possible to do it like this:

exo_var = list(df['TAIEX Rolling STD']) generator = lambda x: exo_var[exo_var.index(x)+1] all_gens= {'TAIEX Rolling STD':generator}

So lets just addres the elephant in the room this is a super hacky quick way of doing it and one imediate problem comes from the fact that we could have 2 elements in a list that have the same value ... altough if we are working with floating point numbers that is pretty unlikley and we could just manually add some insignificant "salt", and secondly the out of index error but that could be fixed with a try: code except IndexError, i don't know if i understood the problem correctly so i apologize in advance.

... or we actualy need the value of the variable in a future time step , that in this case we could not obtain

petroniocandido commented 5 years ago

Yes! it is possible! Good idea!

petroniocandido commented 5 years ago

I just updated the code on Google Colab to fix some recent bugs

ghost commented 5 years ago

I just updated the code on Google Colab to fix some recent bugs

Hi sorry but i cant find which notebook you updated would you mind posting the link 👍

petroniocandido commented 5 years ago

Hi. I am testing the new features for complex generators here: https://colab.research.google.com/drive/1ZadJuuCqlP-E2_pX2LiEEbst3_gR6Kof , but it is not finished yet.

petroniocandido commented 5 years ago

Thanks for your colaboration @jetychill , you give a really useful contribution for this project. Your request make me do a code refactoring on the generators parameter. Now this parameter requires one entry for each dataframe column, not one entry for each variable as before. I already updated the documentation and demonstration codes.

Now it is possible to use an MVFTS model as an generator for a column, but it isn't possible to use other methods yet (for example an high order method).

At the colab notebook I used a dataframe with 3 columns (date, temperature and load) and built two models. The first one is an MVFTS that use the hour, month (both extracted from date field) and temperature to forecast the temperature. The second one is an MVFTS that use the temperature and the load to forecast the load. With this last model I tested the forecast for the next 24 hours, using the first model as the generator for the temperature.

This method stacking works well for the first 10 hours and then, as expected, started to degrade. This is the first time we perform this kind of operation on pyFTS and I will expect to improve it much more, allowing several models to be used.

Once more, thanks for your collaboration and more suggestions are always welcome!

Best regards.

ghost commented 5 years ago

@petroniocandido Awesome i am very happy that i could help, i will continue to collaborate and make this library more accessible and easy to use, can't wait to see what problems people will tackle with it.