Error while using SimpleExpSmoothing in time series forecast

760 views Asked by At
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt

fit1 = SimpleExpSmoothing(train_df).fit(smoothing_level=0.2,optimized=False)

fcast1 = fit1.forecast(4).rename(r'$\alpha=0.2$')

fcast1.plot(marker='o', color='blue', legend=True)
fit1.fittedvalues.plot(marker='o',  color='blue')

My dataframe, train_df has two columns, first column with stock value price, second column serial number(like 1,2,3...)

Here i am trying to forecast those values of stock using exponential smoothing

This is the error

NotImplementedError: Only 1 dimensional data supported

1

There are 1 answers

0
Ruthger Righart On

It would be best if you could give a data example. Nevertheless, I created a small data example myself.

from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
import pandas as pd

The following creates a DataFrame as you describe:

train_df = pd.DataFrame({'stock':[80,90,105,130,160,200], 'number':[1,2,3,4,5,6]})

You need however as input a pd.Series of Stock:

train_ps = pd.Series(train_df['stock'])

Last, you put in train_ps into your model:

fit1 = SimpleExpSmoothing(train_ps).fit(smoothing_level=0.2,optimized=False)

fcast1 = fit1.forecast(4).rename(r'$\alpha=0.2$')

fcast1.plot(marker='o', color='blue', legend=True)
fit1.fittedvalues.plot(marker='o',  color='blue')