Extrapolation Method Demonstrations¶
[ ]:
import pandas as pd
import matplotlib.pyplot as plt
from vtools import extrapolate_ts
plt.style.use('ggplot')
[ ]:
ts = pd.Series([1, 3, 4], index=pd.date_range('2020-01-01', periods=3, freq='D'))
ts.plot(marker='o', label='Original')
plt.title('Original Time Series')
plt.legend()
plt.show()

Ffill¶
[ ]:
extrapolated = extrapolate_ts(ts, end='2020-01-06', method='ffill')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Ffill')
plt.legend()
plt.show()
2020-01-01 00:00:00 2020-01-01 00:00:00 2020-01-06 00:00:00 2020-01-03 00:00:00

Bfill¶
[ ]:
print(ts)
extrapolated = extrapolate_ts(ts, start='2019-12-28', method='bfill')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Bfill')
plt.legend()
plt.show()
2020-01-01 1
2020-01-02 3
2020-01-03 4
Freq: D, dtype: int64
2019-12-28 00:00:00 2020-01-01 00:00:00 2020-01-03 00:00:00 2020-01-03 00:00:00

Linear Slope¶
[ ]:
extrapolated = extrapolate_ts(ts, start='2019-12-28', end='2020-01-06', method='linear_slope')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Linear Slope')
plt.legend()
plt.show()
2019-12-28 00:00:00 2020-01-01 00:00:00 2020-01-06 00:00:00 2020-01-03 00:00:00

Taper Forward¶
[ ]:
extrapolated = extrapolate_ts(ts, end='2020-01-06', val=0.0, method='taper')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Taper Forward')
plt.legend()
plt.show()
2020-01-01 00:00:00 2020-01-01 00:00:00 2020-01-06 00:00:00 2020-01-03 00:00:00

Taper Backward¶
[ ]:
extrapolated = extrapolate_ts(ts, start='2019-12-28', val=11.0, method='taper')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Taper Backward')
plt.legend()
plt.show()
2019-12-28 00:00:00 2020-01-01 00:00:00 2020-01-03 00:00:00 2020-01-03 00:00:00

Constant Forward¶
[ ]:
extrapolated = extrapolate_ts(ts, end='2020-01-06', val=-1, method='constant')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Constant Forward')
plt.legend()
plt.show()
2020-01-01 00:00:00 2020-01-01 00:00:00 2020-01-06 00:00:00 2020-01-03 00:00:00

Constant Backward¶
[ ]:
extrapolated = extrapolate_ts(ts, start='2019-12-28', val=-1, method='constant')
extrapolated.plot(marker='o', label='Extrapolated')
ts.plot(marker='o', label='Original')
plt.title('Constant Backward')
plt.legend()
plt.show()
2019-12-28 00:00:00 2020-01-01 00:00:00 2020-01-03 00:00:00 2020-01-03 00:00:00
