What if the World GDP fits a logistic growth ?
This notebook is based on the dataset consisting of the yearly gross domestic product (GDP) of countries and regions worldwide since the 1960s. Source of dataset
The purpose of the notebook is to try to answer the question :
What if the World GDP fits a logistic growth ?
As a first hypothesis, I've first searched for an exponential growth fit of the World GDP time series. This hypothesis is obviously wrong but the model fits quite well the data.
Then, as a second hypothesis, we'll see a logistic model is a better fit to the data.
We can hence use the model to predict nearly future values of the World GDP. Specifically, if a logistic model captures some reality of economic growth, then it means we are in 2020 at an inflection point.
import pandas as pd
import numpy as np
from scipy import stats
import scipy.optimize as opt
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme(style="dark")
sns.set(rc = {'figure.figsize':(15,8)})Preparation of the data :
Loading of data :
gdp = pd.read_csv('gdp_data.csv', index_col=None)gdp.head()Checking for missing values :
GDP Dataset has no missing values.
# GDP dataframe :
na_val = gdp.isnull().sum().sum() / (gdp.shape[0] * gdp.shape[1]) * 100.
print('Missing values : ', na_val, '%')Data cleaning :
I convert Year column to Datatime object and select the World 'region'.
gdp['Year'] = pd.to_datetime(gdp['Year'], format='%Y')
world = gdp.loc[gdp['Country Name']=='World', :]
Adding test values :
I build a new dataframe with some test values : world GDP of years 2017, 2018, 2019, 2020.
new_years = np.array([2017, 2018, 2019, 2020])
new_values = np.array([81181875.70e6, 86251213.55e6,87555184.72e6, 84679924.81e6])
new_world = world.copy()
new_world['Year'] = new_world['Year'].dt.year
df = pd.DataFrame({'Country Name': ['World']*4, 'Country Code': ['WLD']*4, 'Year': new_years, 'Value': new_values})
new_world = pd.concat([new_world, df])
new_world.reset_index(drop=True, inplace=True)
new_world.tail()Data visualization of the World GDP :
Let's check the evolution of the World GDP across the years.
sns.lineplot(
data=world, x="Year", y="Value",
estimator=None, color="0", linewidth=2
).set(title="World global GDP Evolution", xlabel='Year', ylabel='GDP (billions of $)');Finding an exponential model of the GDP :
Does the GDP grow as an exponential function ?
Let's try to fit a linear model to the data recoded in a log scale of GDP values.