T-002 / pycast

Python forecasting and smoothing library
MIT License
68 stars 15 forks source link

Documentation need improve #4

Open asdf8601 opened 8 years ago

asdf8601 commented 8 years ago

Hi everybody,

I try to use the pycast library reading the documentation but I don't get nothing clear for me.

How can I make a simple exponential smoothing?

alfa = 0.1
es = pycast.methods.ExponentialSmoothing(smoothingFactor=alfa, valuesToForecast=4)
esm = es.execute(data.YT1.values)

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-14-a2d0589e322f> in <module>()
      1 alfa = 0.1
      2 es = pycast.methods.ExponentialSmoothing(smoothingFactor=alfa, valuesToForecast=4)
----> 3 esm = es.execute(data.YT1.values)

/Users/mmngreco/anaconda/envs/py2/lib/python2.7/site-packages/pycast/methods/exponentialsmoothing.pyc in execute(self, timeSeries)
    104             ## get the initial estimate
    105             if None == estimator:
--> 106                 estimator = t[1]
    107                 continue
    108 

IndexError: invalid index to scalar variable.
T-002 commented 8 years ago

Hi Maximilano,

assuming data.YT1.values is a list, you should do the following:

tsdata = pycast.common.TimeSeries.from_twodim_list(data.YT1.values, tsformat=None)
esm = es.execute(tsdata)

Using the TimeSeries instance makes sure that all normalization and sorting requirements are meet.

Best Regards,

Christian

asdf8601 commented 8 years ago

Hi Christian,

Thanks for you answer. I see, maybe, a mistake in tsformat=None rather format=None?? It's correct the assumption but doesn't work yet.

The data:


print(data.head())

                   YT1         YT2        YT3           YT4
obs                                                        
1977-01-01  299.888916  155.612167  20.621498  295961.18750
1977-04-01  309.952911  160.179184  24.661081  301999.03125
1977-07-01  320.075104  164.102615  21.050383  308159.75000
1977-10-01  329.241852  170.582764  22.007036  314433.12500
1978-01-01  337.308044  174.714935  21.286356  320814.09375

print(data.tail())

                    YT1        YT2        YT3           YT4
obs                                                        
2008-10-01  1542.907593  790.39679  27.648138  22784.337891
2009-01-01          NaN        NaN        NaN           NaN
2009-04-01          NaN        NaN        NaN           NaN
2009-07-01          NaN        NaN        NaN           NaN
2009-10-01          NaN        NaN        NaN           NaN

I try:

alfa = 0.1
tsdata = pycast.common.TimeSeries.from_twodim_list(data.YT1.values, format=None, )
esm = es.execute(tsdata)

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-29-9da3b1eee9a1> in <module>()
      1 alfa = 0.1
----> 2 tsdata = pycast.common.TimeSeries.from_twodim_list(data.YT1.dropna().values, format=None, )
      3 esm = es.execute(tsdata)

/Users/mmngreco/anaconda/envs/py2/lib/python2.7/site-packages/pycast/common/timeseries.pyc in from_twodim_list(cls, datalist, format)
    184 
    185         for entry in datalist:
--> 186             ts.add_entry(*entry[:2])
    187 
    188         ## set the normalization level

IndexError: invalid index to scalar variable.