# Time series forecasting with Prophet

In this example, I am forecasting the future price of the AAPL stock, using data from the kaggle [dataset](https://www.kaggle.com/datasets/guillemservera/aapl-stock-data) starting with prices after 2015. View complete notebook [here](https://github.com/Unizomby/online_retail_eda/blob/main/Prophet_02_Forecast_AAPL.ipynb).

This model uses the Prophet library

```python
from prophet import Prophet
```

After importing the AAPL price data from csv, I created a graph of the price over time.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709312101264/33010ba7-e57c-44a7-8e91-691e8704bb44.png align="center")

The dataset includes column for Volume each day, which I will use as a regressor in the prophet model

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709312284831/bf172f3f-c709-40a7-b8a6-2a69fc256f65.png align="center")

I trained it on the whole dataset, predicting for future data 31 days in the future.

›

```python
# building the model
m = Prophet(
            seasonality_mode=sm,
            seasonality_prior_scale=sps,
            changepoint_prior_scale=cps)
m.add_regressor('Volume')
m.fit(training)
```

Creating predictions is pretty simple, just passing the future data frame.

```python
# Forecasting
forecast = m.predict(future)
forecast.head(5)
```

Plotting the predictions

```python
# Forecasting
forecast = m.predict(future_df)
m.plot(forecast);
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709312463082/7b4bdf93-9449-4a29-89a4-3f25e82e96ad.png align="center")

The model shows a downward trend for the next 31 days.

It also makes plotting the model components easy. So you can see the yearly, weekly trends

```python
# Components
m.plot_components(forecast);
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1709312612634/fd4f9ffd-85f0-46fa-a816-ee7345a0fb38.png align="center")

I will be forecasting this same dataset using some other forecasting models to compare results. And combining them together.
