Neural Market Trends |||

Forecasting Medium Subscriber Count With Facebook Prophet

I’m going to share some code that I stole and cobbled together to forecast my Medium subscriber growth using ARIMA and Facebook’s Prophet python package.

I did ARIMA for shits and giggles and wanted to see where how far I’ve deviated from my upward trend. For the actual forecasting, I used FB Prophet and liked it a lot.

FB Prophet requires some specific setup for your data with a column called ds for your timestamp and y for your numerical value.

It runs your data and automatically adjusts for things like seasonality and holidays, which I like a lot. The package does a lot of heavy lifting if you do time series for forecasting a lot.

Plus, it produces some nice graphs too. Here’s what my forecasted growth looks like.

My Medium subscriber growth is estimated to close around 700 by the end of the year. What’s interesting is the seasonality” of my subscriber growth. It looks like there’s a big bump between February and April with a late summer bump in August. That leads me to wonder if I should post more often in those time frames than at other times of the year.

Anyway, here’s the code.

Medium subscriber forecast python code

#!/usr/bin/env python
# coding: utf-8

# In[1]:

#Stole from
import pandas as pd
from pandas import to_datetime
import matplotlib.pyplot as plt
import numpy as np

from pmdarima.arima import auto_arima

from fbprophet import Prophet

# In[2]:

data = pd.read_csv('data/thomasottio-subscriber-stats.csv')

# convert data type
data['period_end'] = pd.to_datetime(data['period_end'])

df = data[['period_end', 'followers_total']]

# In[3]:

# convert data type
data['period_end'] = pd.to_datetime(data['period_end'])
# set period_end as index
data.set_index('period_end', drop = True, inplace = True)
# select relevant column
data = data['followers_total']
# set the frequency of index to monthly
data = data.asfreq('M')

# check data index after all changes

# In[4]:


# In[5]:


# In[6]:

data.plot(figsize=(15, 6))

# In[7]:

train, test = data.iloc[:-TEST_SIZE], data.iloc[-TEST_SIZE:]
x_train, x_test = np.array(range(train.shape[0])), np.array(range(train.shape[0], data.shape[0]))
train.shape, x_train.shape, test.shape, x_test.shape

# In[8]:

fig, ax = plt.subplots(1, 1, figsize=(15, 5))
ax.plot(x_train, train)
ax.plot(x_test, test)

# In[9]:

model = auto_arima(train, start_p=1, start_q=1,
                      max_p=5, max_q=5,

# In[10]:


# In[11]:

# Forecast

prediction, confint = model.predict(n_periods=TEST_SIZE, return_conf_int=True)


# In[12]:

cf= pd.DataFrame(confint)

# In[13]:

prediction_series = pd.Series(prediction,index=test.index)
fig, ax = plt.subplots(1, 1, figsize=(15, 5))

# In[16]:

#!conda install -c conda-forge fbprophet -y

# In[17]:


# In[18]:

df = df.rename(columns={"period_end": "ds", "followers_total": "y"})

# In[19]:

#df["ds"]= to_datetime(df["ds"])

# In[20]:


# In[21]:

# define the model
model = Prophet(interval_width=0.95)

# In[22]:

#stole code from

# In[23]:

# fit the model

# In[24]:

#stole code from

future_dates = model.make_future_dataframe(periods=18, freq='MS')

# In[25]:

forecast = model.predict(future_dates)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()

# In[26]:

model.plot(forecast, uncertainty=True)

# In[27]:


# In[28]:

fig1 = model.plot_components(forecast)
Up next NVDA I’m going to sue all of you
Latest posts GBPUSD Flash Crash to 1.04 In the End, Climate Change Is the Only Story That Matters The Colorado River Is Dying. Lawns Are Dumb SPX Inflation Check - Energy Prices Keep Going Lower Inflation Check - Soft Commodity Prices Starting To Break Inflation Check - Meat Prices Starting To Break Inflation Check - Grain Prices Starting To Break It’s either to the moon or wendys More Bosses Are Spying on Quiet Quitters TensorStore for High-Performance, Scalable Array Storage recent sale 1875s united states trade dollar recent sales 187477 counterfeit united states CEO Pichai fields questions on cost cuts at all hands meeting" /> CO2 than the entire Western hemisphere" /> #Design Patterns for Deep Learning Architectures Quantitative Easing and Rates meme Selling AI KB Homes and Real Estate Reckoning GME - What A Hunk Of Crap GILT Weekly Chart Heating Oil Keeps Dropping - Thank Goodness! SPY This is why I don't sell Great Wall of China Locations FMS, an agent based Financial Market Simulator — FMS 0. The Fed forecasts hiking rates as high as 4pt6pct before ending inflation fight JPOW must be house shopping" /> I’m going to sue all of you Forecasting Medium Subscriber Count With Facebook Prophet