Stock Price Prediction with Facebook Prophet Model

Stock Price Prediction means to determine the future value of the stocks or other financial instruments of an organisation. If you master the art to predict stock prices, you can earn a lot by investing and selling at the right time, and you can even earn by mentoring other people who want to explore trading.

Facebook Prophet Model

Facebook Prophet is an algorithm developed by Facebook’s Core Data Science team. It is used in the applications of time series forecasting. It is very much used when there is a possibility of seasonal effects. The Time Series Forecasting is very much used in Stock Price Prediction. In this article, I will take you through the application of Facebook Prophet model for Google Stock Price Prediction.

Stock Price Prediction using Facebook Prophet Model

I will use the latest dataset that I just downloaded from yahoo finance. If you want to practice this task on the same dataset that I have taken, then you can download it here.

If you want to practice this on the latest dataset when you are reading this article, then you can download the latest one from the yahoo finance. If you find any problem in downloading the latest dataset you can mention in the comments section below; I will help you out with that.

To predict stock prices using the Facebook Prophet model, you have to install a package named fbprophet, which can be easily installed using the pip command- pip install fbprophet. I hope you have installed this package and now let’s move further by importing the necessary packages we need for this task:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pandas_datareader as web
import warnings
!pip install fbprophet
import fbprophetCode language: Python (python)

Now let’s read and look at the data we are work I with:

from google.colab import files
uploaded = files.upload()
data = pd.read_csv("GOOG.csv")
data.head()Code language: Python (python)
image for post

Before moving forward, let’s visualize the data so that we could get some better insights into the data we will work on:"fivethirtyeight")
plt.title("Google Closing Stock Price")
plt.xlabel("Date", fontsize=18)
plt.ylabel("Close Price USD ($)", fontsize=18) language: Python (python)
Stock Price Prediction

Only two features are needed from the dataset that is Date and Close Prices. So let’s prepare the data for our model:

data = data[["Date","Close"]] 
data = data.rename(columns = {"Date":"ds","Close":"y"})
data.head()Code language: Python (python)
image for post

Now let’s fit the data to the Facebook Prophet model for stock price prediction of Google:

from fbprophet import Prophet
m = Prophet(daily_seasonality=True) language: Python (python)

We have successfully fit the data to the Facebook Prophet model. Now let’s have a look at the stock price prediction made by the model:

future = m.make_future_dataframe(periods=365)
plt.title("Prediction of GOOGLE Stock Price")
plt.ylabel("Closing Stock Price") language: Python (python)
Stock Price Prediction

Now let’s have a look at the seasonal affects on this prediction that is made by our model:

m.plot_components(predictions) language: Python (python)
seasonal effects

Also, Read – What is Big Data?

I hope you liked this article on Stock Price Prediction using the Facebook Prophet model. Feel free to ask your valuable questions in the comments section below. You can also follow me on Medium to learn every topic of Machine Learning.

Also, Read – Object-Oriented Programming for Machine Learning.

Follow Us:

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1535


  1. Hello Sir

    I am a research scholar. I have very much interest in Stock prediction. So I want to take this as my research topic. It can be like -“Prediction of Stock Exchange using Machine Learning Techniques with ……” . I am not able to fill the blank as I am a beginner. May you help me out to finalized my topic. It will be a great help from your side.

Leave a Reply