Модель прогноза — Python — SARIMAPython

Программы на Python
Anonymous
Модель прогноза — Python — SARIMA

Сообщение Anonymous »

У меня возникли проблемы с применением модели SARIMA к моему набору данных на Python. Я использую данные о продажах универмага и хочу спрогнозировать следующий год, разбитый на кварталы. Данные стационарны, и я очистил исторические данные, чтобы разделить их на четверти. Источник данных датирован 31.12.2017.
См. ниже код Python и выходные данные

Код: Выделить всё

from statsmodels.tsa.statespace.sarimax import SARIMAX

model = SARIMAX(quarterly_sales, order=order, seasonal_order=seasonal_order)
results = model. Fit()

forecast = results.get_forecast(steps=4)
forecast_index = pd.date_range(start='2013-01-01', periods=4, freq='Q')
forecast_series = pd.Series(forecast.predicted_mean, index=forecast_index)

print(forecast_series)

# Plot the historical quarterly sales data
quarterly_sales.plot(kind='bar', figsize=(10, 6), label='Historical Quarterly Sales')

# Check if the forecast index aligns with the expected future quarters
print(forecast_series.index)

# Overlay the forecasted sales with more visibility
plt.plot(forecast_series.index, forecast_series, color='red', marker='o', linestyle='dashed', linewidth=2, label='Forecasted Quarterly Sales')

plt.ylim(0, max(quarterly_sales.max(), forecast_series.max()) * 1.1)

plt.title('Quarterly Sales with Forecast')
plt.xlabel('Quarter')
plt.ylabel('Sales')
plt.xticks(rotation=45)

plt.legend()

plt.show()

new_index = [f"Q{date.quarter} {str(date.year)[-2:]}" for date in forecast_series.index]
forecast_series.index = new_index

import matplotlib.pyplot as plt

historical_index = [f"Q{date.quarter} {str(date.year)[-2:]}" for date in quarterly_sales.index]
quarterly_sales.index = historical_index

quarterly_sales.plot(kind='bar', figsize=(10, 6), label='Historical Quarterly Sales')

plt.plot(forecast_series.index, forecast_series, color='red', marker='o', linestyle='dashed', label='Forecasted Quarterly Sales')

plt.title('Quarterly Sales with Forecast')
plt.xlabel('Quarter')
plt.ylabel('Sales')
plt.xticks(rotation=45)

plt.legend()

plt.show()
AS выше - это то, что я пробовал, но я не вижу ни одного своего прогноза на графике визуализации, как указано, разделенного на кварталы на ближайшие 12 месяцев, несмотря на то, что он показан на скриншоте в легенде.

Подробнее здесь: https://stackoverflow.com/questions/783 ... hon-sarima

Вернуться в «Python»