Simulate the trend using the extrapolated generative model. Parameters ---------- periods: Int number of periods to forecast forward. freq: Any valid frequency for pd.date_range, such as 'D' or 'M'. include_history: Boolean to include the historical dates in
(self, periods, freq='D', include_history=True)
| 1849 | return fn(a, *args, **kwargs) |
| 1850 | |
| 1851 | def make_future_dataframe(self, periods, freq='D', include_history=True): |
| 1852 | """Simulate the trend using the extrapolated generative model. |
| 1853 | |
| 1854 | Parameters |
| 1855 | ---------- |
| 1856 | periods: Int number of periods to forecast forward. |
| 1857 | freq: Any valid frequency for pd.date_range, such as 'D' or 'M'. |
| 1858 | include_history: Boolean to include the historical dates in the data |
| 1859 | frame for predictions. |
| 1860 | |
| 1861 | Returns |
| 1862 | ------- |
| 1863 | pd.Dataframe that extends forward from the end of self.history for the |
| 1864 | requested number of periods. |
| 1865 | """ |
| 1866 | if self.history_dates is None: |
| 1867 | raise Exception('Model has not been fit.') |
| 1868 | if freq is None: |
| 1869 | # taking the tail makes freq inference more reliable |
| 1870 | freq = pd.infer_freq(self.history_dates.tail(5)) |
| 1871 | # returns None if inference failed |
| 1872 | if freq is None: |
| 1873 | raise Exception('Unable to infer `freq`') |
| 1874 | last_date = self.history_dates.max() |
| 1875 | dates = pd.date_range( |
| 1876 | start=last_date, |
| 1877 | periods=periods + 1, # An extra in case we include start |
| 1878 | freq=freq) |
| 1879 | dates = dates[dates > last_date] # Drop start if equals last_date |
| 1880 | dates = dates[:periods] # Return correct number of periods |
| 1881 | |
| 1882 | if include_history: |
| 1883 | dates = np.concatenate((np.array(self.history_dates), dates)) |
| 1884 | |
| 1885 | return pd.DataFrame({'ds': dates}) |
| 1886 | |
| 1887 | def plot(self, fcst, ax=None, uncertainty=True, plot_cap=True, |
| 1888 | xlabel='ds', ylabel='y', figsize=(10, 6), include_legend=False): |
no outgoing calls