-
-
Save amankharwal/a2784cadc1a48d017313011ec36dda4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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