Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 14, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/a2784cadc1a48d017313011ec36dda4c to your computer and use it in GitHub Desktop.
Save amankharwal/a2784cadc1a48d017313011ec36dda4c to your computer and use it in GitHub Desktop.
m = Prophet()
m.fit(ph_df)
# Create Future dates
future_prices = m.make_future_dataframe(periods=365)
# Predict Prices
forecast = m.predict(future_prices)
import matplotlib.dates as mdates
# Dates
starting_date = dt.datetime(2018, 4, 7)
starting_date1 = mdates.date2num(starting_date)
trend_date = dt.datetime(2018, 6, 7)
trend_date1 = mdates.date2num(trend_date)
pointing_arrow = dt.datetime(2018, 2, 18)
pointing_arrow1 = mdates.date2num(pointing_arrow)
# Learn more Prophet tomorrow and plot the forecast for amazon.
fig = m.plot(forecast)
ax1 = fig.add_subplot(111)
ax1.set_title("Amazon Stock Price Forecast", fontsize=16)
ax1.set_xlabel("Date", fontsize=12)
ax1.set_ylabel("Close Price", fontsize=12)
# Forecast initialization arrow
ax1.annotate('Forecast \n Initialization', xy=(pointing_arrow1, 1350), xytext=(starting_date1,1700),
arrowprops=dict(facecolor='#ff7f50', shrink=0.1),
)
# Trend emphasis arrow
ax1.annotate('Upward Trend', xy=(trend_date1, 1225), xytext=(trend_date1,950),
arrowprops=dict(facecolor='#6cff6c', shrink=0.1),
)
ax1.axhline(y=1260, color='b', linestyle='-')
plt.show()
@BenedettaFrancesconi
Copy link

Hi Aman,

thank you for sharing your work! I have a question though: I'm trying to replicate your code but when I try to create the forecasts (forecast=m.predict(future_prices)), an error appears saying that the model has not been fit. Do you know how I should resolve it?

Kind regards,
Benedetta Francesconi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment